Shell.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: Shell.h //////////////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, September 2001
  25. // Description: Shell menu representations
  26. //
  27. // Using The Shell:
  28. // ----------------
  29. //
  30. // The Shell makes use of the window layouts to represent screens. You can push and
  31. // pop screens on the stack so that you don't have to keep track of how you got
  32. // to which screen.
  33. //
  34. // Here is what happens when you push a layout on the shell stack:
  35. // 1) The layout name is stored as a "pending push"
  36. // 2) The top of the stack has the Shutdown() method run
  37. // 3) The Shutdown() method (or other mechanisms like Update()) will call
  38. // Shell::shutdownComplete() when the shutdown process for that layout is "complete"
  39. // 4) Shell::shutdownComplete() sees the "pending push" in the shell
  40. // 5) "Pending push" layout is then loaded from disk and the pending push state is cleared
  41. // 6) The new layout is put on the top of the stack
  42. // 7) The new layout Init() method is called
  43. //
  44. // Here is what happens when you pop the top of the stack
  45. // 1) The stack sets a "pending pop" as in progress
  46. // 2) The top layout of the stack has the Shutdown() method called
  47. // 3) The Shutdown() method (or other mechanisms like Update()) will call
  48. // Shell::shutdownComplete() when the shutdown process for that layout is "complete"
  49. // 4) Shell::shutdownComplete() sees the "pending pop" in the shell
  50. // 5) The "pending pop" layout is then destroyed and removed from the stack
  51. // 6) The new top of the stack has the Init() method run
  52. //
  53. // Window Layouts and the Shell:
  54. // -----------------------------
  55. //
  56. // Window Layouts in the shell need the following functions to work property, these
  57. // can be assigned from the GUIEdit window layout tool:
  58. //
  59. // - Init() [OPTIONAL]
  60. // This is called as a result of a push or pop operation (see above for more info)
  61. // The window layout is loaded from disk and then this Init()
  62. // method is run. All shell layout Init() methods should show
  63. // the layout windows. At this point you could move windows
  64. // to starting positions, set a state that the Update() method looks at to
  65. // "animate" the windows to the desired positions.
  66. //
  67. // - Update() [OPTIONAL]
  68. // This is called once at a rate of "shellUpdateDelay" for EVERY screen on the shell
  69. // stack. It does not matter if the screen is on the top, or is hidden, or
  70. // anything, this is always called. Each update is run starting with the screen
  71. // at the top of the stack and progressing to the bottom of the stack.
  72. // States could be set in the Init() or Shutdown() methods of the layout
  73. // that the Update() looks at and reacts to appropriately if desired.
  74. //
  75. // - Shutdown() [REQUIRED]
  76. // This is called when a layout is popped off the stack, or when a new layout
  77. // is pushed on top of this one (see above for more detail on what happens
  78. // during the push/pop process). You can switch into a "shutdown" state and
  79. // animate the layout appropriately in the Update() method for the layout.
  80. // When shutdown is actually complete you should hide the all windows in
  81. // the layout and then you are REQUIRED to notify the shell by calling
  82. // the Shell::shutdownComplete() method.
  83. //
  84. // Shutdown() is also required to be able to handle the paramater "immediatePop".
  85. // If this paramater is TRUE it means that when control returns from the
  86. // shutdown function that the layout will immediately be popped off the
  87. // stack. We need to be able to handle this when in code we want to
  88. // traverse back down the stack rapidly (like when we lose connection to
  89. // an online service, we might pop all the way back to the login screen)
  90. //
  91. ///////////////////////////////////////////////////////////////////////////////////////////////////
  92. #pragma once
  93. #ifndef __SHELL_H_
  94. #define __SHELL_H_
  95. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  96. // FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
  97. class WindowLayout;
  98. class AnimateWindowManager;
  99. class GameWindow;
  100. class ShellMenuSchemeManager;
  101. enum AnimTypes;
  102. //-------------------------------------------------------------------------------------------------
  103. /** This is the interface to the shell system to load, display, and
  104. * manage screen menu shell system layouts */
  105. //-------------------------------------------------------------------------------------------------
  106. class Shell : public SubsystemInterface
  107. {
  108. public:
  109. Shell( void );
  110. ~Shell( void );
  111. // Inhertited from subsystem ====================================================================
  112. virtual void init( void );
  113. virtual void reset( void );
  114. virtual void update( void );
  115. //===============================================================================================
  116. void showShellMap(Bool useShellMap ); ///< access function to turn on and off the shell map
  117. void hide( Bool hide ); ///< show/hide all shell layouts
  118. // pseudo-stack operations for manipulating layouts
  119. void push( AsciiString filename, Bool shutdownImmediate = FALSE ); ///< load new screen on top, optionally doing an immediate shutdown
  120. void pop( void ); ///< pop top layout
  121. void popImmediate( void ); ///< pop now, don't wait for shutdown
  122. void showShell( Bool runInit = TRUE ); ///< init the top of stack
  123. void hideShell( void ); ///< shutdown the top of stack
  124. WindowLayout *top( void ); ///< return top layout
  125. void shutdownComplete( WindowLayout *layout, Bool impendingPush = FALSE ); ///< layout has completed shutdown
  126. WindowLayout *findScreenByFilename( AsciiString filename ); ///< find screen
  127. inline Bool isShellActive( void ) { return m_isShellActive; } ///< Returns true if the shell is active
  128. inline Int getScreenCount(void) { return m_screenCount; } ///< Return the current number of screens
  129. void registerWithAnimateManager( GameWindow *win, AnimTypes animType, Bool needsToFinish, UnsignedInt delayMS = 0);
  130. Bool isAnimFinished( void );
  131. void reverseAnimatewindow( void );
  132. Bool isAnimReversed( void );
  133. void loadScheme( AsciiString name );
  134. ShellMenuSchemeManager *getShellMenuSchemeManager( void ) { return m_schemeManager; }
  135. WindowLayout *getSaveLoadMenuLayout( void ); ///< create if necessary and return layout for save load menu
  136. WindowLayout *getPopupReplayLayout( void ); ///< create if necessary and return layout for replay save menu
  137. WindowLayout *getOptionsLayout( Bool create ); ///< return layout for options menu, create if necessary and we are allowed to.
  138. void destroyOptionsLayout( void ); ///< destroy the shell's options layout.
  139. protected:
  140. void linkScreen( WindowLayout *screen ); ///< link screen to list
  141. void unlinkScreen( WindowLayout *screen ); ///< remove screen from list
  142. void doPush( AsciiString layoutFile ); ///< workhorse for push action
  143. void doPop( Bool impendingPush ); ///< workhorse for pop action
  144. enum { MAX_SHELL_STACK = 16 }; ///< max simultaneous shell screens
  145. WindowLayout *m_screenStack[ MAX_SHELL_STACK ]; ///< the screen layout stack
  146. Int m_screenCount; ///< # of screens in screen stack
  147. WindowLayout *m_background; ///< The Background layout if the 3d shell isn't running
  148. Bool m_clearBackground; ///< Flag if we're going to clear the background or not
  149. Bool m_pendingPush; ///< TRUE when a push is pending
  150. Bool m_pendingPop; ///< TRUE when a pop is pending
  151. AsciiString m_pendingPushName; ///< layout name to be pushed
  152. Bool m_isShellActive; ///< TRUE when the shell is active
  153. Bool m_shellMapOn; ///< TRUE when the shell map is on
  154. AnimateWindowManager *m_animateWindowManager; ///< The animate Window Manager
  155. ShellMenuSchemeManager *m_schemeManager; ///< The Shell Scheme Manager
  156. //
  157. // we keep a pointer to this layout so that we can simply just hide/unhide this
  158. // window layout. Why you ask? Well, as the result of pressing a button to start
  159. // a save game load a super large set of operations will happen as the game
  160. // loads. One of those operations is the destruction of the menu, which although
  161. // it just destroys the windows and puts them on a destroyed list, that destroyed
  162. // list is also processed before we are out of our own window procedure.
  163. // This is a prime example why it's easier to just deal with windows by hiding and
  164. // un-hiding them rather than actually creating and destroying them.
  165. //
  166. WindowLayout *m_saveLoadMenuLayout; ///< save/load menu layout
  167. WindowLayout *m_popupReplayLayout; ///< replay save menu layout
  168. WindowLayout *m_optionsLayout; ///< options menu layout
  169. }; // end class Shell
  170. // INLINING ///////////////////////////////////////////////////////////////////////////////////////
  171. // EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
  172. extern Shell *TheShell; ///< the shell external interface
  173. #endif // __SHELL_H_