MenuScreen_Shell_MatchSettings.cpp 17 KB

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