VR-Engage  2.2
Loading...
Searching...
No Matches
makVre::DtMenuElement Class Reference

Detailed Description

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 &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)
 
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 DtMenuElementcreate (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

DtInitTablemyConfig
 
DtMenumyMenu
 
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
 

Member Enumeration Documentation

◆ ElementType

Types of menu elements.

Defines the behavior of the menu element when selected.

Enumerator
ACTION 

Performs an action when selected.

MENU 

Opens a submenu when selected.

Constructor & Destructor Documentation

◆ DtMenuElement()

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.

Parameters
labelText displayed for this menu element
actionAction identifier to execute when selected
paramParameter to pass with the action
displayConditionsList of conditions that determine when this element is enabled
openMenuOnDisplayConditionMetWhether to automatically open a submenu when conditions are met
hasSubMenuWhether this element has a submenu
cursorCursor name to display when this element is selected
valueMappingList of values for variable substitution
isValidWhether 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().

◆ ~DtMenuElement()

virtual makVre::DtMenuElement::~DtMenuElement ( )
virtual

Virtual destructor.

Cleans up resources used by the menu element and disconnects from attribute callbacks.

Member Function Documentation

◆ setMenu()

virtual void makVre::DtMenuElement::setMenu ( DtMenu * menu)
virtual

Sets the parent menu for this element.

Parameters
menuPointer 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.

◆ type()

virtual ElementType makVre::DtMenuElement::type ( )
inlinevirtual

Gets the element type.

Returns
Type of this menu element (ACTION or MENU)

Retrieves the type of this menu element, which determines its behavior when selected (performing an action or opening a submenu).

References myType.

◆ setSelected()

virtual void makVre::DtMenuElement::setSelected ( bool select)
virtual

Sets the element's selected state.

Parameters
selectTrue 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.

◆ isEnabled()

virtual bool makVre::DtMenuElement::isEnabled ( )
virtual

Checks if this element is currently enabled.

Returns
True if enabled, false if disabled

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.

◆ previouslyEnabled()

virtual bool makVre::DtMenuElement::previouslyEnabled ( )
inlinevirtual

Gets the previous enabled state.

Returns
True if previously enabled, false otherwise

Returns the previously cached enabled state of the element. Used to detect changes in enabled state for updating menus.

References myPreviouslyEnabled.

◆ openMenuOnDisplayConditionMet()

virtual bool makVre::DtMenuElement::openMenuOnDisplayConditionMet ( )
inlinevirtual

Checks if the menu should open automatically when conditions are met.

Returns
True if menu should open automatically, false otherwise

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().

◆ setLabel()

virtual void makVre::DtMenuElement::setLabel ( const std::string & newLabel)
inlinevirtual

Sets the label text for this menu element.

Parameters
newLabelThe new label text

Updates the text that is displayed for this menu element.

References myLabel.

◆ label()

virtual std::string makVre::DtMenuElement::label ( )
virtual

Gets the label for this menu element.

Returns
Label text with any variables resolved

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().

◆ action()

virtual const std::string & makVre::DtMenuElement::action ( )
inlinevirtual

Gets the action identifier.

Returns
Reference to the action string

Returns the action identifier that will be executed when this element is selected.

References myAction.

Referenced by DtMenuElement().

◆ setAction()

virtual void makVre::DtMenuElement::setAction ( const std::string & newAction)
inlinevirtual

Sets the action identifier.

Parameters
newActionThe new action string

Updates the action that will be executed when this element is selected.

References myAction.

◆ parameter()

virtual const std::string & makVre::DtMenuElement::parameter ( )
inlinevirtual

Gets the action parameter.

Returns
Reference to the parameter string

Returns the parameter that will be passed with the action when executed.

References myParameter.

◆ setParameter()

virtual void makVre::DtMenuElement::setParameter ( const std::string & newParam)
inlinevirtual

Sets the action parameter.

Parameters
newParamThe new parameter string

Updates the parameter that will be passed with the action when executed.

References myParameter.

◆ decoratorText()

virtual std::string makVre::DtMenuElement::decoratorText ( )
virtual

Gets the decorator text.

Returns
Decorator text with variables resolved

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.

◆ hasSubMenu()

virtual bool makVre::DtMenuElement::hasSubMenu ( ) const
inlinevirtual

Checks if this element has a submenu.

Returns
True if element has a submenu, false otherwise

Determines whether selecting this element will open a submenu.

References myHasSubMenu.

Referenced by DtMenuElement().

◆ setHasSubMenu()

virtual void makVre::DtMenuElement::setHasSubMenu ( bool val)
inlinevirtual

Sets whether this element has a submenu.

Parameters
valTrue if element should have a submenu, false otherwise

Updates whether selecting this element will open a submenu.

References myHasSubMenu.

◆ setCursor()

virtual void makVre::DtMenuElement::setCursor ( const std::string & cursor)
virtual

Sets the cursor for this element.

Parameters
cursorName of the cursor to display when selected

Updates the cursor that will be shown when this element is selected.

References cursor().

◆ cursor()

virtual const std::string & makVre::DtMenuElement::cursor ( )
inlinevirtual

Gets the cursor name.

Returns
Reference to the cursor name string

Returns the name of the cursor to display when this element is selected.

References myCursor.

Referenced by DtMenuElement(), and setCursor().

◆ valueMapping()

virtual const std::vector< std::string > & makVre::DtMenuElement::valueMapping ( )
inlinevirtual

Gets the value mapping list.

Returns
Reference to the value mapping vector

Returns the list of values used for substituting variables in labels and parameters.

References myValueMapping.

Referenced by DtMenuElement().

◆ isValid()

virtual bool makVre::DtMenuElement::isValid ( ) const
inlinevirtual

Checks if this element is valid.

Returns
True if valid, false otherwise

Determines whether this element is valid and should be displayed. Invalid elements are excluded from menus entirely.

References myIsValid.

Referenced by DtMenuElement().

◆ setIsValid()

virtual void makVre::DtMenuElement::setIsValid ( bool val)
inlinevirtual

Sets the validity of this element.

Parameters
valTrue to mark as valid, false to mark as invalid

Updates whether this element is valid and should be displayed.

References myIsValid.

◆ doAction()

virtual void makVre::DtMenuElement::doAction ( )
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.

◆ create()

static DtMenuElement * makVre::DtMenuElement::create ( DtInitTable & config)
static

Creates a menu element from configuration data.

Parameters
configConfiguration table containing element properties
Returns
Newly created menu element, or NULL if creation failed

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().

◆ reset()

virtual void makVre::DtMenuElement::reset ( )
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.

◆ resolveVars()

std::string makVre::DtMenuElement::resolveVars ( const std::string & str)
protected

Resolves variables in a string with values from attributes.

Parameters
strString containing variables to resolve
Returns
String with variables replaced by their values

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.

◆ handleAttributeChanged()

void makVre::DtMenuElement::handleAttributeChanged ( const DtAttributeHandle & attribute)
protected

Handles attribute change notifications.

Parameters
attributeThe attribute that changed

Called when an attribute this element is monitoring changes. Triggers an update of the parent menu to reflect the changed state.

◆ findStateAttribute()

std::string makVre::DtMenuElement::findStateAttribute ( const std::string & str)
protected

Finds a state attribute referenced in a string.

Parameters
strString potentially containing a state attribute reference
Returns
Name of the referenced state attribute, or empty string if none

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.

◆ checkEnabled()

bool makVre::DtMenuElement::checkEnabled ( )
protected

Checks whether this element should be enabled.

Returns
True if all display conditions are satisfied, false otherwise

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.

Friends And Related Symbol Documentation

◆ DtMenuAttributeObserver

friend class DtMenuAttributeObserver
friend

Friend classes that need access to internals.

References DtMenuAttributeObserver.

Referenced by DtMenuAttributeObserver.

Member Data Documentation

◆ myConfig

DtInitTable* makVre::DtMenuElement::myConfig
protected

Configuration data for this element.

◆ myMenu

DtMenu* makVre::DtMenuElement::myMenu
protected

Parent menu containing this element.

◆ myType

ElementType makVre::DtMenuElement::myType
protected

Type of element (ACTION or MENU)

Referenced by type().

◆ myDisplayConditions

std::vector<std::pair<std::string, bool> > makVre::DtMenuElement::myDisplayConditions
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.

◆ myLabel

std::string makVre::DtMenuElement::myLabel
protected

Label text displayed for this element.

Referenced by setLabel().

◆ myAction

std::string makVre::DtMenuElement::myAction
protected

Action identifier executed when selected.

Referenced by action(), and setAction().

◆ myParameter

std::string makVre::DtMenuElement::myParameter
protected

Parameter passed with the action.

Referenced by parameter(), and setParameter().

◆ myCursor

std::string makVre::DtMenuElement::myCursor
protected

Cursor name to display when selected.

Referenced by cursor().

◆ myStateAttribute

DtAttributeHandle makVre::DtMenuElement::myStateAttribute
protected

Handle to a state attribute for dynamic content.

◆ myValueMapping

std::vector<std::string> makVre::DtMenuElement::myValueMapping
protected

List of values for variable substitution.

Referenced by valueMapping().

◆ myAttributeCallback

DtAttributeChangeCallback makVre::DtMenuElement::myAttributeCallback
protected

Callback for attribute change notifications.

◆ myHasSubMenu

bool makVre::DtMenuElement::myHasSubMenu
protected

Whether this element has a submenu.

Referenced by hasSubMenu(), and setHasSubMenu().

◆ myIsValid

bool makVre::DtMenuElement::myIsValid
protected

Whether this element is valid and should be displayed.

Referenced by isValid(), and setIsValid().

◆ myPreviouslyEnabled

bool makVre::DtMenuElement::myPreviouslyEnabled
protected

Previously cached enabled state.

Referenced by previouslyEnabled().

◆ myOpenMenuOnDisplayConditionMet

bool makVre::DtMenuElement::myOpenMenuOnDisplayConditionMet
protected

Whether to open submenu automatically when conditions are met.

Referenced by openMenuOnDisplayConditionMet().


The documentation for this class was generated from the following file: