VR-Engage  2.2
Loading...
Searching...
No Matches
roleSelectionControl.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file roleSelectionControl.h
7//! \brief Component that enables switching between different roles on the same entity
8//! \ingroup vreCommonComponents
9
10#pragma once
11
13
16
17#include <vector>
18
20
21namespace makVre
22{
23class DtPlayerStation;
24
26{
27//! \ingroup RoleConfigParams
28//! \defgroup RoleSelectionControlRoleParams Role Selection Control Role Parameters
29//! \roleInherits{PlayerComponentRoleParams}
30//! Configuration Options for role selection control role.
31//! @{
32
33//! \vreRoleParam{availableRolesAttributeName,string,"availableRoles",roleSelectionControl,Name of the state attribute that stores the list of available role names for selection.}
34constexpr const char* availableRolesAttributeName = "availableRolesAttributeName";
35
36//! \vreRoleParam{excludedRoles,table,{},roleSelectionControl,Table of role names to exclude from the available roles list.}
37constexpr const char* excludedRoles = "excludedRoles";
38
39//! \vreRoleParam{hasAvailableRolesAttributeName,string,"hasAvailableRoles",roleSelectionControl,Name of the boolean state attribute indicating whether any roles are available for selection.}
40constexpr const char* hasAvailableRolesAttributeName = "hasAvailableRolesAttributeName";
41
42//! \vreRoleParam{inputConfigFile,string,"",roleSelectionControl,Input configuration file path for role selection key bindings.}
43constexpr const char* inputConfigFile = "inputConfigFile";
44
45//! \vreRoleParam{inputConfigGroup,string,"general",roleSelectionControl,Input configuration group name for role selection controls.}
46constexpr const char* inputConfigGroup = "inputConfigGroup";
47
48//! \vreRoleParam{nextRoleBinding,string,"next-role",roleSelectionControl,Input binding name for selecting the next available role.}
49constexpr const char* nextRoleBinding = "nextRoleBinding";
50
51//! \vreRoleParam{previousRoleBinding,string,"previous-role",roleSelectionControl,Input binding name for selecting the previous available role.}
52constexpr const char* previousRoleBinding = "previousRoleBinding";
53
54//! \vreRoleParam{rolesList,table,{},roleSelectionControl,Table of specific role names to include in the role selection list (overrides automatic discovery).}
55constexpr const char* rolesList = "rolesList";
56
57//! \vreRoleParam{selectRoleMenuAction,string,"selectRole",roleSelectionControl,Menu action name for triggering role selection via the menu system.}
58constexpr const char* selectRoleMenuAction = "selectRoleMenuAction";
59
60//! @}
61} // namespace RoleSelectionControlConfig
62
63//! \brief Type identifier for DtRoleSelectionControl component
64constexpr const char* DtRoleSelectionControlType = "DtRoleSelectionControl";
65
66//! \brief Component that enables switching between different roles on the same entity
67//!
68//! DtRoleSelectionControl provides functionality for cycling through and selecting
69//! different roles available on the current ownship entity. It tracks which roles
70//! are available (not occupied or engaged by other players), maintains state attributes
71//! for the UI to display, and handles the role switching process through input bindings
72//! or menu actions. It supports both direct-engaged roles and embark-engaged roles where
73//! a human avatar must be re-embarked in a specific slot.
75{
76public:
77 //! \brief Constructor for DtRoleSelectionControl
78 //!
79 //! Initializes the component with default settings
81
82 //! \brief Virtual destructor for DtRoleSelectionControl
83 virtual ~DtRoleSelectionControl() override;
84
85 //! \brief Initializes the role selection control component
86 //! \param player Pointer to the player station this component belongs to
87 //! \param config Configuration table containing role selection settings
88 //! \return True if initialization succeeded, false otherwise
89 //!
90 //! Sets up available roles list, determines the component mode (stacked or direct),
91 //! configures input bindings, and registers message handlers
92 virtual bool initialize(DtPlayerStation* player, DtInitTable& config) override;
93 //! \brief Performs post-initialization after all components are initialized
94 //! \return True if post-initialization succeeded, false otherwise
95 //!
96 //! Completes any setup that requires other components to be initialized first
97 virtual bool postInitialize() override;
98
99 //! \brief Called every frame to update the component state
100 //! \param dt Delta time since the last frame in seconds
101 //!
102 //! For stacked roles, periodically requests embarkation information to
103 //! update slot availability status
104 virtual void tick(double dt) override;
105 //! \brief Shuts down the role selection control component
106 //!
107 //! Removes message handlers and input bindings
108 virtual void shutdown() override;
109
110 //! \brief Returns the type identifier for this component
111 //! \return The type string for DtRoleSelectionControl
112 virtual const char* type() const override;
113
114 //! \brief Switches to a specific role on the ownship entity
115 //! \param roleName Name of the role to switch to
116 //!
117 //! For stacked roles, embarks the human player in the new role slot.
118 //! For direct-engaged roles, assigns the player to the new role directly.
119 virtual void selectRole(const std::string& roleName);
120
121 //! \brief Handles simulation state messages
122 //! \param msg Simulation state message
123 //! \return Message handling result indicating if the message was handled
124 //!
125 //! Updates role engagement status based on information in simulation state messages
127
128 //! \brief Handles menu action messages
129 //! \param msg Menu action message
130 //! \return Message handling result indicating if the message was handled
131 //!
132 //! Processes role selection menu actions
134
135 //! \brief Handles entity embarkation information messages
136 //! \param msg Entity embarkation information message
137 //! \return Message handling result indicating if the message was handled
138 //!
139 //! Updates slot occupancy status based on embarkation information
141
142 //! \brief Input handler for cycling to the next available role
143 //! \param keyState Input value (1.0 for pressed, 0.0 for released)
144 //!
145 //! When triggered, finds the next non-occupied, non-engaged role and switches to it
146 virtual void nextRole(double keyState);
147
148 //! \brief Input handler for cycling to the previous available role
149 //! \param keyState Input value (1.0 for pressed, 0.0 for released)
150 //!
151 //! When triggered, finds the previous non-occupied, non-engaged role and switches to it
152 virtual void previousRole(double keyState);
153
154protected:
155 //! \brief Updates the available roles state attributes
156 //!
157 //! Builds a list of available roles based on occupancy and engagement status
158 //! and updates the corresponding state attributes for UI display
160
161 //! \brief Structure representing a role with its availability status
163 {
164 //! \brief Constructor for RoleListItem
165 //! \param _name Role name
166 //! \param _slotOccupied Flag indicating if the corresponding slot is occupied
167 //! \param _roleEngaged Flag indicating if the role is currently engaged by another player
168 RoleListItem(const std::string& _name, bool _slotOccupied, bool _roleEngaged)
169 : name(_name)
170 , slotOccupied(_slotOccupied)
171 , roleEngaged(_roleEngaged)
172 {
173 }
174
175 //! \brief Name of the role
176 std::string name;
177
178 //! \brief Flag indicating if the corresponding slot is occupied
180
181 //! \brief Flag indicating if the role is currently engaged by another player
183 };
184
185 //! \brief List of roles available on the current entity
186 std::vector<RoleListItem> myRolesList;
187
188 //! \brief Index of the current role in the roles list
189 unsigned int myRoleIndex;
190
191 //! \brief Name of the attribute indicating if there are available roles
193
194 //! \brief Name of the attribute containing the list of available roles
196
197 //! \brief Name of the menu action for selecting a role
199
200 //! \brief Flag indicating if this is a stacked role (embarked) versus direct-engaged
202
203 //! \brief Input logic for handling role selection bindings
205};
206
207} // namespace makVre
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Class for managing input configuration and handling in VR-Engage.
Definition inputLogic.h:35
virtual DtPlayerStation & player()
Gets the player station.
DtPlayerComponent()
Constructor.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
std::string myHasAvailableRolesAttributeName
Name of the attribute indicating if there are available roles.
Definition roleSelectionControl.h:192
virtual void tick(double dt) override
Called every frame to update the component state.
DtInputLogic myInputLogic
Input logic for handling role selection bindings.
Definition roleSelectionControl.h:204
virtual void selectRole(const std::string &roleName)
Switches to a specific role on the ownship entity.
std::vector< RoleListItem > myRolesList
List of roles available on the current entity.
Definition roleSelectionControl.h:186
virtual const char * type() const override
Returns the type identifier for this component.
unsigned int myRoleIndex
Index of the current role in the roles list.
Definition roleSelectionControl.h:189
virtual DtVreMessageResult handleSimState(DtVreMessage *msg)
Handles simulation state messages.
virtual bool postInitialize() override
Performs post-initialization after all components are initialized.
std::string mySelectRoleMenuAction
Name of the menu action for selecting a role.
Definition roleSelectionControl.h:198
virtual ~DtRoleSelectionControl() override
Virtual destructor for DtRoleSelectionControl.
std::string myAvailableRolesAttributeName
Name of the attribute containing the list of available roles.
Definition roleSelectionControl.h:195
virtual DtVreMessageResult handleMenuAction(DtVreMessage *msg)
Handles menu action messages.
virtual void shutdown() override
Shuts down the role selection control component.
virtual bool initialize(DtPlayerStation *player, DtInitTable &config) override
Initializes the role selection control component.
virtual void nextRole(double keyState)
Input handler for cycling to the next available role.
bool myIsStackedRole
Flag indicating if this is a stacked role (embarked) versus direct-engaged.
Definition roleSelectionControl.h:201
virtual DtVreMessageResult handleEntityEmbarkationInformation(DtVreMessage *msg)
Handles entity embarkation information messages.
virtual void previousRole(double keyState)
Input handler for cycling to the previous available role.
DtRoleSelectionControl()
Constructor for DtRoleSelectionControl.
virtual void updateAvailableRolesAttribute()
Updates the available roles state attributes.
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
constexpr const char * inputConfigGroup
Definition roleSelectionControl.h:46
constexpr const char * hasAvailableRolesAttributeName
Definition roleSelectionControl.h:40
constexpr const char * nextRoleBinding
Definition roleSelectionControl.h:49
constexpr const char * previousRoleBinding
Definition roleSelectionControl.h:52
constexpr const char * excludedRoles
Definition roleSelectionControl.h:37
constexpr const char * rolesList
Definition roleSelectionControl.h:55
constexpr const char * selectRoleMenuAction
Definition roleSelectionControl.h:58
constexpr const char * availableRolesAttributeName
Definition roleSelectionControl.h:34
constexpr const char * inputConfigFile
Definition roleSelectionControl.h:43
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Defines the DtInputLogic class for handling input in VR-Engage.
Definition roleSelectionControl.h:26
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
constexpr const char * DtRoleSelectionControlType
Type identifier for DtRoleSelectionControl component.
Definition roleSelectionControl.h:64
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Defines the DtPlayerComponent base class for VR-Engage role components.
bool slotOccupied
Flag indicating if the corresponding slot is occupied.
Definition roleSelectionControl.h:179
std::string name
Name of the role.
Definition roleSelectionControl.h:176
bool roleEngaged
Flag indicating if the role is currently engaged by another player.
Definition roleSelectionControl.h:182
RoleListItem(const std::string &_name, bool _slotOccupied, bool _roleEngaged)
Constructor for RoleListItem.
Definition roleSelectionControl.h:168
Defines the base class for all VREngage messages.