VR-Engage  2.3
Loading...
Searching...
No Matches
vreChatManager.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file vreChatManager.h
7//! \brief Declares DtChatCommand and DtVreChatManager.
8//!
9//! DtVreChatManager is the high-level chat manager accessible from any C++
10//! player-station plugin without Qt headers. It absorbs the command registry
11//! formerly in DtChatCommandsManager and the message-handler logic formerly
12//! in DtVreChatWindow.
13
14#pragma once
15
18#include "vreUtil/baseClass.h"
21
22#include <vlutil/vlFilename.h>
23
24#include <memory>
25#include <string>
26#include <unordered_map>
27#include <vector>
28
29namespace makVre
30{
31
33
34//! \brief Abstract base class for chat slash-commands.
35//!
36//! Formerly declared in vreChatCommandsManager.h.
37//! Register concrete implementations with DtVreChatManager::addCommand().
38class PLAYERSTATION_DLL DtChatCommand : public std::enable_shared_from_this<DtChatCommand>
39{
40public:
41 //! \brief Virtual destructor
42 virtual ~DtChatCommand() = default;
43
44 //! \brief Executes this command with the given parameter string
45 //! \param parameters Everything after the command name
46 //! \return True if the command executed successfully
47 virtual bool execute(const std::string& parameters) = 0;
48
49 //! \brief Returns a weak pointer to this command instance
50 virtual std::weak_ptr<DtChatCommand> getWeak() { return shared_from_this(); }
51
52 //! \brief Returns help text for this command
53 //! \param parameters Optional context passed when generating help
54 virtual std::string help(const std::string& parameters) { return parameters; }
55
56 //! \brief Whether this command appears in /help output
57 virtual bool showInHelp() const { return false; }
58
59 //! \brief Splits a string into tokens on a delimiter
60 //! \param stringToSplit Input string
61 //! \param tokenized Output token vector
62 //! \param delimiter Split character (default: space)
63 //! \return True if split produced tokens
64 static bool splitString(const std::string& stringToSplit,
65 std::vector<std::string>& tokenized, const char delimiter = ' ');
66};
67
68//! \brief High-level chat manager for VR-Engage player-station plugins.
69//!
70//! DtVreChatManager provides a Qt-free public API for sending chat messages,
71//! managing channels, controlling the chat window UI, and registering slash
72//! commands. It is a member of DtPlayerStationApp and is available through
73//! app.chatManager().
74//!
75//! DtVreChatManager participates in the per-class creator factory via
76//! DtVreUniqueBase. Override the default implementation by calling
77//! DtVreChatManager::registerCreator<MyManager>() before app initialization.
78//! Custom subclasses must have a default constructor and override initialize().
79class PLAYERSTATION_DLL DtVreChatManager : public DtVreUniqueBase<DtVreChatManager>
80{
81public:
82 //! \brief Default constructor (required by DtVreUniqueBase factory)
84
85 //! \brief Virtual destructor; removes registered message handlers
87
88 //! \brief Phase-2 initializer — call immediately after create()
89 //! \param app Reference to the owning player station application
90 //!
91 //! Registers all message handlers, sets up configuration file paths,
92 //! and connects the application state change callback.
93 //! \note Must be called once before the first window is constructed.
94 virtual void initialize(DtPlayerStationApp& app);
95
96 //! \brief Wires the concrete chat window to this manager
97 //! \param window Non-owning pointer to the DtChatWindowInterface implementation
98 //!
99 //! Called automatically by DtVreChatWindow at the end of its constructor.
100 //! Triggers initial channel configuration load and updateAvailableChannels().
101 //! Guarded: all subsequent window calls check for null.
102 virtual void setWindow(DtChatWindowInterface* window);
103
104 // -------------------------------------------------------------------------
105 // Send pipeline
106 // -------------------------------------------------------------------------
107
108 //! \brief Sends a message or slash command through the chat window
109 //! \param message Text or /command string
110 virtual void send(const std::string& message);
111
112 //! \brief Sends a chat message to a specific channel
113 virtual void sendChatMessage(const std::string& message,
114 const std::string& channel, int force);
115
116 //! \brief Sends a message to the system notification channel
117 virtual void sendToSystemChannel(const std::string& message);
118
119 //! \brief Checks whether a channel is currently active
120 virtual bool isChannelActive(const std::string& channelName, int force) const;
121
122 // -------------------------------------------------------------------------
123 // UI state
124 // -------------------------------------------------------------------------
125
126 //! \brief Opens the chat window
127 virtual void open();
128
129 //! \brief Closes the chat window
130 virtual void close();
131
132 //! \brief Opens the chat window or focuses its input if already open
133 virtual void openOrFocus();
134
135 //! \brief Toggles the pinned (always-visible) state of the chat window
136 virtual void togglePinChat();
137
138 //! \brief Returns true if the chat window root item is visible
139 virtual bool isVisible() const;
140
141 //! \brief Returns true if the full chat panel is visible
142 virtual bool isFullChatVisible() const;
143
144 //! \brief Returns true if the chat window is permitted to be shown
145 virtual bool isShowingAllowed() const;
146
147 //! \brief Sets whether the chat window is permitted to be shown
148 virtual void setShowingAllowed(bool canShow);
149
150 // -------------------------------------------------------------------------
151 // Channel / config management
152 // -------------------------------------------------------------------------
153
154 //! \brief Updates chat channels from a scenario file
155 //! \param scenario Full path to the scenario file
156 //! \return True if the configuration changed
157 virtual bool updateChatChannelsFromScenario(const DtFilename& scenario);
158
159 //! \brief Updates chat channels from a configuration file
160 //! \param chatConfigFile Path to the chat channel config (.mtl) file
161 //! \return True if the configuration changed
162 virtual bool updateChatChannelsFromConfigFile(const DtFilename& chatConfigFile);
163
164 //! \brief Returns the chat config file to use for a given scenario
165 //! \param scenarioFilename Full path to the scenario (may be empty)
166 //! \return Path to the appropriate chat config file
167 virtual DtFilename getChatConfigFile(const DtFilename& scenarioFilename) const;
168
169 // -------------------------------------------------------------------------
170 // Command registry (absorbed from DtChatCommandsManager)
171 // -------------------------------------------------------------------------
172
173 //! \brief Registers a slash command
174 //! \param commandString Trigger word (without the leading slash)
175 //! \param command Shared pointer to the command implementation
176 //! \param takeOwnership If true, manager holds a strong reference
177 //! \return True if the command was added successfully
178 virtual bool addCommand(const std::string& commandString,
179 std::shared_ptr<DtChatCommand> command, bool takeOwnership = false);
180
181 //! \brief Unregisters a slash command by its trigger word
182 virtual void removeCommand(const std::string& commandString);
183
184 //! \brief Executes a slash command from a console input string
185 //! \param consoleString Full string (e.g. "help" or "username Alice")
186 //! \return True if a matching command was found and executed
187 virtual bool runCommand(const std::string& consoleString);
188
189 //! \brief Generates formatted help text for all visible commands
190 //! \param parameters Optional filter or context string
191 //! \return Multi-line help string
192 virtual std::string helpText(const std::string& parameters) const;
193
194protected:
195 //! @{
196 //! \brief Message handlers (moved from DtVreChatWindow)
203 virtual void onCurrentStateChanged(std::string state);
204 //! @}
205
206protected:
207 //! \brief Non-owning pointer to the active chat window; set via setWindow()
209
210 //! \brief Owning application reference; set in initialize()
212
213 //! @{
214 //! \brief Configuration file paths (moved from DtVreChatWindow)
217 DtFilename myDefaultConfigFilename = DtFilename("defaultChatConfig.mtl");
218 DtFilename myDefaultConfigDirectory = DtFilename("$(APP_DIR)/settings");
219 DtFilename myDefaultChatConfigUserFilenamePostfix = DtFilename("_ChatConfig.mtl");
220 DtFilename myDefaultChatConfigUserDirectory = DtFilename("$(USER_DIR)/chatConfigs");
221 //! @}
222
223 //! \brief Tracks attribute change callbacks; ensures cleanup on destruction
225
226 //! @{
227 //! \brief Slash-command registry (absorbed from DtChatCommandsManager)
228 std::unordered_map<std::string, std::weak_ptr<DtChatCommand>> myCommandMap;
229 std::unordered_map<std::string, std::shared_ptr<DtChatCommand>> myOwnedCommandMap;
230 //! @}
231};
232
233} // namespace makVre
Provides a callback mechanism for attribute changes in the VREngage system.
Provides base classes for shared pointer managed objects with factory creation support.
Convenience manager that owns and organises a collection of attribute callbacks.
Definition attributeCallback.h:223
Abstract base class for chat slash-commands.
Definition vreChatManager.h:39
virtual std::string help(const std::string &parameters)
Returns help text for this command.
Definition vreChatManager.h:54
static bool splitString(const std::string &stringToSplit, std::vector< std::string > &tokenized, const char delimiter=' ')
Splits a string into tokens on a delimiter.
virtual std::weak_ptr< DtChatCommand > getWeak()
Returns a weak pointer to this command instance.
Definition vreChatManager.h:50
virtual ~DtChatCommand()=default
Virtual destructor.
virtual bool execute(const std::string &parameters)=0
Executes this command with the given parameter string.
virtual bool showInHelp() const
Whether this command appears in /help output.
Definition vreChatManager.h:57
Pure abstract interface for the chat window component.
Definition vreChatWindowInterface.h:28
Top-level class representing the VR-Engage application.
Definition playerStationApp.h:155
virtual bool addCommand(const std::string &commandString, std::shared_ptr< DtChatCommand > command, bool takeOwnership=false)
Registers a slash command.
virtual void initialize(DtPlayerStationApp &app)
Phase-2 initializer — call immediately after create()
virtual bool runCommand(const std::string &consoleString)
Executes a slash command from a console input string.
virtual void openOrFocus()
Opens the chat window or focuses its input if already open.
std::unordered_map< std::string, std::shared_ptr< DtChatCommand > > myOwnedCommandMap
Slash-command registry (absorbed from DtChatCommandsManager)
Definition vreChatManager.h:229
DtFilename myDefaultChatConfigFile
Configuration file paths (moved from DtVreChatWindow)
Definition vreChatManager.h:215
DtVreChatManager()
Default constructor (required by DtVreUniqueBase factory)
virtual DtVreMessageResult handlePlayerCreatedMessage(DtVreMessage *msg)
Message handlers (moved from DtVreChatWindow)
virtual void sendToSystemChannel(const std::string &message)
Sends a message to the system notification channel.
virtual std::string helpText(const std::string &parameters) const
Generates formatted help text for all visible commands.
virtual bool isShowingAllowed() const
Returns true if the chat window is permitted to be shown.
virtual DtVreMessageResult handleIncomingChatMessage(DtVreMessage *msg)
Message handlers (moved from DtVreChatWindow)
virtual void onCurrentStateChanged(std::string state)
Message handlers (moved from DtVreChatWindow)
virtual void setShowingAllowed(bool canShow)
Sets whether the chat window is permitted to be shown.
virtual bool updateChatChannelsFromScenario(const DtFilename &scenario)
Updates chat channels from a scenario file.
DtFilename myDefaultConfigDirectory
Configuration file paths (moved from DtVreChatWindow)
Definition vreChatManager.h:218
DtAttributeCallbackManager myAttributeCallbacks
Tracks attribute change callbacks; ensures cleanup on destruction.
Definition vreChatManager.h:224
virtual void togglePinChat()
Toggles the pinned (always-visible) state of the chat window.
DtFilename myDefaultChatConfigUserDirectory
Configuration file paths (moved from DtVreChatWindow)
Definition vreChatManager.h:220
virtual void close()
Closes the chat window.
virtual DtVreMessageResult handleVrfSessionStatusMessage(DtVreMessage *msg)
Message handlers (moved from DtVreChatWindow)
std::unordered_map< std::string, std::weak_ptr< DtChatCommand > > myCommandMap
Slash-command registry (absorbed from DtChatCommandsManager)
Definition vreChatManager.h:228
virtual DtVreMessageResult handleExitPlayerState(DtVreMessage *msg)
Message handlers (moved from DtVreChatWindow)
DtFilename myCurrentChatConfigFile
Configuration file paths (moved from DtVreChatWindow)
Definition vreChatManager.h:216
virtual bool isVisible() const
Returns true if the chat window root item is visible.
virtual bool isChannelActive(const std::string &channelName, int force) const
Checks whether a channel is currently active.
virtual ~DtVreChatManager()
Virtual destructor; removes registered message handlers.
virtual void send(const std::string &message)
Sends a message or slash command through the chat window.
virtual DtFilename getChatConfigFile(const DtFilename &scenarioFilename) const
Returns the chat config file to use for a given scenario.
virtual DtVreMessageResult handleEnterPlayerState(DtVreMessage *msg)
Message handlers (moved from DtVreChatWindow)
virtual void open()
Opens the chat window.
virtual void removeCommand(const std::string &commandString)
Unregisters a slash command by its trigger word.
DtFilename myDefaultConfigFilename
Configuration file paths (moved from DtVreChatWindow)
Definition vreChatManager.h:217
DtChatWindowInterface * myWindow
Non-owning pointer to the active chat window; set via setWindow()
Definition vreChatManager.h:208
virtual bool updateChatChannelsFromConfigFile(const DtFilename &chatConfigFile)
Updates chat channels from a configuration file.
virtual DtVreMessageResult handlePlayerDestroyedMessage(DtVreMessage *msg)
Message handlers (moved from DtVreChatWindow)
DtPlayerStationApp * myApp
Owning application reference; set in initialize()
Definition vreChatManager.h:211
DtFilename myDefaultChatConfigUserFilenamePostfix
Configuration file paths (moved from DtVreChatWindow)
Definition vreChatManager.h:219
virtual void sendChatMessage(const std::string &message, const std::string &channel, int force)
Sends a chat message to a specific channel.
virtual bool isFullChatVisible() const
Returns true if the full chat panel is visible.
virtual void setWindow(DtChatWindowInterface *window)
Wires the concrete chat window to this manager.
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
DtVreUniqueBase()
Definition baseClass.h:358
Defines export macros for the VR-Engage Player Station library.
#define PLAYERSTATION_DLL
Definition export.h:24
!
Definition glsVreMessageUtil.h:50
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Declares the DtChatWindowInterface pure abstract interface.
Defines the base class for all VREngage messages.