MenuScreen_Shell_GameOptions.cpp (14954B)
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_GAME_OPTIONS_OPTIONS = 8; 33 34 const float MIN_FOV = 80.0f; 35 const float MAX_FOV = 100.0f; 36 37 const float MIN_FOV_GUN = 3.0f; 38 const float MAX_FOV_GUN = 0.0f; 39 40 /* 41 ======================== 42 idMenuScreen_Shell_GameOptions::Initialize 43 ======================== 44 */ 45 void idMenuScreen_Shell_GameOptions::Initialize( idMenuHandler * data ) { 46 idMenuScreen::Initialize( data ); 47 48 if ( data != NULL ) { 49 menuGUI = data->GetGUI(); 50 } 51 52 SetSpritePath( "menuGameOptions" ); 53 54 options = new (TAG_SWF) idMenuWidget_DynamicList(); 55 options->SetNumVisibleOptions( NUM_GAME_OPTIONS_OPTIONS ); 56 options->SetSpritePath( GetSpritePath(), "info", "options" ); 57 options->SetWrappingAllowed( true ); 58 options->SetControlList( true ); 59 options->Initialize( data ); 60 AddChild( options ); 61 62 btnBack = new (TAG_SWF) idMenuWidget_Button(); 63 btnBack->Initialize( data ); 64 btnBack->SetLabel( "#str_swf_settings" ); 65 btnBack->SetSpritePath( GetSpritePath(), "info", "btnBack" ); 66 btnBack->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_GO_BACK ); 67 AddChild( btnBack ); 68 69 idMenuWidget_ControlButton * control; 70 71 control = new (TAG_SWF) idMenuWidget_ControlButton(); 72 control->SetOptionType( OPTION_SLIDER_TEXT ); 73 control->SetLabel( "#str_swf_fov" ); 74 control->SetDataSource( &systemData, idMenuDataSource_GameSettings::GAME_FIELD_FOV ); 75 control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() ); 76 control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() ); 77 options->AddChild( control ); 78 79 control = new (TAG_SWF) idMenuWidget_ControlButton(); 80 control->SetOptionType( OPTION_SLIDER_TOGGLE ); 81 control->SetLabel( "#str_swf_checkpoints" ); 82 control->SetDataSource( &systemData, idMenuDataSource_GameSettings::GAME_FIELD_CHECKPOINTS ); 83 control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() ); 84 control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() ); 85 options->AddChild( control ); 86 87 control = new (TAG_SWF) idMenuWidget_ControlButton(); 88 control->SetOptionType( OPTION_SLIDER_TOGGLE ); 89 control->SetLabel( "#str_02135" ); // Auto Weapon Switch 90 control->SetDataSource( &systemData, idMenuDataSource_GameSettings::GAME_FIELD_AUTO_SWITCH ); 91 control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() ); 92 control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() ); 93 options->AddChild( control ); 94 95 control = new (TAG_SWF) idMenuWidget_ControlButton(); 96 control->SetOptionType( OPTION_SLIDER_TOGGLE ); 97 control->SetLabel( "#str_02134" ); // Auto Weapon Reload 98 control->SetDataSource( &systemData, idMenuDataSource_GameSettings::GAME_FIELD_AUTO_RELOAD ); 99 control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() ); 100 control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() ); 101 options->AddChild( control ); 102 103 control = new (TAG_SWF) idMenuWidget_ControlButton(); 104 control->SetOptionType( OPTION_SLIDER_TOGGLE ); 105 control->SetLabel( "#str_swf_aim_assist" ); // Aim Assist 106 control->SetDataSource( &systemData, idMenuDataSource_GameSettings::GAME_FIELD_AIM_ASSIST ); 107 control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() ); 108 control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() ); 109 options->AddChild( control ); 110 111 control = new (TAG_SWF) idMenuWidget_ControlButton(); 112 control->SetOptionType( OPTION_SLIDER_TOGGLE ); 113 control->SetLabel( "#str_04102" ); // Always Run 114 control->SetDataSource( &systemData, idMenuDataSource_GameSettings::GAME_FIELD_ALWAYS_SPRINT ); 115 control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() ); 116 control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() ); 117 options->AddChild( control ); 118 119 control = new (TAG_SWF) idMenuWidget_ControlButton(); 120 control->SetOptionType( OPTION_SLIDER_TOGGLE ); 121 control->SetLabel( "#str_swf_flashlight_shadows" ); 122 control->SetDataSource( &systemData, idMenuDataSource_GameSettings::GAME_FIELD_FLASHLIGHT_SHADOWS ); 123 control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() ); 124 control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() ); 125 options->AddChild( control ); 126 127 options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN ) ); 128 options->AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP ) ); 129 options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) ); 130 options->AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) ); 131 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 ) ); 132 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 ) ); 133 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 ) ); 134 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 ) ); 135 } 136 137 /* 138 ======================== 139 idMenuScreen_Shell_GameOptions::Update 140 ======================== 141 */ 142 void idMenuScreen_Shell_GameOptions::Update() { 143 144 if ( menuData != NULL ) { 145 idMenuWidget_CommandBar * cmdBar = menuData->GetCmdBar(); 146 if ( cmdBar != NULL ) { 147 cmdBar->ClearAllButtons(); 148 idMenuWidget_CommandBar::buttonInfo_t * buttonInfo; 149 buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 ); 150 if ( menuData->GetPlatform() != 2 ) { 151 buttonInfo->label = "#str_00395"; 152 } 153 buttonInfo->action.Set( WIDGET_ACTION_GO_BACK ); 154 155 buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 ); 156 buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED ); 157 } 158 } 159 160 idSWFScriptObject & root = GetSWFObject()->GetRootObject(); 161 if ( BindSprite( root ) ) { 162 idSWFTextInstance * heading = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtHeading" ); 163 if ( heading != NULL ) { 164 heading->SetText( "#str_02129" ); // SYSTEM SETTINGS 165 heading->SetStrokeInfo( true, 0.75f, 1.75f ); 166 } 167 168 idSWFSpriteInstance * gradient = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "gradient" ); 169 if ( gradient != NULL && heading != NULL ) { 170 gradient->SetXPos( heading->GetTextLength() ); 171 } 172 } 173 174 if ( btnBack != NULL ) { 175 btnBack->BindSprite( root ); 176 } 177 178 idMenuScreen::Update(); 179 } 180 181 /* 182 ======================== 183 idMenuScreen_Shell_GameOptions::ShowScreen 184 ======================== 185 */ 186 void idMenuScreen_Shell_GameOptions::ShowScreen( const mainMenuTransition_t transitionType ) { 187 systemData.LoadData(); 188 idMenuScreen::ShowScreen( transitionType ); 189 } 190 191 /* 192 ======================== 193 idMenuScreen_Shell_GameOptions::HideScreen 194 ======================== 195 */ 196 void idMenuScreen_Shell_GameOptions::HideScreen( const mainMenuTransition_t transitionType ) { 197 if ( systemData.IsDataChanged() ) { 198 systemData.CommitData(); 199 } 200 idMenuScreen::HideScreen( transitionType ); 201 } 202 203 /* 204 ======================== 205 idMenuScreen_Shell_GameOptions::HandleAction h 206 ======================== 207 */ 208 bool idMenuScreen_Shell_GameOptions::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) { 209 210 if ( menuData == NULL ) { 211 return true; 212 } 213 214 if ( menuData->ActiveScreen() != SHELL_AREA_GAME_OPTIONS ) { 215 return false; 216 } 217 218 widgetAction_t actionType = action.GetType(); 219 const idSWFParmList & parms = action.GetParms(); 220 221 switch ( actionType ) { 222 case WIDGET_ACTION_GO_BACK: { 223 menuData->SetNextScreen( SHELL_AREA_SETTINGS, MENU_TRANSITION_SIMPLE ); 224 return true; 225 } 226 case WIDGET_ACTION_PRESS_FOCUSED: { 227 228 if ( options == NULL ) { 229 return true; 230 } 231 232 int selectionIndex = options->GetFocusIndex(); 233 if ( parms.Num() > 0 ) { 234 selectionIndex = parms[0].ToInteger(); 235 } 236 237 if ( selectionIndex != options->GetFocusIndex() ) { 238 options->SetViewIndex( options->GetViewOffset() + selectionIndex ); 239 options->SetFocusIndex( selectionIndex ); 240 } 241 242 systemData.AdjustField( selectionIndex, 1 ); 243 options->Update(); 244 245 return true; 246 } 247 case WIDGET_ACTION_START_REPEATER: { 248 if ( parms.Num() == 4 ) { 249 int selectionIndex = parms[3].ToInteger(); 250 if ( selectionIndex != options->GetFocusIndex() ) { 251 options->SetViewIndex( options->GetViewOffset() + selectionIndex ); 252 options->SetFocusIndex( selectionIndex ); 253 } 254 } 255 break; 256 } 257 } 258 259 return idMenuWidget::HandleAction( action, event, widget, forceHandled ); 260 } 261 262 ///////////////////////////////// 263 // SCREEN SETTINGS 264 ///////////////////////////////// 265 266 extern idCVar ui_autoSwitch; 267 extern idCVar ui_autoReload; 268 extern idCVar aa_targetAimAssistEnable; 269 extern idCVar in_alwaysRun; 270 extern idCVar g_checkpoints; 271 extern idCVar g_weaponShadows; 272 273 /* 274 ======================== 275 idMenuScreen_Shell_GameOptions::idMenuDataSource_AudioSettings::idMenuDataSource_AudioSettings 276 ======================== 277 */ 278 idMenuScreen_Shell_GameOptions::idMenuDataSource_GameSettings::idMenuDataSource_GameSettings() { 279 fields.SetNum( MAX_GAME_FIELDS ); 280 originalFields.SetNum( MAX_GAME_FIELDS ); 281 } 282 283 /* 284 ======================== 285 idMenuScreen_Shell_GameOptions::idMenuDataSource_AudioSettings::LoadData 286 ======================== 287 */ 288 void idMenuScreen_Shell_GameOptions::idMenuDataSource_GameSettings::LoadData() { 289 fields[ GAME_FIELD_FOV ].SetInteger( g_fov.GetFloat() ); 290 fields[ GAME_FIELD_CHECKPOINTS ].SetBool( g_checkpoints.GetBool() ); 291 fields[ GAME_FIELD_AUTO_SWITCH ].SetBool( ui_autoSwitch.GetBool() ); 292 fields[ GAME_FIELD_AUTO_RELOAD ].SetBool( ui_autoReload.GetBool() ); 293 fields[ GAME_FIELD_AIM_ASSIST ].SetBool( aa_targetAimAssistEnable.GetBool() ); 294 fields[ GAME_FIELD_ALWAYS_SPRINT ].SetBool( in_alwaysRun.GetBool() ); 295 fields[ GAME_FIELD_FLASHLIGHT_SHADOWS ].SetBool( g_weaponShadows.GetBool() ); 296 originalFields = fields; 297 } 298 299 /* 300 ======================== 301 idMenuScreen_Shell_GameOptions::idMenuDataSource_AudioSettings::CommitData 302 ======================== 303 */ 304 void idMenuScreen_Shell_GameOptions::idMenuDataSource_GameSettings::CommitData() { 305 306 g_fov.SetFloat( fields[ GAME_FIELD_FOV ].ToFloat() ); 307 g_gun_x.SetFloat( Lerp( MIN_FOV_GUN, MAX_FOV_GUN, ( fields[ GAME_FIELD_FOV ].ToFloat() - MIN_FOV ) / ( MAX_FOV - MIN_FOV ) ) ); 308 309 g_checkpoints.SetBool( fields[ GAME_FIELD_CHECKPOINTS ].ToBool() ); 310 ui_autoSwitch.SetBool( fields[ GAME_FIELD_AUTO_SWITCH ].ToBool() ); 311 ui_autoReload.SetBool( fields[ GAME_FIELD_AUTO_RELOAD ].ToBool() ); 312 aa_targetAimAssistEnable.SetBool( fields[ GAME_FIELD_AIM_ASSIST ].ToBool() ); 313 in_alwaysRun.SetBool( fields[ GAME_FIELD_ALWAYS_SPRINT ].ToBool() ); 314 g_weaponShadows.SetBool( fields[ GAME_FIELD_FLASHLIGHT_SHADOWS ].ToBool() ); 315 316 cvarSystem->SetModifiedFlags( CVAR_ARCHIVE ); 317 318 // make the committed fields into the backup fields 319 originalFields = fields; 320 } 321 322 /* 323 ======================== 324 idMenuScreen_Shell_GameOptions::idMenuDataSource_AudioSettings::AdjustField 325 ======================== 326 */ 327 void idMenuScreen_Shell_GameOptions::idMenuDataSource_GameSettings::AdjustField( const int fieldIndex, const int adjustAmount ) { 328 if ( fieldIndex == GAME_FIELD_FOV ) { 329 fields[ fieldIndex ].SetInteger( idMath::ClampInt( MIN_FOV, MAX_FOV, fields[ fieldIndex ].ToInteger() + adjustAmount * 5 ) ); 330 } else { 331 fields[ fieldIndex ].SetBool( !fields[ fieldIndex ].ToBool() ); 332 } 333 } 334 335 /* 336 ======================== 337 idMenuScreen_Shell_GameOptions::idMenuDataSource_AudioSettings::IsDataChanged 338 ======================== 339 */ 340 bool idMenuScreen_Shell_GameOptions::idMenuDataSource_GameSettings::IsDataChanged() const { 341 342 if ( fields[ GAME_FIELD_FOV ].ToInteger() != originalFields[ GAME_FIELD_FOV ].ToInteger() ) { 343 return true; 344 } 345 346 if ( fields[ GAME_FIELD_CHECKPOINTS ].ToBool() != originalFields[ GAME_FIELD_CHECKPOINTS ].ToBool() ) { 347 return true; 348 } 349 350 if ( fields[ GAME_FIELD_AUTO_SWITCH ].ToBool() != originalFields[ GAME_FIELD_AUTO_SWITCH ].ToBool() ) { 351 return true; 352 } 353 354 if ( fields[ GAME_FIELD_AUTO_RELOAD ].ToBool() != originalFields[ GAME_FIELD_AUTO_RELOAD ].ToBool() ) { 355 return true; 356 } 357 358 if ( fields[ GAME_FIELD_AIM_ASSIST ].ToBool() != originalFields[ GAME_FIELD_AIM_ASSIST ].ToBool() ) { 359 return true; 360 } 361 362 if ( fields[ GAME_FIELD_ALWAYS_SPRINT ].ToBool() != originalFields[ GAME_FIELD_ALWAYS_SPRINT ].ToBool() ) { 363 return true; 364 } 365 366 if ( fields[ GAME_FIELD_FLASHLIGHT_SHADOWS ].ToBool() != originalFields[ GAME_FIELD_FLASHLIGHT_SHADOWS ].ToBool() ) { 367 return true; 368 } 369 370 return false; 371 }