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.

196 lines
5.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "cbase.h"
  8. #include "hud.h"
  9. #include "hudelement.h"
  10. #include "c_tf_player.h"
  11. #include "iclientmode.h"
  12. #include "ienginevgui.h"
  13. #include <vgui/ILocalize.h>
  14. #include <vgui/ISurface.h>
  15. #include <vgui/IVGui.h>
  16. #include <vgui_controls/Label.h>
  17. #include <vgui_controls/EditablePanel.h>
  18. #include "tf_imagepanel.h"
  19. #include "tf_gamerules.h"
  20. #include "c_tf_team.h"
  21. #include "tf_hud_freezepanel.h"
  22. // memdbgon must be the last include file in a .cpp file!!!
  23. #include "tier0/memdbgon.h"
  24. using namespace vgui;
  25. extern ConVar tf_arena_preround_time;
  26. //-----------------------------------------------------------------------------
  27. // Purpose:
  28. //-----------------------------------------------------------------------------
  29. class CHudArenaCapPointCountdown : public CHudElement, public EditablePanel
  30. {
  31. DECLARE_CLASS_SIMPLE( CHudArenaCapPointCountdown, EditablePanel );
  32. public:
  33. CHudArenaCapPointCountdown( const char *pElementName );
  34. virtual void ApplySchemeSettings( IScheme *scheme );
  35. virtual void OnTick( void );
  36. virtual bool ShouldDraw( void );
  37. virtual bool IsVisible( void );
  38. private:
  39. bool m_bFire5SecRemain;
  40. bool m_bFire4SecRemain;
  41. bool m_bFire3SecRemain;
  42. bool m_bFire2SecRemain;
  43. bool m_bFire1SecRemain;
  44. bool m_bFire0SecRemain;
  45. };
  46. DECLARE_HUDELEMENT( CHudArenaCapPointCountdown );
  47. //-----------------------------------------------------------------------------
  48. // Purpose:
  49. //-----------------------------------------------------------------------------
  50. CHudArenaCapPointCountdown::CHudArenaCapPointCountdown( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "HudArenaCapPointCountdown" )
  51. {
  52. Panel *pParent = g_pClientMode->GetViewport();
  53. SetParent( pParent );
  54. SetHiddenBits( HIDEHUD_MISCSTATUS );
  55. vgui::ivgui()->AddTickSignal( GetVPanel() );
  56. SetVisible( true );
  57. m_bFire5SecRemain = true;
  58. m_bFire4SecRemain = true;
  59. m_bFire3SecRemain = true;
  60. m_bFire2SecRemain = true;
  61. m_bFire1SecRemain = true;
  62. m_bFire0SecRemain = true;
  63. RegisterForRenderGroup( "mid" );
  64. }
  65. //-----------------------------------------------------------------------------
  66. // Purpose:
  67. //-----------------------------------------------------------------------------
  68. void CHudArenaCapPointCountdown::ApplySchemeSettings( IScheme *pScheme )
  69. {
  70. // load control settings...
  71. LoadControlSettings( "resource/UI/HudArenaCapPointCountdown.res" );
  72. BaseClass::ApplySchemeSettings( pScheme );
  73. SetVisible( true );
  74. }
  75. //-----------------------------------------------------------------------------
  76. // Purpose:
  77. //-----------------------------------------------------------------------------
  78. bool CHudArenaCapPointCountdown::IsVisible( void )
  79. {
  80. if ( IsInFreezeCam() == true )
  81. return false;
  82. if ( ShouldDraw() == false )
  83. return false;
  84. return BaseClass::IsVisible();
  85. }
  86. //-----------------------------------------------------------------------------
  87. // Purpose:
  88. //-----------------------------------------------------------------------------
  89. void CHudArenaCapPointCountdown::OnTick( void )
  90. {
  91. BaseClass::OnTick();
  92. if ( TFGameRules() == NULL || ( TFGameRules() && TFGameRules()->IsInArenaMode() == false ) )
  93. {
  94. SetVisible( false );
  95. return;
  96. }
  97. if ( TFGameRules()->State_Get() != GR_STATE_STALEMATE || ShouldDraw() == false )
  98. {
  99. SetVisible( false );
  100. return;
  101. }
  102. C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
  103. if ( !pLocalPlayer )
  104. {
  105. SetVisible( false );
  106. return;
  107. }
  108. int iTimeLeft = ceil( TFGameRules()->GetCapturePointTime() - gpGlobals->curtime );
  109. if ( iTimeLeft > 5 || iTimeLeft <= 0 )
  110. {
  111. if ( iTimeLeft <= 0 && m_bFire0SecRemain )
  112. {
  113. m_bFire0SecRemain = false;
  114. pLocalPlayer->EmitSound( "Announcer.AM_CapEnabledRandom" );
  115. }
  116. m_bFire5SecRemain = true;
  117. m_bFire4SecRemain = true;
  118. m_bFire3SecRemain = true;
  119. m_bFire2SecRemain = true;
  120. m_bFire1SecRemain = true;
  121. SetVisible( false );
  122. return;
  123. }
  124. SetVisible( true );
  125. wchar_t wzTimeLeft[128];
  126. _snwprintf( wzTimeLeft, ARRAYSIZE( wzTimeLeft ), L"%i", iTimeLeft );
  127. SetDialogVariable( "capturetime", wzTimeLeft );
  128. if ( iTimeLeft <= 5 && m_bFire5SecRemain )
  129. {
  130. m_bFire5SecRemain = false;
  131. pLocalPlayer->EmitSound( "Announcer.RoundBegins5Seconds" );
  132. }
  133. else if ( iTimeLeft <= 4 && m_bFire4SecRemain )
  134. {
  135. m_bFire4SecRemain = false;
  136. pLocalPlayer->EmitSound( "Announcer.RoundBegins4Seconds" );
  137. }
  138. else if ( iTimeLeft <= 3 && m_bFire3SecRemain )
  139. {
  140. m_bFire3SecRemain = false;
  141. pLocalPlayer->EmitSound( "Announcer.RoundBegins3Seconds" );
  142. }
  143. else if ( iTimeLeft <= 2 && m_bFire2SecRemain )
  144. {
  145. m_bFire2SecRemain = false;
  146. pLocalPlayer->EmitSound( "Announcer.RoundBegins2Seconds" );
  147. }
  148. else if ( iTimeLeft <= 1 && m_bFire1SecRemain )
  149. {
  150. m_bFire1SecRemain = false;
  151. m_bFire0SecRemain = true;
  152. pLocalPlayer->EmitSound( "Announcer.RoundBegins1Seconds" );
  153. }
  154. }
  155. bool CHudArenaCapPointCountdown::ShouldDraw( void )
  156. {
  157. return CHudElement::ShouldDraw();
  158. }