source-engine/game/client/tf2base/tf_hud_cloakmeter.cpp
2022-08-13 03:20:41 +03:00

105 lines
2.9 KiB
C++

//========= Copyright © 1996-2002, Valve LLC, 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>
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CHudSpyCloakMeter : public CHudElement, public EditablePanel
{
DECLARE_CLASS_SIMPLE( CHudSpyCloakMeter, EditablePanel );
public:
CHudSpyCloakMeter( const char *pElementName );
virtual void ApplySchemeSettings( IScheme *scheme );
virtual bool ShouldDraw( void );
virtual void OnTick( void );
private:
vgui::ContinuousProgressBar *m_pCloakMeter;
};
DECLARE_HUDELEMENT( CHudSpyCloakMeter );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CHudSpyCloakMeter::CHudSpyCloakMeter( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "HudCloakMeter" )
{
Panel *pParent = g_pClientMode->GetViewport();
SetParent( pParent );
m_pCloakMeter = new ContinuousProgressBar( this, "CloakMeter" );
SetHiddenBits( HIDEHUD_MISCSTATUS );
vgui::ivgui()->AddTickSignal( GetVPanel() );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudSpyCloakMeter::ApplySchemeSettings( IScheme *pScheme )
{
// load control settings...
LoadControlSettings( "resource/UI/HudCloakMeter.res" );
BaseClass::ApplySchemeSettings( pScheme );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CHudSpyCloakMeter::ShouldDraw( void )
{
C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pPlayer || !pPlayer->IsPlayerClass( TF_CLASS_SPY ) )
{
return false;
}
if ( !pPlayer->IsAlive() )
{
return false;
}
return CHudElement::ShouldDraw();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudSpyCloakMeter::OnTick( void )
{
C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pPlayer )
return;
if ( m_pCloakMeter )
{
m_pCloakMeter->SetProgress( pPlayer->m_Shared.GetSpyCloakMeter() / 100.0f );
}
}