PopupSaveLoad.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. //Kris: Patch 1.01 - November 12, 2003
  286. //If you are in the game, then bring up the popup save menu, select a save game, click delete,
  287. //hit ESC (brings you back to menu), then hit save/load again, the delete confirmation is still up
  288. //and clicking on yes causes it to crash. So whenever we hit esc to leave this interface, kill
  289. //the confirmation, and re-enable the listbox and buttonFrame.
  290. deleteConfirm->winHide( TRUE );
  291. listboxGames->winEnable( TRUE );
  292. buttonFrame->winEnable( TRUE );
  293. TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
  294. (WindowMsgData)button, buttonBackKey );
  295. } // end if
  296. // don't let key fall through anywhere else
  297. return MSG_HANDLED;
  298. } // end escape
  299. } // end switch( key )
  300. } // end char
  301. } // end switch( msg )
  302. return MSG_IGNORED;
  303. }
  304. // ------------------------------------------------------------------------------------------------
  305. /** Get the file info of the selected savegame file in the listbox */
  306. // ------------------------------------------------------------------------------------------------
  307. static AvailableGameInfo *getSelectedSaveFileInfo( GameWindow *window )
  308. {
  309. // get the listbox
  310. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( window, listboxGamesKey );
  311. DEBUG_ASSERTCRASH( listboxGames != NULL, ("SaveLoadMenuInit - Unable to find games listbox\n") );
  312. // which item is selected
  313. Int selected;
  314. GadgetListBoxGetSelected( listboxGames, &selected );
  315. // get the item data of the selection
  316. AvailableGameInfo *selectedGameInfo;
  317. selectedGameInfo = (AvailableGameInfo *)GadgetListBoxGetItemData( listboxGames, selected );
  318. return selectedGameInfo;
  319. } // end getSelectedSaveFileInfo
  320. // ---------------------------------------------------con------------------------------------------
  321. // ------------------------------------------------------------------------------------------------ // close the save/load menu
  322. static void doLoadGame( void )
  323. {
  324. // get listbox of games
  325. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  326. DEBUG_ASSERTCRASH( listboxGames, ("doLoadGame: Unable to find game listbox\n") );
  327. // get selected game info
  328. AvailableGameInfo *selectedGameInfo = getSelectedSaveFileInfo( listboxGames );
  329. DEBUG_ASSERTCRASH( selectedGameInfo, ("doLoadGame: No selected game info found\n") );
  330. // when loading a game we also close the quit/esc menu for the user when in-game
  331. if( TheShell->isShellActive() == FALSE )
  332. {
  333. destroyQuitMenu();
  334. // ToggleQuitMenu();
  335. // TheTransitionHandler->remove("QuitNoSave");
  336. // TheTransitionHandler->remove("QuitFull");
  337. }
  338. else
  339. {
  340. TheTransitionHandler->remove("MainMenuLoadReplayMenu");
  341. TheTransitionHandler->remove("MainMenuLoadReplayMenuBack");
  342. TheGameLogic->prepareNewGame( GAME_SINGLE_PLAYER, DIFFICULTY_NORMAL, 0 );
  343. }
  344. //
  345. // load game, note the *copy* of the selected game info is passed here because we will
  346. // loose these allocated user data pointers attached as listbox item data when the
  347. // engine resets
  348. //
  349. if (TheGameState->loadGame( *selectedGameInfo ) != SC_OK)
  350. {
  351. if (TheGameLogic->isInGame())
  352. TheGameLogic->clearGameData( FALSE );
  353. TheGameEngine->reset();
  354. TheShell->showShell(TRUE);
  355. }
  356. } // end doLoadGame
  357. // ------------------------------------------------------------------------------------------------
  358. /** Close the save/load menu */
  359. // ------------------------------------------------------------------------------------------------
  360. static void closeSaveMenu( GameWindow *window )
  361. {
  362. if(isPopup)
  363. {
  364. WindowLayout *saveLoadMenuLayout = window->winGetLayout();
  365. if( saveLoadMenuLayout )
  366. saveLoadMenuLayout->hide( TRUE );
  367. }
  368. else
  369. TheShell->hideShell();
  370. } // end closeSaveMenu
  371. // ------------------------------------------------------------------------------------------------
  372. // ------------------------------------------------------------------------------------------------
  373. static void setEditDescription( GameWindow *editControl )
  374. {
  375. UnicodeString defaultDesc;
  376. Campaign *campaign = TheCampaignManager->getCurrentCampaign();
  377. //
  378. // if we have a campaign we will use a default description that describes the
  379. // location and map in the campaign nicely, otherwise we will default to just
  380. // the map name (which is really only used in debug)
  381. //
  382. if( campaign )
  383. defaultDesc.format( L"%s %d",
  384. TheGameText->fetch( campaign->m_campaignNameLabel ).str(),
  385. TheCampaignManager->getCurrentMissionNumber() + 1 );
  386. else
  387. {
  388. const char *mapName = TheGlobalData->m_mapName.reverseFind( '\\' );
  389. if( mapName )
  390. defaultDesc.format( L"%S", mapName + 1 );
  391. else
  392. defaultDesc.format( L"%S", TheGlobalData->m_mapName.str() );
  393. //Keep the extension out of the descriptive name.
  394. if( (defaultDesc.getLength() >= 4) && (defaultDesc.getCharAt(defaultDesc.getLength()-4) == '.') )
  395. {
  396. for( Int stripIndex = 0; stripIndex < 4; stripIndex++ )
  397. {
  398. defaultDesc.removeLastChar();
  399. }
  400. }
  401. } // end else
  402. // set into edit control
  403. GadgetTextEntrySetText( editControl, defaultDesc );
  404. } // end setEditDescription
  405. //----------------------------------------------------------------------------------------------
  406. static void processLoadButtonPress(GameWindow *window)
  407. {
  408. // get the filename of the selected savegame in the listbox
  409. AvailableGameInfo *selectedGameInfo = getSelectedSaveFileInfo( window );
  410. if( selectedGameInfo )
  411. {
  412. //
  413. // if we're in the shell we do not need a confirmation dialog that states we will
  414. // lose the current loaded game data cause we're not in a game
  415. //
  416. if( TheShell->isShellActive() == TRUE )
  417. {
  418. // just close the menu and do the load game logic
  419. closeSaveMenu( window );
  420. doLoadGame();
  421. } // end if
  422. else
  423. {
  424. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  425. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  426. //GameWindow *loadConfirm = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:LoadConfirmParent" ) );
  427. // disable listbox and buttons
  428. listboxGames->winEnable( FALSE );
  429. buttonFrame->winEnable( FALSE );
  430. // show the load confirm dialog
  431. loadConfirm->winHide( FALSE );
  432. } // end else
  433. } // end if
  434. }
  435. //-------------------------------------------------------------------------------------------------
  436. /** SaveLoad menu system callback */
  437. //-------------------------------------------------------------------------------------------------
  438. WindowMsgHandledType SaveLoadMenuSystem( GameWindow *window, UnsignedInt msg,
  439. WindowMsgData mData1, WindowMsgData mData2 )
  440. {
  441. switch( msg )
  442. {
  443. // --------------------------------------------------------------------------------------------
  444. case GWM_CREATE:
  445. {
  446. break;
  447. } // end create
  448. //---------------------------------------------------------------------------------------------
  449. case GWM_DESTROY:
  450. {
  451. break;
  452. } // end case
  453. //----------------------------------------------------------------------------------------------
  454. case GWM_INPUT_FOCUS:
  455. {
  456. // if we're givin the opportunity to take the keyboard focus we must say we want it
  457. if( mData1 == TRUE )
  458. *(Bool *)mData2 = TRUE;
  459. break;
  460. } // end input
  461. //----------------------------------------------------------------------------------------------
  462. case GLM_DOUBLE_CLICKED:
  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. if (listboxGames != NULL) {
  468. int rowSelected = mData2;
  469. GadgetListBoxSetSelected(listboxGames, rowSelected);
  470. if (control == listboxGames)
  471. {
  472. processLoadButtonPress(window);
  473. }
  474. }
  475. break;
  476. }
  477. // --------------------------------------------------------------------------------------------
  478. case GLM_SELECTED:
  479. {
  480. GameWindow *control = (GameWindow *)mData1;
  481. GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( window, listboxGamesKey );
  482. DEBUG_ASSERTCRASH( listboxGames != NULL, ("SaveLoadMenuInit - Unable to find games listbox\n") );
  483. //
  484. // handle games listbox, when certain items are selected in the listbox only some
  485. // commands are available
  486. //
  487. if( control == listboxGames )
  488. updateMenuActions();
  489. break;
  490. } // end selected
  491. //---------------------------------------------------------------------------------------------
  492. case GBM_SELECTED:
  493. {
  494. GameWindow *control = (GameWindow *)mData1;
  495. Int controlID = control->winGetWindowId();
  496. if( controlID == buttonLoadKey )
  497. {
  498. processLoadButtonPress(window);
  499. } // end if
  500. else if( controlID == buttonSaveKey )
  501. {
  502. // sanity
  503. DEBUG_ASSERTCRASH( currentLayoutType == SLLT_SAVE_AND_LOAD ||
  504. currentLayoutType == SLLT_SAVE_ONLY,
  505. ("SaveLoadMenuSystem - layout type '%d' does not allow saving\n",
  506. currentLayoutType) );
  507. // get save file info
  508. AvailableGameInfo *selectedGameInfo = getSelectedSaveFileInfo( window );
  509. // if there is no file info, this is a new game
  510. if( selectedGameInfo == NULL )
  511. {
  512. // show the save description window
  513. //GameWindow *saveDesc = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:SaveDescParent" ) );
  514. saveDesc->winHide( FALSE );
  515. // set the description text entry field to default value
  516. //GameWindow *editDesc = TheWindowManager->winGetWindowFromId( saveDesc, NAMEKEY( "PopupSaveLoad.wnd:EntryDesc" ) );
  517. setEditDescription( editDesc );
  518. // disable the listbox of games
  519. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  520. listboxGames->winEnable( FALSE );
  521. // disable the frame window of buttons for the main save/load menu
  522. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  523. //buttonFrame->winEnable( FALSE );
  524. TheWindowManager->winSetFocus(editDesc);
  525. } // end if
  526. else
  527. {
  528. // disable listbox of games
  529. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  530. listboxGames->winEnable( FALSE );
  531. // disable and therefore lock out main save/load menu buttons
  532. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  533. buttonFrame->winEnable( FALSE );
  534. // show the save save confirm
  535. //GameWindow *overwriteConfirm = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:OverwriteConfirmParent" ) );
  536. overwriteConfirm->winHide( FALSE );
  537. } // end else
  538. }
  539. else if( controlID == buttonDeleteKey )
  540. {
  541. // which item is selected in the game listbox
  542. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  543. Int selected;
  544. GadgetListBoxGetSelected( listboxGames, &selected );
  545. AvailableGameInfo *selectedGameInfo;
  546. selectedGameInfo = (AvailableGameInfo *)GadgetListBoxGetItemData( listboxGames, selected );
  547. // delete file
  548. if( selectedGameInfo )
  549. {
  550. // disable games listbox
  551. listboxGames->winEnable( FALSE );
  552. // disable menu buttons
  553. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  554. buttonFrame->winEnable( FALSE );
  555. // unhide confirmation dialog
  556. //GameWindow *deleteConfirm = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:DeleteConfirmParent" ) );
  557. deleteConfirm->winHide( FALSE );
  558. } // end if
  559. } // end else if
  560. else if( controlID == buttonBackKey )
  561. {
  562. if(isPopup)
  563. {
  564. // close the save/load menu
  565. closeSaveMenu( window );
  566. }
  567. else
  568. {
  569. TheShell->pop();
  570. }
  571. } // end if
  572. else if( controlID == buttonDeleteConfirm || controlID == buttonDeleteCancel )
  573. {
  574. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  575. // delete if confirm
  576. if( controlID == buttonDeleteConfirm )
  577. {
  578. // which item is selected in the game listbox
  579. Int selected;
  580. GadgetListBoxGetSelected( listboxGames, &selected );
  581. AvailableGameInfo *selectedGameInfo;
  582. selectedGameInfo = (AvailableGameInfo *)GadgetListBoxGetItemData( listboxGames, selected );
  583. // construct path to filename
  584. AsciiString filepath = TheGameState->getFilePathInSaveDirectory(selectedGameInfo->filename);
  585. // delete the file
  586. DeleteFile( filepath.str() );
  587. // repopulate the listbox
  588. TheGameState->populateSaveGameListbox( listboxGames, currentLayoutType );
  589. } // end if
  590. // hide the confirm dialog
  591. //GameWindow *deleteConfirm = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:DeleteConfirmParent" ) );
  592. deleteConfirm->winHide( TRUE );
  593. // enable listbox of games
  594. listboxGames->winEnable( TRUE );
  595. // enable menu actions pane
  596. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  597. buttonFrame->winEnable( TRUE );
  598. updateMenuActions();
  599. } // end if
  600. else if( controlID == buttonOverwriteCancel || controlID == buttonOverwriteConfirm )
  601. {
  602. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  603. // hide save confirm dialog
  604. //GameWindow *overwriteConfirm = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:OverwriteConfirmParent" ) );
  605. overwriteConfirm->winHide( TRUE );
  606. // if saving, do the save for the selected listbox item
  607. if( controlID == buttonOverwriteConfirm )
  608. {
  609. // show the save description window
  610. // GameWindow *saveDesc = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:SaveDescParent" ) );
  611. // saveDesc->winHide( FALSE );
  612. // get save game info for the currently selected game in the listbox
  613. Int selected;
  614. GadgetListBoxGetSelected( listboxGames, &selected );
  615. // get the item data of the selection
  616. AvailableGameInfo *selectedGameInfo;
  617. selectedGameInfo = (AvailableGameInfo *)GadgetListBoxGetItemData( listboxGames, selected );
  618. DEBUG_ASSERTCRASH( selectedGameInfo, ("SaveLoadMenuSystem: Internal error, listbox entry to overwrite game has no item data set into listbox element\n") );
  619. // enable the listbox of games
  620. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  621. listboxGames->winEnable( TRUE );
  622. // enable the frame window of buttons for the main save/load menu
  623. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  624. buttonFrame->winEnable( TRUE );
  625. updateMenuActions();
  626. //Added By Sadullah Nader
  627. //Fix for bug
  628. // close save menuu
  629. closeSaveMenu( window );
  630. //
  631. // given the context of this menu figure out which type of save game we're acutally
  632. // saving right now. As it turns out, when this menu is used in the save only
  633. // mode it means that the save is a mission save between maps because you can only
  634. // save the game between maps and can of course not load one
  635. //
  636. SaveFileType fileType;
  637. if( currentLayoutType == SLLT_SAVE_AND_LOAD )
  638. fileType = SAVE_FILE_TYPE_NORMAL;
  639. else
  640. fileType = SAVE_FILE_TYPE_MISSION;
  641. // save the game
  642. AsciiString filename;
  643. if( selectedGameInfo )
  644. filename = selectedGameInfo->filename;
  645. TheGameState->saveGame( filename, selectedGameInfo->saveGameInfo.description, fileType );
  646. /*
  647. // set the description text entry field to default value
  648. GameWindow *editDesc = TheWindowManager->winGetWindowFromId( saveDesc, NAMEKEY( "PopupSaveLoad.wnd:EntryDesc" ) );
  649. setEditDescription( editDesc );
  650. */
  651. } // end if
  652. else if( controlID == buttonOverwriteCancel )
  653. {
  654. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  655. // enable buttons and list box on main parent
  656. buttonFrame->winEnable( TRUE );
  657. updateMenuActions();
  658. listboxGames->winEnable( TRUE );
  659. } // end else if
  660. } // end else if
  661. else if( controlID == buttonSaveDescConfirm )
  662. {
  663. // get description window
  664. //GameWindow *saveDesc = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:SaveDescParent" ) );
  665. // get description text
  666. //GameWindow *entryDesc = TheWindowManager->winGetWindowFromId( saveDesc, NAMEKEY( "PopupSaveLoad.wnd:EntryDesc" ) );
  667. UnicodeString desc = GadgetTextEntryGetText( editDesc );
  668. // hide desc window
  669. saveDesc->winHide( TRUE );
  670. // enable the listbox of games
  671. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  672. listboxGames->winEnable( TRUE );
  673. // enable the frame window of buttons for the main save/load menu
  674. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  675. buttonFrame->winEnable( TRUE );
  676. updateMenuActions();
  677. // close save menuu
  678. closeSaveMenu( window );
  679. // get save filename
  680. AvailableGameInfo *selectedGameInfo = getSelectedSaveFileInfo( listboxGames );
  681. //
  682. // given the context of this menu figure out which type of save game we're acutally
  683. // saving right now. As it turns out, when this menu is used in the save only
  684. // mode it means that the save is a mission save between maps because you can only
  685. // save the game between maps and can of course not load one
  686. //
  687. SaveFileType fileType;
  688. if( currentLayoutType == SLLT_SAVE_AND_LOAD )
  689. fileType = SAVE_FILE_TYPE_NORMAL;
  690. else
  691. fileType = SAVE_FILE_TYPE_MISSION;
  692. // save the game
  693. AsciiString filename;
  694. if( selectedGameInfo )
  695. filename = selectedGameInfo->filename;
  696. TheGameState->saveGame( filename, desc, fileType );
  697. } // end else if
  698. else if( controlID == buttonSaveDescCancel )
  699. {
  700. // hide the desc window
  701. //GameWindow *saveDesc = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:SaveDescParent" ) );
  702. saveDesc->winHide( TRUE );
  703. // enable the listbox of games
  704. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  705. listboxGames->winEnable( TRUE );
  706. // enable the frame window of buttons for the main save/load menu
  707. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  708. buttonFrame->winEnable( TRUE );
  709. updateMenuActions();
  710. } // end else if
  711. else if( controlID == buttonLoadConfirm || controlID == buttonLoadCancel )
  712. {
  713. // hide confirm dialog
  714. //GameWindow *loadConfirm = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:LoadConfirmParent" ) );
  715. loadConfirm->winHide( TRUE );
  716. // enable the listbox of games again
  717. //GameWindow *listboxGames = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:ListboxGames" ) );
  718. listboxGames->winEnable( TRUE );
  719. // enable the main save/load menu button controls
  720. //GameWindow *buttonFrame = TheWindowManager->winGetWindowFromId( parent, NAMEKEY( "PopupSaveLoad.wnd:MenuButtonFrame" ) );
  721. buttonFrame->winEnable( TRUE );
  722. updateMenuActions();
  723. // do the load game
  724. if( controlID == buttonLoadConfirm )
  725. {
  726. //Moved by Sadullah Nader
  727. //moved to fix the
  728. // close save/load layout menu
  729. closeSaveMenu( window );
  730. doLoadGame();
  731. }
  732. } // end else if
  733. break;
  734. } // end selected
  735. default:
  736. return MSG_IGNORED;
  737. } // end switch
  738. return MSG_HANDLED;
  739. }