MenuScreen_Shell_ModeSelect.cpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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_SETTING_OPTIONS = 8;
  24. /*
  25. ========================
  26. idMenuScreen_Shell_ModeSelect::Initialize
  27. ========================
  28. */
  29. void idMenuScreen_Shell_ModeSelect::Initialize( idMenuHandler * data ) {
  30. idMenuScreen::Initialize( data );
  31. if ( data != NULL ) {
  32. menuGUI = data->GetGUI();
  33. }
  34. SetSpritePath( "menuModeSelect" );
  35. options = new (TAG_SWF) idMenuWidget_DynamicList();
  36. options->SetNumVisibleOptions( NUM_SETTING_OPTIONS );
  37. options->SetSpritePath( GetSpritePath(), "info", "options" );
  38. options->SetWrappingAllowed( true );
  39. AddChild( options );
  40. idMenuWidget_Help * const helpWidget = new ( TAG_SWF ) idMenuWidget_Help();
  41. helpWidget->SetSpritePath( GetSpritePath(), "info", "helpTooltip" );
  42. AddChild( helpWidget );
  43. const idStrList & modes = common->GetModeDisplayList();
  44. idList< idList< idStr, TAG_IDLIB_LIST_MENU >, TAG_IDLIB_LIST_MENU > menuOptions;
  45. for ( int i = 0; i < modes.Num(); ++i ) {
  46. idList< idStr > option;
  47. option.Append( modes[i] );
  48. menuOptions.Append( option );
  49. }
  50. options->SetListData( menuOptions );
  51. const char * tips[] = { "#str_swf_deathmatch_desc", "#str_swf_tourney_desc", "#str_swf_team_deathmatch_desc", "#str_swf_lastman_desc", "#str_swf_ctf_desc" };
  52. while ( options->GetChildren().Num() < NUM_SETTING_OPTIONS ) {
  53. idMenuWidget_Button * const buttonWidget = new (TAG_SWF) idMenuWidget_Button();
  54. buttonWidget->Initialize( data );
  55. buttonWidget->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, options->GetChildren().Num() );
  56. if ( options->GetChildren().Num() < menuOptions.Num() ) {
  57. buttonWidget->SetDescription( tips[options->GetChildren().Num()] );
  58. }
  59. buttonWidget->RegisterEventObserver( helpWidget );
  60. options->AddChild( buttonWidget );
  61. }
  62. options->Initialize( data );
  63. btnBack = new (TAG_SWF) idMenuWidget_Button();
  64. btnBack->Initialize( data );
  65. btnBack->SetLabel( "#str_swf_multiplayer" );
  66. btnBack->SetSpritePath( GetSpritePath(), "info", "btnBack" );
  67. btnBack->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_GO_BACK );
  68. AddChild( btnBack );
  69. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN ) );
  70. options->AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP ) );
  71. options->AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) );
  72. options->AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) );
  73. 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 ) );
  74. 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 ) );
  75. 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 ) );
  76. 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 ) );
  77. }
  78. /*
  79. ========================
  80. idMenuScreen_Shell_ModeSelect::Update
  81. ========================
  82. */
  83. void idMenuScreen_Shell_ModeSelect::Update() {
  84. if ( menuData != NULL ) {
  85. idMenuWidget_CommandBar * cmdBar = menuData->GetCmdBar();
  86. if ( cmdBar != NULL ) {
  87. cmdBar->ClearAllButtons();
  88. idMenuWidget_CommandBar::buttonInfo_t * buttonInfo;
  89. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 );
  90. if ( menuData->GetPlatform() != 2 ) {
  91. buttonInfo->label = "#str_00395";
  92. }
  93. buttonInfo->action.Set( WIDGET_ACTION_GO_BACK );
  94. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 );
  95. if ( menuData->GetPlatform() != 2 ) {
  96. buttonInfo->label = "#str_SWF_SELECT";
  97. }
  98. buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED );
  99. }
  100. }
  101. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  102. if ( BindSprite( root ) ) {
  103. idSWFTextInstance * heading = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtHeading" );
  104. if ( heading != NULL ) {
  105. heading->SetText( "#str_swf_find_match_heading" );
  106. heading->SetStrokeInfo( true, 0.75f, 1.75f );
  107. }
  108. idSWFSpriteInstance * gradient = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "gradient" );
  109. if ( gradient != NULL && heading != NULL ) {
  110. gradient->SetXPos( heading->GetTextLength() );
  111. }
  112. }
  113. if ( btnBack != NULL ) {
  114. btnBack->BindSprite( root );
  115. }
  116. idMenuScreen::Update();
  117. }
  118. /*
  119. ========================
  120. idMenuScreen_Shell_ModeSelect::ShowScreen
  121. ========================
  122. */
  123. void idMenuScreen_Shell_ModeSelect::ShowScreen( const mainMenuTransition_t transitionType ) {
  124. idMenuScreen::ShowScreen( transitionType );
  125. }
  126. /*
  127. ========================
  128. idMenuScreen_Shell_ModeSelect::HideScreen
  129. ========================
  130. */
  131. void idMenuScreen_Shell_ModeSelect::HideScreen( const mainMenuTransition_t transitionType ) {
  132. idMenuScreen::HideScreen( transitionType );
  133. }
  134. /*
  135. ========================
  136. idMenuScreen_Shell_ModeSelect::HandleAction h
  137. ========================
  138. */
  139. bool idMenuScreen_Shell_ModeSelect::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) {
  140. if ( menuData == NULL ) {
  141. return true;
  142. }
  143. if ( menuData->ActiveScreen() != SHELL_AREA_MODE_SELECT ) {
  144. return false;
  145. }
  146. widgetAction_t actionType = action.GetType();
  147. const idSWFParmList & parms = action.GetParms();
  148. switch ( actionType ) {
  149. case WIDGET_ACTION_GO_BACK: {
  150. menuData->SetNextScreen( SHELL_AREA_PARTY_LOBBY, MENU_TRANSITION_SIMPLE );
  151. return true;
  152. }
  153. case WIDGET_ACTION_PRESS_FOCUSED: {
  154. if ( options == NULL ) {
  155. return true;
  156. }
  157. int selectionIndex = options->GetViewIndex();
  158. if ( parms.Num() == 1 ) {
  159. selectionIndex = parms[0].ToInteger();
  160. }
  161. if ( options->GetFocusIndex() != selectionIndex ) {
  162. options->SetFocusIndex( selectionIndex );
  163. options->SetViewIndex( options->GetViewOffset() + selectionIndex );
  164. }
  165. idMatchParameters matchParameters = idMatchParameters( session->GetPartyLobbyBase().GetMatchParms() );
  166. matchParameters.gameMap = GAME_MAP_RANDOM;
  167. matchParameters.gameMode = selectionIndex;
  168. // Always a public match.
  169. matchParameters.matchFlags &= ~MATCH_INVITE_ONLY;
  170. session->UpdatePartyParms( matchParameters );
  171. // Update flags for game lobby.
  172. matchParameters.matchFlags = DefaultPartyFlags | DefaultPublicGameFlags;
  173. cvarSystem->MoveCVarsToDict( CVAR_SERVERINFO, matchParameters.serverInfo );
  174. // Force a default value for the si_timelimit and si_fraglimit for quickmatch
  175. matchParameters.serverInfo.SetInt( "si_timelimit", 15 );
  176. matchParameters.serverInfo.SetInt( "si_fraglimit", 10 );
  177. session->FindOrCreateMatch( matchParameters );
  178. return true;
  179. }
  180. }
  181. return idMenuWidget::HandleAction( action, event, widget, forceHandled );
  182. }