PopupSaveLoad.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  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: PopupSaveLoad.cpp /////////////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Electronic Arts Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2002 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Project: RTS3
  34. //
  35. // File name: PopupSaveLoad.cpp
  36. //
  37. // Created: Chris Brue, June 2002
  38. //
  39. // Desc: the Save/Load window control
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  44. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  45. #include "Common/GameEngine.h"
  46. #include "Common/GameState.h"
  47. #include "Common/MessageStream.h"
  48. #include "GameClient/CampaignManager.h"
  49. #include "GameClient/GadgetListBox.h"
  50. #include "GameClient/GadgetTextEntry.h"
  51. #include "GameClient/GameText.h"
  52. #include "GameClient/GameWindowManager.h"
  53. #include "GameClient/GUICallbacks.h"
  54. #include "GameClient/Shell.h"
  55. #include "GameLogic/GameLogic.h"
  56. #include "GameClient/GameWindowTransitions.h"
  57. // PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
  58. static NameKeyType buttonBackKey = NAMEKEY_INVALID;
  59. static NameKeyType buttonSaveKey = NAMEKEY_INVALID;
  60. static NameKeyType buttonLoadKey = NAMEKEY_INVALID;
  61. static NameKeyType buttonDeleteKey = NAMEKEY_INVALID;
  62. static NameKeyType listboxGamesKey = NAMEKEY_INVALID;
  63. static NameKeyType buttonOverwriteCancel = NAMEKEY_INVALID;
  64. static NameKeyType buttonOverwriteConfirm = NAMEKEY_INVALID;
  65. static NameKeyType buttonLoadCancel = NAMEKEY_INVALID;
  66. static NameKeyType buttonLoadConfirm = NAMEKEY_INVALID;
  67. static NameKeyType buttonSaveDescCancel = NAMEKEY_INVALID;
  68. static NameKeyType buttonSaveDescConfirm = NAMEKEY_INVALID;
  69. static NameKeyType buttonDeleteConfirm = NAMEKEY_INVALID;
  70. static NameKeyType buttonDeleteCancel = NAMEKEY_INVALID;
  71. static GameWindow *buttonFrame = NULL;
  72. static GameWindow *overwriteConfirm = NULL;
  73. static GameWindow *loadConfirm = NULL;
  74. static GameWindow *saveDesc = NULL;
  75. static GameWindow *listboxGames = NULL;
  76. static GameWindow *editDesc = NULL;
  77. static GameWindow *deleteConfirm = NULL;
  78. static GameWindow *parent = NULL;
  79. static SaveLoadLayoutType currentLayoutType = SLLT_INVALID;
  80. static Bool isPopup = FALSE;
  81. static Int initialGadgetDelay = 2;
  82. static Bool justEntered = FALSE;
  83. static Bool isShuttingDown = false;
  84. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////////////////////////
  85. extern Bool DontShowMainMenu; //KRIS
  86. extern Bool ReplayWasPressed;
  87. // ------------------------------------------------------------------------------------------------
  88. /** Given the current layout and selection in the game listbox, update the main save/load
  89. * menu buttons to be enabled or disabled */
  90. // ------------------------------------------------------------------------------------------------
  91. static void updateMenuActions( void )
  92. {
  93. // for loading only, disable the save button, otherwise enable it
  94. GameWindow *saveButton = TheWindowManager->winGetWindowFromId( NULL, buttonSaveKey );
  95. DEBUG_ASSERTCRASH( saveButton, ("SaveLoadMenuInit: Unable to find save button\n") );
  96. if( currentLayoutType == SLLT_LOAD_ONLY )
  97. saveButton->winEnable( FALSE );
  98. else
  99. saveButton->winEnable( TRUE );
  100. // get the games listbox
  101. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( NULL, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  102. // if something with a game file is selected we can use load and delete
  103. Int selected;
  104. GadgetListBoxGetSelected( listboxGames, &selected );
  105. AvailableGameInfo *selectedGameInfo;
  106. selectedGameInfo = (AvailableGameInfo *)GadgetListBoxGetItemData( listboxGames, selected );
  107. GameWindow *buttonLoad = TheWindowManager->winGetWindowFromId( NULL, buttonLoadKey );
  108. buttonLoad->winEnable( selectedGameInfo != NULL );
  109. GameWindow *buttonDelete = TheWindowManager->winGetWindowFromId( NULL, buttonDeleteKey );
  110. buttonDelete->winEnable( selectedGameInfo != NULL );
  111. } // end updateMenuActions
  112. //-------------------------------------------------------------------------------------------------
  113. /** Initialize the SaveLoad menu */
  114. //-------------------------------------------------------------------------------------------------
  115. void SaveLoadMenuInit( WindowLayout *layout, void *userData )
  116. {
  117. // set default behavior for this menu
  118. currentLayoutType = SLLT_SAVE_AND_LOAD;
  119. isPopup = TRUE;
  120. // get layout type if present
  121. if( userData )
  122. currentLayoutType = *((SaveLoadLayoutType *)userData);
  123. // get ids for our children controls
  124. buttonBackKey = NAMEKEY( "PopupSaveLoad.wnd:ButtonBack" );
  125. buttonSaveKey = NAMEKEY( "PopupSaveLoad.wnd:ButtonSave" );
  126. buttonLoadKey = NAMEKEY( "PopupSaveLoad.wnd:ButtonLoad" );
  127. buttonDeleteKey = NAMEKEY( "PopupSaveLoad.wnd:ButtonDelete" );
  128. listboxGamesKey = NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" );
  129. buttonOverwriteCancel = NAMEKEY( "PopupSaveLoad.wnd:ButtonOverwriteCancel" );
  130. buttonOverwriteConfirm = NAMEKEY( "PopupSaveLoad.wnd:ButtonOverwriteConfirm" );
  131. buttonLoadCancel = NAMEKEY( "PopupSaveLoad.wnd:ButtonLoadCancel" );
  132. buttonLoadConfirm = NAMEKEY( "PopupSaveLoad.wnd:ButtonLoadConfirm" );
  133. buttonSaveDescCancel = NAMEKEY( "PopupSaveLoad.wnd:ButtonSaveDescCancel" );
  134. buttonSaveDescConfirm = NAMEKEY( "PopupSaveLoad.wnd:ButtonSaveDescConfirm" );
  135. buttonDeleteConfirm = NAMEKEY( "PopupSaveLoad.wnd:ButtonDeleteConfirm" );
  136. buttonDeleteCancel = NAMEKEY( "PopupSaveLoad.wnd:ButtonDeleteCancel" );
  137. //set keyboard focus to main parent and set modal
  138. NameKeyType parentID = TheNameKeyGenerator->nameToKey("PopupSaveLoad.wnd:SaveLoadMenu");
  139. parent = TheWindowManager->winGetWindowFromId( NULL, parentID );
  140. TheWindowManager->winSetFocus( parent );
  141. TheWindowManager->winSetModal( parent );
  142. // enable the menu action buttons
  143. buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  144. buttonFrame->winEnable( TRUE );
  145. // get confirmation windows and hide
  146. overwriteConfirm = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:OverwriteConfirmParent" ) );
  147. overwriteConfirm->winHide( TRUE );
  148. loadConfirm = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:LoadConfirmParent" ) );
  149. loadConfirm->winHide( TRUE );
  150. saveDesc = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:SaveDescParent" ) );
  151. saveDesc->winHide( TRUE );
  152. deleteConfirm = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:DeleteConfirmParent" ) );
  153. editDesc = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:EntryDesc" ) );
  154. // get the listbox that will have the save games in it
  155. listboxGames = TheWindowManager->winGetWindowFromId( NULL, listboxGamesKey );
  156. DEBUG_ASSERTCRASH( listboxGames != NULL, ("SaveLoadMenuInit - Unable to find games listbox\n") );
  157. // populate the listbox with the save games on disk
  158. TheGameState->populateSaveGameListbox( listboxGames, currentLayoutType );
  159. // update the availability of the menu buttons
  160. updateMenuActions();
  161. } // end SaveLoadMenuInit
  162. //-------------------------------------------------------------------------------------------------
  163. /** Initialize the SaveLoad menu */
  164. //-------------------------------------------------------------------------------------------------
  165. void SaveLoadMenuFullScreenInit( WindowLayout *layout, void *userData )
  166. {
  167. TheShell->showShellMap(TRUE);
  168. isPopup = FALSE;
  169. // set default behavior for this menu
  170. currentLayoutType = SLLT_LOAD_ONLY;
  171. // get layout type if present
  172. if( userData )
  173. currentLayoutType = *((SaveLoadLayoutType *)userData);
  174. // get ids for our children controls
  175. buttonBackKey = NAMEKEY( "SaveLoad.wnd:ButtonBack" );
  176. buttonSaveKey = NAMEKEY( "SaveLoad.wnd:ButtonSave" );
  177. buttonLoadKey = NAMEKEY( "SaveLoad.wnd:ButtonLoad" );
  178. buttonDeleteKey = NAMEKEY( "SaveLoad.wnd:ButtonDelete" );
  179. listboxGamesKey = NAMEKEY( "SaveLoad.wnd:ListboxGames" );
  180. buttonOverwriteCancel = NAMEKEY( "SaveLoad.wnd:ButtonOverwriteCancel" );
  181. buttonOverwriteConfirm = NAMEKEY( "SaveLoad.wnd:ButtonOverwriteConfirm" );
  182. buttonLoadCancel = NAMEKEY( "SaveLoad.wnd:ButtonLoadCancel" );
  183. buttonLoadConfirm = NAMEKEY( "SaveLoad.wnd:ButtonLoadConfirm" );
  184. buttonSaveDescCancel = NAMEKEY( "SaveLoad.wnd:ButtonSaveDescCancel" );
  185. buttonSaveDescConfirm = NAMEKEY( "SaveLoad.wnd:ButtonSaveDescConfirm" );
  186. buttonDeleteConfirm = NAMEKEY( "SaveLoad.wnd:ButtonDeleteConfirm" );
  187. buttonDeleteCancel = NAMEKEY( "SaveLoad.wnd:ButtonDeleteCancel" );
  188. //set keyboard focus to main parent and set modal
  189. NameKeyType parentID = TheNameKeyGenerator->nameToKey("SaveLoad.wnd:SaveLoadMenu");
  190. parent = TheWindowManager->winGetWindowFromId( NULL, parentID );
  191. TheWindowManager->winSetFocus( parent );
  192. // TheWindowManager->winSetModal( parent );
  193. // enable the menu action buttons
  194. buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "SaveLoad.wnd:MenuButtonFrame" ) );
  195. buttonFrame->winEnable( TRUE );
  196. // get confirmation windows and hide
  197. overwriteConfirm = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "SaveLoad.wnd:OverwriteConfirmParent" ) );
  198. overwriteConfirm->winHide( TRUE );
  199. loadConfirm = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "SaveLoad.wnd:LoadConfirmParent" ) );
  200. loadConfirm->winHide( TRUE );
  201. saveDesc = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "SaveLoad.wnd:SaveDescParent" ) );
  202. saveDesc->winHide( TRUE );
  203. editDesc = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "SaveLoad.wnd:EntryDesc" ) );
  204. deleteConfirm = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "SaveLoad.wnd:DeleteConfirmParent" ) );
  205. // get the listbox that will have the save games in it
  206. listboxGames = TheWindowManager->winGetWindowFromId( NULL, listboxGamesKey );
  207. DEBUG_ASSERTCRASH( listboxGames != NULL, ("SaveLoadMenuInit - Unable to find games listbox\n") );
  208. // populate the listbox with the save games on disk
  209. TheGameState->populateSaveGameListbox( listboxGames, currentLayoutType );
  210. // update the availability of the menu buttons
  211. updateMenuActions();
  212. layout->hide(FALSE);
  213. justEntered = TRUE;
  214. initialGadgetDelay = 2;
  215. if(parent)
  216. parent->winHide(TRUE);
  217. isShuttingDown = false;
  218. } // end SaveLoadMenuInit
  219. //-------------------------------------------------------------------------------------------------
  220. /** SaveLoad menu shutdown method */
  221. //-------------------------------------------------------------------------------------------------
  222. void SaveLoadMenuShutdown( WindowLayout *layout, void *userData )
  223. {
  224. Bool popImmediate = *(Bool *)userData;
  225. if( popImmediate )
  226. {
  227. layout->hide( TRUE );
  228. TheShell->shutdownComplete( layout );
  229. return;
  230. } //end if
  231. // our shutdown is complete
  232. TheTransitionHandler->reverse("SaveLoadMenuFade");
  233. isShuttingDown = TRUE;
  234. } // end SaveLoadMenuShutdown
  235. //-------------------------------------------------------------------------------------------------
  236. /** SaveLoad menu update method */
  237. //-------------------------------------------------------------------------------------------------
  238. void SaveLoadMenuUpdate( WindowLayout *layout, void *userData )
  239. {
  240. if(DontShowMainMenu && justEntered)
  241. justEntered = FALSE;
  242. if(ReplayWasPressed && justEntered)
  243. {
  244. justEntered = FALSE;
  245. ReplayWasPressed = FALSE;
  246. }
  247. if(justEntered)
  248. {
  249. if(initialGadgetDelay == 1)
  250. {
  251. TheTransitionHandler->remove("MainMenuDefaultMenuLogoFade");
  252. TheTransitionHandler->setGroup("SaveLoadMenuFade");
  253. initialGadgetDelay = 2;
  254. justEntered = FALSE;
  255. }
  256. else
  257. initialGadgetDelay--;
  258. }
  259. if(isShuttingDown && TheShell->isAnimFinished()&& TheTransitionHandler->isFinished())
  260. TheShell->shutdownComplete( layout );
  261. } // end SaveLoadMenuUpdate
  262. // ------------------------------------------------------------------------------------------------
  263. // ------------------------------------------------------------------------------------------------
  264. WindowMsgHandledType SaveLoadMenuInput( GameWindow *window, UnsignedInt msg, WindowMsgData mData1, WindowMsgData mData2 )
  265. {
  266. switch( msg )
  267. {
  268. // --------------------------------------------------------------------------------------------
  269. case GWM_CHAR:
  270. {
  271. UnsignedByte key = mData1;
  272. UnsignedByte state = mData2;
  273. switch( key )
  274. {
  275. // ----------------------------------------------------------------------------------------
  276. case KEY_ESC:
  277. {
  278. //
  279. // send a simulated selected event to the parent window of the
  280. // back/exit button
  281. //
  282. if( BitTest( state, KEY_STATE_UP ) )
  283. {
  284. GameWindow *button = TheWindowManager->winGetWindowFromId( parent, buttonBackKey );
  285. TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
  286. (WindowMsgData)button, buttonBackKey );
  287. } // end if
  288. // don't let key fall through anywhere else
  289. return MSG_HANDLED;
  290. } // end escape
  291. } // end switch( key )
  292. } // end char
  293. } // end switch( msg )
  294. return MSG_IGNORED;
  295. }
  296. // ------------------------------------------------------------------------------------------------
  297. /** Get the file info of the selected savegame file in the listbox */
  298. // ------------------------------------------------------------------------------------------------
  299. static AvailableGameInfo *getSelectedSaveFileInfo( GameWindow *window )
  300. {
  301. // get the listbox
  302. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( window, listboxGamesKey );
  303. DEBUG_ASSERTCRASH( listboxGames != NULL, ("SaveLoadMenuInit - Unable to find games listbox\n") );
  304. // which item is selected
  305. Int selected;
  306. GadgetListBoxGetSelected( listboxGames, &selected );
  307. // get the item data of the selection
  308. AvailableGameInfo *selectedGameInfo;
  309. selectedGameInfo = (AvailableGameInfo *)GadgetListBoxGetItemData( listboxGames, selected );
  310. return selectedGameInfo;
  311. } // end getSelectedSaveFileInfo
  312. // ---------------------------------------------------con------------------------------------------
  313. // ------------------------------------------------------------------------------------------------ // close the save/load menu
  314. static void doLoadGame( void )
  315. {
  316. // get listbox of games
  317. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  318. DEBUG_ASSERTCRASH( listboxGames, ("doLoadGame: Unable to find game listbox\n") );
  319. // get selected game info
  320. AvailableGameInfo *selectedGameInfo = getSelectedSaveFileInfo( listboxGames );
  321. DEBUG_ASSERTCRASH( selectedGameInfo, ("doLoadGame: No selected game info found\n") );
  322. // when loading a game we also close the quit/esc menu for the user when in-game
  323. if( TheShell->isShellActive() == FALSE )
  324. {
  325. destroyQuitMenu();
  326. // ToggleQuitMenu();
  327. // TheTransitionHandler->remove("QuitNoSave");
  328. // TheTransitionHandler->remove("QuitFull");
  329. }
  330. else
  331. {
  332. TheTransitionHandler->remove("MainMenuLoadReplayMenu");
  333. TheTransitionHandler->remove("MainMenuLoadReplayMenuBack");
  334. TheGameLogic->prepareNewGame( GAME_SINGLE_PLAYER, DIFFICULTY_NORMAL, 0 );
  335. }
  336. //
  337. // load game, note the *copy* of the selected game info is passed here because we will
  338. // loose these allocated user data pointers attached as listbox item data when the
  339. // engine resets
  340. //
  341. if (TheGameState->loadGame( *selectedGameInfo ) != SC_OK)
  342. {
  343. if (TheGameLogic->isInGame())
  344. TheGameLogic->clearGameData( FALSE );
  345. TheGameEngine->reset();
  346. TheShell->showShell(TRUE);
  347. }
  348. } // end doLoadGame
  349. // ------------------------------------------------------------------------------------------------
  350. /** Close the save/load menu */
  351. // ------------------------------------------------------------------------------------------------
  352. static void closeSaveMenu( GameWindow *window )
  353. {
  354. if(isPopup)
  355. {
  356. WindowLayout *saveLoadMenuLayout = window->winGetLayout();
  357. if( saveLoadMenuLayout )
  358. saveLoadMenuLayout->hide( TRUE );
  359. }
  360. else
  361. TheShell->hideShell();
  362. } // end closeSaveMenu
  363. // ------------------------------------------------------------------------------------------------
  364. // ------------------------------------------------------------------------------------------------
  365. static void setEditDescription( GameWindow *editControl )
  366. {
  367. UnicodeString defaultDesc;
  368. Campaign *campaign = TheCampaignManager->getCurrentCampaign();
  369. //
  370. // if we have a campaign we will use a default description that describes the
  371. // location and map in the campaign nicely, otherwise we will default to just
  372. // the map name (which is really only used in debug)
  373. //
  374. if( campaign )
  375. defaultDesc.format( L"%s %d",
  376. TheGameText->fetch( campaign->m_campaignNameLabel ).str(),
  377. TheCampaignManager->getCurrentMissionNumber() + 1 );
  378. else
  379. {
  380. const char *mapName = TheGlobalData->m_mapName.reverseFind( '\\' );
  381. if( mapName )
  382. defaultDesc.format( L"%S", mapName + 1 );
  383. else
  384. defaultDesc.format( L"%S", TheGlobalData->m_mapName.str() );
  385. } // end else
  386. // set into edit control
  387. GadgetTextEntrySetText( editControl, defaultDesc );
  388. } // end setEditDescription
  389. //----------------------------------------------------------------------------------------------
  390. static void processLoadButtonPress(GameWindow *window)
  391. {
  392. // get the filename of the selected savegame in the listbox
  393. AvailableGameInfo *selectedGameInfo = getSelectedSaveFileInfo( window );
  394. if( selectedGameInfo )
  395. {
  396. //
  397. // if we're in the shell we do not need a confirmation dialog that states we will
  398. // lose the current loaded game data cause we're not in a game
  399. //
  400. if( TheShell->isShellActive() == TRUE )
  401. {
  402. // just close the menu and do the load game logic
  403. closeSaveMenu( window );
  404. doLoadGame();
  405. } // end if
  406. else
  407. {
  408. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  409. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  410. //GameWindow *loadConfirm = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:LoadConfirmParent" ) );
  411. // disable listbox and buttons
  412. listboxGames->winEnable( FALSE );
  413. buttonFrame->winEnable( FALSE );
  414. // show the load confirm dialog
  415. loadConfirm->winHide( FALSE );
  416. } // end else
  417. } // end if
  418. }
  419. //-------------------------------------------------------------------------------------------------
  420. /** SaveLoad menu system callback */
  421. //-------------------------------------------------------------------------------------------------
  422. WindowMsgHandledType SaveLoadMenuSystem( GameWindow *window, UnsignedInt msg,
  423. WindowMsgData mData1, WindowMsgData mData2 )
  424. {
  425. switch( msg )
  426. {
  427. // --------------------------------------------------------------------------------------------
  428. case GWM_CREATE:
  429. {
  430. break;
  431. } // end create
  432. //---------------------------------------------------------------------------------------------
  433. case GWM_DESTROY:
  434. {
  435. break;
  436. } // end case
  437. //----------------------------------------------------------------------------------------------
  438. case GWM_INPUT_FOCUS:
  439. {
  440. // if we're givin the opportunity to take the keyboard focus we must say we want it
  441. if( mData1 == TRUE )
  442. *(Bool *)mData2 = TRUE;
  443. break;
  444. } // end input
  445. //----------------------------------------------------------------------------------------------
  446. case GLM_DOUBLE_CLICKED:
  447. {
  448. GameWindow *control = (GameWindow *)mData1;
  449. GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( window, listboxGamesKey );
  450. DEBUG_ASSERTCRASH( listboxGames != NULL, ("SaveLoadMenuInit - Unable to find games listbox\n") );
  451. if (listboxGames != NULL) {
  452. int rowSelected = mData2;
  453. GadgetListBoxSetSelected(listboxGames, rowSelected);
  454. if (control == listboxGames)
  455. {
  456. processLoadButtonPress(window);
  457. }
  458. }
  459. break;
  460. }
  461. // --------------------------------------------------------------------------------------------
  462. case GLM_SELECTED:
  463. {
  464. GameWindow *control = (GameWindow *)mData1;
  465. GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( window, listboxGamesKey );
  466. DEBUG_ASSERTCRASH( listboxGames != NULL, ("SaveLoadMenuInit - Unable to find games listbox\n") );
  467. //
  468. // handle games listbox, when certain items are selected in the listbox only some
  469. // commands are available
  470. //
  471. if( control == listboxGames )
  472. updateMenuActions();
  473. break;
  474. } // end selected
  475. //---------------------------------------------------------------------------------------------
  476. case GBM_SELECTED:
  477. {
  478. GameWindow *control = (GameWindow *)mData1;
  479. Int controlID = control->winGetWindowId();
  480. if( controlID == buttonLoadKey )
  481. {
  482. processLoadButtonPress(window);
  483. } // end if
  484. else if( controlID == buttonSaveKey )
  485. {
  486. // sanity
  487. DEBUG_ASSERTCRASH( currentLayoutType == SLLT_SAVE_AND_LOAD ||
  488. currentLayoutType == SLLT_SAVE_ONLY,
  489. ("SaveLoadMenuSystem - layout type '%d' does not allow saving\n",
  490. currentLayoutType) );
  491. // get save file info
  492. AvailableGameInfo *selectedGameInfo = getSelectedSaveFileInfo( window );
  493. // if there is no file info, this is a new game
  494. if( selectedGameInfo == NULL )
  495. {
  496. // show the save description window
  497. //GameWindow *saveDesc = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:SaveDescParent" ) );
  498. saveDesc->winHide( FALSE );
  499. // set the description text entry field to default value
  500. //GameWindow *editDesc = TheWindowManager->winGetWindowFromId( saveDesc, NAMEKEY( "PopupSaveLoad.wnd:EntryDesc" ) );
  501. setEditDescription( editDesc );
  502. // disable the listbox of games
  503. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  504. listboxGames->winEnable( FALSE );
  505. // disable the frame window of buttons for the main save/load menu
  506. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  507. //buttonFrame->winEnable( FALSE );
  508. TheWindowManager->winSetFocus(editDesc);
  509. } // end if
  510. else
  511. {
  512. // disable listbox of games
  513. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  514. listboxGames->winEnable( FALSE );
  515. // disable and therefore lock out main save/load menu buttons
  516. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  517. buttonFrame->winEnable( FALSE );
  518. // show the save save confirm
  519. //GameWindow *overwriteConfirm = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:OverwriteConfirmParent" ) );
  520. overwriteConfirm->winHide( FALSE );
  521. } // end else
  522. }
  523. else if( controlID == buttonDeleteKey )
  524. {
  525. // which item is selected in the game listbox
  526. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  527. Int selected;
  528. GadgetListBoxGetSelected( listboxGames, &selected );
  529. AvailableGameInfo *selectedGameInfo;
  530. selectedGameInfo = (AvailableGameInfo *)GadgetListBoxGetItemData( listboxGames, selected );
  531. // delete file
  532. if( selectedGameInfo )
  533. {
  534. // disable games listbox
  535. listboxGames->winEnable( FALSE );
  536. // disable menu buttons
  537. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  538. buttonFrame->winEnable( FALSE );
  539. // unhide confirmation dialog
  540. //GameWindow *deleteConfirm = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:DeleteConfirmParent" ) );
  541. deleteConfirm->winHide( FALSE );
  542. } // end if
  543. } // end else if
  544. else if( controlID == buttonBackKey )
  545. {
  546. if(isPopup)
  547. {
  548. // close the save/load menu
  549. closeSaveMenu( window );
  550. }
  551. else
  552. {
  553. TheShell->pop();
  554. }
  555. } // end if
  556. else if( controlID == buttonDeleteConfirm || controlID == buttonDeleteCancel )
  557. {
  558. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  559. // delete if confirm
  560. if( controlID == buttonDeleteConfirm )
  561. {
  562. // which item is selected in the game listbox
  563. Int selected;
  564. GadgetListBoxGetSelected( listboxGames, &selected );
  565. AvailableGameInfo *selectedGameInfo;
  566. selectedGameInfo = (AvailableGameInfo *)GadgetListBoxGetItemData( listboxGames, selected );
  567. // construct path to filename
  568. AsciiString filepath = TheGameState->getFilePathInSaveDirectory(selectedGameInfo->filename);
  569. // delete the file
  570. DeleteFile( filepath.str() );
  571. // repopulate the listbox
  572. TheGameState->populateSaveGameListbox( listboxGames, currentLayoutType );
  573. } // end if
  574. // hide the confirm dialog
  575. //GameWindow *deleteConfirm = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:DeleteConfirmParent" ) );
  576. deleteConfirm->winHide( TRUE );
  577. // enable listbox of games
  578. listboxGames->winEnable( TRUE );
  579. // enable menu actions pane
  580. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  581. buttonFrame->winEnable( TRUE );
  582. updateMenuActions();
  583. } // end if
  584. else if( controlID == buttonOverwriteCancel || controlID == buttonOverwriteConfirm )
  585. {
  586. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  587. // hide save confirm dialog
  588. //GameWindow *overwriteConfirm = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:OverwriteConfirmParent" ) );
  589. overwriteConfirm->winHide( TRUE );
  590. // if saving, do the save for the selected listbox item
  591. if( controlID == buttonOverwriteConfirm )
  592. {
  593. // show the save description window
  594. // GameWindow *saveDesc = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:SaveDescParent" ) );
  595. // saveDesc->winHide( FALSE );
  596. // get save game info for the currently selected game in the listbox
  597. Int selected;
  598. GadgetListBoxGetSelected( listboxGames, &selected );
  599. // get the item data of the selection
  600. AvailableGameInfo *selectedGameInfo;
  601. selectedGameInfo = (AvailableGameInfo *)GadgetListBoxGetItemData( listboxGames, selected );
  602. DEBUG_ASSERTCRASH( selectedGameInfo, ("SaveLoadMenuSystem: Internal error, listbox entry to overwrite game has no item data set into listbox element\n") );
  603. // enable the listbox of games
  604. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  605. listboxGames->winEnable( TRUE );
  606. // enable the frame window of buttons for the main save/load menu
  607. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  608. buttonFrame->winEnable( TRUE );
  609. updateMenuActions();
  610. //Added By Sadullah Nader
  611. //Fix for bug
  612. // close save menuu
  613. closeSaveMenu( window );
  614. //
  615. // given the context of this menu figure out which type of save game we're acutally
  616. // saving right now. As it turns out, when this menu is used in the save only
  617. // mode it means that the save is a mission save between maps because you can only
  618. // save the game between maps and can of course not load one
  619. //
  620. SaveFileType fileType;
  621. if( currentLayoutType == SLLT_SAVE_AND_LOAD )
  622. fileType = SAVE_FILE_TYPE_NORMAL;
  623. else
  624. fileType = SAVE_FILE_TYPE_MISSION;
  625. // save the game
  626. AsciiString filename;
  627. if( selectedGameInfo )
  628. filename = selectedGameInfo->filename;
  629. TheGameState->saveGame( filename, selectedGameInfo->saveGameInfo.description, fileType );
  630. /*
  631. // set the description text entry field to default value
  632. GameWindow *editDesc = TheWindowManager->winGetWindowFromId( saveDesc, NAMEKEY( "PopupSaveLoad.wnd:EntryDesc" ) );
  633. setEditDescription( editDesc );
  634. */
  635. } // end if
  636. else if( controlID == buttonOverwriteCancel )
  637. {
  638. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  639. // enable buttons and list box on main parent
  640. buttonFrame->winEnable( TRUE );
  641. updateMenuActions();
  642. listboxGames->winEnable( TRUE );
  643. } // end else if
  644. } // end else if
  645. else if( controlID == buttonSaveDescConfirm )
  646. {
  647. // get description window
  648. //GameWindow *saveDesc = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:SaveDescParent" ) );
  649. // get description text
  650. //GameWindow *entryDesc = TheWindowManager->winGetWindowFromId( saveDesc, NAMEKEY( "PopupSaveLoad.wnd:EntryDesc" ) );
  651. UnicodeString desc = GadgetTextEntryGetText( editDesc );
  652. // hide desc window
  653. saveDesc->winHide( TRUE );
  654. // enable the listbox of games
  655. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  656. listboxGames->winEnable( TRUE );
  657. // enable the frame window of buttons for the main save/load menu
  658. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  659. buttonFrame->winEnable( TRUE );
  660. updateMenuActions();
  661. // close save menuu
  662. closeSaveMenu( window );
  663. // get save filename
  664. AvailableGameInfo *selectedGameInfo = getSelectedSaveFileInfo( listboxGames );
  665. //
  666. // given the context of this menu figure out which type of save game we're acutally
  667. // saving right now. As it turns out, when this menu is used in the save only
  668. // mode it means that the save is a mission save between maps because you can only
  669. // save the game between maps and can of course not load one
  670. //
  671. SaveFileType fileType;
  672. if( currentLayoutType == SLLT_SAVE_AND_LOAD )
  673. fileType = SAVE_FILE_TYPE_NORMAL;
  674. else
  675. fileType = SAVE_FILE_TYPE_MISSION;
  676. // save the game
  677. AsciiString filename;
  678. if( selectedGameInfo )
  679. filename = selectedGameInfo->filename;
  680. TheGameState->saveGame( filename, desc, fileType );
  681. } // end else if
  682. else if( controlID == buttonSaveDescCancel )
  683. {
  684. // hide the desc window
  685. //GameWindow *saveDesc = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:SaveDescParent" ) );
  686. saveDesc->winHide( TRUE );
  687. // enable the listbox of games
  688. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  689. listboxGames->winEnable( TRUE );
  690. // enable the frame window of buttons for the main save/load menu
  691. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  692. buttonFrame->winEnable( TRUE );
  693. updateMenuActions();
  694. } // end else if
  695. else if( controlID == buttonLoadConfirm || controlID == buttonLoadCancel )
  696. {
  697. // hide confirm dialog
  698. //GameWindow *loadConfirm = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:LoadConfirmParent" ) );
  699. loadConfirm->winHide( TRUE );
  700. // enable the listbox of games again
  701. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  702. listboxGames->winEnable( TRUE );
  703. // enable the main save/load menu button controls
  704. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  705. buttonFrame->winEnable( TRUE );
  706. updateMenuActions();
  707. // do the load game
  708. if( controlID == buttonLoadConfirm )
  709. {
  710. //Moved by Sadullah Nader
  711. //moved to fix the
  712. // close save/load layout menu
  713. closeSaveMenu( window );
  714. doLoadGame();
  715. }
  716. } // end else if
  717. break;
  718. } // end selected
  719. default:
  720. return MSG_IGNORED;
  721. } // end switch
  722. return MSG_HANDLED;
  723. }