MenuHandler_Scoreboard.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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. /*
  24. ========================
  25. idMenuHandler_Scoreboard::Update
  26. ========================
  27. */
  28. void idMenuHandler_Scoreboard::Update() {
  29. if ( gui == NULL || !gui->IsActive() ) {
  30. return;
  31. }
  32. if ( nextScreen != activeScreen ) {
  33. if ( nextScreen == SCOREBOARD_AREA_INVALID ) {
  34. if ( activeScreen > SCOREBOARD_AREA_INVALID && activeScreen < SCOREBOARD_NUM_AREAS && menuScreens[ activeScreen ] != NULL ) {
  35. menuScreens[ activeScreen ]->HideScreen( static_cast<mainMenuTransition_t>(transition) );
  36. }
  37. idMenuWidget_CommandBar * cmdBar = dynamic_cast< idMenuWidget_CommandBar * >( GetChildFromIndex( SCOREBOARD_WIDGET_CMD_BAR ) );
  38. if ( cmdBar != NULL ) {
  39. cmdBar->ClearAllButtons();
  40. cmdBar->Update();
  41. }
  42. idSWFSpriteInstance * bg = gui->GetRootObject().GetNestedSprite( "background" );
  43. if ( bg != NULL ) {
  44. bg->PlayFrame( "rollOff" );
  45. }
  46. } else {
  47. if ( activeScreen > SCOREBOARD_AREA_INVALID && activeScreen < SCOREBOARD_NUM_AREAS && menuScreens[ activeScreen ] != NULL ) {
  48. menuScreens[ activeScreen ]->HideScreen( static_cast<mainMenuTransition_t>(transition) );
  49. }
  50. if ( nextScreen > SCOREBOARD_AREA_INVALID && nextScreen < SCOREBOARD_NUM_AREAS && menuScreens[ nextScreen ] != NULL ) {
  51. menuScreens[ nextScreen ]->UpdateCmds();
  52. menuScreens[ nextScreen ]->ShowScreen( static_cast<mainMenuTransition_t>(transition) );
  53. }
  54. }
  55. transition = MENU_TRANSITION_INVALID;
  56. activeScreen = nextScreen;
  57. }
  58. idMenuHandler::Update();
  59. }
  60. /*
  61. ========================
  62. idMenuHandler_Scoreboard::ActivateMenu
  63. ========================
  64. */
  65. void idMenuHandler_Scoreboard::TriggerMenu() {
  66. nextScreen = activationScreen;
  67. }
  68. /*
  69. ========================
  70. idMenuHandler_Scoreboard::ActivateMenu
  71. ========================
  72. */
  73. void idMenuHandler_Scoreboard::ActivateMenu( bool show ) {
  74. idMenuHandler::ActivateMenu( show );
  75. idPlayer * player = gameLocal.GetLocalPlayer();
  76. if ( player == NULL ) {
  77. return;
  78. }
  79. if ( show ) {
  80. idMenuWidget_CommandBar * cmdBar = dynamic_cast< idMenuWidget_CommandBar * >( GetChildFromIndex( SCOREBOARD_WIDGET_CMD_BAR ) );
  81. if ( cmdBar != NULL ) {
  82. cmdBar->ClearAllButtons();
  83. cmdBar->Update();
  84. }
  85. nextScreen = SCOREBOARD_AREA_INVALID;
  86. activeScreen = SCOREBOARD_AREA_INVALID;
  87. } else {
  88. activeScreen = SCOREBOARD_AREA_INVALID;
  89. nextScreen = SCOREBOARD_AREA_INVALID;
  90. }
  91. class idSWFScriptFunction_activateMenu : public idSWFScriptFunction_RefCounted {
  92. public:
  93. idSWFScriptFunction_activateMenu( idMenuHandler * _handler ) {
  94. handler = _handler;
  95. }
  96. idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  97. if ( handler != NULL ) {
  98. handler->TriggerMenu();
  99. }
  100. return idSWFScriptVar();
  101. }
  102. private:
  103. idMenuHandler * handler;
  104. };
  105. gui->SetGlobal( "activateMenus", new (TAG_SWF) idSWFScriptFunction_activateMenu( this ) );
  106. }
  107. /*
  108. ========================
  109. idMenuHandler_Scoreboard::Initialize
  110. ========================
  111. */
  112. void idMenuHandler_Scoreboard::Initialize( const char * swfFile, idSoundWorld * sw ) {
  113. idMenuHandler::Initialize( swfFile, sw );
  114. //---------------------
  115. // Initialize the menus
  116. //---------------------
  117. #define BIND_SCOREBOARD_SCREEN( screenId, className, menuHandler ) \
  118. menuScreens[ (screenId) ] = new className(); \
  119. menuScreens[ (screenId) ]->Initialize( menuHandler ); \
  120. menuScreens[ (screenId) ]->AddRef();
  121. for ( int i = 0; i < SCOREBOARD_NUM_AREAS; ++i ) {
  122. menuScreens[ i ] = NULL;
  123. }
  124. BIND_SCOREBOARD_SCREEN( SCOREBOARD_AREA_DEFAULT, idMenuScreen_Scoreboard, this );
  125. BIND_SCOREBOARD_SCREEN( SCOREBOARD_AREA_TEAM, idMenuScreen_Scoreboard_Team, this );
  126. //
  127. // command bar
  128. //
  129. idMenuWidget_CommandBar * const commandBarWidget = new (TAG_SWF) idMenuWidget_CommandBar();
  130. commandBarWidget->SetAlignment( idMenuWidget_CommandBar::LEFT );
  131. commandBarWidget->SetSpritePath( "prompts" );
  132. commandBarWidget->Initialize( this );
  133. AddChild( commandBarWidget );
  134. class idScoreboardGUIClose : public idSWFScriptFunction_RefCounted {
  135. public:
  136. idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  137. gameLocal.mpGame.SetScoreboardActive( false );
  138. return idSWFScriptVar();
  139. }
  140. };
  141. if ( gui != NULL ) {
  142. gui->SetGlobal( "closeScoreboard", new idScoreboardGUIClose() );
  143. }
  144. // precache sounds
  145. // don't load gui music for the pause menu to save some memory
  146. const idSoundShader * soundShader = NULL;
  147. soundShader = declManager->FindSound( "gui/list_scroll", true );
  148. if ( soundShader != NULL ) {
  149. sounds[ GUI_SOUND_SCROLL ] = soundShader->GetName();
  150. }
  151. soundShader = declManager->FindSound( "gui/btn_PDA_advance", true );
  152. if ( soundShader != NULL ) {
  153. sounds[ GUI_SOUND_ADVANCE ] = soundShader->GetName();
  154. }
  155. soundShader = declManager->FindSound( "gui/btn_PDA_back", true );
  156. if ( soundShader != NULL ) {
  157. sounds[ GUI_SOUND_BACK ] = soundShader->GetName();
  158. }
  159. soundShader = declManager->FindSound( "gui/pda_next_tab", true );
  160. if ( soundShader != NULL ) {
  161. sounds[ GUI_SOUND_BUILD_ON ] = soundShader->GetName();
  162. }
  163. soundShader = declManager->FindSound( "gui/pda_prev_tab", true );
  164. if ( soundShader != NULL ) {
  165. sounds[ GUI_SOUND_BUILD_OFF ] = soundShader->GetName();
  166. }
  167. soundShader = declManager->FindSound( "gui/btn_set_focus", true );
  168. if ( soundShader != NULL ) {
  169. sounds[ GUI_SOUND_FOCUS ] = soundShader->GetName();
  170. }
  171. soundShader = declManager->FindSound( "gui/btn_roll_over", true );
  172. if ( soundShader != NULL ) {
  173. sounds[ GUI_SOUND_ROLL_OVER ] = soundShader->GetName();
  174. }
  175. soundShader = declManager->FindSound( "gui/btn_roll_out", true );
  176. if ( soundShader != NULL ) {
  177. sounds[ GUI_SOUND_ROLL_OUT ] = soundShader->GetName();
  178. }
  179. }
  180. /*
  181. ========================
  182. idMenuHandler_Scoreboard::GetMenuScreen
  183. ========================
  184. */
  185. idMenuScreen * idMenuHandler_Scoreboard::GetMenuScreen( int index ) {
  186. if ( index < 0 || index >= SCOREBOARD_NUM_AREAS ) {
  187. return NULL;
  188. }
  189. return menuScreens[ index ];
  190. }
  191. /*
  192. ========================
  193. idMenuHandler_Scoreboard::HandleAction
  194. ========================
  195. */
  196. bool idMenuHandler_Scoreboard::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) {
  197. if ( activeScreen == SCOREBOARD_AREA_INVALID ) {
  198. return true;
  199. }
  200. widgetAction_t actionType = action.GetType();
  201. //const idSWFParmList & parms = action.GetParms();
  202. if ( event.type == WIDGET_EVENT_COMMAND ) {
  203. if ( menuScreens[ activeScreen ] != NULL && !forceHandled ) {
  204. if ( menuScreens[ activeScreen ]->HandleAction( action, event, widget, true ) ) {
  205. if ( actionType == WIDGET_ACTION_GO_BACK ) {
  206. PlaySound( GUI_SOUND_BACK );
  207. } else {
  208. PlaySound( GUI_SOUND_ADVANCE );
  209. }
  210. return true;
  211. }
  212. }
  213. }
  214. return idMenuHandler::HandleAction( action, event, widget, forceHandled );
  215. }
  216. /*
  217. ========================
  218. idMenuHandler_Scoreboard::AddPlayerInfo
  219. ========================
  220. */
  221. void idMenuHandler_Scoreboard::AddPlayerInfo( int index, voiceStateDisplay_t voiceState, int team, idStr name, int score, int wins, int ping, idStr spectateData ) {
  222. scoreboardInfo_t info;
  223. idList< idStr > values;
  224. values.Append( name );
  225. if ( spectateData.IsEmpty() || gameLocal.mpGame.GetGameState() == idMultiplayerGame::GAMEREVIEW ) {
  226. values.Append( va( "%i", score ) );
  227. } else {
  228. values.Append( spectateData );
  229. }
  230. values.Append( va( "%i", wins ) );
  231. values.Append( va( "%i", ping ) );
  232. info.index = index;
  233. info.voiceState = voiceState;
  234. info.values = values;
  235. if ( team == 1 ) {
  236. blueInfo.Append( info );
  237. } else {
  238. redInfo.Append( info );
  239. }
  240. }
  241. /*
  242. ========================
  243. idMenuHandler_Scoreboard::UpdateScoreboard
  244. ========================
  245. */
  246. void idMenuHandler_Scoreboard::UpdateSpectating( idStr spectate, idStr follow ) {
  247. if ( nextScreen == SCOREBOARD_AREA_DEFAULT ) {
  248. idMenuScreen_Scoreboard * screen = dynamic_cast< idMenuScreen_Scoreboard * >( menuScreens[ SCOREBOARD_AREA_DEFAULT ] );
  249. if ( screen ) {
  250. screen->UpdateSpectating( spectate, follow );
  251. }
  252. } else if ( nextScreen == SCOREBOARD_AREA_TEAM ) {
  253. idMenuScreen_Scoreboard * screen = dynamic_cast< idMenuScreen_Scoreboard * >( menuScreens[ SCOREBOARD_AREA_TEAM ] );
  254. if ( screen ) {
  255. screen->UpdateSpectating( spectate, follow );
  256. }
  257. }
  258. }
  259. /*
  260. ========================
  261. idMenuHandler_Scoreboard::UpdateScoreboard
  262. ========================
  263. */
  264. void idMenuHandler_Scoreboard::UpdateScoreboard( idList< mpScoreboardInfo > & data, idStr gameInfo ) {
  265. bool changed = false;
  266. if ( data.Num() != scoreboardInfo.Num() ) {
  267. changed = true;
  268. } else {
  269. for ( int i = 0; i < data.Num(); ++i ) {
  270. if ( data[i] != scoreboardInfo[i] ) {
  271. changed = true;
  272. break;
  273. }
  274. }
  275. }
  276. if ( nextScreen == SCOREBOARD_AREA_DEFAULT ) {
  277. idMenuScreen_Scoreboard * screen = dynamic_cast< idMenuScreen_Scoreboard * >( menuScreens[ SCOREBOARD_AREA_DEFAULT ] );
  278. if ( screen ) {
  279. screen->UpdateGameInfo( gameInfo );
  280. screen->UpdateTeamScores( redScore, blueScore );
  281. }
  282. } else if ( nextScreen == SCOREBOARD_AREA_TEAM ) {
  283. idMenuScreen_Scoreboard * screen = dynamic_cast< idMenuScreen_Scoreboard * >( menuScreens[ SCOREBOARD_AREA_TEAM ] );
  284. if ( screen ) {
  285. screen->UpdateGameInfo( gameInfo );
  286. screen->UpdateTeamScores( redScore, blueScore );
  287. }
  288. }
  289. redInfo.Clear();
  290. blueInfo.Clear();
  291. for ( int i = 0; i < data.Num(); ++i ) {
  292. AddPlayerInfo( data[i].playerNum, data[i].voiceState, data[i].team, data[i].name, data[i].score, data[i].wins, data[i].ping, data[i].spectateData );
  293. }
  294. idList< scoreboardInfo_t, TAG_IDLIB_LIST_MENU > listItemInfo;
  295. for ( int i = 0; i < redInfo.Num(); ++i ) {
  296. listItemInfo.Append( redInfo[i] );
  297. }
  298. // add empty items to list
  299. if ( blueInfo.Num() > 0 ) {
  300. while ( listItemInfo.Num() < 4 ) {
  301. scoreboardInfo_t info;
  302. listItemInfo.Append( info );
  303. }
  304. }
  305. for ( int i = 0; i < blueInfo.Num(); ++i ) {
  306. listItemInfo.Append( blueInfo[i] );
  307. }
  308. while ( listItemInfo.Num() < 8 ) {
  309. scoreboardInfo_t info;
  310. listItemInfo.Append( info );
  311. }
  312. if ( nextScreen == SCOREBOARD_AREA_DEFAULT || activationScreen == SCOREBOARD_AREA_DEFAULT ) {
  313. idMenuScreen_Scoreboard * screen = dynamic_cast< idMenuScreen_Scoreboard * >( menuScreens[ SCOREBOARD_AREA_DEFAULT ] );
  314. if ( screen ) {
  315. screen->SetPlayerData( listItemInfo );
  316. }
  317. } else if ( nextScreen == SCOREBOARD_AREA_TEAM || activationScreen == SCOREBOARD_AREA_TEAM ) {
  318. idMenuScreen_Scoreboard * screen = dynamic_cast< idMenuScreen_Scoreboard * >( menuScreens[ SCOREBOARD_AREA_TEAM ] );
  319. if ( screen ) {
  320. screen->SetPlayerData( listItemInfo );
  321. }
  322. }
  323. scoreboardInfo = data;
  324. }
  325. /*
  326. ========================
  327. idMenuHandler_Scoreboard::SetTeamScore
  328. ========================
  329. */
  330. void idMenuHandler_Scoreboard::SetTeamScores( int r, int b ) {
  331. redScore = r;
  332. blueScore = b;
  333. }
  334. /*
  335. ========================
  336. idMenuHandler_Scoreboard::GetNumPlayers
  337. ========================
  338. */
  339. int idMenuHandler_Scoreboard::GetNumPlayers( int team ) {
  340. if ( team == 1 ) {
  341. return blueInfo.Num();
  342. } else {
  343. return redInfo.Num();
  344. }
  345. }
  346. /*
  347. ========================
  348. idMenuHandler_Scoreboard::SetActivationScreen
  349. ========================
  350. */
  351. void idMenuHandler_Scoreboard::SetActivationScreen( int screen, int trans ) {
  352. activationScreen = screen;
  353. transition = trans;
  354. }
  355. /*
  356. ========================
  357. idMenuHandler_Scoreboard::GetUserID
  358. ========================
  359. */
  360. void idMenuHandler_Scoreboard::GetUserID( int slot, lobbyUserID_t & luid ) {
  361. idList< int > redList;
  362. idList< int > blueList;
  363. for ( int i = 0; i < scoreboardInfo.Num(); ++i ) {
  364. if ( scoreboardInfo[i].team == 1 ) {
  365. blueList.Append( scoreboardInfo[i].playerNum );
  366. } else {
  367. redList.Append( scoreboardInfo[i].playerNum );
  368. }
  369. }
  370. idList< int > displayList;
  371. for ( int i = 0; i < redList.Num(); ++i ) {
  372. displayList.Append( redList[ i ] );
  373. }
  374. for ( int i = 0; i < blueList.Num(); ++i ) {
  375. displayList.Append( blueList[ i ] );
  376. }
  377. if ( slot >= displayList.Num() ) {
  378. return;
  379. }
  380. luid = gameLocal.lobbyUserIDs[ displayList[ slot ] ];
  381. }
  382. /*
  383. ========================
  384. idMenuHandler_Scoreboard::ViewPlayerProfile
  385. ========================
  386. */
  387. void idMenuHandler_Scoreboard::ViewPlayerProfile( int slot ) {
  388. lobbyUserID_t luid;
  389. GetUserID( slot, luid );
  390. if ( luid.IsValid() ) {
  391. session->ShowLobbyUserGamerCardUI( luid );
  392. }
  393. }
  394. /*
  395. ========================
  396. idMenuHandler_Scoreboard::MutePlayer
  397. ========================
  398. */
  399. void idMenuHandler_Scoreboard::MutePlayer( int slot ) {
  400. lobbyUserID_t luid;
  401. GetUserID( slot, luid );
  402. if ( luid.IsValid() ) {
  403. session->ToggleLobbyUserVoiceMute( luid );
  404. }
  405. }
  406. /*
  407. ========================
  408. idMenuHandler_Scoreboard::UpdateScoreboardSelection
  409. ========================
  410. */
  411. void idMenuHandler_Scoreboard::UpdateScoreboardSelection() {
  412. if ( nextScreen == SCOREBOARD_AREA_DEFAULT || activationScreen == SCOREBOARD_AREA_DEFAULT ) {
  413. idMenuScreen_Scoreboard * screen = dynamic_cast< idMenuScreen_Scoreboard * >( menuScreens[ SCOREBOARD_AREA_DEFAULT ] );
  414. if ( screen ) {
  415. screen->UpdateHighlight();
  416. }
  417. } else if ( nextScreen == SCOREBOARD_AREA_TEAM || activationScreen == SCOREBOARD_AREA_TEAM ) {
  418. idMenuScreen_Scoreboard * screen = dynamic_cast< idMenuScreen_Scoreboard * >( menuScreens[ SCOREBOARD_AREA_TEAM ] );
  419. if ( screen ) {
  420. screen->UpdateHighlight();
  421. }
  422. }
  423. }