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.

206 lines
5.5 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 "tf_gamerules.h"
  14. #include "tf_logic_halloween_2014.h"
  15. #include <vgui/ILocalize.h>
  16. #include <vgui/ISurface.h>
  17. #include <vgui/IVGui.h>
  18. #include <vgui_controls/EditablePanel.h>
  19. #include <vgui_controls/ProgressBar.h>
  20. #include <vgui_controls/Label.h>
  21. // memdbgon must be the last include file in a .cpp file!!!
  22. #include "tier0/memdbgon.h"
  23. using namespace vgui;
  24. //-----------------------------------------------------------------------------
  25. // Purpose:
  26. //-----------------------------------------------------------------------------
  27. class CHudDemomanPipes : public CHudElement, public EditablePanel
  28. {
  29. DECLARE_CLASS_SIMPLE( CHudDemomanPipes, EditablePanel );
  30. public:
  31. CHudDemomanPipes( const char *pElementName );
  32. virtual void ApplySchemeSettings( IScheme *scheme );
  33. virtual bool ShouldDraw( void );
  34. virtual void OnTick( void );
  35. private:
  36. vgui::EditablePanel *m_pPipesPresent;
  37. vgui::EditablePanel *m_pNoPipesPresent;
  38. vgui::Label *m_pChargeLabel;
  39. vgui::ContinuousProgressBar *m_pChargeMeter;
  40. bool m_bChargeMode;
  41. float m_flOldProgress;
  42. int m_iLastPipes;
  43. };
  44. DECLARE_HUDELEMENT( CHudDemomanPipes );
  45. //-----------------------------------------------------------------------------
  46. // Purpose:
  47. //-----------------------------------------------------------------------------
  48. CHudDemomanPipes::CHudDemomanPipes( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "HudDemomanPipes" )
  49. {
  50. Panel *pParent = g_pClientMode->GetViewport();
  51. SetParent( pParent );
  52. m_pPipesPresent = new EditablePanel( this, "PipesPresentPanel" );
  53. m_pNoPipesPresent = new EditablePanel( this, "NoPipesPresentPanel" );
  54. SetHiddenBits( HIDEHUD_MISCSTATUS );
  55. vgui::ivgui()->AddTickSignal( GetVPanel(), 100 );
  56. m_bChargeMode = false;
  57. m_flOldProgress = 1.f;
  58. m_iLastPipes = -1;
  59. if ( !m_pChargeMeter )
  60. {
  61. m_pChargeMeter = new ContinuousProgressBar( this, "ChargeMeter" );
  62. }
  63. if ( !m_pChargeLabel )
  64. {
  65. m_pChargeLabel = new Label( this, "ChargeLabel", "" );
  66. }
  67. RegisterForRenderGroup( "inspect_panel" );
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Purpose:
  71. //-----------------------------------------------------------------------------
  72. void CHudDemomanPipes::ApplySchemeSettings( IScheme *pScheme )
  73. {
  74. // load control settings...
  75. LoadControlSettings( "resource/UI/HudDemomanPipes.res" );
  76. BaseClass::ApplySchemeSettings( pScheme );
  77. }
  78. //-----------------------------------------------------------------------------
  79. // Purpose:
  80. //-----------------------------------------------------------------------------
  81. bool CHudDemomanPipes::ShouldDraw( void )
  82. {
  83. C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
  84. if ( !pPlayer || !pPlayer->IsPlayerClass( TF_CLASS_DEMOMAN ) )
  85. return false;
  86. if ( !pPlayer->IsAlive() )
  87. return false;
  88. if ( pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_GHOST_MODE ) )
  89. return false;
  90. if ( CTFMinigameLogic::GetMinigameLogic() && CTFMinigameLogic::GetMinigameLogic()->GetActiveMinigame() )
  91. return false;
  92. if ( TFGameRules() && TFGameRules()->ShowMatchSummary() )
  93. return false;
  94. return CHudElement::ShouldDraw();
  95. }
  96. //-----------------------------------------------------------------------------
  97. // Purpose:
  98. //-----------------------------------------------------------------------------
  99. void CHudDemomanPipes::OnTick( void )
  100. {
  101. if ( !IsVisible() )
  102. return;
  103. C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
  104. if ( !pPlayer )
  105. return;
  106. int iPipes = pPlayer->GetNumActivePipebombs();
  107. if ( iPipes != m_iLastPipes )
  108. {
  109. // SetDialogVariable is expensive as it does lots of localization work, so only call it if we need to
  110. m_pPipesPresent->SetDialogVariable( "activepipes", iPipes );
  111. m_pNoPipesPresent->SetDialogVariable( "activepipes", iPipes );
  112. m_pPipesPresent->SetVisible( iPipes > 0 );
  113. m_pNoPipesPresent->SetVisible( iPipes <= 0 );
  114. m_iLastPipes = iPipes;
  115. }
  116. m_pChargeMeter->SetVisible( false );
  117. m_pChargeLabel->SetVisible( false );
  118. if ( !m_bChargeMode )
  119. {
  120. if ( pPlayer->m_Shared.IsShieldEquipped() )
  121. {
  122. m_bChargeMode = true;
  123. }
  124. }
  125. else
  126. {
  127. if ( !pPlayer->m_Shared.IsShieldEquipped() )
  128. {
  129. m_bChargeMode = false;
  130. }
  131. else
  132. {
  133. m_pChargeMeter->SetVisible( true );
  134. m_pChargeLabel->SetVisible( true );
  135. m_pPipesPresent->SetVisible( false );
  136. m_pNoPipesPresent->SetVisible( false );
  137. float flProgress = pPlayer->m_Shared.GetDemomanChargeMeter() / 100.f;
  138. m_pChargeMeter->SetProgress( flProgress );
  139. if ( pPlayer->m_Shared.InCond( TF_COND_SHIELD_CHARGE ) )
  140. {
  141. if ( flProgress <= 0.33f )
  142. {
  143. m_pChargeMeter->SetFgColor( Color( 255, 0, 0, 255 ) );
  144. }
  145. else if ( flProgress <= 0.75f )
  146. {
  147. m_pChargeMeter->SetFgColor( Color( 255, 178, 0, 255 ) );
  148. }
  149. else
  150. {
  151. m_pChargeMeter->SetFgColor( Color( 153, 255, 153, 255 ) );
  152. }
  153. }
  154. else
  155. {
  156. m_pChargeMeter->SetFgColor( Color( 255, 255, 255, 255 ) );
  157. // Play a sound if we are newly ready.
  158. if ( C_TFPlayer::GetLocalTFPlayer() && flProgress >= 1.f && m_flOldProgress < 1.f )
  159. {
  160. m_flOldProgress = flProgress;
  161. if ( C_TFPlayer::GetLocalTFPlayer()->IsAlive() )
  162. {
  163. C_TFPlayer::GetLocalTFPlayer()->EmitSound( "TFPlayer.ReCharged" );
  164. }
  165. }
  166. else
  167. {
  168. m_flOldProgress = flProgress;
  169. }
  170. }
  171. }
  172. }
  173. }