|
VR-Engage
2.2
|
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 ¶m) |
Static Protected Member Functions | |
| static std::string | replaceEach (const std::string &string, std::string const &key, std::string const &value) |
Protected Attributes | |
| DtMenu * | myMenu |
| DtAttributeHandle | myState |
| DtAttributeChangeCallback | myChangeCallback |
| DtMenuElement * | myPrototype |
| std::vector< DtMenuElement * > | myElements |
| makVre::DtMenuAttributeObserver::DtMenuAttributeObserver | ( | DtMenu * | menu, |
| DtAttributeHandle | state, | ||
| const std::string & | attributeName, | ||
| DtMenuElement * | prototype ) |
Constructor.
| menu | Pointer to the menu to populate with elements |
| state | Attribute handle to the player attribute store |
| attributeName | Name of the attribute to observe |
| prototype | Prototype 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.
|
virtual |
Virtual destructor.
Ensures proper cleanup of derived observer classes.
|
protectedvirtual |
Handles attribute change notifications.
| attribute | The 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.
|
staticprotected |
Replaces a key with a value in a string.
| string | Source string to search |
| key | Key to find and replace |
| value | Value to substitute for the key |
Utility method for substituting a specific key with a value in a string. Used for generating dynamic element labels and parameters from templates.
|
protectedvirtual |
Creates a new menu element from the prototype.
| label | Label string for the new menu element |
| param | Param 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.
|
protected |
Menu to populate with generated elements.
|
protected |
Attribute handle to the player attribute store.
|
protected |
Callback for attribute change notifications.
|
protected |
Prototype element to clone for each generated element.
|
protected |
List of elements generated by this observer.