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.

218 lines
6.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "tf_hud_pve_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_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_hud_mann_vs_machine_status.h"
  25. #include "tf_gamerules.h"
  26. // memdbgon must be the last include file in a .cpp file!!!
  27. #include "tier0/memdbgon.h"
  28. //-----------------------------------------------------------------------------
  29. // Purpose: Constructor
  30. //-----------------------------------------------------------------------------
  31. CTFPVEWinPanel::CTFPVEWinPanel( IViewPort *pViewPort ) : EditablePanel( NULL, "PVEWinPanel" )
  32. {
  33. //SetAlpha( 0 );
  34. SetScheme( "ClientScheme" );
  35. ListenForGameEvent( "pve_win_panel" );
  36. ListenForGameEvent( "teamplay_round_start" );
  37. ListenForGameEvent( "teamplay_game_over" );
  38. ListenForGameEvent( "tf_game_over" );
  39. m_bShouldBeVisible = false;
  40. m_pRespecContainerPanel = NULL;
  41. m_pRespecBackground = NULL;
  42. m_pRespecCountLabel = NULL;
  43. m_pRespecTextLabel = NULL;
  44. vgui::ivgui()->AddTickSignal( GetVPanel(), 50 );
  45. }
  46. //-----------------------------------------------------------------------------
  47. // Purpose:
  48. //-----------------------------------------------------------------------------
  49. void CTFPVEWinPanel::ApplySettings( KeyValues *inResourceData )
  50. {
  51. BaseClass::ApplySettings( inResourceData );
  52. }
  53. //-----------------------------------------------------------------------------
  54. // Purpose:
  55. //-----------------------------------------------------------------------------
  56. void CTFPVEWinPanel::FireGameEvent( IGameEvent * event )
  57. {
  58. const char *pEventName = event->GetName();
  59. if ( Q_strcmp( "teamplay_round_start", pEventName ) == 0 ||
  60. Q_strcmp( "teamplay_game_over", pEventName ) == 0 ||
  61. Q_strcmp( "tf_game_over", pEventName ) == 0 ||
  62. Q_strcmp( "training_complete", pEventName ) == 0 )
  63. {
  64. m_bShouldBeVisible = false;
  65. }
  66. else if ( Q_strcmp( "pve_win_panel", pEventName ) == 0 )
  67. {
  68. if ( !g_PR )
  69. return;
  70. int iWinningTeam = event->GetInt( "winning_team" );
  71. int iWinReason = event->GetInt( "winreason" );
  72. if ( iWinningTeam != TF_TEAM_PVE_INVADERS )
  73. {
  74. // Only show this when the robots win
  75. return;
  76. }
  77. LoadControlSettings( "resource/UI/HudPVEWinPanel.res" );
  78. InvalidateLayout( false, true );
  79. SetDialogVariable( "WinningTeamLabel", "" );
  80. SetDialogVariable( "WinReasonLabel", "" );
  81. SetDialogVariable( "DetailsLabel", "" );
  82. wchar_t *pwchWinReason = L"";
  83. switch ( iWinReason )
  84. {
  85. case 0:
  86. default:
  87. pwchWinReason = g_pVGuiLocalize->Find( "#Winpanel_PVE_Bomb_Deployed" );
  88. }
  89. SetDialogVariable( "WinReasonLabel", pwchWinReason );
  90. SetDialogVariable( "DetailsLabel", g_pVGuiLocalize->Find( "#TF_PVE_RestoreToCheckpointDetailed" ) );
  91. m_bShouldBeVisible = true;
  92. MoveToFront();
  93. }
  94. }
  95. //-----------------------------------------------------------------------------
  96. // Purpose: Applies scheme settings
  97. //-----------------------------------------------------------------------------
  98. void CTFPVEWinPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
  99. {
  100. BaseClass::ApplySchemeSettings( pScheme );
  101. LoadControlSettings( "resource/UI/HudPVEWinPanel.res" );
  102. m_pRespecBackground = dynamic_cast< vgui::ScalableImagePanel* >( FindChildByName( "RespecBackground" ) );
  103. m_pRespecContainerPanel = dynamic_cast< vgui::EditablePanel* >( FindChildByName( "RespecContainer" ) );
  104. if ( m_pRespecContainerPanel )
  105. {
  106. m_pRespecTextLabel = dynamic_cast< vgui::Label* >( m_pRespecContainerPanel->FindChildByName( "RespecTextLabelLoss" ) );
  107. m_pRespecCountLabel = dynamic_cast< vgui::Label* >( m_pRespecContainerPanel->FindChildByName( "RespecCountLabel" ) );
  108. }
  109. }
  110. void CTFPVEWinPanel::OnTick()
  111. {
  112. if ( m_bShouldBeVisible == true )
  113. {
  114. IViewPortPanel *scoreboard = gViewPortInterface->FindPanelByName( PANEL_SCOREBOARD );
  115. if ( (scoreboard && scoreboard->IsVisible() == true) || IsInFreezeCam() == true )
  116. {
  117. SetVisible( false );
  118. return;
  119. }
  120. // We dont want the stats panel showing up at the same time
  121. CTFStatPanel *pStatPanel = GetStatPanel();
  122. if ( pStatPanel && pStatPanel->IsVisible() )
  123. {
  124. pStatPanel->Hide();
  125. }
  126. if ( TFGameRules() && TFGameRules()->State_Get() != GR_STATE_TEAM_WIN )
  127. {
  128. m_bShouldBeVisible = false;
  129. }
  130. // Respec
  131. if ( m_pRespecContainerPanel && m_pRespecBackground && m_pRespecCountLabel && m_pRespecTextLabel )
  132. {
  133. CMannVsMachineStats *pStats = MannVsMachineStats_GetInstance();
  134. if ( pStats )
  135. {
  136. uint16 nRespecs = pStats->GetNumRespecsEarnedInWave();
  137. bool bRespecVisible = nRespecs > 0;
  138. // Do this only once
  139. if ( bRespecVisible && !m_pRespecBackground->IsVisible() )
  140. {
  141. g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "RespecEarnedPulseLoss" );
  142. C_TFPlayer *pLocalTFPlayer = C_TFPlayer::GetLocalTFPlayer();
  143. if ( pLocalTFPlayer )
  144. {
  145. pLocalTFPlayer->EmitSound( "MVM.RespecAwarded" );
  146. }
  147. }
  148. if ( m_pRespecContainerPanel->IsVisible() != bRespecVisible )
  149. {
  150. m_pRespecContainerPanel->SetVisible( bRespecVisible );
  151. }
  152. if ( m_pRespecBackground->IsVisible() != bRespecVisible )
  153. {
  154. m_pRespecBackground->SetVisible( bRespecVisible );
  155. }
  156. if ( m_pRespecCountLabel->IsVisible() != bRespecVisible )
  157. {
  158. m_pRespecCountLabel->SetVisible( bRespecVisible );
  159. }
  160. if ( m_pRespecTextLabel->IsVisible() != bRespecVisible )
  161. {
  162. m_pRespecTextLabel->SetVisible( bRespecVisible );
  163. }
  164. if ( bRespecVisible )
  165. {
  166. m_pRespecContainerPanel->SetDialogVariable( "respeccount", nRespecs );
  167. }
  168. }
  169. }
  170. }
  171. SetVisible( m_bShouldBeVisible );
  172. }
  173. void CTFPVEWinPanel::Reset( void )
  174. {
  175. Update();
  176. m_bShouldBeVisible = false;
  177. }
  178. void CTFPVEWinPanel::Update( void )
  179. {
  180. }