VR-Engage  2.3
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
94 //! \brief Performs post-initialization after all components are initialized
95 //! \return True if post-initialization succeeded, false otherwise
96 //!
97 //! Completes any setup that requires other components to be initialized first
98 virtual bool postInitialize() override;
99
100 //! \brief Builds the list of available roles on the current entity
101 //!
102 //! called from initialize() to populate the myRolesList vector
103 virtual bool buildRolesList(DtInitTable& config);
104
105 //! \brief Called every frame to update the component state
106 //! \param dt Delta time since the last frame in seconds
107 //!
108 //! For stacked roles, periodically requests embarkation information to
109 //! update slot availability status
110 virtual void tick(double dt) override;
111 //! \brief Shuts down the role selection control component
112 //!
113 //! Removes message handlers and input bindings
114 virtual void shutdown() override;
115
116 //! \brief Returns the type identifier for this component
117 //! \return The type string for DtRoleSelectionControl
118 virtual const char* type() const override;
119
120 //! \brief Switches to a specific role on the ownship entity
121 //! \param roleName Name of the role to switch to
122 //!
123 //! For stacked roles, embarks the human player in the new role slot.
124 //! For direct-engaged roles, assigns the player to the new role directly.
125 virtual void selectRole(const std::string& roleName);
126
127 //! \brief Handles simulation state messages
128 //! \param msg Simulation state message
129 //! \return Message handling result indicating if the message was handled
130 //!
131 //! Updates role engagement status based on information in simulation state messages
133
134 //! \brief Handles menu action messages
135 //! \param msg Menu action message
136 //! \return Message handling result indicating if the message was handled
137 //!
138 //! Processes role selection menu actions
140
141 //! \brief Handles entity embarkation information messages
142 //! \param msg Entity embarkation information message
143 //! \return Message handling result indicating if the message was handled
144 //!
145 //! Updates slot occupancy status based on embarkation information
147
148 //! \brief Input handler for cycling to the next available role
149 //! \param keyState Input value (1.0 for pressed, 0.0 for released)
150 //!
151 //! When triggered, finds the next non-occupied, non-engaged role and switches to it
152 virtual void nextRole(double keyState);
153
154 //! \brief Input handler for cycling to the previous available role
155 //! \param keyState Input value (1.0 for pressed, 0.0 for released)
156 //!
157 //! When triggered, finds the previous non-occupied, non-engaged role and switches to it
158 virtual void previousRole(double keyState);
159
160protected:
161 //! \brief Updates the available roles state attributes
162 //!
163 //! Builds a list of available roles based on occupancy and engagement status
164 //! and updates the corresponding state attributes for UI display
166
167 //! \brief Structure representing a role with its availability status
169 {
170 //! \brief Constructor for RoleListItem
171 //! \param _name Role name
172 //! \param _slotOccupied Flag indicating if the corresponding slot is occupied
173 //! \param _roleEngaged Flag indicating if the role is currently engaged by another player
174 RoleListItem(const std::string& _name, bool _slotOccupied, bool _roleEngaged)
175 : name(_name)
176 , slotOccupied(_slotOccupied)
177 , roleEngaged(_roleEngaged)
178 {
179 }
180
181 //! \brief Name of the role
182 std::string name;
183
184 //! \brief Flag indicating if the corresponding slot is occupied
186
187 //! \brief Flag indicating if the role is currently engaged by another player
189 };
190
191 //! \brief List of roles available on the current entity
192 std::vector<RoleListItem> myRolesList;
193
194 //! \brief Index of the current role in the roles list
195 unsigned int myRoleIndex;
196
197 //! \brief Name of the attribute indicating if there are available roles
199
200 //! \brief Name of the attribute containing the list of available roles
202
203 //! \brief Name of the menu action for selecting a role
205
206 //! \brief Flag indicating if this is a stacked role (embarked) versus direct-engaged
208
209 //! \brief Input logic for handling role selection bindings
211};
212
213} // 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:39
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:198
virtual bool buildRolesList(DtInitTable &config)
Builds the list of available roles on the current entity.
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:210
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:192
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:195
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:204
virtual ~DtRoleSelectionControl() override
Virtual destructor for DtRoleSelectionControl.
std::string myAvailableRolesAttributeName
Name of the attribute containing the list of available roles.
Definition roleSelectionControl.h:201
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:207
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
!
Definition glsVreMessageUtil.h:50
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:185
std::string name
Name of the role.
Definition roleSelectionControl.h:182
bool roleEngaged
Flag indicating if the role is currently engaged by another player.
Definition roleSelectionControl.h:188
RoleListItem(const std::string &_name, bool _slotOccupied, bool _roleEngaged)
Constructor for RoleListItem.
Definition roleSelectionControl.h:174
Defines the base class for all VREngage messages.