|
VR-Engage
2.2
|
DtMenuElement represents a single selectable item in a menu. It can represent an action to be executed, or a submenu to be displayed. Each element has a label that is shown to the user, and attributes that control its behavior, such as an action to be taken when selected, display conditions, and visual properties.
Menu elements can be dynamically enabled or disabled based on conditions defined in the player attribute store, allowing for context-sensitive menu options.
#include <actionMenuElement.h>
Public Types | |
| enum | ElementType { ACTION , MENU } |
Public Member Functions | |
| DtMenuElement (const std::string &label, const std::string &action, const std::string ¶m="", const std::vector< std::pair< std::string, bool > > &displayConditions=std::vector< std::pair< std::string, bool > >(), bool openMenuOnDisplayConditionMet=false, bool hasSubMenu=false, const std::string &cursor="", std::vector< std::string > valueMapping=std::vector< std::string >(), bool isValid=true) | |
| virtual | ~DtMenuElement () |
| virtual void | setMenu (DtMenu *menu) |
| virtual ElementType | type () |
| virtual void | setSelected (bool select) |
| virtual bool | isEnabled () |
| virtual bool | previouslyEnabled () |
| virtual bool | openMenuOnDisplayConditionMet () |
| virtual void | setLabel (const std::string &newLabel) |
| virtual std::string | label () |
| virtual const std::string & | action () |
| virtual void | setAction (const std::string &newAction) |
| virtual const std::string & | parameter () |
| virtual void | setParameter (const std::string &newParam) |
| virtual std::string | decoratorText () |
| virtual bool | hasSubMenu () const |
| virtual void | setHasSubMenu (bool val) |
| virtual void | setCursor (const std::string &cursor) |
| virtual const std::string & | cursor () |
| virtual const std::vector< std::string > & | valueMapping () |
| virtual bool | isValid () const |
| virtual void | setIsValid (bool val) |
| virtual void | doAction () |
| virtual void | reset () |
Static Public Member Functions | |
| static DtMenuElement * | create (DtInitTable &config) |
Protected Member Functions | |
| std::string | resolveVars (const std::string &str) |
| void | handleAttributeChanged (const DtAttributeHandle &attribute) |
| std::string | findStateAttribute (const std::string &str) |
| bool | checkEnabled () |
Protected Attributes | |
| DtInitTable * | myConfig |
| DtMenu * | myMenu |
| ElementType | myType |
| std::vector< std::pair< std::string, bool > > | myDisplayConditions |
| std::string | myLabel |
| std::string | myAction |
| std::string | myParameter |
| std::string | myCursor |
| DtAttributeHandle | myStateAttribute |
| std::vector< std::string > | myValueMapping |
| DtAttributeChangeCallback | myAttributeCallback |
| bool | myHasSubMenu |
| bool | myIsValid |
| bool | myPreviouslyEnabled |
| bool | myOpenMenuOnDisplayConditionMet |
Friends | |
| class | DtMenuAttributeObserver |
| makVre::DtMenuElement::DtMenuElement | ( | const std::string & | label, |
| const std::string & | action, | ||
| const std::string & | param = "", | ||
| const std::vector< std::pair< std::string, bool > > & | displayConditions = std::vector< std::pair< std::string, bool > >(), | ||
| bool | openMenuOnDisplayConditionMet = false, | ||
| bool | hasSubMenu = false, | ||
| const std::string & | cursor = "", | ||
| std::vector< std::string > | valueMapping = std::vector< std::string >(), | ||
| bool | isValid = true ) |
Constructor for a menu element.
| label | Text displayed for this menu element |
| action | Action identifier to execute when selected |
| param | Parameter to pass with the action |
| displayConditions | List of conditions that determine when this element is enabled |
| openMenuOnDisplayConditionMet | Whether to automatically open a submenu when conditions are met |
| hasSubMenu | Whether this element has a submenu |
| cursor | Cursor name to display when this element is selected |
| valueMapping | List of values for variable substitution |
| isValid | Whether this element is valid and can be displayed |
Creates a new menu element with the specified properties. The element's type (ACTION or MENU) is determined automatically based on the action parameter. If action is "selectMenu", the type will be MENU, otherwise ACTION.
References action(), cursor(), hasSubMenu(), isValid(), label(), openMenuOnDisplayConditionMet(), and valueMapping().
Referenced by create().
|
virtual |
Virtual destructor.
Cleans up resources used by the menu element and disconnects from attribute callbacks.
|
virtual |
Sets the parent menu for this element.
| menu | Pointer to the parent menu |
Associates this element with a menu and sets up attribute callbacks for dynamic state tracking. When the parent menu is set, the element will look for relevant state attributes in the player attribute store and connect to them.
|
inlinevirtual |
Gets the element type.
Retrieves the type of this menu element, which determines its behavior when selected (performing an action or opening a submenu).
References myType.
|
virtual |
Sets the element's selected state.
| select | True to select this element, false to deselect it |
Called when the selection state of this element changes. When an element is selected, it updates the active cursor to match its specified cursor.
|
virtual |
Checks if this element is currently enabled.
Determines whether this menu element is currently enabled based on its display conditions. Disabled elements cannot be selected and may be visually grayed out or hidden depending on the menu implementation.
|
inlinevirtual |
Gets the previous enabled state.
Returns the previously cached enabled state of the element. Used to detect changes in enabled state for updating menus.
References myPreviouslyEnabled.
|
inlinevirtual |
Checks if the menu should open automatically when conditions are met.
If true and if this menu item has display conditions, open the item's menu when the conditions become true. Useful for context-sensitive actions like open a nearby door when you walk up to it.
References myOpenMenuOnDisplayConditionMet.
Referenced by DtMenuElement().
|
inlinevirtual |
Sets the label text for this menu element.
| newLabel | The new label text |
Updates the text that is displayed for this menu element.
References myLabel.
|
virtual |
Gets the label for this menu element.
Retrieves the display text for this menu element, resolving any variable references in the process. Variables are replaced with values from the player attribute store.
Referenced by DtMenuElement().
|
inlinevirtual |
Gets the action identifier.
Returns the action identifier that will be executed when this element is selected.
References myAction.
Referenced by DtMenuElement().
|
inlinevirtual |
Sets the action identifier.
| newAction | The new action string |
Updates the action that will be executed when this element is selected.
References myAction.
|
inlinevirtual |
Gets the action parameter.
Returns the parameter that will be passed with the action when executed.
References myParameter.
|
inlinevirtual |
Sets the action parameter.
| newParam | The new parameter string |
Updates the parameter that will be passed with the action when executed.
References myParameter.
|
virtual |
Gets the decorator text.
Retrieves additional text displayed alongside the label, such as a current value or state information. This may include resolved variable references to show dynamic information.
|
inlinevirtual |
Checks if this element has a submenu.
Determines whether selecting this element will open a submenu.
References myHasSubMenu.
Referenced by DtMenuElement().
|
inlinevirtual |
Sets whether this element has a submenu.
| val | True if element should have a submenu, false otherwise |
Updates whether selecting this element will open a submenu.
References myHasSubMenu.
|
virtual |
Sets the cursor for this element.
| cursor | Name of the cursor to display when selected |
Updates the cursor that will be shown when this element is selected.
References cursor().
|
inlinevirtual |
Gets the cursor name.
Returns the name of the cursor to display when this element is selected.
References myCursor.
Referenced by DtMenuElement(), and setCursor().
|
inlinevirtual |
Gets the value mapping list.
Returns the list of values used for substituting variables in labels and parameters.
References myValueMapping.
Referenced by DtMenuElement().
|
inlinevirtual |
Checks if this element is valid.
Determines whether this element is valid and should be displayed. Invalid elements are excluded from menus entirely.
References myIsValid.
Referenced by DtMenuElement().
|
inlinevirtual |
Sets the validity of this element.
| val | True to mark as valid, false to mark as invalid |
Updates whether this element is valid and should be displayed.
References myIsValid.
|
virtual |
Executes this element's action.
Performs the action associated with this menu element. For ACTION type elements, this creates and sends a MenuActionMessage with the element's action and parameter. For MENU type elements, this creates and sends a MenuSetStateMessage to show the specified submenu and closes the current menu.
|
static |
Creates a menu element from configuration data.
| config | Configuration table containing element properties |
Factory method that creates a menu element from a configuration table. This is used when loading menu definitions from files or dynamic sources.
References DtMenuElement().
|
virtual |
Resets the element's state.
Disconnects all attribute callbacks and clears state attributes. Called during cleanup or when the element needs to be completely reset.
|
protected |
Resolves variables in a string with values from attributes.
| str | String containing variables to resolve |
Processes a string and replaces variable references (marked with $) with values from the player attribute store. This is used to create dynamic labels and parameters based on current state.
|
protected |
Handles attribute change notifications.
| attribute | The attribute that changed |
Called when an attribute this element is monitoring changes. Triggers an update of the parent menu to reflect the changed state.
|
protected |
Finds a state attribute referenced in a string.
| str | String potentially containing a state attribute reference |
Parses a string to find embedded state attribute references. These references can be used to create labels or parameters that dynamically reflect the current state.
|
protected |
Checks whether this element should be enabled.
Evaluates all display conditions for this element to determine if it should be enabled. Each condition refers to a boolean attribute in the player attribute store, optionally inverted.
|
friend |
Friend classes that need access to internals.
References DtMenuAttributeObserver.
Referenced by DtMenuAttributeObserver.
|
protected |
Configuration data for this element.
|
protected |
Parent menu containing this element.
|
protected |
Type of element (ACTION or MENU)
Referenced by type().
|
protected |
List of display conditions for this element.
Each pair contains the name of a boolean state attribute and a flag indicating whether the condition should be inverted. The element is enabled only when all conditions are satisfied.
|
protected |
Label text displayed for this element.
Referenced by setLabel().
|
protected |
Action identifier executed when selected.
Referenced by action(), and setAction().
|
protected |
Parameter passed with the action.
Referenced by parameter(), and setParameter().
|
protected |
Cursor name to display when selected.
Referenced by cursor().
|
protected |
Handle to a state attribute for dynamic content.
|
protected |
List of values for variable substitution.
Referenced by valueMapping().
|
protected |
Callback for attribute change notifications.
|
protected |
Whether this element has a submenu.
Referenced by hasSubMenu(), and setHasSubMenu().
|
protected |
Whether this element is valid and should be displayed.
Referenced by isValid(), and setIsValid().
|
protected |
Previously cached enabled state.
Referenced by previouslyEnabled().
|
protected |
Whether to open submenu automatically when conditions are met.
Referenced by openMenuOnDisplayConditionMet().