Button Module
Factory module for managing detail panel buttons with callback registration and execution by ID.
Factory module for managing detail panel buttons with callback registration and execution by ID.
Overview
buttonModule provides a factory (create()) that produces button management instances. Each instance tracks registered buttons with auto-incrementing IDs and executes callbacks when buttons are clicked in the grid selector detail panel.
Module path: lua/ge/extensions/ui/gridSelectorUtils/buttonModule.lua (loaded via require)
Exports (M)
| Function | Signature | Description |
|---|---|---|
create | () | Creates and returns a new button manager instance. |
Instance Methods
| Method | Signature | Description |
|---|---|---|
addButton | (callback, meta) | Registers a button, returns meta with buttonId. |
executeButton | (buttonId, additionalData?) | Calls the callback for the given button ID. |
clearButtonFunctions | () | Clears all registered buttons. |
getButtonInfo | (buttonId) | Returns {callback, meta} for a button. |
getAllButtonInfos | () | Returns all registered button infos. |
Internals
Button Registration
Each addButton call assigns an auto-incrementing ID and stores the callback:
local function addButton(callback, meta)
local buttonId = getFreeButtonId()
meta = meta or {}
meta.buttonId = buttonId
buttonsInfos[buttonId] = { callback = callback, meta = meta }
return meta
endTypical Usage
Tile generators register buttons when building detail panels:
local buttonInstance = require("ge/extensions/ui/gridSelectorUtils/buttonModule").create()
-- In a detail handler:
table.insert(data.buttonInfo,
buttonInstance.addButton(function()
backend.trackRecent(itemDetails.key)
gameplay_missions_missionManager.startWithLoadingLevel(mission)
end, {
label = "Start Mission",
icon = "play",
primary = true,
isDoubleClickAction = true,
})
)
-- When UI clicks the button:
buttonInstance.executeButton(buttonId)Meta Properties
Common meta fields used by the UI:
label- button texticon- icon identifierprimary- highlighted as main actionisDoubleClickAction- triggered on tile double-clickwaitForLoadingScreen- shows loading screen after click
How It Works
- Backend creates a button instance via
buttonModule.create() - Detail panel handlers register buttons with
addButton(callback, meta) - UI renders buttons using the returned
meta(label, icon, primary) - User clicks → UI calls
executeButton(buttonId) - The stored callback fires, performing the action (start mission, etc.)
Additional Exports
The following exports are available but not yet documented in detail:
M.create