VR-Engage  2.2
Loading...
Searching...
No Matches
extendedEngagedState.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2025 MAK Technologies, Inc.
3 * All rights reserved.
4 ******************************************************************************/
5
6//! \file extendedEngagedState.h
7//! \brief Extended engaged state demonstrating custom player station state extension
8//!
9//! This example shows how to extend VR-Engage's built-in engaged state with
10//! custom UI elements, message handling, and Qt Quick integration. It demonstrates
11//! the player station state machine extension pattern.
12
13#pragma once
14
18
19class QQuickItem;
20
21namespace makVre
22{
24
25//! \brief Extended engaged state demonstrating custom UI and message handling.
26//!
27//! This class shows how to extend VR-Engage's built-in DtEngagedState with custom
28//! functionality. It demonstrates proper integration with the Qt framework, state
29//! lifecycle management, and VR-Engage message handling patterns.
30//!
31//! Key patterns demonstrated:
32//! - Player station state extension and registration
33//! - State lifecycle methods (onEnter, onExit, onStacked, onExposed)
34//! - Qt Quick window management within a state
35//! - VR-Engage message handler registration and cleanup
36//! - Proper resource lifecycle management
37//!
38//! This is a REUSABLE pattern for any custom player station state that needs to:
39//! - Add custom UI elements during specific states
40//! - Handle simulation messages specific to a state
41//! - Manage Qt-based windows with proper show/hide on state transitions
43{
44public:
45 //! \brief Constructs the extended engaged state.
46 //!
47 //! \param app The player station application instance managing this state
49
50 //! \brief Destructor for cleanup of state resources.
51 virtual ~DtExtendedEngagedState() override;
52
53 //! \brief Called when transitioning into this state.
54 //!
55 //! This override demonstrates the proper pattern for state initialization:
56 //! - Creating or showing custom UI windows
57 //! - Registering message handlers specific to this state
58 //! - Calling base class onEnter to maintain proper state chain
59 //!
60 //! \param args Optional state transition arguments
61 virtual void onEnter(const DtPlayerStationStateArgs* args) override;
62
63 //! \brief Called when transitioning out of this state.
64 //!
65 //! This override demonstrates proper cleanup patterns:
66 //! - Hiding or closing custom UI windows
67 //! - Unregistering message handlers to prevent leaks
68 //! - Calling base class onExit to maintain proper state chain
69 virtual void onExit() override;
70
71 //! \brief Called each frame while this state is active.
72 //!
73 //! \param dt Delta time in seconds since last tick
74 virtual void tick(double dt) override;
75
76 //! \brief Called when this state becomes the active state after being stacked.
77 //!
78 //! This demonstrates showing UI elements when the state becomes visible again.
79 virtual void onExposed() override;
80
81 //! \brief Called when another state is pushed on top of this state.
82 //!
83 //! This demonstrates hiding UI elements when the state is no longer visible.
84 virtual void onStacked() override;
85
86 //! \brief Handles incoming text messages from the simulation.
87 //!
88 //! This method demonstrates the VR-Engage message handler pattern:
89 //! - Type-safe message casting using ASSERT_TYPE
90 //! - Accessing message data fields
91 //! - Using entity resolver for display names
92 //! - Returning HANDLED to indicate message was processed
93 //!
94 //! \param message The VR-Engage message to handle
95 //! \return HANDLED if message was processed, UNHANDLED otherwise
97
98protected:
99 //! \brief Custom Qt Quick chat window managed by this state.
100 //!
101 //! Lifecycle: Created on first onEnter, reused on subsequent enters.
102 //! The state is responsible for showing/hiding this window appropriately.
104};
105} // namespace makVre
DtEngagedState(DtPlayerStationApp &app)
Constructor.
Qt Quick window managing the chat UI.
Definition exampleQtQuick.h:187
virtual void onEnter(const DtPlayerStationStateArgs *args) override
Called when transitioning into this state.
virtual void onExposed() override
Called when this state becomes the active state after being stacked.
virtual ~DtExtendedEngagedState() override
Destructor for cleanup of state resources.
virtual void tick(double dt) override
Called each frame while this state is active.
virtual void onStacked() override
Called when another state is pushed on top of this state.
DtExampleChatWindow * myChatWindow
Custom Qt Quick chat window managed by this state.
Definition extendedEngagedState.h:103
virtual void onExit() override
Called when transitioning out of this state.
virtual DtVreMessageResult handleTextMessage(DtVreMessage *message)
Handles incoming text messages from the simulation.
DtExtendedEngagedState(DtPlayerStationApp &app)
Constructs the extended engaged state.
Top-level class representing the VR-Engage application.
Definition playerStationApp.h:163
Class for passing arguments during state transitions.
Definition playerStationState.h:45
DtPlayerStationApp & app() const
Gets a reference to the player station application.
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Defines the DtEngagedState class for gameplay control.
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Defines base classes for the VR-Engage state management system.
Defines the base class for all VREngage messages.