MenuScreen_Shell_Load.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code 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. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #pragma hdrstop
  21. #include "../../idLib/precompiled.h"
  22. #include "../Game_local.h"
  23. const static int NUM_LOAD_OPTIONS = 10;
  24. /*
  25. ========================
  26. idMenuScreen_Shell_Load::Initialize
  27. ========================
  28. */
  29. void idMenuScreen_Shell_Load::Initialize( idMenuHandler * data ) {
  30. idMenuScreen::Initialize( data );
  31. if ( data != NULL ) {
  32. menuGUI = data->GetGUI();
  33. }
  34. SetSpritePath( "menuLoad" );
  35. saveInfo = new (TAG_SWF) idMenuWidget_Shell_SaveInfo();
  36. saveInfo->SetSpritePath( GetSpritePath(), "info", "details" );
  37. saveInfo->Initialize( data );
  38. options = new (TAG_SWF) idMenuWidget_DynamicList();
  39. options->SetNumVisibleOptions( NUM_LOAD_OPTIONS );
  40. options->SetSpritePath( GetSpritePath(), "info", "options" );
  41. options->SetWrappingAllowed( true );
  42. while ( options->GetChildren().Num() < NUM_LOAD_OPTIONS ) {
  43. idMenuWidget_Button * const buttonWidget = new (TAG_SWF) idMenuWidget_Button();
  44. buttonWidget->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() );
  45. buttonWidget->RegisterEventObserver( saveInfo );
  46. buttonWidget->Initialize( data );
  47. options->AddChild( buttonWidget );
  48. }
  49. options->Initialize( data );
  50. AddChild( options );
  51. AddChild( saveInfo );
  52. btnBack = new (TAG_SWF) idMenuWidget_Button();
  53. btnBack->Initialize( data );
  54. idMenuHandler_Shell * handler = dynamic_cast< idMenuHandler_Shell * >( data );
  55. if ( handler != NULL && handler->GetInGame() ) {
  56. btnBack->SetLabel( "#str_swf_pause_menu" );
  57. } else {
  58. btnBack->SetLabel( "#str_swf_campaign" );
  59. }
  60. btnBack->SetSpritePath( GetSpritePath(), "info", "btnBack" );
  61. btnBack->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_GO_BACK );
  62. AddChild( btnBack );
  63. btnDelete = new idMenuWidget_Button();
  64. btnDelete->Initialize( data );
  65. btnDelete->SetLabel( "" );
  66. btnDelete->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_JOY3_ON_PRESS );
  67. btnDelete->SetSpritePath( GetSpritePath(), "info", "btnDelete" );
  68. AddChild( btnDelete );
  69. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN ) );
  70. options->AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP ) );
  71. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) );
  72. options->AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) );
  73. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN_LSTICK ) );
  74. options->AddEventAction( WIDGET_EVENT_SCROLL_UP_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP_LSTICK ) );
  75. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_LSTICK_RELEASE ) );
  76. options->AddEventAction( WIDGET_EVENT_SCROLL_UP_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_LSTICK_RELEASE ) );
  77. }
  78. /*
  79. ========================
  80. idMenuScreen_Shell_Load::Update
  81. ========================
  82. */
  83. void idMenuScreen_Shell_Load::Update() {
  84. UpdateSaveEnumerations();
  85. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  86. if ( BindSprite( root ) ) {
  87. idSWFTextInstance * heading = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtHeading" );
  88. if ( heading != NULL ) {
  89. heading->SetText( "#str_02187" ); // LOAD GAME
  90. heading->SetStrokeInfo( true, 0.75f, 1.75f );
  91. }
  92. idSWFSpriteInstance * gradient = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "gradient" );
  93. if ( gradient != NULL && heading != NULL ) {
  94. gradient->SetXPos( heading->GetTextLength() );
  95. }
  96. }
  97. if ( btnBack != NULL ) {
  98. btnBack->BindSprite( root );
  99. }
  100. idMenuScreen::Update();
  101. }
  102. /*
  103. ========================
  104. idMenuScreen_Shell_Load::UpdateSaveEnumerations
  105. ========================
  106. */
  107. void idMenuScreen_Shell_Load::UpdateSaveEnumerations() {
  108. const saveGameDetailsList_t & saveGameInfo = session->GetSaveGameManager().GetEnumeratedSavegames();
  109. sortedSaves = saveGameInfo;
  110. sortedSaves.Sort( idSort_SavesByDate() );
  111. if ( options != NULL ) {
  112. idList< idList< idStr, TAG_IDLIB_LIST_MENU >, TAG_IDLIB_LIST_MENU > saveList;
  113. if ( session->GetSaveGameManager().IsWorking() ) {
  114. idList< idStr > saveName;
  115. saveName.Append( "#str_dlg_refreshing" );
  116. saveList.Append( saveName );
  117. } else if ( sortedSaves.Num() == 0 ) {
  118. idList< idStr > saveName;
  119. saveName.Append( "#str_no_saves_found" );
  120. saveList.Append( saveName );
  121. } else {
  122. saveList.SetNum( sortedSaves.Num() );
  123. for ( int slot = 0; slot < sortedSaves.Num(); ++slot ) {
  124. idStr & slotSaveName = saveList[slot].Alloc();
  125. const idSaveGameDetails & details = sortedSaves[slot];
  126. if ( details.damaged ) {
  127. slotSaveName = va( S_COLOR_RED "%s", idLocalization::GetString( "#str_swf_corrupt_file" ) );
  128. } else if ( details.GetSaveVersion() > BUILD_NUMBER ) {
  129. slotSaveName = va( S_COLOR_RED "%s", idLocalization::GetString( "#str_swf_wrong_version" ) );
  130. } else {
  131. if ( details.slotName.Icmp( "autosave" ) == 0 ) {
  132. slotSaveName.Append( S_COLOR_YELLOW );
  133. } else if ( details.slotName.Icmp( "quick" ) == 0 ) {
  134. slotSaveName.Append( S_COLOR_ORANGE );
  135. }
  136. slotSaveName.Append( details.GetMapName() );
  137. }
  138. }
  139. }
  140. options->SetListData( saveList );
  141. options->Update();
  142. }
  143. if ( menuData != NULL ) {
  144. idMenuWidget_CommandBar * cmdBar = menuData->GetCmdBar();
  145. if ( cmdBar != NULL ) {
  146. cmdBar->ClearAllButtons();
  147. idMenuWidget_CommandBar::buttonInfo_t * buttonInfo;
  148. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 );
  149. if ( menuData->GetPlatform() != 2 ) {
  150. buttonInfo->label = "#str_00395"; // BACK
  151. }
  152. buttonInfo->action.Set( WIDGET_ACTION_GO_BACK );
  153. if ( sortedSaves.Num() > 0 && !session->GetSaveGameManager().IsWorking() ) {
  154. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 );
  155. if ( menuData->GetPlatform() != 2 ) {
  156. buttonInfo->label = "#str_02187"; // LOAD GAME
  157. }
  158. buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED );
  159. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY3 );
  160. if ( menuData->GetPlatform() != 2 ) {
  161. buttonInfo->label = "#str_02315"; // DELETE GAME
  162. }
  163. buttonInfo->action.Set( WIDGET_ACTION_JOY3_ON_PRESS );
  164. if ( btnDelete != NULL ) {
  165. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  166. if ( btnDelete->BindSprite( root ) ) {
  167. if ( menuData->GetPlatform() != 2 ) {
  168. btnDelete->SetLabel( "" );
  169. } else {
  170. btnDelete->GetSprite()->SetVisible( true );
  171. btnDelete->SetLabel( "#str_02315" );
  172. }
  173. }
  174. btnDelete->Update();
  175. }
  176. } else {
  177. if ( btnDelete != NULL ) {
  178. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  179. if ( btnDelete->BindSprite( root ) ) {
  180. btnDelete->SetLabel( "" );
  181. btnDelete->Update();
  182. }
  183. }
  184. }
  185. cmdBar->Update();
  186. }
  187. }
  188. if ( saveInfo != NULL ) {
  189. saveInfo->Update();
  190. }
  191. if ( options != NULL && options->GetTotalNumberOfOptions() > 0 && options->GetViewIndex() >= options->GetTotalNumberOfOptions() ) {
  192. options->SetViewIndex( options->GetTotalNumberOfOptions() - 1 );
  193. if ( options->GetViewOffset() > options->GetViewIndex() ) {
  194. options->SetViewOffset( options->GetViewIndex() );
  195. }
  196. options->SetFocusIndex( options->GetViewIndex() - options->GetViewOffset() );
  197. }
  198. }
  199. /*
  200. ========================
  201. idMenuScreen_Shell_Load::ShowScreen
  202. ========================
  203. */
  204. void idMenuScreen_Shell_Load::ShowScreen( const mainMenuTransition_t transitionType ) {
  205. idMenuScreen::ShowScreen( transitionType );
  206. }
  207. /*
  208. ========================
  209. idMenuScreen_Shell_Load::HideScreen
  210. ========================
  211. */
  212. void idMenuScreen_Shell_Load::HideScreen( const mainMenuTransition_t transitionType ) {
  213. idMenuScreen::HideScreen( transitionType );
  214. }
  215. /*
  216. ========================
  217. idMenuScreen_Shell_Load::LoadDamagedGame
  218. ========================
  219. */
  220. void idMenuScreen_Shell_Load::LoadDamagedGame( int index ) {
  221. if ( index >= sortedSaves.Num() ) {
  222. return;
  223. }
  224. class idSWFScriptFunction_LoadDamaged : public idSWFScriptFunction_RefCounted {
  225. public:
  226. idSWFScriptFunction_LoadDamaged( gameDialogMessages_t _msg, bool _accept, int _index, idMenuScreen_Shell_Load * _screen ) {
  227. msg = _msg;
  228. accept = _accept;
  229. index = _index;
  230. screen = _screen;
  231. }
  232. idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  233. common->Dialog().ClearDialog( msg );
  234. if ( accept ) {
  235. screen->DeleteGame( index );
  236. }
  237. return idSWFScriptVar();
  238. }
  239. private:
  240. gameDialogMessages_t msg;
  241. int index;
  242. bool accept;
  243. idMenuScreen_Shell_Load * screen;
  244. };
  245. idStaticList< idSWFScriptFunction *, 4 > callbacks;
  246. callbacks.Append( new (TAG_SWF) idSWFScriptFunction_LoadDamaged( GDM_LOAD_DAMAGED_FILE, true, index, this ) );
  247. callbacks.Append( new (TAG_SWF) idSWFScriptFunction_LoadDamaged( GDM_LOAD_DAMAGED_FILE, false, index, this ) );
  248. idStaticList< idStrId, 4 > optionText;
  249. optionText.Append( idStrId( "#str_02315" ) ); // DELETE
  250. optionText.Append( idStrId( "#STR_SWF_CANCEL" ) );
  251. common->Dialog().AddDynamicDialog( GDM_LOAD_DAMAGED_FILE, callbacks, optionText, false, "" );
  252. }
  253. /*
  254. ========================
  255. idMenuScreen_Shell_Load::LoadGame
  256. ========================
  257. */
  258. void idMenuScreen_Shell_Load::LoadGame( int index ) {
  259. if ( menuData == NULL ) {
  260. return;
  261. }
  262. if ( index < GetSortedSaves().Num() && GetSortedSaves()[index].damaged ) {
  263. LoadDamagedGame( index );
  264. return;
  265. }
  266. bool isDead = false;
  267. idPlayer * player = gameLocal.GetLocalPlayer();
  268. if ( player != NULL && player->health <= 0 ) {
  269. isDead = true;
  270. }
  271. idMenuHandler_Shell * mgr = dynamic_cast< idMenuHandler_Shell * >( menuData );
  272. if ( mgr != NULL && mgr->GetInGame() && !isDead ) {
  273. class idSWFScriptFunction_LoadDialog : public idSWFScriptFunction_RefCounted {
  274. public:
  275. idSWFScriptFunction_LoadDialog( gameDialogMessages_t _msg, bool _accept, const char * _name ) {
  276. msg = _msg;
  277. accept = _accept;
  278. name = _name;
  279. }
  280. idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  281. common->Dialog().ClearDialog( msg );
  282. if ( accept && name != NULL ) {
  283. cmdSystem->AppendCommandText( va( "loadgame %s\n", name ) );
  284. }
  285. return idSWFScriptVar();
  286. }
  287. private:
  288. gameDialogMessages_t msg;
  289. bool accept;
  290. const char * name;
  291. };
  292. if ( index < sortedSaves.Num() ) {
  293. const idStr & name = sortedSaves[ index ].slotName;
  294. common->Dialog().AddDialog( GDM_SP_LOAD_SAVE, DIALOG_ACCEPT_CANCEL, new idSWFScriptFunction_LoadDialog( GDM_SP_LOAD_SAVE, true, name.c_str() ), new idSWFScriptFunction_LoadDialog( GDM_SP_LOAD_SAVE, false, name.c_str() ), false );
  295. }
  296. } else {
  297. if ( index < sortedSaves.Num() ) {
  298. const idStr & name = sortedSaves[ index ].slotName;
  299. cmdSystem->AppendCommandText( va( "loadgame %s\n", name.c_str() ) );
  300. }
  301. }
  302. }
  303. /*
  304. ========================
  305. idMenuScreen_Shell_Save::DeleteGame
  306. ========================
  307. */
  308. void idMenuScreen_Shell_Load::DeleteGame( int index ) {
  309. class idSWFScriptFunction_DeleteGame : public idSWFScriptFunction_RefCounted {
  310. public:
  311. idSWFScriptFunction_DeleteGame( gameDialogMessages_t _msg, bool _accept, int _index, idMenuScreen_Shell_Load * _screen ) {
  312. msg = _msg;
  313. accept = _accept;
  314. index = _index;
  315. screen = _screen;
  316. }
  317. idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  318. common->Dialog().ClearDialog( msg );
  319. if ( accept && screen != NULL ) {
  320. if ( index < screen->GetSortedSaves().Num() ) {
  321. session->DeleteSaveGameSync( screen->GetSortedSaves()[ index ].slotName );
  322. }
  323. }
  324. return idSWFScriptVar();
  325. }
  326. private:
  327. gameDialogMessages_t msg;
  328. int index;
  329. bool accept;
  330. idMenuScreen_Shell_Load * screen;
  331. };
  332. common->Dialog().AddDialog( GDM_DELETE_SAVE, DIALOG_ACCEPT_CANCEL, new idSWFScriptFunction_DeleteGame( GDM_DELETE_SAVE, true, index, this ), new idSWFScriptFunction_DeleteGame( GDM_DELETE_SAVE, false, index, this ), false );
  333. }
  334. /*
  335. ========================
  336. idMenuScreen_Shell_Load::HandleAction h
  337. ========================
  338. */
  339. bool idMenuScreen_Shell_Load::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) {
  340. if ( menuData != NULL ) {
  341. if ( menuData->ActiveScreen() != SHELL_AREA_LOAD ) {
  342. return false;
  343. }
  344. }
  345. widgetAction_t actionType = action.GetType();
  346. const idSWFParmList & parms = action.GetParms();
  347. switch ( actionType ) {
  348. case WIDGET_ACTION_JOY4_ON_PRESS: {
  349. return true;
  350. }
  351. case WIDGET_ACTION_JOY3_ON_PRESS: {
  352. if ( options == NULL ) {
  353. return true;
  354. }
  355. int selectionIndex = options->GetViewIndex();
  356. DeleteGame( selectionIndex );
  357. return true;
  358. }
  359. case WIDGET_ACTION_GO_BACK: {
  360. if ( menuData != NULL ) {
  361. if ( game->IsInGame() ) {
  362. menuData->SetNextScreen( SHELL_AREA_ROOT, MENU_TRANSITION_SIMPLE );
  363. } else {
  364. menuData->SetNextScreen( SHELL_AREA_CAMPAIGN, MENU_TRANSITION_SIMPLE );
  365. }
  366. }
  367. return true;
  368. }
  369. case WIDGET_ACTION_PRESS_FOCUSED: {
  370. if ( options == NULL ) {
  371. return true;
  372. }
  373. if ( sortedSaves.Num() == 0 ) {
  374. return true;
  375. }
  376. int selectionIndex = options->GetViewIndex();
  377. if ( parms.Num() == 1 ) {
  378. selectionIndex = parms[0].ToInteger();
  379. if ( selectionIndex != options->GetFocusIndex() ) {
  380. options->SetViewIndex( options->GetViewOffset() + selectionIndex );
  381. options->SetFocusIndex( selectionIndex );
  382. } else {
  383. LoadGame( options->GetViewOffset() + selectionIndex );
  384. }
  385. } else {
  386. LoadGame( options->GetViewIndex() );
  387. }
  388. return true;
  389. }
  390. case WIDGET_ACTION_SCROLL_VERTICAL: {
  391. return true;
  392. }
  393. }
  394. return idMenuWidget::HandleAction( action, event, widget, forceHandled );
  395. }