MenuScreen_Shell_ControllerLayout.cpp (12039B)
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_LAYOUT_OPTIONS = 1; 33 34 const static int MAX_CONTROLLER_CONFIGS = 2; 35 36 typedef struct { 37 const char * textField; 38 int keyNum; 39 } gamepadBindInfo_t; 40 41 static gamepadBindInfo_t gamepadBinds[] = { 42 { "txtJoy1", K_JOY1 }, 43 { "txtJoy2", K_JOY2 }, 44 { "txtJoy3", K_JOY3 }, 45 { "txtJoy4", K_JOY4 }, 46 { "txtDpad", K_JOY_DPAD_UP }, 47 { "txtStart", K_JOY9 }, 48 { "txtBack", K_JOY10 }, 49 { "txtLClick", K_JOY7 }, 50 { "txtRClick", K_JOY8 }, 51 { "txtLBumper", K_JOY5 }, 52 { "txtRBumper", K_JOY6 }, 53 { "txtLStick", K_JOY_STICK1_UP }, 54 { "txtRStick", K_JOY_STICK2_UP }, 55 { "txtLTrigger", K_JOY_TRIGGER1 }, 56 { "txtRTrigger", K_JOY_TRIGGER2 } 57 }; 58 59 static const int numGamepadBinds = sizeof( gamepadBinds ) / sizeof( gamepadBinds[0] ); 60 61 /* 62 ======================== 63 idMenuScreen_Shell_ControllerLayout::Initialize 64 ======================== 65 */ 66 void idMenuScreen_Shell_ControllerLayout::Initialize( idMenuHandler * data ) { 67 idMenuScreen::Initialize( data ); 68 69 if ( data != NULL ) { 70 menuGUI = data->GetGUI(); 71 } 72 73 SetSpritePath( "menuControllerLayout" ); 74 75 options = new (TAG_SWF) idMenuWidget_DynamicList(); 76 options->SetNumVisibleOptions( NUM_LAYOUT_OPTIONS ); 77 options->SetSpritePath( GetSpritePath(), "info", "controlInfo", "options" ); 78 options->SetWrappingAllowed( true ); 79 options->SetControlList( true ); 80 options->Initialize( data ); 81 AddChild( options ); 82 83 btnBack = new (TAG_SWF) idMenuWidget_Button(); 84 btnBack->Initialize( data ); 85 btnBack->SetLabel( "#str_swf_gamepad_heading" ); // CONTROLS 86 btnBack->SetSpritePath( GetSpritePath(), "info", "btnBack" ); 87 btnBack->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_GO_BACK ); 88 AddChild( btnBack ); 89 90 idMenuWidget_ControlButton * control = new (TAG_SWF) idMenuWidget_ControlButton(); 91 control->SetOptionType( OPTION_BUTTON_FULL_TEXT_SLIDER ); 92 control->SetLabel( "CONTROL LAYOUT" ); // Auto Weapon Reload 93 control->SetDataSource( &layoutData, idMenuDataSource_LayoutSettings::LAYOUT_FIELD_LAYOUT ); 94 control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() ); 95 control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() ); 96 options->AddChild( control ); 97 } 98 99 /* 100 ======================== 101 idMenuScreen_Shell_ControllerLayout::Update 102 ======================== 103 */ 104 void idMenuScreen_Shell_ControllerLayout::Update() { 105 106 if ( menuData != NULL ) { 107 idMenuWidget_CommandBar * cmdBar = menuData->GetCmdBar(); 108 if ( cmdBar != NULL ) { 109 cmdBar->ClearAllButtons(); 110 idMenuWidget_CommandBar::buttonInfo_t * buttonInfo; 111 buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 ); 112 if ( menuData->GetPlatform() != 2 ) { 113 buttonInfo->label = "#str_00395"; 114 } 115 buttonInfo->action.Set( WIDGET_ACTION_GO_BACK ); 116 117 buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 ); 118 buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED ); 119 } 120 } 121 122 idSWFScriptObject & root = GetSWFObject()->GetRootObject(); 123 if ( BindSprite( root ) ) { 124 idSWFTextInstance * heading = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtHeading" ); 125 if ( heading != NULL ) { 126 heading->SetText( "#str_swf_controller_layout" ); // CONTROLLER LAYOUT 127 heading->SetStrokeInfo( true, 0.75f, 1.75f ); 128 } 129 130 idSWFSpriteInstance * gradient = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "gradient" ); 131 if ( gradient != NULL && heading != NULL ) { 132 gradient->SetXPos( heading->GetTextLength() ); 133 } 134 135 if ( menuData != NULL ) { 136 idSWFSpriteInstance * layout = NULL; 137 138 layout = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "controlInfo", "layout360" ); 139 140 if ( layout != NULL ) { 141 if ( menuData->GetPlatform( true ) == 2 ) { 142 layout->StopFrame( 1 ); 143 } else { 144 layout->StopFrame( menuData->GetPlatform( true ) + 1 ); 145 } 146 } 147 } 148 } 149 150 if ( btnBack != NULL ) { 151 btnBack->BindSprite( root ); 152 } 153 154 155 156 idMenuScreen::Update(); 157 } 158 159 /* 160 ======================== 161 idMenuScreen_Shell_ControllerLayout::ShowScreen 162 ======================== 163 */ 164 void idMenuScreen_Shell_ControllerLayout::ShowScreen( const mainMenuTransition_t transitionType ) { 165 layoutData.LoadData(); 166 idMenuScreen::ShowScreen( transitionType ); 167 168 if ( GetSprite() != NULL ) { 169 170 idSWFSpriteInstance * layout360 = NULL; 171 idSWFSpriteInstance * layoutPS3 = NULL; 172 173 layout360 = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "controlInfo", "layout360" ); 174 layoutPS3 = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "controlInfo", "layoutPS3" ); 175 176 if ( layout360 != NULL && layoutPS3 != NULL ) { 177 layout360->SetVisible( true ); 178 layoutPS3->SetVisible( false ); 179 } 180 } 181 182 UpdateBindingInfo(); 183 } 184 185 /* 186 ======================== 187 idMenuScreen_Shell_ControllerLayout::HideScreen 188 ======================== 189 */ 190 void idMenuScreen_Shell_ControllerLayout::HideScreen( const mainMenuTransition_t transitionType ) { 191 layoutData.CommitData(); 192 idMenuScreen::HideScreen( transitionType ); 193 } 194 195 /* 196 ======================== 197 idMenuScreen_Shell_ControllerLayout::UpdateBindingInfo 198 ======================== 199 */ 200 void idMenuScreen_Shell_ControllerLayout::UpdateBindingInfo() { 201 202 if ( !GetSprite() ) { 203 return; 204 } 205 206 for ( int i = 0; i < numGamepadBinds; ++i ) { 207 208 const char * txtField = gamepadBinds[i].textField; 209 int keyNum = gamepadBinds[i].keyNum; 210 211 idSWFTextInstance * txtVal = NULL; 212 213 txtVal = GetSprite()->GetScriptObject()->GetNestedText( "info", "controlInfo", "layout360", txtField ); 214 215 if ( txtVal != NULL ) { 216 const char * binding = idKeyInput::GetBinding( keyNum ); 217 if ( binding == NULL || binding[0] == 0 ) { 218 txtVal->SetText( "" ); 219 } else if ( keyNum == K_JOY7 ) { 220 idStr action = idLocalization::GetString( va( "#str_swf_action%s", binding ) ); 221 txtVal->SetText( action.c_str() ); 222 } else if ( keyNum == K_JOY8 ) { 223 idStr action = idLocalization::GetString( va( "#str_swf_action%s", binding ) ); 224 txtVal->SetText( action.c_str() ); 225 } else { 226 txtVal->SetText( va( "#str_swf_action%s", binding ) ); 227 } 228 } 229 } 230 } 231 232 /* 233 ======================== 234 idMenuScreen_Shell_ControllerLayout::HandleAction h 235 ======================== 236 */ 237 bool idMenuScreen_Shell_ControllerLayout::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) { 238 239 if ( menuData == NULL ) { 240 return true; 241 } 242 243 if ( menuData->ActiveScreen() != SHELL_AREA_CONTROLLER_LAYOUT ) { 244 return false; 245 } 246 247 widgetAction_t actionType = action.GetType(); 248 const idSWFParmList & parms = action.GetParms(); 249 250 switch ( actionType ) { 251 case WIDGET_ACTION_GO_BACK: { 252 menuData->SetNextScreen( SHELL_AREA_GAMEPAD, MENU_TRANSITION_SIMPLE ); 253 return true; 254 } 255 case WIDGET_ACTION_PRESS_FOCUSED: { 256 if ( parms.Num() != 1 ) { 257 return true; 258 } 259 260 if ( options == NULL ) { 261 return true; 262 } 263 264 int selectionIndex = parms[0].ToInteger(); 265 if ( selectionIndex != options->GetFocusIndex() ) { 266 options->SetViewIndex( options->GetViewOffset() + selectionIndex ); 267 options->SetFocusIndex( selectionIndex ); 268 } 269 270 layoutData.AdjustField( selectionIndex, 1 ); 271 options->Update(); 272 UpdateBindingInfo(); 273 return true; 274 } 275 case WIDGET_ACTION_START_REPEATER: { 276 277 if ( options == NULL ) { 278 return true; 279 } 280 281 if ( parms.Num() == 4 ) { 282 int selectionIndex = parms[3].ToInteger(); 283 if ( selectionIndex != options->GetFocusIndex() ) { 284 options->SetViewIndex( options->GetViewOffset() + selectionIndex ); 285 options->SetFocusIndex( selectionIndex ); 286 } 287 } 288 break; 289 } 290 case WIDGET_ACTION_ADJUST_FIELD: { 291 if ( widget != NULL && widget->GetDataSource() != NULL ) { 292 widget->GetDataSource()->AdjustField( widget->GetDataSourceFieldIndex(), parms[ 0 ].ToInteger() ); 293 widget->Update(); 294 } 295 UpdateBindingInfo(); 296 return true; 297 } 298 } 299 300 return idMenuWidget::HandleAction( action, event, widget, forceHandled ); 301 } 302 303 /* 304 ======================== 305 idMenuScreen_Shell_ControllerLayout::idMenuDataSource_AudioSettings::idMenuDataSource_AudioSettings 306 ======================== 307 */ 308 idMenuScreen_Shell_ControllerLayout::idMenuDataSource_LayoutSettings::idMenuDataSource_LayoutSettings() { 309 fields.SetNum( MAX_LAYOUT_FIELDS ); 310 originalFields.SetNum( MAX_LAYOUT_FIELDS ); 311 } 312 313 /* 314 ======================== 315 idMenuScreen_Shell_ControllerLayout::idMenuDataSource_AudioSettings::LoadData 316 ======================== 317 */ 318 void idMenuScreen_Shell_ControllerLayout::idMenuDataSource_LayoutSettings::LoadData() { 319 320 idPlayerProfile * profile = session->GetProfileFromMasterLocalUser(); 321 if ( profile == NULL ) { 322 return; 323 } 324 325 int configSet = profile->GetConfig(); 326 327 fields[ LAYOUT_FIELD_LAYOUT ].SetString( idLocalization::GetString( va( "#str_swf_config_360_%i", configSet ) ) ); 328 329 originalFields = fields; 330 } 331 332 /* 333 ======================== 334 idMenuScreen_Shell_ControllerLayout::idMenuDataSource_AudioSettings::CommitData 335 ======================== 336 */ 337 void idMenuScreen_Shell_ControllerLayout::idMenuDataSource_LayoutSettings::CommitData() { 338 339 if ( IsDataChanged() ) { 340 cvarSystem->SetModifiedFlags( CVAR_ARCHIVE ); 341 } 342 343 // make the committed fields into the backup fields 344 originalFields = fields; 345 } 346 347 /* 348 ======================== 349 idMenuScreen_Shell_ControllerLayout::idMenuDataSource_AudioSettings::AdjustField 350 ======================== 351 */ 352 void idMenuScreen_Shell_ControllerLayout::idMenuDataSource_LayoutSettings::AdjustField( const int fieldIndex, const int adjustAmount ) { 353 354 idPlayerProfile * profile = session->GetProfileFromMasterLocalUser(); 355 if ( profile == NULL ) { 356 return; 357 } 358 359 int configSet = profile->GetConfig(); 360 361 if ( fieldIndex == LAYOUT_FIELD_LAYOUT ) { 362 configSet += adjustAmount; 363 if ( configSet < 0 ) { 364 configSet = MAX_CONTROLLER_CONFIGS - 1; 365 } else if ( configSet >= MAX_CONTROLLER_CONFIGS ) { 366 configSet = 0; 367 } 368 } 369 370 fields[ LAYOUT_FIELD_LAYOUT ].SetString( idLocalization::GetString( va( "#str_swf_config_360_%i", configSet ) ) ); 371 372 profile->SetConfig( configSet, false ); 373 374 } 375 376 /* 377 ======================== 378 idMenuScreen_Shell_ControllerLayout::idMenuDataSource_AudioSettings::IsDataChanged 379 ======================== 380 */ 381 bool idMenuScreen_Shell_ControllerLayout::idMenuDataSource_LayoutSettings::IsDataChanged() const { 382 bool hasLocalChanges = false; 383 384 if ( fields[ LAYOUT_FIELD_LAYOUT ].ToString() != originalFields[ LAYOUT_FIELD_LAYOUT ].ToString() ) { 385 return true; 386 } 387 388 return hasLocalChanges; 389 }