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

Detailed Description

DtMenuAttributeListObserver monitors a list attribute in the player attribute store and generates a menu element for each item in the list. This is used to create dynamic menus where the available options depend on the current state, such as a list of available weapons or targets.

#include <actionMenuElement.h>

Public Member Functions

 DtMenuAttributeObserver (DtMenu *menu, DtAttributeHandle state, const std::string &attributeName, DtMenuElement *prototype)
 
virtual ~DtMenuAttributeObserver ()
 

Protected Member Functions

virtual void handleAttributeChanged (const DtAttributeHandle &attribute)
 
virtual void createMenuElement (const std::string &label, const std::string &param)
 

Static Protected Member Functions

static std::string replaceEach (const std::string &string, std::string const &key, std::string const &value)
 

Protected Attributes

DtMenumyMenu
 
DtAttributeHandle myState
 
DtAttributeChangeCallback myChangeCallback
 
DtMenuElementmyPrototype
 
std::vector< DtMenuElement * > myElements
 

Constructor & Destructor Documentation

◆ DtMenuAttributeObserver()

makVre::DtMenuAttributeObserver::DtMenuAttributeObserver ( DtMenu * menu,
DtAttributeHandle state,
const std::string & attributeName,
DtMenuElement * prototype )

Constructor.

Parameters
menuPointer to the menu to populate with elements
stateAttribute handle to the player attribute store
attributeNameName of the attribute to observe
prototypePrototype menu element to clone for each generated element

Creates a new instance that will monitor the specified attribute and generate menu elements using the prototype element as a template.

A new menu element is generated for each item in the attribute list. If the attribute is a vector of strings, the keyword "$EACH" in the prototype's label and param fields is replaced with the string. If the attribute is a map of key/value string pairs, the keyword "$KEY" in the prototype's label and param fields is replaced with the key, and the keyword "$VALUE" is replaced with the associated sting value.

◆ ~DtMenuAttributeObserver()

virtual makVre::DtMenuAttributeObserver::~DtMenuAttributeObserver ( )
virtual

Virtual destructor.

Ensures proper cleanup of derived observer classes.

Member Function Documentation

◆ handleAttributeChanged()

virtual void makVre::DtMenuAttributeObserver::handleAttributeChanged ( const DtAttributeHandle & attribute)
protectedvirtual

Handles attribute change notifications.

Parameters
attributeThe attribute that changed

Called when the observed list attribute changes. Regenerates the menu elements based on the new list content, removing old elements and creating new ones as needed.

◆ replaceEach()

static std::string makVre::DtMenuAttributeObserver::replaceEach ( const std::string & string,
std::string const & key,
std::string const & value )
staticprotected

Replaces a key with a value in a string.

Parameters
stringSource string to search
keyKey to find and replace
valueValue to substitute for the key
Returns
String with all instances of the key replaced by the value

Utility method for substituting a specific key with a value in a string. Used for generating dynamic element labels and parameters from templates.

◆ createMenuElement()

virtual void makVre::DtMenuAttributeObserver::createMenuElement ( const std::string & label,
const std::string & param )
protectedvirtual

Creates a new menu element from the prototype.

Parameters
labelLabel string for the new menu element
paramParam string for the new menu element

Instantiates a new DtMenuElement using the prototype template and the given label and param strings and adds the new element to the menu.

Member Data Documentation

◆ myMenu

DtMenu* makVre::DtMenuAttributeObserver::myMenu
protected

Menu to populate with generated elements.

◆ myState

DtAttributeHandle makVre::DtMenuAttributeObserver::myState
protected

Attribute handle to the player attribute store.

◆ myChangeCallback

DtAttributeChangeCallback makVre::DtMenuAttributeObserver::myChangeCallback
protected

Callback for attribute change notifications.

◆ myPrototype

DtMenuElement* makVre::DtMenuAttributeObserver::myPrototype
protected

Prototype element to clone for each generated element.

◆ myElements

std::vector<DtMenuElement*> makVre::DtMenuAttributeObserver::myElements
protected

List of elements generated by this observer.


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