A crosswalk client module to handle UI menus using tagged instances (built with the tag-effect library).
Add @crosswalk-game/menu-handler
in your dependencies:
yarn add @crosswalk-game/menu-handler
Or if you are using npm
:
npm install @crosswalk-game/menu-handler
-
Description: Opens the menu with the specified ID. Closes any menu that are not explicitly marked as compatible with the ID.
-
Parameters:
menuId
: The unique identifier of the menu to open.
-
Description: Closes the menu with the specified ID.
-
Parameters:
menuId
: The unique identifier of the menu to close.
-
Description: Toggles the state (open/close) of the menu with the specified ID.
-
Parameters:
menuId
: The unique identifier of the menu to toggle.
-
Description: Executes the specified effect while the menu with the specified ID is open. The effect will automatically be cleaned up when the menu is closed.
-
Parameters:
menuId
: The unique identifier of the menu to target.effect
: The effect to execute while the menu is open. This function return any kind of teardown object (for example:nil
, a cleanup function or event connections) that will automatically get cleaned up when the menu is closed.
-
Returns: A function to remove the effect.
This module defines a series of tag-effects to define menus (that can be opened or closed) or buttons to open, close or toggle those menus.
Allowed instance class: GuiObject
, LayerCollector
, ProximityPrompt
Those two tag-effects are used to define a new menu with the given id
. The difference between a MenuInstance
and a MenuExtension
is how they influence other menus:
- when a
MenuInstance
is opened, all otherMenuInstance
will be closed (except otherMenuInstance
objects explicitly marked as compatible with the opened menuid
) - when a
MenuExtension
is opened, it does not change otherMenuInstance
orMenuExtension
objects
Both tag-effects have the same base configuration:
Configuration:
id
(string): identifier for the menu
Optional:
defaultState
(boolean): define if the menu is visible (or not) by default
Optionally, the MenuInstance
tag effect can also be configured to mark other menus as compatible with itself, by adding string attributes set to other compatible menu id
. For example, one could add an attribute compatibleWithStore = "Store"
, where Store
would be another MenuInstance
id
.
These tag-effects can be used bind a signal to open, close or toggle a menu. They can be applied to any kind of instances:
GuiButton
: which will trigger on theActivated
eventClickDetector
: which will trigger on theMouseClick
eventProximityPrompt
: which will trigger on theTriggered
event- Any other instance, if the
eventName
attribute is set to an appropriate event name
Configuration:
id
(string): identifier of the menu that needs to be opened
Optional:
eventName
(string): specify which signal to use to bind the behavior
This project is available under the MIT license. See LICENSE.txt for details.