MenuScreen_Shell_GameLobby.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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_LOBBY_OPTIONS = 8;
  24. extern idCVar net_inviteOnly;
  25. enum gameLobbyCmd_t {
  26. GAME_CMD_START,
  27. GAME_CMD_INVITE,
  28. GAME_CMD_SETTINGS,
  29. GAME_CMD_TOGGLE_PRIVACY,
  30. };
  31. /*
  32. ========================
  33. idMenuScreen_Shell_GameLobby::Initialize
  34. ========================
  35. */
  36. void idMenuScreen_Shell_GameLobby::Initialize( idMenuHandler * data ) {
  37. idMenuScreen::Initialize( data );
  38. if ( data != NULL ) {
  39. menuGUI = data->GetGUI();
  40. }
  41. SetSpritePath( "menuGameLobby" );
  42. options = new (TAG_SWF) idMenuWidget_DynamicList();
  43. options->SetNumVisibleOptions( NUM_LOBBY_OPTIONS );
  44. options->SetSpritePath( GetSpritePath(), "info", "options" );
  45. options->SetWrappingAllowed( true );
  46. AddChild( options );
  47. idMenuWidget_Help * const helpWidget = new ( TAG_SWF ) idMenuWidget_Help();
  48. helpWidget->SetSpritePath( GetSpritePath(), "info", "helpTooltip" );
  49. AddChild( helpWidget );
  50. while ( options->GetChildren().Num() < NUM_LOBBY_OPTIONS ) {
  51. idMenuWidget_Button * const buttonWidget = new (TAG_SWF) idMenuWidget_Button();
  52. buttonWidget->Initialize( data );
  53. buttonWidget->RegisterEventObserver( helpWidget );
  54. options->AddChild( buttonWidget );
  55. }
  56. options->Initialize( data );
  57. lobby = new (TAG_SWF) idMenuWidget_LobbyList();
  58. lobby->SetNumVisibleOptions( 8 );
  59. lobby->SetSpritePath( GetSpritePath(), "options" );
  60. lobby->SetWrappingAllowed( true );
  61. lobby->Initialize( data );
  62. while ( lobby->GetChildren().Num() < 8 ) {
  63. idMenuWidget_LobbyButton * const buttonWidget = new (TAG_SWF) idMenuWidget_LobbyButton();
  64. buttonWidget->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_SELECT_GAMERTAG, lobby->GetChildren().Num() );
  65. buttonWidget->AddEventAction( WIDGET_EVENT_COMMAND ).Set( WIDGET_ACTION_MUTE_PLAYER, lobby->GetChildren().Num() );
  66. buttonWidget->Initialize( data );
  67. lobby->AddChild( buttonWidget );
  68. }
  69. AddChild( lobby );
  70. btnBack = new (TAG_SWF) idMenuWidget_Button();
  71. btnBack->Initialize( data );
  72. btnBack->SetLabel( "#str_swf_multiplayer" );
  73. btnBack->SetSpritePath( GetSpritePath(), "info", "btnBack" );
  74. btnBack->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_GO_BACK );
  75. AddChild( btnBack );
  76. AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN ) );
  77. AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP ) );
  78. AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) );
  79. AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) );
  80. AddEventAction( WIDGET_EVENT_SCROLL_DOWN_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN_LSTICK ) );
  81. AddEventAction( WIDGET_EVENT_SCROLL_UP_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP_LSTICK ) );
  82. AddEventAction( WIDGET_EVENT_SCROLL_DOWN_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_LSTICK_RELEASE ) );
  83. AddEventAction( WIDGET_EVENT_SCROLL_UP_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( options, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_LSTICK_RELEASE ) );
  84. AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( lobby, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RSTICK ) );
  85. AddEventAction( WIDGET_EVENT_SCROLL_UP_RSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( lobby, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP_RSTICK ) );
  86. AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( lobby, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RSTICK_RELEASE ) );
  87. AddEventAction( WIDGET_EVENT_SCROLL_UP_RSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( lobby, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RSTICK_RELEASE ) );
  88. }
  89. /*
  90. ========================
  91. idMenuScreen_Shell_GameLobby::Update
  92. ========================
  93. */
  94. void idMenuScreen_Shell_GameLobby::Update() {
  95. idLobbyBase & activeLobby = session->GetActivePlatformLobbyBase();
  96. if ( lobby != NULL ) {
  97. if ( activeLobby.GetNumActiveLobbyUsers() != 0 ) {
  98. if ( lobby->GetFocusIndex() >= activeLobby.GetNumActiveLobbyUsers() ) {
  99. lobby->SetFocusIndex( activeLobby.GetNumActiveLobbyUsers() - 1 );
  100. lobby->SetViewIndex( lobby->GetViewOffset() + lobby->GetFocusIndex() );
  101. }
  102. }
  103. }
  104. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  105. if ( BindSprite( root ) ) {
  106. idSWFTextInstance * heading = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtHeading" );
  107. if ( heading != NULL ) {
  108. heading->SetText( "#str_swf_multiplayer" ); // MULTIPLAYER
  109. heading->SetStrokeInfo( true, 0.75f, 1.75f );
  110. }
  111. idSWFSpriteInstance * gradient = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "gradient" );
  112. if ( gradient != NULL && heading != NULL ) {
  113. gradient->SetXPos( heading->GetTextLength() );
  114. }
  115. }
  116. if ( privateGameLobby && options != NULL ) {
  117. if ( session->GetActivePlatformLobbyBase().IsHost() && !isHost ) {
  118. menuOptions.Clear();
  119. idList< idStr > option;
  120. isHost = true;
  121. isPeer = false;
  122. option.Append( "#str_swf_start_match" ); // Start match
  123. menuOptions.Append( option );
  124. option.Clear();
  125. option.Append( "#str_swf_match_settings" ); // Match Settings
  126. menuOptions.Append( option );
  127. option.Clear();
  128. option.Append( "#str_swf_invite_only" ); // Toggle privacy
  129. menuOptions.Append( option );
  130. option.Clear();
  131. option.Append( "#str_swf_invite_friends" ); // Invite Friends
  132. menuOptions.Append( option );
  133. option.Clear();
  134. idMenuWidget_Button * buttonWidget = NULL;
  135. int index = 0;
  136. options->GetChildByIndex( index ).ClearEventActions();
  137. options->GetChildByIndex( index ).AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, GAME_CMD_START, 0 );
  138. buttonWidget = dynamic_cast< idMenuWidget_Button * >( &options->GetChildByIndex( index ) );
  139. if ( buttonWidget != NULL ) {
  140. buttonWidget->SetDescription( "#str_swf_quick_start_desc" );
  141. }
  142. index++;
  143. options->GetChildByIndex( index ).ClearEventActions();
  144. options->GetChildByIndex( index ).AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, GAME_CMD_SETTINGS, 1 );
  145. buttonWidget = dynamic_cast< idMenuWidget_Button * >( &options->GetChildByIndex( index ) );
  146. if ( buttonWidget != NULL ) {
  147. buttonWidget->SetDescription( "#str_swf_match_setting_desc" );
  148. }
  149. index++;
  150. options->GetChildByIndex( index ).ClearEventActions();
  151. options->GetChildByIndex( index ).AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, GAME_CMD_TOGGLE_PRIVACY, 2 );
  152. buttonWidget = dynamic_cast< idMenuWidget_Button * >( &options->GetChildByIndex( index ) );
  153. if ( buttonWidget != NULL ) {
  154. buttonWidget->SetDescription( "#str_swf_toggle_privacy_desc" );
  155. }
  156. index++;
  157. options->GetChildByIndex( index ).ClearEventActions();
  158. options->GetChildByIndex( index ).AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, GAME_CMD_INVITE, 3 );
  159. buttonWidget = dynamic_cast< idMenuWidget_Button * >( &options->GetChildByIndex( index ) );
  160. if ( buttonWidget != NULL ) {
  161. buttonWidget->SetDescription( "#str_swf_invite_desc" );
  162. }
  163. index++;
  164. options->SetListData( menuOptions );
  165. } else if ( session->GetActivePlatformLobbyBase().IsPeer() ) {
  166. if ( !isPeer ) {
  167. menuOptions.Clear();
  168. idList< idStr > option;
  169. option.Append( "#str_swf_invite_friends" ); // Invite Friends
  170. menuOptions.Append( option );
  171. option.Clear();
  172. idMenuWidget_Button * buttonWidget = NULL;
  173. int index = 0;
  174. options->GetChildByIndex( index ).ClearEventActions();
  175. options->GetChildByIndex( index ).AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, GAME_CMD_INVITE, 0 );
  176. buttonWidget = dynamic_cast< idMenuWidget_Button * >( &options->GetChildByIndex( index ) );
  177. if ( buttonWidget != NULL ) {
  178. buttonWidget->SetDescription( "#str_swf_invite_desc" );
  179. }
  180. options->SetListData( menuOptions );
  181. }
  182. isPeer = true;
  183. isHost = false;
  184. }
  185. }
  186. if ( menuData != NULL ) {
  187. idMenuWidget_CommandBar * cmdBar = menuData->GetCmdBar();
  188. if ( cmdBar != NULL ) {
  189. cmdBar->ClearAllButtons();
  190. idMenuWidget_CommandBar::buttonInfo_t * buttonInfo;
  191. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 );
  192. if ( menuData->GetPlatform() != 2 ) {
  193. buttonInfo->label = "#str_00395";
  194. }
  195. buttonInfo->action.Set( WIDGET_ACTION_GO_BACK );
  196. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY3 );
  197. if ( menuData->GetPlatform() != 2 ) {
  198. buttonInfo->label = "#str_swf_view_profile";
  199. }
  200. buttonInfo->action.Set( WIDGET_ACTION_SELECT_GAMERTAG );
  201. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 );
  202. if ( menuData->GetPlatform() != 2 ) {
  203. buttonInfo->label = "#str_SWF_SELECT";
  204. }
  205. buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED );
  206. lobbyUserID_t luid;
  207. if ( isHost && CanKickSelectedPlayer( luid ) ) {
  208. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY4 );
  209. buttonInfo->label = "#str_swf_kick";
  210. buttonInfo->action.Set( WIDGET_ACTION_JOY4_ON_PRESS );
  211. }
  212. }
  213. }
  214. if ( btnBack != NULL ) {
  215. btnBack->BindSprite( root );
  216. }
  217. idMenuScreen::Update();
  218. }
  219. /*
  220. ========================
  221. idMenuScreen_Shell_GameLobby::ShowScreen
  222. ========================
  223. */
  224. void idMenuScreen_Shell_GameLobby::ShowScreen( const mainMenuTransition_t transitionType ) {
  225. if ( options != NULL ) {
  226. options->SetFocusIndex( 0 );
  227. options->SetViewIndex( 0 );
  228. }
  229. isHost = false;
  230. isPeer = false;
  231. idMatchParameters matchParameters = session->GetActivePlatformLobbyBase().GetMatchParms();
  232. // Make sure map name is up to date.
  233. if ( matchParameters.gameMap >= 0 ) {
  234. matchParameters.mapName = common->GetMapList()[ matchParameters.gameMap ].mapFile;
  235. }
  236. privateGameLobby = MatchTypeIsPrivate( matchParameters.matchFlags );
  237. if ( !privateGameLobby ) { // Public Game Lobby
  238. menuOptions.Clear();
  239. idList< idStr > option;
  240. if ( options != NULL ) {
  241. option.Append( "#str_swf_invite_friends" ); // Invite Friends
  242. menuOptions.Append( option );
  243. option.Clear();
  244. int index = 0;
  245. options->GetChildByIndex( index ).ClearEventActions();
  246. options->GetChildByIndex( index ).AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_COMMAND, GAME_CMD_INVITE, 0 );
  247. idMenuWidget_Button * buttonWidget = dynamic_cast< idMenuWidget_Button * >( &options->GetChildByIndex( index ) );
  248. if ( buttonWidget != NULL ) {
  249. buttonWidget->SetDescription( "#str_swf_invite_desc" );
  250. }
  251. options->SetListData( menuOptions );
  252. }
  253. longCountdown = Sys_Milliseconds() + WAIT_START_TIME_LONG;
  254. longCountRemaining = longCountdown;
  255. shortCountdown = Sys_Milliseconds() + WAIT_START_TIME_SHORT;
  256. }
  257. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  258. if ( BindSprite( root ) ) {
  259. idSWFSpriteInstance * waitTime = GetSprite()->GetScriptObject()->GetNestedSprite( "waitTime" );
  260. if ( waitTime != NULL ) {
  261. waitTime->SetVisible( !privateGameLobby );
  262. }
  263. }
  264. idMenuScreen::ShowScreen( transitionType );
  265. if ( lobby != NULL ) {
  266. lobby->SetFocusIndex( 0 );
  267. }
  268. session->UpdateMatchParms( matchParameters );
  269. }
  270. /*
  271. ========================
  272. idMenuScreen_Shell_GameLobby::HideScreen
  273. ========================
  274. */
  275. void idMenuScreen_Shell_GameLobby::HideScreen( const mainMenuTransition_t transitionType ) {
  276. idMenuScreen::HideScreen( transitionType );
  277. }
  278. /*
  279. ========================
  280. idMenuScreen_Shell_GameLobby::CanKickSelectedPlayer
  281. ========================
  282. */
  283. bool idMenuScreen_Shell_GameLobby::CanKickSelectedPlayer( lobbyUserID_t & luid ) {
  284. idMatchParameters matchParameters = session->GetActivePlatformLobbyBase().GetMatchParms();
  285. const int playerId = lobby->GetFocusIndex();
  286. // can't kick yourself
  287. idLobbyBase & activeLobby = session->GetActivePlatformLobbyBase();
  288. luid = activeLobby.GetLobbyUserIdByOrdinal( playerId );
  289. if ( session->GetSignInManager().GetMasterLocalUser() == activeLobby.GetLocalUserFromLobbyUser( luid ) ) {
  290. return false;
  291. }
  292. return true;
  293. }
  294. /*
  295. ========================
  296. idMenuScreen_Shell_GameLobby::HandleAction h
  297. ========================
  298. */
  299. bool idMenuScreen_Shell_GameLobby::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) {
  300. if ( menuData == NULL ) {
  301. return true;
  302. }
  303. if ( menuData->ActiveScreen() != SHELL_AREA_GAME_LOBBY ) {
  304. return false;
  305. }
  306. widgetAction_t actionType = action.GetType();
  307. const idSWFParmList & parms = action.GetParms();
  308. switch ( actionType ) {
  309. case WIDGET_ACTION_JOY4_ON_PRESS: {
  310. idLobbyBase & activeLobby = session->GetActivePlatformLobbyBase();
  311. lobbyUserID_t luid;
  312. if ( CanKickSelectedPlayer( luid ) ) {
  313. activeLobby.KickLobbyUser( luid );
  314. }
  315. return true;
  316. }
  317. case WIDGET_ACTION_GO_BACK: {
  318. class idSWFScriptFunction_Accept : public idSWFScriptFunction_RefCounted {
  319. public:
  320. idSWFScriptFunction_Accept() { }
  321. idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  322. common->Dialog().ClearDialog( GDM_LEAVE_LOBBY_RET_NEW_PARTY );
  323. session->Cancel();
  324. return idSWFScriptVar();
  325. }
  326. };
  327. class idSWFScriptFunction_Cancel : public idSWFScriptFunction_RefCounted {
  328. public:
  329. idSWFScriptFunction_Cancel() { }
  330. idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  331. common->Dialog().ClearDialog( GDM_LEAVE_LOBBY_RET_NEW_PARTY );
  332. return idSWFScriptVar();
  333. }
  334. };
  335. idLobbyBase & activeLobby = session->GetActivePlatformLobbyBase();
  336. if( activeLobby.GetNumActiveLobbyUsers() > 1 ) {
  337. common->Dialog().AddDialog( GDM_LEAVE_LOBBY_RET_NEW_PARTY, DIALOG_ACCEPT_CANCEL, new (TAG_SWF) idSWFScriptFunction_Accept(), new (TAG_SWF) idSWFScriptFunction_Cancel(), false );
  338. } else {
  339. session->Cancel();
  340. }
  341. return true;
  342. }
  343. case WIDGET_ACTION_MUTE_PLAYER: {
  344. if ( parms.Num() != 1 ) {
  345. return true;
  346. }
  347. int index = parms[0].ToInteger();
  348. idLobbyBase & activeLobby = session->GetActivePlatformLobbyBase();
  349. lobbyUserID_t luid = activeLobby.GetLobbyUserIdByOrdinal( index );
  350. if ( luid.IsValid() ) {
  351. session->ToggleLobbyUserVoiceMute( luid );
  352. }
  353. return true;
  354. }
  355. case WIDGET_ACTION_COMMAND: {
  356. if ( options == NULL ) {
  357. return true;
  358. }
  359. int selectionIndex = options->GetFocusIndex();
  360. if ( parms.Num() > 1 ) {
  361. selectionIndex = parms[1].ToInteger();
  362. }
  363. if ( selectionIndex != options->GetFocusIndex() ) {
  364. options->SetViewIndex( options->GetViewOffset() + selectionIndex );
  365. options->SetFocusIndex( selectionIndex );
  366. }
  367. switch ( parms[0].ToInteger() ) {
  368. case GAME_CMD_START: {
  369. idMenuHandler_Shell * handler = dynamic_cast< idMenuHandler_Shell * const >( menuData );
  370. if ( handler != NULL ) {
  371. handler->SetTimeRemaining( 0 );
  372. }
  373. break;
  374. }
  375. case GAME_CMD_SETTINGS: {
  376. menuData->SetNextScreen( SHELL_AREA_MATCH_SETTINGS, MENU_TRANSITION_SIMPLE );
  377. break;
  378. }
  379. case GAME_CMD_TOGGLE_PRIVACY: {
  380. idMatchParameters matchParameters = idMatchParameters( session->GetActivePlatformLobbyBase().GetMatchParms() );
  381. matchParameters.matchFlags ^= MATCH_INVITE_ONLY;
  382. session->UpdateMatchParms( matchParameters );
  383. int bitSet = ( matchParameters.matchFlags & MATCH_INVITE_ONLY );
  384. net_inviteOnly.SetBool( bitSet != 0 ? true : false );
  385. // Must update the party parameters too for Xbox JSIP to work in game lobbies.
  386. idMatchParameters partyParms = session->GetPartyLobbyBase().GetMatchParms();
  387. if ( MatchTypeInviteOnly( matchParameters.matchFlags ) ) {
  388. partyParms.matchFlags |= MATCH_INVITE_ONLY;
  389. } else {
  390. partyParms.matchFlags &= ~MATCH_INVITE_ONLY;
  391. }
  392. session->UpdatePartyParms( partyParms );
  393. break;
  394. }
  395. case GAME_CMD_INVITE: {
  396. if ( session->GetActivePlatformLobbyBase().IsLobbyFull() ) {
  397. common->Dialog().AddDialog( GDM_CANNOT_INVITE_LOBBY_FULL, DIALOG_CONTINUE, NULL, NULL, true, __FUNCTION__, __LINE__, false );
  398. return true;
  399. }
  400. InvitePartyOrFriends();
  401. break;
  402. }
  403. }
  404. return true;
  405. }
  406. case WIDGET_ACTION_START_REPEATER: {
  407. if ( options == NULL ) {
  408. return true;
  409. }
  410. if ( parms.Num() == 4 ) {
  411. int selectionIndex = parms[3].ToInteger();
  412. if ( selectionIndex != options->GetFocusIndex() ) {
  413. options->SetViewIndex( options->GetViewOffset() + selectionIndex );
  414. options->SetFocusIndex( selectionIndex );
  415. }
  416. }
  417. break;
  418. }
  419. case WIDGET_ACTION_SELECT_GAMERTAG: {
  420. int selectionIndex = lobby->GetFocusIndex();
  421. if ( parms.Num() > 0 ) {
  422. selectionIndex = parms[0].ToInteger();
  423. }
  424. if ( selectionIndex != lobby->GetFocusIndex() ) {
  425. lobby->SetViewIndex( lobby->GetViewOffset() + selectionIndex );
  426. lobby->SetFocusIndex( selectionIndex );
  427. return true;
  428. }
  429. idLobbyBase & activeLobby = session->GetActivePlatformLobbyBase();
  430. lobbyUserID_t luid = activeLobby.GetLobbyUserIdByOrdinal( selectionIndex );
  431. if ( luid.IsValid() ) {
  432. session->ShowLobbyUserGamerCardUI( luid );
  433. }
  434. return true;
  435. }
  436. }
  437. return idMenuWidget::HandleAction( action, event, widget, forceHandled );
  438. }
  439. /*
  440. ========================
  441. idMenuScreen_Shell_GameLobby::UpdateLobby
  442. ========================
  443. */
  444. void idMenuScreen_Shell_GameLobby::UpdateLobby() {
  445. if ( menuData != NULL && menuData->ActiveScreen() != SHELL_AREA_GAME_LOBBY ) {
  446. return;
  447. }
  448. // Keep this menu in sync with the session host/peer status.
  449. if ( session->GetActivePlatformLobbyBase().IsHost() && !isHost ) {
  450. Update();
  451. }
  452. if ( session->GetActivePlatformLobbyBase().IsPeer() && !isPeer ) {
  453. Update();
  454. }
  455. if ( !privateGameLobby ) {
  456. int ms = 0;
  457. if ( session->GetActivePlatformLobbyBase().IsHost() ) {
  458. idMenuHandler_Shell * handler = dynamic_cast< idMenuHandler_Shell * const >( menuData );
  459. if ( handler != NULL ) {
  460. if ( session->GetActivePlatformLobbyBase().IsLobbyFull() ) {
  461. longCountdown = Sys_Milliseconds() + longCountRemaining;
  462. int timeRemaining = shortCountdown - Sys_Milliseconds();
  463. if ( timeRemaining < 0 ) {
  464. timeRemaining = 0;
  465. }
  466. ms = (int) ceilf( timeRemaining / 1000.0f );
  467. handler->SetTimeRemaining( timeRemaining );
  468. } else if ( session->GetActivePlatformLobbyBase().GetNumLobbyUsers() > 1 ) {
  469. int timeRemaining = longCountdown - Sys_Milliseconds();
  470. if ( timeRemaining > WAIT_START_TIME_SHORT ) {
  471. shortCountdown = Sys_Milliseconds() + WAIT_START_TIME_SHORT;
  472. } else {
  473. shortCountdown = timeRemaining;
  474. }
  475. longCountRemaining = timeRemaining;
  476. if ( timeRemaining < 0 ) {
  477. timeRemaining = 0;
  478. }
  479. ms = (int) ceilf( timeRemaining / 1000.0f );
  480. handler->SetTimeRemaining( timeRemaining );
  481. } else {
  482. ms = 0;
  483. longCountdown = Sys_Milliseconds() + WAIT_START_TIME_LONG;
  484. longCountRemaining = longCountdown;
  485. shortCountdown = Sys_Milliseconds() + WAIT_START_TIME_SHORT;
  486. handler->SetTimeRemaining( longCountRemaining );
  487. }
  488. }
  489. } else {
  490. if ( menuData != NULL ) {
  491. idMenuHandler_Shell * handler = dynamic_cast< idMenuHandler_Shell * const >( menuData );
  492. if ( handler != NULL ) {
  493. ms = (int) ceilf( handler->GetTimeRemaining() / 1000.0f );
  494. }
  495. }
  496. }
  497. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  498. if ( BindSprite( root ) ) {
  499. idSWFTextInstance * waitTime = GetSprite()->GetScriptObject()->GetNestedText( "waitTime", "txtVal" );
  500. if ( waitTime != NULL ) {
  501. idStr status;
  502. if ( ms == 1 ) {
  503. status = idLocalization::GetString( "#str_online_game_starts_in_second" );
  504. status.Replace( "<DNT_VAL>", idStr( ms ) );
  505. waitTime->SetText( status );
  506. } else if ( ms > 0 && ms < 30 ) {
  507. status = idLocalization::GetString( "#str_online_game_starts_in_seconds" );
  508. status.Replace( "<DNT_VAL>", idStr( ms ) );
  509. waitTime->SetText( status );
  510. } else {
  511. waitTime->SetText( "" );
  512. }
  513. waitTime->SetStrokeInfo( true, 0.75f, 2.0f );
  514. }
  515. }
  516. Update();
  517. } else {
  518. if ( isPeer ) {
  519. Update();
  520. }
  521. }
  522. if ( session->GetState() == idSession::GAME_LOBBY ) {
  523. if ( options != NULL ) {
  524. if ( options->GetFocusIndex() >= options->GetTotalNumberOfOptions() && options->GetTotalNumberOfOptions() > 0 ) {
  525. options->SetViewIndex( options->GetTotalNumberOfOptions() - 1 );
  526. options->SetFocusIndex( options->GetTotalNumberOfOptions() - 1 );
  527. }
  528. }
  529. idMatchParameters matchParameters = session->GetActivePlatformLobbyBase().GetMatchParms();
  530. idSWFTextInstance * mapName = GetSprite()->GetScriptObject()->GetNestedText( "matchInfo", "txtMapName" );
  531. idSWFTextInstance * modeName = GetSprite()->GetScriptObject()->GetNestedText( "matchInfo", "txtModeName" );
  532. if ( mapName != NULL ){
  533. const idList< mpMap_t > maps = common->GetMapList();
  534. idStr name = idLocalization::GetString( maps[ idMath::ClampInt( 0, maps.Num() - 1, matchParameters.gameMap ) ].mapName );
  535. mapName->SetText( name );
  536. mapName->SetStrokeInfo( true );
  537. }
  538. if ( modeName != NULL ) {
  539. const idStrList & modes = common->GetModeDisplayList();
  540. idStr mode = idLocalization::GetString( modes[ idMath::ClampInt( 0, modes.Num() - 1, matchParameters.gameMode ) ] );
  541. modeName->SetText( mode );
  542. modeName->SetStrokeInfo( true );
  543. }
  544. idSWFTextInstance * privacy = GetSprite()->GetScriptObject()->GetNestedText( "matchInfo", "txtPrivacy" );
  545. if ( privacy != NULL ) {
  546. if ( isPeer || !privateGameLobby ) {
  547. privacy->SetText( "" );
  548. } else {
  549. int bitSet = ( matchParameters.matchFlags & MATCH_INVITE_ONLY );
  550. bool privacySet = ( bitSet != 0 ? true : false );
  551. if ( privacySet ) {
  552. privacy->SetText( "#str_swf_privacy_closed" );
  553. privacy->SetStrokeInfo( true );
  554. } else if ( !privacySet ) {
  555. privacy->SetText( "#str_swf_privacy_open" );
  556. privacy->SetStrokeInfo( true );
  557. }
  558. }
  559. }
  560. idLocalUser * user = session->GetSignInManager().GetMasterLocalUser();
  561. if ( user != NULL && options != NULL ) {
  562. if ( user->IsInParty() && user->GetPartyCount() > 1 && !session->IsPlatformPartyInLobby() && menuOptions.Num() > 0 ) {
  563. if ( menuOptions[ menuOptions.Num() - 1 ][0] != "#str_swf_invite_xbox_live_party" ) {
  564. menuOptions[ menuOptions.Num() - 1 ][0] = "#str_swf_invite_xbox_live_party"; // invite Xbox LIVE party
  565. options->SetListData( menuOptions );
  566. options->Update();
  567. }
  568. } else if ( menuOptions.Num() > 0 ) {
  569. if ( menuOptions[ menuOptions.Num() - 1 ][0] != "#str_swf_invite_friends" ) {
  570. menuOptions[ menuOptions.Num() - 1 ][0] = "#str_swf_invite_friends"; // invite Xbox LIVE party
  571. options->SetListData( menuOptions );
  572. options->Update();
  573. }
  574. }
  575. }
  576. }
  577. // setup names for lobby;
  578. if ( lobby != NULL ) {
  579. idMenuHandler_Shell * mgr = dynamic_cast< idMenuHandler_Shell * >( menuData );
  580. if ( mgr != NULL ) {
  581. mgr->UpdateLobby( lobby );
  582. lobby->Update();
  583. }
  584. if ( lobby->GetNumEntries() > 0 && lobby->GetFocusIndex() >= lobby->GetNumEntries() ) {
  585. lobby->SetFocusIndex( lobby->GetNumEntries() - 1 );
  586. lobby->SetViewIndex( lobby->GetNumEntries() - 1 );
  587. }
  588. }
  589. }