SinglePlayerMenu.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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: SinglePlayerMenu.cpp /////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, October 2001
  25. // Description: Single Player Menus
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/GameEngine.h"
  30. #include "GameClient/AnimateWindowManager.h"
  31. #include "GameClient/WindowLayout.h"
  32. #include "GameClient/Gadget.h"
  33. #include "GameClient/Shell.h"
  34. #include "GameClient/KeyDefs.h"
  35. #include "GameClient/GameWindowManager.h"
  36. static Bool isShuttingDown = false;
  37. static Bool buttonPushed = false;
  38. //-------------------------------------------------------------------------------------------------
  39. /** This is called when a shutdown is complete for this menu */
  40. //-------------------------------------------------------------------------------------------------
  41. static void shutdownComplete( WindowLayout *layout )
  42. {
  43. isShuttingDown = false;
  44. // hide the layout
  45. layout->hide( TRUE );
  46. // our shutdown is complete
  47. TheShell->shutdownComplete( layout );
  48. } // end if
  49. //-------------------------------------------------------------------------------------------------
  50. /** Initialize the single player menu */
  51. //-------------------------------------------------------------------------------------------------
  52. void SinglePlayerMenuInit( WindowLayout *layout, void *userData )
  53. {
  54. TheShell->showShellMap(TRUE);
  55. buttonPushed = false;
  56. isShuttingDown = false;
  57. // show menu
  58. layout->hide( FALSE );
  59. // set keyboard focus to main parent
  60. AsciiString parentName( "SinglePlayerMenu.wnd:SinglePlayerMenuParent" );
  61. NameKeyType parentID = TheNameKeyGenerator->nameToKey( parentName );
  62. GameWindow *parent = TheWindowManager->winGetWindowFromId( NULL, parentID );
  63. TheWindowManager->winSetFocus( parent );
  64. NameKeyType buttonNewID = TheNameKeyGenerator->nameToKey( AsciiString("SinglePlayerMenu.wnd:ButtonNew") );
  65. GameWindow *buttonNew = TheWindowManager->winGetWindowFromId( NULL, buttonNewID );
  66. TheShell->registerWithAnimateManager(buttonNew, WIN_ANIMATION_SLIDE_LEFT, TRUE,1);
  67. NameKeyType buttonLoadID = TheNameKeyGenerator->nameToKey( AsciiString("SinglePlayerMenu.wnd:ButtonLoad") );
  68. GameWindow *buttonLoad = TheWindowManager->winGetWindowFromId( NULL, buttonLoadID );
  69. TheShell->registerWithAnimateManager(buttonLoad, WIN_ANIMATION_SLIDE_LEFT, TRUE,200);
  70. NameKeyType buttonBackID = TheNameKeyGenerator->nameToKey( AsciiString("SinglePlayerMenu.wnd:ButtonBack") );
  71. GameWindow *buttonBack = TheWindowManager->winGetWindowFromId( NULL, buttonBackID );
  72. TheShell->registerWithAnimateManager(buttonBack, WIN_ANIMATION_SLIDE_RIGHT, TRUE,1);
  73. //TheShell->registerWithAnimateManager(parent, WIN_ANIMATION_SLIDE_TOP, TRUE);
  74. } // end SinglePlayerMenuInit
  75. //-------------------------------------------------------------------------------------------------
  76. /** single player menu shutdown method */
  77. //-------------------------------------------------------------------------------------------------
  78. void SinglePlayerMenuShutdown( WindowLayout *layout, void *userData )
  79. {
  80. isShuttingDown = true;
  81. // if we are shutting down for an immediate pop, skip the animations
  82. Bool popImmediate = *(Bool *)userData;
  83. if( popImmediate )
  84. {
  85. shutdownComplete( layout );
  86. return;
  87. } //end if
  88. TheShell->reverseAnimatewindow();
  89. } // end SinglePlayerMenuShutdown
  90. //-------------------------------------------------------------------------------------------------
  91. /** single player menu update method */
  92. //-------------------------------------------------------------------------------------------------
  93. void SinglePlayerMenuUpdate( WindowLayout *layout, void *userData )
  94. {
  95. // We'll only be successful if we've requested to
  96. if(isShuttingDown && TheShell->isAnimFinished())
  97. shutdownComplete(layout);
  98. } // end SinglePlayerMenuUpdate
  99. //-------------------------------------------------------------------------------------------------
  100. /** SinglePlayer menu input callback */
  101. //-------------------------------------------------------------------------------------------------
  102. WindowMsgHandledType SinglePlayerMenuInput( GameWindow *window, UnsignedInt msg,
  103. WindowMsgData mData1, WindowMsgData mData2 )
  104. {
  105. switch( msg )
  106. {
  107. // --------------------------------------------------------------------------------------------
  108. case GWM_CHAR:
  109. {
  110. UnsignedByte key = mData1;
  111. UnsignedByte state = mData2;
  112. if (buttonPushed)
  113. break;
  114. switch( key )
  115. {
  116. // ----------------------------------------------------------------------------------------
  117. case KEY_ESC:
  118. {
  119. //
  120. // send a simulated selected event to the parent window of the
  121. // back/exit button
  122. //
  123. if( BitTest( state, KEY_STATE_UP ) )
  124. {
  125. AsciiString buttonName( "SinglePlayerMenu.wnd:ButtonBack" );
  126. NameKeyType buttonID = TheNameKeyGenerator->nameToKey( buttonName );
  127. GameWindow *button = TheWindowManager->winGetWindowFromId( window, buttonID );
  128. TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
  129. (WindowMsgData)button, buttonID );
  130. } // end if
  131. // don't let key fall through anywhere else
  132. return MSG_HANDLED;
  133. } // end escape
  134. } // end switch( key )
  135. } // end char
  136. } // end switch( msg )
  137. return MSG_IGNORED;
  138. } // end SinglePlayerMenuInput
  139. //-------------------------------------------------------------------------------------------------
  140. /** single player menu window system callback */
  141. //-------------------------------------------------------------------------------------------------
  142. WindowMsgHandledType SinglePlayerMenuSystem( GameWindow *window, UnsignedInt msg,
  143. WindowMsgData mData1, WindowMsgData mData2 )
  144. {
  145. static NameKeyType buttonNew = NAMEKEY_INVALID;
  146. static NameKeyType buttonLoad = NAMEKEY_INVALID;
  147. static NameKeyType buttonBack = NAMEKEY_INVALID;
  148. switch( msg )
  149. {
  150. // --------------------------------------------------------------------------------------------
  151. case GWM_CREATE:
  152. {
  153. // get ids for our children controls
  154. buttonNew = TheNameKeyGenerator->nameToKey( AsciiString("SinglePlayerMenu.wnd:ButtonNew") );
  155. buttonLoad = TheNameKeyGenerator->nameToKey( AsciiString("SinglePlayerMenu.wnd:ButtonLoad") );
  156. buttonBack = TheNameKeyGenerator->nameToKey( AsciiString("SinglePlayerMenu.wnd:ButtonBack") );
  157. break;
  158. } // end create
  159. //---------------------------------------------------------------------------------------------
  160. case GWM_DESTROY:
  161. {
  162. break;
  163. } // end case
  164. // --------------------------------------------------------------------------------------------
  165. case GWM_INPUT_FOCUS:
  166. {
  167. // if we're givin the opportunity to take the keyboard focus we must say we want it
  168. if( mData1 == TRUE )
  169. *(Bool *)mData2 = TRUE;
  170. return MSG_HANDLED;
  171. } // end input
  172. //---------------------------------------------------------------------------------------------
  173. case GBM_SELECTED:
  174. {
  175. GameWindow *control = (GameWindow *)mData1;
  176. Int controlID = control->winGetWindowId();
  177. if (buttonPushed)
  178. break;
  179. if( controlID == buttonNew )
  180. {
  181. // open up the map select menu
  182. TheShell->push( AsciiString( "Menus/MapSelectMenu.wnd" ) );
  183. buttonPushed = true;
  184. } // end if
  185. else if( controlID == buttonLoad )
  186. {
  187. } // end else if
  188. else if( controlID == buttonBack )
  189. {
  190. // thou art directed to return to thy known solar system immediately!
  191. TheShell->pop();
  192. buttonPushed = true;
  193. } // end else if
  194. break;
  195. } // end selected
  196. default:
  197. return MSG_IGNORED;
  198. } // end switch
  199. return MSG_HANDLED;
  200. } // end SinglePlayerMenuSystem