MenuScreen_Shell_MatchSettings.cpp (16993B)
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 ======================== 35 idMenuScreen_Shell_MatchSettings::Initialize 36 ======================== 37 */ 38 void idMenuScreen_Shell_MatchSettings::Initialize( idMenuHandler * data ) { 39 idMenuScreen::Initialize( data ); 40 41 if ( data != NULL ) { 42 menuGUI = data->GetGUI(); 43 } 44 45 SetSpritePath( "menuMatchSettings" ); 46 47 options = new (TAG_SWF) idMenuWidget_DynamicList(); 48 options->SetNumVisibleOptions( NUM_GAME_OPTIONS_OPTIONS ); 49 options->SetSpritePath( GetSpritePath(), "info", "options" ); 50 options->SetWrappingAllowed( true ); 51 options->SetControlList( true ); 52 options->Initialize( data ); 53 AddChild( options ); 54 55 btnBack = new (TAG_SWF) idMenuWidget_Button(); 56 btnBack->Initialize( data ); 57 btnBack->SetLabel( "#str_swf_multiplayer" ); 58 btnBack->SetSpritePath( GetSpritePath(), "info", "btnBack" ); 59 btnBack->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_GO_BACK ); 60 AddChild( btnBack ); 61 62 idMenuWidget_ControlButton * control; 63 control = new (TAG_SWF) idMenuWidget_ControlButton(); 64 control->SetOptionType( OPTION_SLIDER_TEXT ); 65 control->SetLabel( "#str_swf_mode" ); // Mode 66 control->SetDataSource( &matchData, idMenuDataSource_MatchSettings::MATCH_FIELD_MODE ); 67 control->SetupEvents( DEFAULT_REPEAT_TIME, options->GetChildren().Num() ); 68 control->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() ); 69 options->AddChild( control ); 70 71 control = new (TAG_SWF) idMenuWidget_ControlButton(); 72 control->SetOptionType( OPTION_SLIDER_TEXT ); 73 control->SetLabel( "#str_02049" ); // Map 74 control->SetDataSource( &matchData, idMenuDataSource_MatchSettings::MATCH_FIELD_MAP ); 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_TEXT ); 81 control->SetLabel( "#str_02183" ); // Time 82 control->SetDataSource( &matchData, idMenuDataSource_MatchSettings::MATCH_FIELD_TIME ); 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_TEXT ); 89 control->SetLabel( "#str_00100917" ); // Score 90 control->SetDataSource( &matchData, idMenuDataSource_MatchSettings::MATCH_FIELD_SCORE ); 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 options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN ) ); 96 options->AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP ) ); 97 options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) ); 98 options->AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) ); 99 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 ) ); 100 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 ) ); 101 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 ) ); 102 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 ) ); 103 } 104 105 /* 106 ======================== 107 idMenuScreen_Shell_MatchSettings::Update 108 ======================== 109 */ 110 void idMenuScreen_Shell_MatchSettings::Update() { 111 112 if ( menuData != NULL ) { 113 idMenuWidget_CommandBar * cmdBar = menuData->GetCmdBar(); 114 if ( cmdBar != NULL ) { 115 cmdBar->ClearAllButtons(); 116 idMenuWidget_CommandBar::buttonInfo_t * buttonInfo; 117 buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 ); 118 if ( menuData->GetPlatform() != 2 ) { 119 buttonInfo->label = "#str_00395"; 120 } 121 buttonInfo->action.Set( WIDGET_ACTION_GO_BACK ); 122 123 buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 ); 124 buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED ); 125 } 126 } 127 128 idSWFScriptObject & root = GetSWFObject()->GetRootObject(); 129 if ( BindSprite( root ) ) { 130 idSWFTextInstance * heading = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtHeading" ); 131 if ( heading != NULL ) { 132 heading->SetText( "#str_swf_match_settings_heading" ); // SYSTEM SETTINGS 133 heading->SetStrokeInfo( true, 0.75f, 1.75f ); 134 } 135 136 idSWFSpriteInstance * gradient = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "gradient" ); 137 if ( gradient != NULL && heading != NULL ) { 138 gradient->SetXPos( heading->GetTextLength() ); 139 } 140 } 141 142 if ( btnBack != NULL ) { 143 btnBack->BindSprite( root ); 144 } 145 146 idMenuScreen::Update(); 147 } 148 149 /* 150 ======================== 151 idMenuScreen_Shell_MatchSettings::ShowScreen 152 ======================== 153 */ 154 void idMenuScreen_Shell_MatchSettings::ShowScreen( const mainMenuTransition_t transitionType ) { 155 matchData.LoadData(); 156 idMenuScreen::ShowScreen( transitionType ); 157 } 158 159 /* 160 ======================== 161 idMenuScreen_Shell_MatchSettings::HideScreen 162 ======================== 163 */ 164 void idMenuScreen_Shell_MatchSettings::HideScreen( const mainMenuTransition_t transitionType ) { 165 if ( matchData.IsDataChanged() ) { 166 matchData.CommitData(); 167 } 168 idMenuScreen::HideScreen( transitionType ); 169 } 170 171 /* 172 ======================== 173 idMenuScreen_Shell_MatchSettings::HandleAction h 174 ======================== 175 */ 176 bool idMenuScreen_Shell_MatchSettings::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) { 177 178 if ( menuData == NULL ) { 179 return true; 180 } 181 182 if ( menuData->ActiveScreen() != SHELL_AREA_MATCH_SETTINGS ) { 183 return false; 184 } 185 186 widgetAction_t actionType = action.GetType(); 187 const idSWFParmList & parms = action.GetParms(); 188 189 switch ( actionType ) { 190 case WIDGET_ACTION_ADJUST_FIELD: { 191 if ( widget != NULL && widget->GetDataSource() != NULL && options != NULL ) { 192 widget->GetDataSource()->AdjustField( widget->GetDataSourceFieldIndex(), parms[ 0 ].ToInteger() ); 193 widget->Update(); 194 195 if ( matchData.MapChanged() ) { 196 idMenuWidget_ControlButton * button = dynamic_cast< idMenuWidget_ControlButton * >( &options->GetChildByIndex( 1 ) ); 197 if ( button != NULL ) { 198 button->Update(); 199 } 200 matchData.ClearMapChanged(); 201 } 202 } 203 return true; 204 } 205 case WIDGET_ACTION_GO_BACK: { 206 menuData->SetNextScreen( SHELL_AREA_GAME_LOBBY, MENU_TRANSITION_SIMPLE ); 207 return true; 208 } 209 case WIDGET_ACTION_PRESS_FOCUSED: { 210 211 if ( options == NULL ) { 212 return true; 213 } 214 215 int selectionIndex = options->GetFocusIndex(); 216 if ( parms.Num() > 0 ) { 217 selectionIndex = parms[0].ToInteger(); 218 } 219 220 if ( selectionIndex != options->GetFocusIndex() ) { 221 options->SetViewIndex( options->GetViewOffset() + selectionIndex ); 222 options->SetFocusIndex( selectionIndex ); 223 } 224 225 matchData.AdjustField( selectionIndex, 1 ); 226 options->Update(); 227 return true; 228 } 229 case WIDGET_ACTION_START_REPEATER: { 230 231 if ( options == NULL ) { 232 return true; 233 } 234 235 if ( parms.Num() == 4 ) { 236 int selectionIndex = parms[3].ToInteger(); 237 if ( selectionIndex != options->GetFocusIndex() ) { 238 options->SetViewIndex( options->GetViewOffset() + selectionIndex ); 239 options->SetFocusIndex( selectionIndex ); 240 } 241 } 242 break; 243 } 244 } 245 246 return idMenuWidget::HandleAction( action, event, widget, forceHandled ); 247 } 248 249 ///////////////////////////////// 250 // SCREEN SETTINGS 251 ///////////////////////////////// 252 253 extern idCVar si_timeLimit; 254 extern idCVar si_fragLimit; 255 extern idCVar si_map; 256 extern idCVar si_mode; 257 258 /* 259 ======================== 260 idMenuScreen_Shell_MatchSettings::idMenuDataSource_MatchSettings::idMenuDataSource_MatchSettings 261 ======================== 262 */ 263 idMenuScreen_Shell_MatchSettings::idMenuDataSource_MatchSettings::idMenuDataSource_MatchSettings() { 264 fields.SetNum( MAX_MATCH_FIELDS ); 265 originalFields.SetNum( MAX_MATCH_FIELDS ); 266 updateMap = false; 267 } 268 269 /* 270 ======================== 271 idMenuScreen_Shell_MatchSettings::idMenuDataSource_MatchSettings::LoadData 272 ======================== 273 */ 274 void idMenuScreen_Shell_MatchSettings::idMenuDataSource_MatchSettings::LoadData() { 275 updateMap = false; 276 idMatchParameters matchParameters = session->GetActivePlatformLobbyBase().GetMatchParms(); 277 idStr val; 278 GetMapName( matchParameters.gameMap, val ); 279 fields[ MATCH_FIELD_MAP ].SetString( val ); 280 GetModeName( matchParameters.gameMode, val ); 281 fields[ MATCH_FIELD_MODE ].SetString( val ); 282 283 int time = matchParameters.serverInfo.GetInt( "si_timeLimit" ); 284 if ( time == 0 ) { 285 fields[ MATCH_FIELD_TIME ].SetString( "#str_02844" ); // none 286 } else { 287 fields[ MATCH_FIELD_TIME ].SetString( va( "%i", time ) ); 288 } 289 290 int fragLimit = matchParameters.serverInfo.GetInt( "si_fragLimit" ); 291 fields[ MATCH_FIELD_SCORE ].SetInteger( fragLimit ); 292 293 originalFields = fields; 294 } 295 296 /* 297 ======================== 298 idMenuScreen_Shell_MatchSettings::idMenuDataSource_MatchSettings::CommitData 299 ======================== 300 */ 301 void idMenuScreen_Shell_MatchSettings::idMenuDataSource_MatchSettings::CommitData() { 302 303 cvarSystem->SetModifiedFlags( CVAR_ARCHIVE ); 304 305 // make the committed fields into the backup fields 306 originalFields = fields; 307 } 308 309 /* 310 ======================== 311 idMenuScreen_Shell_MatchSettings::idMenuDataSource_MatchSettings::GetMapName 312 ======================== 313 */ 314 void idMenuScreen_Shell_MatchSettings::idMenuDataSource_MatchSettings::GetMapName( int index, idStr & name ) { 315 idLobbyBase & lobby = session->GetActivePlatformLobbyBase(); 316 const idMatchParameters & matchParameters = lobby.GetMatchParms(); 317 name = "#str_swf_filter_random"; 318 if ( matchParameters.gameMap >= 0 ) { 319 const idList< mpMap_t > maps = common->GetMapList(); 320 name = idLocalization::GetString( maps[ idMath::ClampInt( 0, maps.Num() - 1, matchParameters.gameMap ) ].mapName ); 321 } 322 } 323 324 /* 325 ======================== 326 idMenuScreen_Shell_MatchSettings::idMenuDataSource_MatchSettings::GetModeName 327 ======================== 328 */ 329 void idMenuScreen_Shell_MatchSettings::idMenuDataSource_MatchSettings::GetModeName( int index, idStr & name ) { 330 idLobbyBase & lobby = session->GetActivePlatformLobbyBase(); 331 const idMatchParameters & matchParameters = lobby.GetMatchParms(); 332 name = "#str_swf_filter_random"; 333 if ( matchParameters.gameMode >= 0 ) { 334 const idStrList & modes = common->GetModeDisplayList(); 335 name = idLocalization::GetString( modes[ idMath::ClampInt( 0, modes.Num() - 1, matchParameters.gameMode ) ] ); 336 } 337 } 338 339 /* 340 ======================== 341 idMenuScreen_Shell_MatchSettings::idMenuDataSource_MatchSettings::AdjustField 342 ======================== 343 */ 344 void idMenuScreen_Shell_MatchSettings::idMenuDataSource_MatchSettings::AdjustField( const int fieldIndex, const int adjustAmount ) { 345 346 const idStrList & modes = common->GetModeList(); 347 const idList< mpMap_t > maps = common->GetMapList(); 348 349 idMatchParameters matchParameters = session->GetActivePlatformLobbyBase().GetMatchParms(); 350 if ( fieldIndex == MATCH_FIELD_MAP ) { 351 for ( int i = 0; i < maps.Num(); i++ ) { 352 // Don't allow random maps in the game lobby 353 matchParameters.gameMap += adjustAmount; 354 if ( matchParameters.gameMap < 0 ) { 355 matchParameters.gameMap = maps.Num() - 1; 356 } 357 matchParameters.gameMap %= maps.Num(); 358 matchParameters.mapName = maps[ matchParameters.gameMap ].mapFile; 359 if ( ( maps[matchParameters.gameMap].supportedModes & BIT(matchParameters.gameMode) ) != 0 ) { 360 // This map supports this mode 361 break; 362 } 363 } 364 session->UpdateMatchParms( matchParameters ); 365 366 idStr val; 367 GetMapName( matchParameters.gameMap, val ); 368 si_map.SetInteger( matchParameters.gameMap ); 369 fields[ MATCH_FIELD_MAP ].SetString( val ); 370 371 } else if ( fieldIndex == MATCH_FIELD_MODE ) { 372 // Don't allow random modes in the game lobby 373 matchParameters.gameMode += adjustAmount; 374 375 if ( matchParameters.gameMode < 0 ) { 376 matchParameters.gameMode = modes.Num() - 1; 377 } 378 matchParameters.gameMode %= modes.Num(); 379 updateMap = false; 380 if ( ( maps[matchParameters.gameMap].supportedModes & BIT(matchParameters.gameMode) ) == 0 ) { 381 for ( int i = 0; i < maps.Num(); ++i ) { 382 if ( ( maps[i].supportedModes & BIT(matchParameters.gameMode) ) != 0 ) { 383 matchParameters.gameMap = i; 384 updateMap = true; 385 break; 386 } 387 } 388 } 389 390 session->UpdateMatchParms( matchParameters ); 391 idStr val; 392 393 GetModeName( matchParameters.gameMode, val ); 394 si_mode.SetInteger( matchParameters.gameMode ); 395 fields[ MATCH_FIELD_MODE ].SetString( val ); 396 397 if ( updateMap ) { 398 GetMapName( matchParameters.gameMap, val ); 399 si_map.SetInteger( matchParameters.gameMap ); 400 fields[ MATCH_FIELD_MAP ].SetString( val ); 401 } 402 403 } else if ( fieldIndex == MATCH_FIELD_TIME ) { 404 int time = si_timeLimit.GetInteger() + ( adjustAmount * 5 ); 405 if ( time < 0 ) { 406 time = 60; 407 } else if ( time > 60 ) { 408 time = 0; 409 } 410 411 if ( time == 0 ) { 412 fields[ MATCH_FIELD_TIME ].SetString( "#str_02844" ); // none 413 } else { 414 fields[ MATCH_FIELD_TIME ].SetString( va( "%i", time ) ); 415 } 416 417 si_timeLimit.SetInteger( time ); 418 419 matchParameters.serverInfo.SetInt( "si_timeLimit", si_timeLimit.GetInteger() ); 420 session->UpdateMatchParms( matchParameters ); 421 422 } else if ( fieldIndex == MATCH_FIELD_SCORE ) { 423 424 int val = fields[ fieldIndex ].ToInteger() + ( adjustAmount * 5 ); 425 if ( val < 5 ) { 426 val = MP_PLAYER_MAXFRAGS; 427 } else if ( val > MP_PLAYER_MAXFRAGS ) { 428 val = 5; 429 } 430 431 fields[ fieldIndex ].SetInteger( val ); 432 si_fragLimit.SetInteger( val ); 433 434 matchParameters.serverInfo.SetInt( "si_fragLimit", si_fragLimit.GetInteger() ); 435 session->UpdateMatchParms( matchParameters ); 436 } 437 438 cvarSystem->ClearModifiedFlags( CVAR_ARCHIVE ); 439 } 440 441 /* 442 ======================== 443 idMenuScreen_Shell_MatchSettings::idMenuDataSource_MatchSettings::IsDataChanged 444 ======================== 445 */ 446 bool idMenuScreen_Shell_MatchSettings::idMenuDataSource_MatchSettings::IsDataChanged() const { 447 448 if ( fields[ MATCH_FIELD_TIME ].ToString() != originalFields[ MATCH_FIELD_TIME ].ToString() ) { 449 return true; 450 } 451 452 if ( fields[ MATCH_FIELD_MAP ].ToString() != originalFields[ MATCH_FIELD_MAP ].ToString() ) { 453 return true; 454 } 455 456 if ( fields[ MATCH_FIELD_MODE ].ToString() != originalFields[ MATCH_FIELD_MODE ].ToString() ) { 457 return true; 458 } 459 460 if ( fields[ MATCH_FIELD_SCORE ].ToInteger() != originalFields[ MATCH_FIELD_SCORE ].ToInteger() ) { 461 return true; 462 } 463 464 return false; 465 }