UIElement:active_bindings
Returns a table of active input bindings within this element for a given player. A binding is considered active for a player when:
- The element can receive input
- Its relevance condition is met.
Since the output of this function changes based on what is currently focused, you may use it to implement indicators telling the player what actions are currently available to them by pressing which buttons.
Usage
ui_element:active_bindings(player_index)
Arguments
| Name | Type | Description |
|---|---|---|
player_index | number | Number identifying the player whose bindings to consider. |
Returns
| Name | Type | Description |
|---|---|---|
bindings | table | Table of active bindings. |
Keys into the bindings table are action names. Values are lists of bindings, where each binding is itself a table with the following content:
owner: UI Element which registered the binding.relevance: BindingRelevance the binding was registered with.details: optional payload passed in to add_binding.callback: function to execute when this input is handled.
Examples
local buy_menu = crystal.Overlay:new();
buy_menu:bind_input("+ui_cancel", "always", "Exit Buy Menu", function()
-- Logic to exit buy menu here
end);
local bindings = buy_menu:active_bindings(1);
assert(bindings["+ui_cancel"][1].details == "Exit Buy Menu");