MenuScreen_Shell_Singleplayer.cpp (12031B)
1 /* 2 =========================================================================== 3 4 Doom 3 BFG Edition GPL Source Code 5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 6 7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). 8 9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>. 21 22 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. 23 24 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. 25 26 =========================================================================== 27 */ 28 #pragma hdrstop 29 #include "../../idLib/precompiled.h" 30 #include "../Game_local.h" 31 32 const static int NUM_SINGLEPLAYER_OPTIONS = 8; 33 /* 34 ======================== 35 idMenuScreen_Shell_Singleplayer::Initialize 36 ======================== 37 */ 38 void idMenuScreen_Shell_Singleplayer::Initialize( idMenuHandler * data ) { 39 idMenuScreen::Initialize( data ); 40 41 if ( data != NULL ) { 42 menuGUI = data->GetGUI(); 43 } 44 45 SetSpritePath( "menuCampaign" ); 46 47 options = new (TAG_SWF) idMenuWidget_DynamicList(); 48 options->SetNumVisibleOptions( NUM_SINGLEPLAYER_OPTIONS ); 49 options->SetSpritePath( GetSpritePath(), "info", "options" ); 50 options->SetWrappingAllowed( true ); 51 AddChild( options ); 52 53 idMenuWidget_Help * const helpWidget = new ( TAG_SWF ) idMenuWidget_Help(); 54 helpWidget->SetSpritePath( GetSpritePath(), "info", "helpTooltip" ); 55 AddChild( helpWidget ); 56 57 while ( options->GetChildren().Num() < NUM_SINGLEPLAYER_OPTIONS ) { 58 idMenuWidget_Button * const buttonWidget = new (TAG_SWF) idMenuWidget_Button(); 59 buttonWidget->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() ); 60 buttonWidget->RegisterEventObserver( helpWidget ); 61 buttonWidget->Initialize( data ); 62 options->AddChild( buttonWidget ); 63 } 64 options->Initialize( data ); 65 66 btnBack = new (TAG_SWF) idMenuWidget_Button(); 67 btnBack->Initialize( data ); 68 btnBack->SetLabel( "#str_02305" ); 69 btnBack->SetSpritePath( GetSpritePath(), "info", "btnBack" ); 70 btnBack->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_GO_BACK ); 71 72 AddChild( btnBack ); 73 74 options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN ) ); 75 options->AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP ) ); 76 options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) ); 77 options->AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) ); 78 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 ) ); 79 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 ) ); 80 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 ) ); 81 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 ) ); 82 } 83 84 /* 85 ======================== 86 idMenuScreen_Shell_Singleplayer::Update 87 ======================== 88 */ 89 void idMenuScreen_Shell_Singleplayer::Update() { 90 91 if ( menuData != NULL ) { 92 idMenuWidget_CommandBar * cmdBar = menuData->GetCmdBar(); 93 if ( cmdBar != NULL ) { 94 cmdBar->ClearAllButtons(); 95 idMenuWidget_CommandBar::buttonInfo_t * buttonInfo; 96 buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 ); 97 if ( menuData->GetPlatform() != 2 ) { 98 buttonInfo->label = "#str_00395"; 99 } 100 buttonInfo->action.Set( WIDGET_ACTION_GO_BACK ); 101 102 buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 ); 103 if ( menuData->GetPlatform() != 2 ) { 104 buttonInfo->label = "#str_SWF_SELECT"; 105 } 106 buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED ); 107 } 108 } 109 110 idSWFScriptObject & root = GetSWFObject()->GetRootObject(); 111 if ( BindSprite( root ) ) { 112 idSWFTextInstance * heading = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtHeading" ); 113 if ( heading != NULL ) { 114 heading->SetText( "#str_swf_campaign" ); 115 heading->SetStrokeInfo( true, 0.75f, 1.75f ); 116 } 117 118 idSWFSpriteInstance * gradient = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "gradient" ); 119 if ( gradient != NULL && heading != NULL ) { 120 gradient->SetXPos( heading->GetTextLength() ); 121 } 122 } 123 124 if ( btnBack != NULL ) { 125 btnBack->BindSprite( root ); 126 } 127 128 idMenuScreen::Update(); 129 } 130 131 /* 132 ======================== 133 idMenuScreen_Shell_Singleplayer::ShowScreen 134 ======================== 135 */ 136 void idMenuScreen_Shell_Singleplayer::ShowScreen( const mainMenuTransition_t transitionType ) { 137 138 idList< idList< idStr, TAG_IDLIB_LIST_MENU >, TAG_IDLIB_LIST_MENU > menuOptions; 139 idList< idStr > option; 140 141 canContinue = false; 142 const saveGameDetailsList_t & saveGameInfo = session->GetSaveGameManager().GetEnumeratedSavegames(); 143 canContinue = ( saveGameInfo.Num() > 0 ); 144 if ( canContinue ) { 145 option.Append( "#str_swf_continue_game" ); // continue game 146 menuOptions.Append( option ); 147 option.Clear(); 148 option.Append( "#str_01866" ); // new game 149 menuOptions.Append( option ); 150 option.Clear(); 151 option.Append( "#str_01867" ); // load game 152 menuOptions.Append( option ); 153 154 int index = 0; 155 idMenuWidget_Button * buttonWidget = dynamic_cast< idMenuWidget_Button * >( &options->GetChildByIndex( index ) ); 156 if ( buttonWidget != NULL ) { 157 buttonWidget->SetDescription( "#str_swf_continue_desc" ); 158 } 159 index++; 160 buttonWidget = dynamic_cast< idMenuWidget_Button * >( &options->GetChildByIndex( index ) ); 161 if ( buttonWidget != NULL ) { 162 buttonWidget->SetDescription( "#str_02209" ); 163 } 164 index++; 165 buttonWidget = dynamic_cast< idMenuWidget_Button * >( &options->GetChildByIndex( index ) ); 166 if ( buttonWidget != NULL ) { 167 buttonWidget->SetDescription( "#str_02213" ); 168 } 169 index++; 170 171 } else { 172 option.Append( "#str_01866" ); // new game 173 menuOptions.Append( option ); 174 option.Clear(); 175 option.Append( "#str_01867" ); // load game 176 menuOptions.Append( option ); 177 178 if ( options != NULL ) { 179 int index = 0; 180 idMenuWidget_Button * buttonWidget = dynamic_cast< idMenuWidget_Button * >( &options->GetChildByIndex( index ) ); 181 if ( buttonWidget != NULL ) { 182 buttonWidget->SetDescription( "#str_02209" ); 183 } 184 index++; 185 buttonWidget = dynamic_cast< idMenuWidget_Button * >( &options->GetChildByIndex( index ) ); 186 if ( buttonWidget != NULL ) { 187 buttonWidget->SetDescription( "#str_02213" ); 188 } 189 } 190 } 191 192 if ( options != NULL ) { 193 options->SetListData( menuOptions ); 194 } 195 196 idMenuScreen::ShowScreen( transitionType ); 197 } 198 199 /* 200 ======================== 201 idMenuScreen_Shell_Singleplayer::HideScreen 202 ======================== 203 */ 204 void idMenuScreen_Shell_Singleplayer::HideScreen( const mainMenuTransition_t transitionType ) { 205 idMenuScreen::HideScreen( transitionType ); 206 } 207 208 /* 209 ======================== 210 idMenuScreen_Shell_Singleplayer::ContinueGame 211 ======================== 212 */ 213 void idMenuScreen_Shell_Singleplayer::ContinueGame() { 214 const saveGameDetailsList_t & saveGameInfo = session->GetSaveGameManager().GetEnumeratedSavegames(); 215 saveGameDetailsList_t sortedSaves = saveGameInfo; 216 sortedSaves.Sort( idSort_SavesByDate() ); 217 if ( sortedSaves.Num() > 0 ) { 218 if ( sortedSaves[0].damaged ) { 219 class idSWFScriptFunction_ContinueDamaged : public idSWFScriptFunction_RefCounted { 220 public: 221 idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) { 222 common->Dialog().ClearDialog( GDM_CORRUPT_CONTINUE ); 223 return idSWFScriptVar(); 224 } 225 }; 226 227 idStaticList< idSWFScriptFunction *, 4 > callbacks; 228 callbacks.Append( new (TAG_SWF) idSWFScriptFunction_ContinueDamaged() ); 229 idStaticList< idStrId, 4 > optionText; 230 optionText.Append( idStrId( "#str_04339" ) ); // OK 231 common->Dialog().AddDynamicDialog( GDM_CORRUPT_CONTINUE, callbacks, optionText, false, "" ); 232 } else { 233 const idStr & name = sortedSaves[ 0 ].slotName; 234 cmdSystem->AppendCommandText( va( "loadgame %s\n", name.c_str() ) ); 235 } 236 } 237 } 238 239 /* 240 ======================== 241 idMenuScreen_Shell_Singleplayer::HandleAction 242 ======================== 243 */ 244 bool idMenuScreen_Shell_Singleplayer::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) { 245 246 if ( menuData == NULL ) { 247 return true; 248 } 249 250 if ( menuData->ActiveScreen() != SHELL_AREA_CAMPAIGN ) { 251 return false; 252 } 253 254 widgetAction_t actionType = action.GetType(); 255 const idSWFParmList & parms = action.GetParms(); 256 257 switch ( actionType ) { 258 case WIDGET_ACTION_GO_BACK: { 259 menuData->SetNextScreen( SHELL_AREA_ROOT, MENU_TRANSITION_SIMPLE ); 260 return true; 261 } 262 case WIDGET_ACTION_PRESS_FOCUSED: { 263 if ( options == NULL ) { 264 return true; 265 } 266 267 int selectionIndex = options->GetViewIndex(); 268 if ( parms.Num() == 1 ) { 269 selectionIndex = parms[0].ToInteger(); 270 } 271 272 canContinue = false; 273 const saveGameDetailsList_t & saveGameInfo = session->GetSaveGameManager().GetEnumeratedSavegames(); 274 canContinue = ( saveGameInfo.Num() > 0 ); 275 if ( canContinue ) { 276 if ( selectionIndex == 0 ) { 277 ContinueGame(); 278 279 } else if ( selectionIndex == 1 ) { 280 class idSWFScriptFunction_NewGame : public idSWFScriptFunction_RefCounted { 281 public: 282 idSWFScriptFunction_NewGame( idMenuHandler * _menuData, bool _accept ) { 283 menuData = _menuData; 284 accept = _accept; 285 } 286 idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) { 287 common->Dialog().ClearDialog( GDM_DELETE_AUTOSAVE ); 288 if ( accept ) { 289 menuData->SetNextScreen( SHELL_AREA_NEW_GAME, MENU_TRANSITION_SIMPLE ); 290 } 291 return idSWFScriptVar(); 292 } 293 private: 294 idMenuHandler * menuData; 295 bool accept; 296 }; 297 common->Dialog().AddDialog( GDM_DELETE_AUTOSAVE, DIALOG_ACCEPT_CANCEL, new idSWFScriptFunction_NewGame( menuData, true ), new idSWFScriptFunction_NewGame( menuData, false ), true ); 298 } else if ( selectionIndex == 2 ) { 299 menuData->SetNextScreen( SHELL_AREA_LOAD, MENU_TRANSITION_SIMPLE ); 300 } 301 } else { 302 if ( selectionIndex == 0 ) { 303 menuData->SetNextScreen( SHELL_AREA_NEW_GAME, MENU_TRANSITION_SIMPLE ); 304 } else if ( selectionIndex == 1 ) { 305 menuData->SetNextScreen( SHELL_AREA_LOAD, MENU_TRANSITION_SIMPLE ); 306 } 307 } 308 309 return true; 310 } 311 } 312 313 return idMenuWidget::HandleAction( action, event, widget, forceHandled ); 314 }