summaryrefslogtreecommitdiff
path: root/game/client/tf/tf_hud_demomancharge.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'game/client/tf/tf_hud_demomancharge.cpp')
-rw-r--r--game/client/tf/tf_hud_demomancharge.cpp154
1 files changed, 154 insertions, 0 deletions
diff --git a/game/client/tf/tf_hud_demomancharge.cpp b/game/client/tf/tf_hud_demomancharge.cpp
new file mode 100644
index 0000000..67f4809
--- /dev/null
+++ b/game/client/tf/tf_hud_demomancharge.cpp
@@ -0,0 +1,154 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================
+
+#include "cbase.h"
+#include "hud.h"
+#include "hudelement.h"
+#include "c_tf_player.h"
+#include "iclientmode.h"
+#include "ienginevgui.h"
+#include <vgui/ILocalize.h>
+#include <vgui/ISurface.h>
+#include <vgui/IVGui.h>
+#include <vgui_controls/EditablePanel.h>
+#include <vgui_controls/ProgressBar.h>
+#include "tf_weaponbase.h"
+#include "tf_gamerules.h"
+#include "tf_logic_halloween_2014.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+using namespace vgui;
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+class CHudDemomanChargeMeter : public CHudElement, public EditablePanel
+{
+ DECLARE_CLASS_SIMPLE( CHudDemomanChargeMeter, EditablePanel );
+
+public:
+ CHudDemomanChargeMeter( const char *pElementName );
+
+ virtual void ApplySchemeSettings( IScheme *scheme );
+ virtual bool ShouldDraw( void );
+ virtual void OnTick( void );
+
+private:
+ vgui::ContinuousProgressBar *m_pChargeMeter;
+};
+
+DECLARE_HUDELEMENT( CHudDemomanChargeMeter );
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+CHudDemomanChargeMeter::CHudDemomanChargeMeter( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "HudDemomanCharge" )
+{
+ Panel *pParent = g_pClientMode->GetViewport();
+ SetParent( pParent );
+
+ m_pChargeMeter = new ContinuousProgressBar( this, "ChargeMeter" );
+
+ SetHiddenBits( HIDEHUD_MISCSTATUS );
+
+ vgui::ivgui()->AddTickSignal( GetVPanel() );
+
+ RegisterForRenderGroup( "inspect_panel" );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CHudDemomanChargeMeter::ApplySchemeSettings( IScheme *pScheme )
+{
+ // load control settings...
+ LoadControlSettings( "resource/UI/HudDemomanCharge.res" );
+
+ BaseClass::ApplySchemeSettings( pScheme );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+bool CHudDemomanChargeMeter::ShouldDraw( void )
+{
+ C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
+
+ if ( !pPlayer || !pPlayer->IsAlive() )
+ return false;
+
+ CTFWeaponBase *pWpn = pPlayer->GetActiveTFWeapon();
+ ITFChargeUpWeapon *pChargeupWeapon = dynamic_cast< ITFChargeUpWeapon *>( pWpn );
+ if ( !pWpn || !pChargeupWeapon || !pChargeupWeapon->CanCharge() )
+ return false;
+
+#ifdef STAGING_ONLY
+ int iCustomHUD = 0;
+ CALL_ATTRIB_HOOK_INT_ON_OTHER( pWpn, iCustomHUD, custom_charge_meter );
+ if ( iCustomHUD )
+ return false;
+#endif // STAGING_ONLY
+
+ if ( pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_GHOST_MODE ) )
+ return false;
+
+ if ( CTFMinigameLogic::GetMinigameLogic() && CTFMinigameLogic::GetMinigameLogic()->GetActiveMinigame() )
+ return false;
+
+ if ( TFGameRules() && TFGameRules()->ShowMatchSummary() )
+ return false;
+
+ return CHudElement::ShouldDraw();
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CHudDemomanChargeMeter::OnTick( void )
+{
+ C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
+
+ if ( !pPlayer )
+ return;
+
+ CTFWeaponBase *pWpn = pPlayer->GetActiveTFWeapon();
+
+#ifdef STAGING_ONLY
+ int iCustomHUD = 0;
+ CALL_ATTRIB_HOOK_INT_ON_OTHER( pWpn, iCustomHUD, custom_charge_meter );
+ if ( iCustomHUD )
+ return;
+#endif // STAGING_ONLY
+
+ ITFChargeUpWeapon *pChargeupWeapon = dynamic_cast< ITFChargeUpWeapon *>( pWpn );
+ if ( !pWpn || !pChargeupWeapon || !pChargeupWeapon->CanCharge() )
+ return;
+
+ if ( m_pChargeMeter )
+ {
+ float flChargeMaxTime = pChargeupWeapon->GetChargeMaxTime();
+
+ if ( flChargeMaxTime != 0 )
+ {
+ float flChargeBeginTime = pChargeupWeapon->GetChargeBeginTime();
+
+ if ( flChargeBeginTime > 0 )
+ {
+ float flTimeCharged = MAX( 0, gpGlobals->curtime - flChargeBeginTime );
+ float flPercentCharged = MIN( 1.0, flTimeCharged / flChargeMaxTime );
+
+ m_pChargeMeter->SetProgress( flPercentCharged );
+ }
+ else
+ {
+ m_pChargeMeter->SetProgress( 0.0f );
+ }
+ }
+ }
+} \ No newline at end of file