diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/client/tf/tf_hud_smoke_bomb.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'game/client/tf/tf_hud_smoke_bomb.cpp')
| -rw-r--r-- | game/client/tf/tf_hud_smoke_bomb.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/game/client/tf/tf_hud_smoke_bomb.cpp b/game/client/tf/tf_hud_smoke_bomb.cpp new file mode 100644 index 0000000..a66b950 --- /dev/null +++ b/game/client/tf/tf_hud_smoke_bomb.cpp @@ -0,0 +1,96 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=============================================================================// + +#include "cbase.h" +#include "hudelement.h" +#include <vgui_controls/Panel.h> +#include <vgui/ISurface.h> +#include "c_tf_player.h" +#include "clientmode_tf.h" + + +class CHudSmokeBomb : public CHudElement, public vgui::Panel +{ +public: + DECLARE_CLASS_SIMPLE( CHudSmokeBomb, vgui::Panel ); + + CHudSmokeBomb( const char *name ); + + virtual bool ShouldDraw(); + virtual void Paint(); + virtual void Init(); + +private: + CHudTexture *m_pIcon; +}; + +DECLARE_HUDELEMENT( CHudSmokeBomb ); + +CHudSmokeBomb::CHudSmokeBomb( const char *pName ) : + vgui::Panel( NULL, "HudSmokeBomb" ), CHudElement( pName ) +{ + SetParent( g_pClientMode->GetViewport() ); + m_pIcon = NULL; + + SetHiddenBits( HIDEHUD_PLAYERDEAD ); +} + + +void CHudSmokeBomb::Init() +{ +} + +bool CHudSmokeBomb::ShouldDraw() +{ + C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer(); + + // if we are spectating another player first person, check this player + if ( pPlayer && ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) ) + { + pPlayer = ToTFPlayer( pPlayer->GetObserverTarget() ); + } + + return ( pPlayer && pPlayer->IsAlive() && pPlayer->m_Shared.InCond( TF_COND_SMOKE_BOMB ) ); +} + +extern ConVar tf_smoke_bomb_time; + +void CHudSmokeBomb::Paint() +{ + if ( !m_pIcon ) + { + m_pIcon = gHUD.GetIcon( "cond_smoke_bomb" ); + } + + int x, y, w, h; + GetBounds( x, y, w, h ); + + if ( m_pIcon ) + { + m_pIcon->DrawSelf( 0, 0, w, w, Color(255,255,255,255) ); + } + + // Draw a progress bar for time remaining + int barX = XRES(5); + int barW = w - XRES(10); + int barY = w + YRES(5); + int barH = YRES(10); + + C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer(); + + if ( !pPlayer ) + return; + + float flExpireTime = pPlayer->m_Shared.GetSmokeBombExpireTime(); + + float flPercent = ( flExpireTime - gpGlobals->curtime ) / tf_smoke_bomb_time.GetFloat(); + + surface()->DrawSetColor( Color(0,0,0,255) ); + surface()->DrawFilledRect( barX - 1, barY - 1, barX + barW + 1, barY + barH + 1 ); + + surface()->DrawSetColor( Color(200,200,200,255) ); + surface()->DrawFilledRect( barX, barY, barX + (int)( (float)barW * flPercent ), barY + barH ); +}
\ No newline at end of file |