MenuScreen_Shell_PartyLobby.cpp 25 KB

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