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.

146 lines
4.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/EditablePanel.h>
  17. #include <vgui_controls/ProgressBar.h>
  18. #include "tf_weaponbase.h"
  19. // memdbgon must be the last include file in a .cpp file!!!
  20. #include "tier0/memdbgon.h"
  21. using namespace vgui;
  22. //-----------------------------------------------------------------------------
  23. // Purpose:
  24. //-----------------------------------------------------------------------------
  25. class CHudFlameRocketChargeMeter : public CHudElement, public EditablePanel
  26. {
  27. DECLARE_CLASS_SIMPLE( CHudFlameRocketChargeMeter, EditablePanel );
  28. public:
  29. CHudFlameRocketChargeMeter( const char *pElementName );
  30. virtual void ApplySchemeSettings( IScheme *scheme );
  31. virtual bool ShouldDraw( void );
  32. virtual void OnTick( void );
  33. private:
  34. vgui::ContinuousProgressBar *m_pChargeMeter;
  35. };
  36. DECLARE_HUDELEMENT( CHudFlameRocketChargeMeter );
  37. //-----------------------------------------------------------------------------
  38. // Purpose:
  39. //-----------------------------------------------------------------------------
  40. CHudFlameRocketChargeMeter::CHudFlameRocketChargeMeter( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "HudFlameRocketCharge" )
  41. {
  42. Panel *pParent = g_pClientMode->GetViewport();
  43. SetParent( pParent );
  44. m_pChargeMeter = new ContinuousProgressBar( this, "ChargeMeter" );
  45. SetHiddenBits( HIDEHUD_MISCSTATUS );
  46. vgui::ivgui()->AddTickSignal( GetVPanel() );
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Purpose:
  50. //-----------------------------------------------------------------------------
  51. void CHudFlameRocketChargeMeter::ApplySchemeSettings( IScheme *pScheme )
  52. {
  53. // load control settings...
  54. LoadControlSettings( "resource/UI/HudFlameRocketCharge.res" );
  55. BaseClass::ApplySchemeSettings( pScheme );
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Purpose:
  59. //-----------------------------------------------------------------------------
  60. bool CHudFlameRocketChargeMeter::ShouldDraw( void )
  61. {
  62. C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
  63. if ( !pPlayer || !pPlayer->IsPlayerClass( TF_CLASS_PYRO ) || !pPlayer->IsAlive() )
  64. {
  65. return false;
  66. }
  67. CTFWeaponBase *pWpn = pPlayer->GetActiveTFWeapon();
  68. if ( !pWpn )
  69. {
  70. return false;
  71. }
  72. int iWeaponID = pWpn->GetWeaponID();
  73. if ( iWeaponID != TF_WEAPON_FLAMETHROWER )
  74. {
  75. return false;
  76. }
  77. // @note Tom Bui: This has been co-opted to be a charged airblast and not a charged flame rocket
  78. int iChargedAirblast = 0;
  79. CALL_ATTRIB_HOOK_INT_ON_OTHER( pWpn, iChargedAirblast, set_charged_airblast );
  80. if ( iChargedAirblast == 0 )
  81. {
  82. return false;
  83. }
  84. return CHudElement::ShouldDraw();
  85. }
  86. //-----------------------------------------------------------------------------
  87. // Purpose:
  88. //-----------------------------------------------------------------------------
  89. void CHudFlameRocketChargeMeter::OnTick( void )
  90. {
  91. C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
  92. if ( !pPlayer )
  93. return;
  94. CTFWeaponBase *pWpn = pPlayer->GetActiveTFWeapon();
  95. ITFChargeUpWeapon *pChargeupWeapon = dynamic_cast< ITFChargeUpWeapon *>( pWpn );
  96. if ( !pWpn || !pChargeupWeapon )
  97. return;
  98. if ( m_pChargeMeter )
  99. {
  100. float flChargeMaxTime = pChargeupWeapon->GetChargeMaxTime();
  101. if ( flChargeMaxTime != 0 )
  102. {
  103. float flChargeBeginTime = pChargeupWeapon->GetChargeBeginTime();
  104. if ( flChargeBeginTime > 0 )
  105. {
  106. float flTimeCharged = MAX( 0, gpGlobals->curtime - flChargeBeginTime );
  107. float flPercentCharged = MIN( 1.0, flTimeCharged / flChargeMaxTime );
  108. m_pChargeMeter->SetProgress( flPercentCharged );
  109. }
  110. else
  111. {
  112. m_pChargeMeter->SetProgress( 0.0f );
  113. }
  114. }
  115. }
  116. }