DifficultySelect.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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: DifficultySelect.cpp /////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Electronic Arts Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2002 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // created: Nov 2002
  34. //
  35. // Filename: DifficultySelect.cpp
  36. //
  37. // author: Chris Huybregts
  38. //
  39. // purpose: The popup campaign difficulty select
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. //-----------------------------------------------------------------------------
  44. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  45. //-----------------------------------------------------------------------------
  46. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  47. //-----------------------------------------------------------------------------
  48. // USER INCLUDES //////////////////////////////////////////////////////////////
  49. //-----------------------------------------------------------------------------
  50. #include "Common/UserPreferences.h"
  51. #include "GameClient/WindowLayout.h"
  52. #include "GameClient/Gadget.h"
  53. #include "GameClient/Shell.h"
  54. #include "GameClient/KeyDefs.h"
  55. #include "GameClient/GameWindowManager.h"
  56. #include "GameClient/GadgetPushButton.h"
  57. #include "GameClient/GadgetRadioButton.h"
  58. #include "GameClient/CampaignManager.h"
  59. #include "GameLogic/ScriptEngine.h"
  60. //-----------------------------------------------------------------------------
  61. // DEFINES ////////////////////////////////////////////////////////////////////
  62. //-----------------------------------------------------------------------------
  63. static GameDifficulty s_AIDiff = DIFFICULTY_NORMAL;
  64. static NameKeyType buttonOkID = NAMEKEY_INVALID;
  65. static GameWindow * buttonOk = NULL;
  66. static NameKeyType buttonCancelID = NAMEKEY_INVALID;
  67. static GameWindow * buttonCancel = NULL;
  68. static NameKeyType radioButtonEasyAIID = NAMEKEY_INVALID;
  69. static NameKeyType radioButtonMediumAIID = NAMEKEY_INVALID;
  70. static NameKeyType radioButtonHardAIID = NAMEKEY_INVALID;
  71. static GameWindow * radioButtonEasyAI = NULL;
  72. static GameWindow * radioButtonMediumAI = NULL;
  73. static GameWindow * radioButtonHardAI = NULL;
  74. void setupGameStart(AsciiString mapName, GameDifficulty diff);
  75. //-----------------------------------------------------------------------------
  76. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  77. //-----------------------------------------------------------------------------
  78. static void SetDifficultyRadioButton( void )
  79. {
  80. OptionPreferences pref;
  81. if (!TheScriptEngine)
  82. {
  83. s_AIDiff = DIFFICULTY_NORMAL;
  84. }
  85. else
  86. {
  87. switch (pref.getCampaignDifficulty())
  88. {
  89. case DIFFICULTY_EASY:
  90. {
  91. GadgetRadioSetSelection(radioButtonEasyAI, FALSE);
  92. s_AIDiff = DIFFICULTY_EASY;
  93. break;
  94. }
  95. case DIFFICULTY_NORMAL:
  96. {
  97. GadgetRadioSetSelection(radioButtonMediumAI, FALSE);
  98. s_AIDiff = DIFFICULTY_NORMAL;
  99. break;
  100. }
  101. case DIFFICULTY_HARD:
  102. {
  103. GadgetRadioSetSelection(radioButtonHardAI, FALSE);
  104. s_AIDiff = DIFFICULTY_HARD;
  105. break;
  106. }
  107. default:
  108. {
  109. DEBUG_CRASH(("unrecognized difficulty level in the script engine"));
  110. }
  111. }
  112. } // if (TheScriptEngine)
  113. }
  114. void DifficultySelectInit( WindowLayout *layout, void *userData )
  115. {
  116. AsciiString parentName( "DifficultySelect.wnd:DifficultySelectParent" );
  117. NameKeyType parentID = TheNameKeyGenerator->nameToKey( parentName );
  118. GameWindow *parent = TheWindowManager->winGetWindowFromId( NULL, parentID );
  119. buttonOkID = TheNameKeyGenerator->nameToKey( "DifficultySelect.wnd:ButtonOk" );
  120. buttonOk = TheWindowManager->winGetWindowFromId( parent, buttonOkID );
  121. buttonCancelID = TheNameKeyGenerator->nameToKey( "DifficultySelect.wnd:ButtonCancel" );
  122. buttonCancel = TheWindowManager->winGetWindowFromId( parent, buttonCancelID );
  123. radioButtonEasyAIID = TheNameKeyGenerator->nameToKey( AsciiString("DifficultySelect.wnd:RadioButtonEasy") );
  124. radioButtonEasyAI = TheWindowManager->winGetWindowFromId( parent, radioButtonEasyAIID );
  125. radioButtonMediumAIID = TheNameKeyGenerator->nameToKey( AsciiString("DifficultySelect.wnd:RadioButtonMedium") );
  126. radioButtonMediumAI = TheWindowManager->winGetWindowFromId( parent, radioButtonMediumAIID );
  127. radioButtonHardAIID = TheNameKeyGenerator->nameToKey( AsciiString("DifficultySelect.wnd:RadioButtonHard") );
  128. radioButtonHardAI = TheWindowManager->winGetWindowFromId( parent, radioButtonHardAIID );
  129. s_AIDiff = DIFFICULTY_NORMAL;
  130. SetDifficultyRadioButton();
  131. // set keyboard focus to main parent
  132. // AsciiString parentName( "SkirmishMapSelectMenu.wnd:SkrimishMapSelectMenuParent" );
  133. // NameKeyType parentID = TheNameKeyGenerator->nameToKey( parentName );
  134. // parent = TheWindowManager->winGetWindowFromId( NULL, parentID );
  135. //
  136. // TheWindowManager->winSetFocus( parent );
  137. //
  138. parent->winBringToTop();
  139. TheWindowManager->winSetModal(parent);
  140. } // end SkirmishMapSelectMenuInit
  141. //-------------------------------------------------------------------------------------------------
  142. /** Map select menu input callback */
  143. //-------------------------------------------------------------------------------------------------
  144. WindowMsgHandledType DifficultySelectInput( GameWindow *window, UnsignedInt msg,
  145. WindowMsgData mData1, WindowMsgData mData2 )
  146. {
  147. // switch( msg )
  148. // {
  149. //
  150. // // --------------------------------------------------------------------------------------------
  151. // case GWM_CHAR:
  152. // {
  153. // UnsignedByte key = mData1;
  154. // UnsignedByte state = mData2;
  155. //
  156. // switch( key )
  157. // {
  158. //
  159. // // ----------------------------------------------------------------------------------------
  160. // case KEY_ESC:
  161. // {
  162. //
  163. // //
  164. // // send a simulated selected event to the parent window of the
  165. // // back/exit button
  166. // //
  167. // if( BitTest( state, KEY_STATE_UP ) )
  168. // {
  169. // AsciiString buttonName( "SkirmishMapSelectMenu.wnd:ButtonBack" );
  170. // NameKeyType buttonID = TheNameKeyGenerator->nameToKey( buttonName );
  171. // GameWindow *button = TheWindowManager->winGetWindowFromId( window, buttonID );
  172. //
  173. // TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
  174. // (WindowMsgData)button, buttonID );
  175. //
  176. // } // end if
  177. //
  178. // // don't let key fall through anywhere else
  179. // return MSG_HANDLED;
  180. //
  181. // } // end escape
  182. //
  183. // } // end switch( key )
  184. //
  185. // } // end char
  186. //
  187. // } // end switch( msg )
  188. return MSG_IGNORED;
  189. } // end SkirmishMapSelectMenuInput
  190. //-------------------------------------------------------------------------------------------------
  191. /** MapSelect menu window system callback */
  192. //-------------------------------------------------------------------------------------------------
  193. WindowMsgHandledType DifficultySelectSystem( GameWindow *window, UnsignedInt msg,
  194. WindowMsgData mData1, WindowMsgData mData2 )
  195. {
  196. switch( msg )
  197. {
  198. // --------------------------------------------------------------------------------------------
  199. case GWM_CREATE:
  200. {
  201. break;
  202. } // end create
  203. //---------------------------------------------------------------------------------------------
  204. case GWM_DESTROY:
  205. {
  206. break;
  207. } // end case
  208. // --------------------------------------------------------------------------------------------
  209. case GWM_INPUT_FOCUS:
  210. {
  211. // if we're givin the opportunity to take the keyboard focus we must say we want it
  212. if( mData1 == TRUE )
  213. *(Bool *)mData2 = TRUE;
  214. return MSG_HANDLED;
  215. } // end input
  216. //---------------------------------------------------------------------------------------------
  217. case GBM_SELECTED:
  218. {
  219. // this isn't fixed yet
  220. GameWindow *control = (GameWindow *)mData1;
  221. Int controlID = control->winGetWindowId();
  222. if ( controlID == buttonOkID )
  223. {
  224. OptionPreferences pref;
  225. pref.setCampaignDifficulty(s_AIDiff);
  226. pref.write();
  227. //TheScriptEngine->setGlobalDifficulty(s_AIDiff); // CANNOT DO THIS! REPLAYS WILL BREAK!
  228. WindowLayout *layout = window->winGetLayout();
  229. layout->destroyWindows();
  230. layout->deleteInstance();
  231. setupGameStart(TheCampaignManager->getCurrentMap(), s_AIDiff);
  232. // start the game
  233. }
  234. else if ( controlID == buttonCancelID )
  235. {
  236. TheCampaignManager->setCampaign( AsciiString::TheEmptyString );
  237. TheWindowManager->winUnsetModal(window);
  238. WindowLayout *layout = window->winGetLayout();
  239. layout->destroyWindows();
  240. layout->deleteInstance();
  241. }
  242. else if ( controlID == radioButtonEasyAIID )
  243. {
  244. s_AIDiff = DIFFICULTY_EASY;
  245. }
  246. else if ( controlID == radioButtonMediumAIID )
  247. {
  248. s_AIDiff = DIFFICULTY_NORMAL;
  249. }
  250. else if ( controlID == radioButtonHardAIID )
  251. {
  252. s_AIDiff = DIFFICULTY_HARD;
  253. }
  254. break;
  255. } // end selected
  256. default:
  257. return MSG_IGNORED;
  258. } // end switch
  259. return MSG_HANDLED;
  260. }
  261. //-----------------------------------------------------------------------------
  262. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  263. //-----------------------------------------------------------------------------