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.

153 lines
4.4 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/EditablePanel.h>
  17. #include <vgui_controls/ProgressBar.h>
  18. #include "tf_weaponbase.h"
  19. #include "tf_gamerules.h"
  20. #include "tf_logic_halloween_2014.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 CHudDemomanChargeMeter : public CHudElement, public EditablePanel
  28. {
  29. DECLARE_CLASS_SIMPLE( CHudDemomanChargeMeter, EditablePanel );
  30. public:
  31. CHudDemomanChargeMeter( const char *pElementName );
  32. virtual void ApplySchemeSettings( IScheme *scheme );
  33. virtual bool ShouldDraw( void );
  34. virtual void OnTick( void );
  35. private:
  36. vgui::ContinuousProgressBar *m_pChargeMeter;
  37. };
  38. DECLARE_HUDELEMENT( CHudDemomanChargeMeter );
  39. //-----------------------------------------------------------------------------
  40. // Purpose:
  41. //-----------------------------------------------------------------------------
  42. CHudDemomanChargeMeter::CHudDemomanChargeMeter( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "HudDemomanCharge" )
  43. {
  44. Panel *pParent = g_pClientMode->GetViewport();
  45. SetParent( pParent );
  46. m_pChargeMeter = new ContinuousProgressBar( this, "ChargeMeter" );
  47. SetHiddenBits( HIDEHUD_MISCSTATUS );
  48. vgui::ivgui()->AddTickSignal( GetVPanel() );
  49. RegisterForRenderGroup( "inspect_panel" );
  50. }
  51. //-----------------------------------------------------------------------------
  52. // Purpose:
  53. //-----------------------------------------------------------------------------
  54. void CHudDemomanChargeMeter::ApplySchemeSettings( IScheme *pScheme )
  55. {
  56. // load control settings...
  57. LoadControlSettings( "resource/UI/HudDemomanCharge.res" );
  58. BaseClass::ApplySchemeSettings( pScheme );
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Purpose:
  62. //-----------------------------------------------------------------------------
  63. bool CHudDemomanChargeMeter::ShouldDraw( void )
  64. {
  65. C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
  66. if ( !pPlayer || !pPlayer->IsAlive() )
  67. return false;
  68. CTFWeaponBase *pWpn = pPlayer->GetActiveTFWeapon();
  69. ITFChargeUpWeapon *pChargeupWeapon = dynamic_cast< ITFChargeUpWeapon *>( pWpn );
  70. if ( !pWpn || !pChargeupWeapon || !pChargeupWeapon->CanCharge() )
  71. return false;
  72. #ifdef STAGING_ONLY
  73. int iCustomHUD = 0;
  74. CALL_ATTRIB_HOOK_INT_ON_OTHER( pWpn, iCustomHUD, custom_charge_meter );
  75. if ( iCustomHUD )
  76. return false;
  77. #endif // STAGING_ONLY
  78. if ( pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_GHOST_MODE ) )
  79. return false;
  80. if ( CTFMinigameLogic::GetMinigameLogic() && CTFMinigameLogic::GetMinigameLogic()->GetActiveMinigame() )
  81. return false;
  82. if ( TFGameRules() && TFGameRules()->ShowMatchSummary() )
  83. return false;
  84. return CHudElement::ShouldDraw();
  85. }
  86. //-----------------------------------------------------------------------------
  87. // Purpose:
  88. //-----------------------------------------------------------------------------
  89. void CHudDemomanChargeMeter::OnTick( void )
  90. {
  91. C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
  92. if ( !pPlayer )
  93. return;
  94. CTFWeaponBase *pWpn = pPlayer->GetActiveTFWeapon();
  95. #ifdef STAGING_ONLY
  96. int iCustomHUD = 0;
  97. CALL_ATTRIB_HOOK_INT_ON_OTHER( pWpn, iCustomHUD, custom_charge_meter );
  98. if ( iCustomHUD )
  99. return;
  100. #endif // STAGING_ONLY
  101. ITFChargeUpWeapon *pChargeupWeapon = dynamic_cast< ITFChargeUpWeapon *>( pWpn );
  102. if ( !pWpn || !pChargeupWeapon || !pChargeupWeapon->CanCharge() )
  103. return;
  104. if ( m_pChargeMeter )
  105. {
  106. float flChargeMaxTime = pChargeupWeapon->GetChargeMaxTime();
  107. if ( flChargeMaxTime != 0 )
  108. {
  109. float flChargeBeginTime = pChargeupWeapon->GetChargeBeginTime();
  110. if ( flChargeBeginTime > 0 )
  111. {
  112. float flTimeCharged = MAX( 0, gpGlobals->curtime - flChargeBeginTime );
  113. float flPercentCharged = MIN( 1.0, flTimeCharged / flChargeMaxTime );
  114. m_pChargeMeter->SetProgress( flPercentCharged );
  115. }
  116. else
  117. {
  118. m_pChargeMeter->SetProgress( 0.0f );
  119. }
  120. }
  121. }
  122. }