MenuScreen_Shell_Singleplayer.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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_SINGLEPLAYER_OPTIONS = 8;
  24. /*
  25. ========================
  26. idMenuScreen_Shell_Singleplayer::Initialize
  27. ========================
  28. */
  29. void idMenuScreen_Shell_Singleplayer::Initialize( idMenuHandler * data ) {
  30. idMenuScreen::Initialize( data );
  31. if ( data != NULL ) {
  32. menuGUI = data->GetGUI();
  33. }
  34. SetSpritePath( "menuCampaign" );
  35. options = new (TAG_SWF) idMenuWidget_DynamicList();
  36. options->SetNumVisibleOptions( NUM_SINGLEPLAYER_OPTIONS );
  37. options->SetSpritePath( GetSpritePath(), "info", "options" );
  38. options->SetWrappingAllowed( true );
  39. AddChild( options );
  40. idMenuWidget_Help * const helpWidget = new ( TAG_SWF ) idMenuWidget_Help();
  41. helpWidget->SetSpritePath( GetSpritePath(), "info", "helpTooltip" );
  42. AddChild( helpWidget );
  43. while ( options->GetChildren().Num() < NUM_SINGLEPLAYER_OPTIONS ) {
  44. idMenuWidget_Button * const buttonWidget = new (TAG_SWF) idMenuWidget_Button();
  45. buttonWidget->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() );
  46. buttonWidget->RegisterEventObserver( helpWidget );
  47. buttonWidget->Initialize( data );
  48. options->AddChild( buttonWidget );
  49. }
  50. options->Initialize( data );
  51. btnBack = new (TAG_SWF) idMenuWidget_Button();
  52. btnBack->Initialize( data );
  53. btnBack->SetLabel( "#str_02305" );
  54. btnBack->SetSpritePath( GetSpritePath(), "info", "btnBack" );
  55. btnBack->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_GO_BACK );
  56. AddChild( btnBack );
  57. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN ) );
  58. options->AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP ) );
  59. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) );
  60. options->AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) );
  61. 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 ) );
  62. 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 ) );
  63. 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 ) );
  64. 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 ) );
  65. }
  66. /*
  67. ========================
  68. idMenuScreen_Shell_Singleplayer::Update
  69. ========================
  70. */
  71. void idMenuScreen_Shell_Singleplayer::Update() {
  72. if ( menuData != NULL ) {
  73. idMenuWidget_CommandBar * cmdBar = menuData->GetCmdBar();
  74. if ( cmdBar != NULL ) {
  75. cmdBar->ClearAllButtons();
  76. idMenuWidget_CommandBar::buttonInfo_t * buttonInfo;
  77. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 );
  78. if ( menuData->GetPlatform() != 2 ) {
  79. buttonInfo->label = "#str_00395";
  80. }
  81. buttonInfo->action.Set( WIDGET_ACTION_GO_BACK );
  82. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 );
  83. if ( menuData->GetPlatform() != 2 ) {
  84. buttonInfo->label = "#str_SWF_SELECT";
  85. }
  86. buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED );
  87. }
  88. }
  89. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  90. if ( BindSprite( root ) ) {
  91. idSWFTextInstance * heading = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtHeading" );
  92. if ( heading != NULL ) {
  93. heading->SetText( "#str_swf_campaign" );
  94. heading->SetStrokeInfo( true, 0.75f, 1.75f );
  95. }
  96. idSWFSpriteInstance * gradient = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "gradient" );
  97. if ( gradient != NULL && heading != NULL ) {
  98. gradient->SetXPos( heading->GetTextLength() );
  99. }
  100. }
  101. if ( btnBack != NULL ) {
  102. btnBack->BindSprite( root );
  103. }
  104. idMenuScreen::Update();
  105. }
  106. /*
  107. ========================
  108. idMenuScreen_Shell_Singleplayer::ShowScreen
  109. ========================
  110. */
  111. void idMenuScreen_Shell_Singleplayer::ShowScreen( const mainMenuTransition_t transitionType ) {
  112. idList< idList< idStr, TAG_IDLIB_LIST_MENU >, TAG_IDLIB_LIST_MENU > menuOptions;
  113. idList< idStr > option;
  114. canContinue = false;
  115. const saveGameDetailsList_t & saveGameInfo = session->GetSaveGameManager().GetEnumeratedSavegames();
  116. canContinue = ( saveGameInfo.Num() > 0 );
  117. if ( canContinue ) {
  118. option.Append( "#str_swf_continue_game" ); // continue game
  119. menuOptions.Append( option );
  120. option.Clear();
  121. option.Append( "#str_01866" ); // new game
  122. menuOptions.Append( option );
  123. option.Clear();
  124. option.Append( "#str_01867" ); // load game
  125. menuOptions.Append( option );
  126. int index = 0;
  127. idMenuWidget_Button * buttonWidget = dynamic_cast< idMenuWidget_Button * >( &options->GetChildByIndex( index ) );
  128. if ( buttonWidget != NULL ) {
  129. buttonWidget->SetDescription( "#str_swf_continue_desc" );
  130. }
  131. index++;
  132. buttonWidget = dynamic_cast< idMenuWidget_Button * >( &options->GetChildByIndex( index ) );
  133. if ( buttonWidget != NULL ) {
  134. buttonWidget->SetDescription( "#str_02209" );
  135. }
  136. index++;
  137. buttonWidget = dynamic_cast< idMenuWidget_Button * >( &options->GetChildByIndex( index ) );
  138. if ( buttonWidget != NULL ) {
  139. buttonWidget->SetDescription( "#str_02213" );
  140. }
  141. index++;
  142. } else {
  143. option.Append( "#str_01866" ); // new game
  144. menuOptions.Append( option );
  145. option.Clear();
  146. option.Append( "#str_01867" ); // load game
  147. menuOptions.Append( option );
  148. if ( options != NULL ) {
  149. int index = 0;
  150. idMenuWidget_Button * buttonWidget = dynamic_cast< idMenuWidget_Button * >( &options->GetChildByIndex( index ) );
  151. if ( buttonWidget != NULL ) {
  152. buttonWidget->SetDescription( "#str_02209" );
  153. }
  154. index++;
  155. buttonWidget = dynamic_cast< idMenuWidget_Button * >( &options->GetChildByIndex( index ) );
  156. if ( buttonWidget != NULL ) {
  157. buttonWidget->SetDescription( "#str_02213" );
  158. }
  159. }
  160. }
  161. if ( options != NULL ) {
  162. options->SetListData( menuOptions );
  163. }
  164. idMenuScreen::ShowScreen( transitionType );
  165. }
  166. /*
  167. ========================
  168. idMenuScreen_Shell_Singleplayer::HideScreen
  169. ========================
  170. */
  171. void idMenuScreen_Shell_Singleplayer::HideScreen( const mainMenuTransition_t transitionType ) {
  172. idMenuScreen::HideScreen( transitionType );
  173. }
  174. /*
  175. ========================
  176. idMenuScreen_Shell_Singleplayer::ContinueGame
  177. ========================
  178. */
  179. void idMenuScreen_Shell_Singleplayer::ContinueGame() {
  180. const saveGameDetailsList_t & saveGameInfo = session->GetSaveGameManager().GetEnumeratedSavegames();
  181. saveGameDetailsList_t sortedSaves = saveGameInfo;
  182. sortedSaves.Sort( idSort_SavesByDate() );
  183. if ( sortedSaves.Num() > 0 ) {
  184. if ( sortedSaves[0].damaged ) {
  185. class idSWFScriptFunction_ContinueDamaged : public idSWFScriptFunction_RefCounted {
  186. public:
  187. idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  188. common->Dialog().ClearDialog( GDM_CORRUPT_CONTINUE );
  189. return idSWFScriptVar();
  190. }
  191. };
  192. idStaticList< idSWFScriptFunction *, 4 > callbacks;
  193. callbacks.Append( new (TAG_SWF) idSWFScriptFunction_ContinueDamaged() );
  194. idStaticList< idStrId, 4 > optionText;
  195. optionText.Append( idStrId( "#str_04339" ) ); // OK
  196. common->Dialog().AddDynamicDialog( GDM_CORRUPT_CONTINUE, callbacks, optionText, false, "" );
  197. } else {
  198. const idStr & name = sortedSaves[ 0 ].slotName;
  199. cmdSystem->AppendCommandText( va( "loadgame %s\n", name.c_str() ) );
  200. }
  201. }
  202. }
  203. /*
  204. ========================
  205. idMenuScreen_Shell_Singleplayer::HandleAction
  206. ========================
  207. */
  208. bool idMenuScreen_Shell_Singleplayer::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) {
  209. if ( menuData == NULL ) {
  210. return true;
  211. }
  212. if ( menuData->ActiveScreen() != SHELL_AREA_CAMPAIGN ) {
  213. return false;
  214. }
  215. widgetAction_t actionType = action.GetType();
  216. const idSWFParmList & parms = action.GetParms();
  217. switch ( actionType ) {
  218. case WIDGET_ACTION_GO_BACK: {
  219. menuData->SetNextScreen( SHELL_AREA_ROOT, MENU_TRANSITION_SIMPLE );
  220. return true;
  221. }
  222. case WIDGET_ACTION_PRESS_FOCUSED: {
  223. if ( options == NULL ) {
  224. return true;
  225. }
  226. int selectionIndex = options->GetViewIndex();
  227. if ( parms.Num() == 1 ) {
  228. selectionIndex = parms[0].ToInteger();
  229. }
  230. canContinue = false;
  231. const saveGameDetailsList_t & saveGameInfo = session->GetSaveGameManager().GetEnumeratedSavegames();
  232. canContinue = ( saveGameInfo.Num() > 0 );
  233. if ( canContinue ) {
  234. if ( selectionIndex == 0 ) {
  235. ContinueGame();
  236. } else if ( selectionIndex == 1 ) {
  237. class idSWFScriptFunction_NewGame : public idSWFScriptFunction_RefCounted {
  238. public:
  239. idSWFScriptFunction_NewGame( idMenuHandler * _menuData, bool _accept ) {
  240. menuData = _menuData;
  241. accept = _accept;
  242. }
  243. idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  244. common->Dialog().ClearDialog( GDM_DELETE_AUTOSAVE );
  245. if ( accept ) {
  246. menuData->SetNextScreen( SHELL_AREA_NEW_GAME, MENU_TRANSITION_SIMPLE );
  247. }
  248. return idSWFScriptVar();
  249. }
  250. private:
  251. idMenuHandler * menuData;
  252. bool accept;
  253. };
  254. common->Dialog().AddDialog( GDM_DELETE_AUTOSAVE, DIALOG_ACCEPT_CANCEL, new idSWFScriptFunction_NewGame( menuData, true ), new idSWFScriptFunction_NewGame( menuData, false ), true );
  255. } else if ( selectionIndex == 2 ) {
  256. menuData->SetNextScreen( SHELL_AREA_LOAD, MENU_TRANSITION_SIMPLE );
  257. }
  258. } else {
  259. if ( selectionIndex == 0 ) {
  260. menuData->SetNextScreen( SHELL_AREA_NEW_GAME, MENU_TRANSITION_SIMPLE );
  261. } else if ( selectionIndex == 1 ) {
  262. menuData->SetNextScreen( SHELL_AREA_LOAD, MENU_TRANSITION_SIMPLE );
  263. }
  264. }
  265. return true;
  266. }
  267. }
  268. return idMenuWidget::HandleAction( action, event, widget, forceHandled );
  269. }