Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

659 lines
22 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "tf_hud_arena_winpanel.h"
  9. #include "tf_hud_statpanel.h"
  10. #include "tf_spectatorgui.h"
  11. #include "vgui_controls/AnimationController.h"
  12. #include "iclientmode.h"
  13. #include "engine/IEngineSound.h"
  14. #include "c_tf_playerresource.h"
  15. #include "c_tf_team.h"
  16. #include "tf_clientscoreboard.h"
  17. #include <vgui_controls/Label.h>
  18. #include <vgui_controls/ImagePanel.h>
  19. #include <vgui/ILocalize.h>
  20. #include <vgui/ISurface.h>
  21. #include "vgui_avatarimage.h"
  22. #include "fmtstr.h"
  23. #include "teamplayroundbased_gamerules.h"
  24. #include "tf_gamerules.h"
  25. #include "tf_hud_menu_taunt_selection.h"
  26. // memdbgon must be the last include file in a .cpp file!!!
  27. #include "tier0/memdbgon.h"
  28. extern ConVar tf_arena_max_streak;
  29. extern ConVar mp_bonusroundtime;
  30. extern const char *FormatSeconds( int seconds );
  31. //-----------------------------------------------------------------------------
  32. // Purpose: Constructor
  33. //-----------------------------------------------------------------------------
  34. CTFArenaWinPanel::CTFArenaWinPanel( IViewPort *pViewPort ) : EditablePanel( NULL, "ArenaWinPanel" )
  35. {
  36. SetAlpha( 0 );
  37. SetScheme( "ClientScheme" );
  38. m_pTeamScorePanel = new EditablePanel( this, "ArenaWinPanelScores" );
  39. m_pWinnerPanel = new EditablePanel( this, "ArenaWinPanelWinnersPanel" );
  40. m_pLoserPanel = new EditablePanel( this, "ArenaWinPanelLosersPanel" );
  41. m_flTimeUpdateTeamScore = 0;
  42. m_flFlipScoresTimes = 0;
  43. m_iBlueTeamScore = 0;
  44. m_iRedTeamScore = 0;
  45. ListenForGameEvent( "arena_win_panel" );
  46. ListenForGameEvent( "teamplay_round_start" );
  47. ListenForGameEvent( "teamplay_game_over" );
  48. ListenForGameEvent( "tf_game_over" );
  49. m_bShouldBeVisible = false;
  50. vgui::ivgui()->AddTickSignal( GetVPanel(), 50 );
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Purpose:
  54. //-----------------------------------------------------------------------------
  55. void CTFArenaWinPanel::ApplySettings( KeyValues *inResourceData )
  56. {
  57. BaseClass::ApplySettings( inResourceData );
  58. }
  59. //-----------------------------------------------------------------------------
  60. // Purpose:
  61. //-----------------------------------------------------------------------------
  62. void CTFArenaWinPanel::Reset( void )
  63. {
  64. Update();
  65. m_bShouldBeVisible = false;
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Purpose:
  69. //-----------------------------------------------------------------------------
  70. void CTFArenaWinPanel::Update( void )
  71. {
  72. }
  73. //-----------------------------------------------------------------------------
  74. // Purpose:
  75. //-----------------------------------------------------------------------------
  76. void CTFArenaWinPanel::SetVisible( bool state )
  77. {
  78. if ( state == IsVisible() )
  79. return;
  80. int iRenderGroup = gHUD.LookupRenderGroupIndexByName( "mid" );
  81. if ( state )
  82. {
  83. gHUD.LockRenderGroup( iRenderGroup );
  84. }
  85. else
  86. {
  87. gHUD.UnlockRenderGroup( iRenderGroup );
  88. }
  89. BaseClass::SetVisible( state );
  90. }
  91. //-----------------------------------------------------------------------------
  92. // Purpose:
  93. //-----------------------------------------------------------------------------
  94. void CTFArenaWinPanel::FireGameEvent( IGameEvent * event )
  95. {
  96. const char *pEventName = event->GetName();
  97. if ( Q_strcmp( "teamplay_round_start", pEventName ) == 0 )
  98. {
  99. m_bShouldBeVisible = false;
  100. }
  101. else if ( Q_strcmp( "teamplay_game_over", pEventName ) == 0 )
  102. {
  103. m_bShouldBeVisible = false;
  104. }
  105. else if ( Q_strcmp( "tf_game_over", pEventName ) == 0 )
  106. {
  107. m_bShouldBeVisible = false;
  108. }
  109. else if ( Q_strcmp( "arena_win_panel", pEventName ) == 0 )
  110. {
  111. if ( !g_PR )
  112. return;
  113. m_vecPlayerScore.RemoveAll();
  114. InvalidateLayout( false, true );
  115. if ( TFGameRules() && TFGameRules()->IsInArenaMode() == true && tf_arena_max_streak.GetInt() > 0 && tf_arena_use_queue.GetBool() == true )
  116. {
  117. m_pArenaStreakPanel->SetVisible( true );
  118. m_pArenaStreakLabel->SetVisible( true );
  119. wchar_t wzStreaNum[16];
  120. wchar_t wzStreakString[256]=L"";
  121. _snwprintf( wzStreaNum, ARRAYSIZE( wzStreaNum ), L"%i", tf_arena_max_streak.GetInt() );
  122. g_pVGuiLocalize->ConstructString_safe( wzStreakString, g_pVGuiLocalize->Find( "#TF_Arena_PlayingTo" ), 1, wzStreaNum );
  123. m_pTeamScorePanel->SetDialogVariable( "arenastreaktext", wzStreakString );
  124. }
  125. else
  126. {
  127. m_pArenaStreakPanel->SetVisible( false );
  128. m_pArenaStreakLabel->SetVisible( false );
  129. }
  130. m_iWinningPlayerTeam = event->GetInt( "winning_team" );
  131. int iWinReason = event->GetInt( "winreason" );
  132. SetDialogVariable( "WinningTeamLabel", "" );
  133. SetDialogVariable( "AdvancingTeamLabel", "" );
  134. SetDialogVariable( "WinReasonLabel", "" );
  135. SetDialogVariable( "DetailsLabel", "" );
  136. vgui::ImagePanel *pImagePanelBG = dynamic_cast<vgui::ImagePanel *>( FindChildByName("WinPanelBG") );
  137. Assert( pImagePanelBG );
  138. if ( !pImagePanelBG )
  139. return;
  140. // set the appropriate background image and label text
  141. const wchar_t *pTeamLabel = L"";
  142. const wchar_t *pTopPlayersLabel = L"";
  143. const wchar_t *pLocalizedTeamName = L"";
  144. const wchar_t *pLocalizedLoserTeamName = L"";
  145. C_TFTeam *pBlueTeam = GetGlobalTFTeam( TF_TEAM_BLUE );
  146. const wchar_t *pBlueTeamName = pBlueTeam ? pBlueTeam->Get_Localized_Name() : L"BLU";
  147. C_TFTeam *pRedTeam = GetGlobalTFTeam( TF_TEAM_RED );
  148. const wchar_t *pRedTeamName = pRedTeam ? pRedTeam->Get_Localized_Name() : L"RED";
  149. switch ( m_iWinningPlayerTeam )
  150. {
  151. case TF_TEAM_BLUE:
  152. pImagePanelBG->SetImage( "../hud/winpanel_blue_bg_main.vmt" );
  153. pTopPlayersLabel = g_pVGuiLocalize->Find( "#Winpanel_BlueMVPs" );
  154. pLocalizedTeamName = pBlueTeamName;
  155. pLocalizedLoserTeamName = pRedTeamName;
  156. break;
  157. case TF_TEAM_RED:
  158. pImagePanelBG->SetImage( "../hud/winpanel_red_bg_main.vmt" );
  159. pTopPlayersLabel = g_pVGuiLocalize->Find( "#Winpanel_RedMVPs" );
  160. pLocalizedTeamName = pRedTeamName;
  161. pLocalizedLoserTeamName = pBlueTeamName;
  162. break;
  163. case TEAM_UNASSIGNED: // stalemate
  164. pImagePanelBG->SetImage( "../hud/winpanel_black_bg_main.vmt" );
  165. pTeamLabel = g_pVGuiLocalize->Find( "#Winpanel_Stalemate" );
  166. pTopPlayersLabel = g_pVGuiLocalize->Find( "#Winpanel_TopPlayers" );
  167. break;
  168. default:
  169. Assert( false );
  170. break;
  171. }
  172. SetDialogVariable( "TopPlayersLabel", pTopPlayersLabel );
  173. wchar_t wzTeamWin[256] = L"";
  174. if ( TFGameRules() && TFGameRules()->IsInTournamentMode() )
  175. {
  176. g_pVGuiLocalize->ConstructString_safe( wzTeamWin, g_pVGuiLocalize->Find( "#Winpanel_TournamentTeamWins" ), 1, pLocalizedTeamName );
  177. g_pVGuiLocalize->ConstructString_safe( m_wzTeamLose, g_pVGuiLocalize->Find( "#Winpanel_TournamentTeamLost" ), 2, pLocalizedLoserTeamName );
  178. wchar_t wzTeamMPVs[256];
  179. g_pVGuiLocalize->ConstructString_safe( wzTeamMPVs, g_pVGuiLocalize->Find( "#Winpanel_TournamentMVPs" ), 1, pLocalizedTeamName );
  180. if ( m_iWinningPlayerTeam != TEAM_UNASSIGNED )
  181. {
  182. SetDialogVariable( "TopPlayersLabel", wzTeamMPVs );
  183. }
  184. }
  185. else if ( m_iWinningPlayerTeam != TEAM_UNASSIGNED )
  186. {
  187. g_pVGuiLocalize->ConstructString_safe( wzTeamWin, g_pVGuiLocalize->Find( "#Winpanel_TeamWins" ), 2, pLocalizedTeamName, g_pVGuiLocalize->Find( "#Winpanel_Team1" ) );
  188. g_pVGuiLocalize->ConstructString_safe( m_wzTeamLose, g_pVGuiLocalize->Find( "#Winpanel_TeamLost" ), 2, pLocalizedLoserTeamName, g_pVGuiLocalize->Find( "#Winpanel_Team1" ) );
  189. }
  190. if ( m_iWinningPlayerTeam != TEAM_UNASSIGNED )
  191. {
  192. pTeamLabel = wzTeamWin;
  193. }
  194. SetDialogVariable( "WinningTeamLabel", pTeamLabel );
  195. SetDialogVariable( "LosingTeamLabel", "" );
  196. wchar_t wzWinReason[256] = L"";
  197. switch ( iWinReason )
  198. {
  199. case WINREASON_ALL_POINTS_CAPTURED:
  200. g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_AllPointsCaptured" ), 1, pLocalizedTeamName );
  201. break;
  202. case WINREASON_OPPONENTS_DEAD:
  203. if ( TFGameRules() && TFGameRules()->IsInArenaMode() == true )
  204. {
  205. g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_Arena" ), 1, pLocalizedTeamName );
  206. }
  207. else
  208. {
  209. g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_OpponentsDead" ), 1, pLocalizedTeamName );
  210. }
  211. break;
  212. case WINREASON_STALEMATE:
  213. if ( !TFGameRules() || !TFGameRules()->IsCompetitiveMode() )
  214. {
  215. g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_Stalemate" ), 0 );
  216. }
  217. break;
  218. default:
  219. Assert( false );
  220. break;
  221. }
  222. SetDialogVariable( "WinReasonLabel", wzWinReason );
  223. m_bWasFlawlessVictory = IsFlawlessVictory();
  224. if ( WINREASON_ALL_POINTS_CAPTURED == iWinReason )
  225. {
  226. // if this was a full round that ended with point capture or flag capture, show the winning cappers
  227. const char *pCappers = event->GetString( "cappers" );
  228. int iCappers = Q_strlen( pCappers );
  229. if ( iCappers > 0 )
  230. {
  231. char szPlayerNames[256]="";
  232. wchar_t wzPlayerNames[256]=L"";
  233. wchar_t wzCapMsg[512]=L"";
  234. for ( int i = 0; i < iCappers; i++ )
  235. {
  236. Q_strncat( szPlayerNames, g_PR->GetPlayerName( (int) pCappers[i] ), ARRAYSIZE( szPlayerNames ) );
  237. if ( i < iCappers - 1 )
  238. {
  239. Q_strncat( szPlayerNames, ", ", ARRAYSIZE( szPlayerNames ) );
  240. }
  241. }
  242. g_pVGuiLocalize->ConvertANSIToUnicode( szPlayerNames, wzPlayerNames, sizeof( wzPlayerNames ) );
  243. g_pVGuiLocalize->ConstructString_safe( wzCapMsg, g_pVGuiLocalize->Find( "#Winpanel_WinningCapture" ), 1, wzPlayerNames );
  244. SetDialogVariable( "DetailsLabel", wzCapMsg );
  245. }
  246. }
  247. else if ( TFGameRules()->IsInArenaMode() == true && m_iWinningPlayerTeam != TEAM_UNASSIGNED )
  248. {
  249. if ( m_bWasFlawlessVictory )
  250. {
  251. SetDialogVariable( "DetailsLabel", g_pVGuiLocalize->Find( "#TF_Arena_FlawlessVictory" ) );
  252. }
  253. }
  254. // get the current & previous team scores
  255. int iBlueTeamPrevScore = event->GetInt( "blue_score_prev", 0 );
  256. int iRedTeamPrevScore = event->GetInt( "red_score_prev", 0 );
  257. m_iBlueTeamScore = event->GetInt( "blue_score", 0 );
  258. m_iRedTeamScore = event->GetInt( "red_score", 0 );
  259. if ( m_pTeamScorePanel )
  260. {
  261. m_pTeamScorePanel->SetDialogVariable( "blueteamname", pBlueTeamName );
  262. m_pTeamScorePanel->SetDialogVariable( "redteamname", pRedTeamName );
  263. // set the previous team scores in scoreboard
  264. m_pTeamScorePanel->SetDialogVariable( "blueteamscore", iBlueTeamPrevScore );
  265. m_pTeamScorePanel->SetDialogVariable( "redteamscore", iRedTeamPrevScore );
  266. if ( ( m_iBlueTeamScore != iBlueTeamPrevScore ) || ( m_iRedTeamScore != iRedTeamPrevScore ) )
  267. {
  268. // if the new scores are different, set ourselves to update the scoreboard to the new values after a short delay, so players
  269. // see the scores tick up
  270. m_flTimeUpdateTeamScore = gpGlobals->curtime + 3.5f;
  271. }
  272. // only show team scores if round is complete
  273. m_pTeamScorePanel->SetVisible( true );
  274. }
  275. if ( !g_TF_PR )
  276. return;
  277. int iPanelIndex = 0;
  278. // look for the top 6 players sent in the event
  279. for ( int i = 1; i <= 6; i++ )
  280. {
  281. iPanelIndex = (iPanelIndex % 3) + 1;
  282. EditablePanel *pParentPanel = NULL;
  283. if ( i <= 3 )
  284. {
  285. pParentPanel = m_pWinnerPanel;
  286. }
  287. else
  288. {
  289. pParentPanel = m_pLoserPanel;
  290. }
  291. vgui::Label *pPlayerName = dynamic_cast<Label *>( pParentPanel->FindChildByName( CFmtStr( "Player%dName", iPanelIndex ) ) );
  292. vgui::Label *pPlayerClass = dynamic_cast<Label *>( pParentPanel->FindChildByName( CFmtStr( "Player%dClass", iPanelIndex ) ) );
  293. vgui::Label *pPlayerDamage = dynamic_cast<Label *>( pParentPanel->FindChildByName( CFmtStr( "Player%dDamage", iPanelIndex ) ) );
  294. vgui::Label *pPlayerHealing = dynamic_cast<Label *>( pParentPanel->FindChildByName( CFmtStr( "Player%dHealing", iPanelIndex ) ) );
  295. vgui::Label *pPlayerLifetime = dynamic_cast<Label *>( pParentPanel->FindChildByName( CFmtStr( "Player%dLifetime", iPanelIndex ) ) );
  296. vgui::Label *pPlayerKills = dynamic_cast<Label *>( pParentPanel->FindChildByName( CFmtStr( "Player%dKills", iPanelIndex ) ) );
  297. CAvatarImagePanel *pPlayerAvatar = dynamic_cast<CAvatarImagePanel *>( pParentPanel->FindChildByName( CFmtStr( "Player%dAvatar", iPanelIndex) ) );
  298. if ( !pPlayerName || !pPlayerClass || !pPlayerDamage || !pPlayerHealing || !pPlayerLifetime || !pPlayerKills || !pPlayerAvatar )
  299. continue;
  300. pPlayerName->SetText( "" );
  301. pPlayerClass->SetText( "" );
  302. pPlayerDamage->SetText( "" );
  303. pPlayerHealing->SetText( "" );
  304. pPlayerLifetime->SetText( "" );
  305. pPlayerKills->SetText( "" );
  306. pPlayerAvatar->SetPlayer( NULL );
  307. char szPlayerIndexVal[64]="", szPlayerDamageVal[64]="", szPlayerHealingVal[64]="", szPlayerTimeAliveVal[64]="", szPlayerKillingBlowsVal[64]="";
  308. // get player index and round points from the event
  309. Q_snprintf( szPlayerIndexVal, ARRAYSIZE( szPlayerIndexVal ), "player_%d", i );
  310. Q_snprintf( szPlayerDamageVal, ARRAYSIZE( szPlayerDamageVal ), "player_%d_damage", i );
  311. Q_snprintf( szPlayerHealingVal, ARRAYSIZE( szPlayerHealingVal ), "player_%d_healing", i );
  312. Q_snprintf( szPlayerTimeAliveVal, ARRAYSIZE( szPlayerTimeAliveVal ), "player_%d_lifetime", i );
  313. Q_snprintf( szPlayerKillingBlowsVal, ARRAYSIZE( szPlayerKillingBlowsVal ), "player_%d_kills", i );
  314. int iPlayerIndex = event->GetInt( szPlayerIndexVal, 0 );
  315. if ( iPlayerIndex == 0 )
  316. continue;
  317. if ( g_TF_PR->IsConnected( iPlayerIndex ) == false )
  318. continue;
  319. int iDamageDone = event->GetInt( szPlayerDamageVal, 0 );
  320. int iHealingDone = event->GetInt( szPlayerHealingVal, 0 );
  321. int iTimeAlive = event->GetInt( szPlayerTimeAliveVal, 0 );
  322. int iKillingBlows = event->GetInt( szPlayerKillingBlowsVal, 0 );
  323. PlayerArenaRoundScore_t &playerRoundScore = m_vecPlayerScore[m_vecPlayerScore.AddToTail()];
  324. playerRoundScore.iPlayerIndex = iPlayerIndex;
  325. playerRoundScore.iTotalDamage = iDamageDone;
  326. playerRoundScore.iTotalHealing = iHealingDone;
  327. playerRoundScore.iTimeAlive = iTimeAlive;
  328. playerRoundScore.iKillingBlows = iKillingBlows;
  329. }
  330. m_bShouldBeVisible = true;
  331. SetupPlayerStats();
  332. MoveToFront();
  333. }
  334. }
  335. //-----------------------------------------------------------------------------
  336. // Purpose:
  337. //-----------------------------------------------------------------------------
  338. bool CTFArenaWinPanel::IsFlawlessVictory( void )
  339. {
  340. C_TFTeam *pTeam = GetGlobalTFTeam( m_iWinningPlayerTeam );
  341. bool bAllAlive = true;
  342. if ( pTeam && g_TF_PR )
  343. {
  344. if ( pTeam->GetNumPlayers() == 1 )
  345. return false;
  346. if ( g_TF_PR->GetNumPlayersForTeam( m_iWinningPlayerTeam, true ) != pTeam->GetNumPlayers() )
  347. {
  348. bAllAlive = false;
  349. }
  350. }
  351. return bAllAlive;
  352. }
  353. //-----------------------------------------------------------------------------
  354. // Purpose: Applies scheme settings
  355. //-----------------------------------------------------------------------------
  356. void CTFArenaWinPanel::SetupPlayerStats( void )
  357. {
  358. if ( !g_TF_PR )
  359. return;
  360. m_pWinnerPanel->SetVisible( true );
  361. m_pLoserPanel->SetVisible( false );
  362. m_flFlipScoresTimes = gpGlobals->curtime + ( ( TFGameRules() ? TFGameRules()->GetBonusRoundTime() : 5.0f ) * 0.5f );
  363. int iWinnersAdded = 1;
  364. int iLosersAdded = 1;
  365. int iPlayerAdded = 0;
  366. EditablePanel *pParentPanel = m_pWinnerPanel;
  367. // look for the top 6 players sent in the event
  368. for ( int i = 0; i < m_vecPlayerScore.Count(); i++ )
  369. {
  370. bool bShow = true;
  371. int iPlayerIndex = m_vecPlayerScore[i].iPlayerIndex;
  372. int iIndex = 0;
  373. if ( m_iWinningPlayerTeam != TEAM_UNASSIGNED )
  374. {
  375. if ( m_iWinningPlayerTeam == g_TF_PR->GetTeam( iPlayerIndex ) )
  376. {
  377. pParentPanel = m_pWinnerPanel;
  378. iIndex = iWinnersAdded;
  379. iWinnersAdded++;
  380. }
  381. else
  382. {
  383. pParentPanel = m_pLoserPanel;
  384. iIndex = iLosersAdded;
  385. iLosersAdded++;
  386. }
  387. }
  388. else
  389. {
  390. if ( i >= ( m_vecPlayerScore.Count() * 0.5f ) && pParentPanel != m_pLoserPanel )
  391. {
  392. iPlayerAdded = 0;
  393. pParentPanel = m_pLoserPanel;
  394. }
  395. iIndex = (iPlayerAdded + 1) % 4;
  396. iPlayerAdded++;
  397. }
  398. int iDamageDone = m_vecPlayerScore[i].iTotalDamage;
  399. int iHealingDone = m_vecPlayerScore[i].iTotalHealing;
  400. int iTimeAlive = m_vecPlayerScore[i].iTimeAlive;
  401. int iKillingBlows = m_vecPlayerScore[i].iKillingBlows;
  402. CAvatarImagePanel *pPlayerAvatar = dynamic_cast<CAvatarImagePanel *>( pParentPanel->FindChildByName( CFmtStr( "Player%dAvatar", iIndex) ) );
  403. if ( pPlayerAvatar )
  404. {
  405. pPlayerAvatar->SetShouldScaleImage( true );
  406. pPlayerAvatar->SetShouldDrawFriendIcon( false );
  407. if ( bShow )
  408. {
  409. CBasePlayer *pPlayer = UTIL_PlayerByIndex( iPlayerIndex );
  410. pPlayerAvatar->SetPlayer( pPlayer );
  411. }
  412. pPlayerAvatar->SetVisible( bShow );
  413. }
  414. vgui::Label *pPlayerName = dynamic_cast<Label *>( pParentPanel->FindChildByName( CFmtStr( "Player%dName", iIndex ) ) );
  415. vgui::Label *pPlayerClass = dynamic_cast<Label *>( pParentPanel->FindChildByName( CFmtStr( "Player%dClass", iIndex ) ) );
  416. vgui::Label *pPlayerDamage = dynamic_cast<Label *>( pParentPanel->FindChildByName( CFmtStr( "Player%dDamage", iIndex ) ) );
  417. vgui::Label *pPlayerHealing = dynamic_cast<Label *>( pParentPanel->FindChildByName( CFmtStr( "Player%dHealing", iIndex ) ) );
  418. vgui::Label *pPlayerLifetime = dynamic_cast<Label *>( pParentPanel->FindChildByName( CFmtStr( "Player%dLifetime", iIndex ) ) );
  419. vgui::Label *pPlayerKills = dynamic_cast<Label *>( pParentPanel->FindChildByName( CFmtStr( "Player%dKills", iIndex ) ) );
  420. if ( !pPlayerName || !pPlayerClass || !pPlayerDamage || !pPlayerHealing || !pPlayerLifetime || !pPlayerKills )
  421. continue;
  422. if ( bShow )
  423. {
  424. // set the player labels to team color
  425. Color clr = g_TF_PR->GetTeamColor( g_TF_PR->GetTeam( iPlayerIndex ) );
  426. pPlayerName->SetFgColor( clr );
  427. pPlayerClass->SetFgColor( clr );
  428. pPlayerDamage->SetFgColor( clr );
  429. pPlayerHealing->SetFgColor( clr );
  430. pPlayerLifetime->SetFgColor( clr );
  431. pPlayerKills->SetFgColor( clr );
  432. // set label contents
  433. pPlayerName->SetText( g_TF_PR->GetPlayerName( iPlayerIndex ) );
  434. pPlayerClass->SetText( g_aPlayerClassNames[g_TF_PR->GetPlayerClass( iPlayerIndex )] );
  435. pPlayerDamage->SetText( CFmtStr( "%d", iDamageDone ) );
  436. pPlayerHealing->SetText( CFmtStr( "%d", iHealingDone ) );
  437. pPlayerLifetime->SetText( CFmtStr( "%s", FormatSeconds( iTimeAlive ) ) );
  438. pPlayerKills->SetText( CFmtStr( "%d", iKillingBlows ) );
  439. }
  440. // show or hide labels for this player position
  441. pPlayerName->SetVisible( bShow );
  442. pPlayerClass->SetVisible( bShow );
  443. pPlayerDamage->SetVisible( bShow );
  444. pPlayerHealing->SetVisible( bShow );
  445. pPlayerLifetime->SetVisible( bShow );
  446. pPlayerKills->SetVisible( bShow );
  447. }
  448. }
  449. //-----------------------------------------------------------------------------
  450. // Purpose: Applies scheme settings
  451. //-----------------------------------------------------------------------------
  452. void CTFArenaWinPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
  453. {
  454. BaseClass::ApplySchemeSettings( pScheme );
  455. LoadControlSettings( "resource/UI/HudArenaWinPanel.res" );
  456. m_pArenaStreakPanel = m_pTeamScorePanel->FindChildByName( "ArenaStreaksBG" );
  457. m_pArenaStreakLabel = m_pTeamScorePanel->FindChildByName("ArenaStreakLabel" );
  458. }
  459. //-----------------------------------------------------------------------------
  460. // Purpose: panel think method
  461. //-----------------------------------------------------------------------------
  462. void CTFArenaWinPanel::OnTick()
  463. {
  464. // if we've scheduled ourselves to update the team scores, handle it now
  465. if ( m_flTimeUpdateTeamScore > 0 && ( gpGlobals->curtime > m_flTimeUpdateTeamScore ) && m_pTeamScorePanel )
  466. {
  467. // play a sound
  468. CLocalPlayerFilter filter;
  469. C_BaseEntity::EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, "Hud.EndRoundScored" );
  470. // update the team scores
  471. m_pTeamScorePanel->SetDialogVariable( "blueteamscore", m_iBlueTeamScore );
  472. m_pTeamScorePanel->SetDialogVariable( "redteamscore", m_iRedTeamScore );
  473. m_flTimeUpdateTeamScore = 0;
  474. }
  475. if ( m_flFlipScoresTimes > 0 && ( gpGlobals->curtime > m_flFlipScoresTimes ) )
  476. {
  477. //flip the scores
  478. m_pWinnerPanel->SetVisible( false );
  479. m_pLoserPanel->SetVisible( true );
  480. m_flFlipScoresTimes = 0;
  481. if ( m_iWinningPlayerTeam != TEAM_UNASSIGNED )
  482. {
  483. const wchar_t *pTopPlayersLabel = NULL;
  484. vgui::ImagePanel *pImagePanelBG = dynamic_cast<vgui::ImagePanel *>( FindChildByName("WinPanelBG") );
  485. if ( pImagePanelBG == NULL )
  486. return;
  487. switch ( m_iWinningPlayerTeam )
  488. {
  489. case TF_TEAM_BLUE:
  490. pTopPlayersLabel = g_pVGuiLocalize->Find( "#Winpanel_RedMVPs" );
  491. pImagePanelBG->SetImage( "../hud/winpanel_red_bg_main.vmt" );
  492. break;
  493. case TF_TEAM_RED:
  494. pTopPlayersLabel = g_pVGuiLocalize->Find( "#Winpanel_BlueMVPs" );
  495. pImagePanelBG->SetImage( "../hud/winpanel_blue_bg_main.vmt" );
  496. break;
  497. default:
  498. Assert( false );
  499. break;
  500. }
  501. SetDialogVariable( "TopPlayersLabel", pTopPlayersLabel );
  502. SetDialogVariable( "LosingTeamLabel", m_wzTeamLose );
  503. SetDialogVariable( "WinningTeamLabel", "" );
  504. if ( m_bWasFlawlessVictory )
  505. {
  506. CLocalPlayerFilter filter;
  507. if ( m_iWinningPlayerTeam == GetLocalPlayerTeam() )
  508. {
  509. C_BaseEntity::EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, "Announcer.AM_FlawlessVictoryRandom" );
  510. }
  511. else if ( GetLocalPlayerTeam() == TEAM_SPECTATOR )
  512. {
  513. C_BaseEntity::EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, "Announcer.AM_FlawlessVictory01" );
  514. }
  515. else
  516. {
  517. C_BaseEntity::EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, "Announcer.AM_FlawlessDefeatRandom" );
  518. }
  519. }
  520. }
  521. }
  522. if ( m_bShouldBeVisible == true )
  523. {
  524. IViewPortPanel *scoreboard = gViewPortInterface->FindPanelByName( PANEL_SCOREBOARD );
  525. if ( ( scoreboard && scoreboard->IsVisible() ) || IsInFreezeCam() )
  526. {
  527. SetVisible( false );
  528. return;
  529. }
  530. CHudMenuTauntSelection *pMenuTauntSelection = ( CHudMenuTauntSelection * )GET_HUDELEMENT( CHudMenuTauntSelection );
  531. if ( pMenuTauntSelection && pMenuTauntSelection->IsVisible() )
  532. {
  533. SetVisible( false );
  534. return;
  535. }
  536. if ( TFGameRules() && TFGameRules()->State_Get() != GR_STATE_TEAM_WIN )
  537. {
  538. m_bShouldBeVisible = false;
  539. }
  540. }
  541. SetVisible( m_bShouldBeVisible );
  542. }