mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-01-07 09:43:40 +08:00
118 lines
3.6 KiB
C++
118 lines
3.6 KiB
C++
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
|
//
|
|
// Purpose:
|
|
//
|
|
//=============================================================================//
|
|
|
|
#include "hudelement.h"
|
|
#include "hud_numericdisplay.h"
|
|
#include <vgui_controls/Panel.h>
|
|
#include "cbase.h"
|
|
#include "hud.h"
|
|
#include "hud_suitpower.h"
|
|
#include "hud_macros.h"
|
|
#include "iclientmode.h"
|
|
#include <vgui_controls/AnimationController.h>
|
|
#include <vgui/ISurface.h>
|
|
|
|
// memdbgon must be the last include file in a .cpp file!!!
|
|
#include "tier0/memdbgon.h"
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: Shows the flashlight icon
|
|
//-----------------------------------------------------------------------------
|
|
class CHudFlashlight : public CHudElement, public vgui::Panel
|
|
{
|
|
DECLARE_CLASS_SIMPLE( CHudFlashlight, vgui::Panel );
|
|
|
|
public:
|
|
CHudFlashlight( const char *pElementName );
|
|
virtual void Init( void );
|
|
|
|
void SetFlashlightState( bool flashlightOn );
|
|
|
|
protected:
|
|
virtual void Paint();
|
|
|
|
private:
|
|
CPanelAnimationVar( vgui::HFont, m_hTextFont, "TextFont", "Default" );
|
|
CPanelAnimationVar( Color, m_TextColor, "TextColor", "FgColor" );
|
|
CPanelAnimationVarAliasType( float, text_xpos, "text_xpos", "8", "proportional_float" );
|
|
CPanelAnimationVarAliasType( float, text_ypos, "text_ypos", "20", "proportional_float" );
|
|
|
|
bool m_bFlashlightOn;
|
|
};
|
|
|
|
using namespace vgui;
|
|
|
|
//!! flashlight disabled for now, indicator moved into hud_suitpower
|
|
//!! if that is successful this file can be just removed
|
|
// DECLARE_HUDELEMENT( CHudFlashlight, HudFlashlight );
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: Constructor
|
|
//-----------------------------------------------------------------------------
|
|
CHudFlashlight::CHudFlashlight( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "HudFlashlight" )
|
|
{
|
|
vgui::Panel *pParent = g_pClientMode->GetViewport();
|
|
SetParent( pParent );
|
|
m_bFlashlightOn = true;
|
|
|
|
SetHiddenBits( HIDEHUD_HEALTH | HIDEHUD_PLAYERDEAD | HIDEHUD_NEEDSUIT );
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose:
|
|
//-----------------------------------------------------------------------------
|
|
void CHudFlashlight::Init()
|
|
{
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: data accessor
|
|
//-----------------------------------------------------------------------------
|
|
void CHudFlashlight::SetFlashlightState( bool flashlightOn )
|
|
{
|
|
if ( m_bFlashlightOn == flashlightOn )
|
|
return;
|
|
|
|
if ( flashlightOn )
|
|
{
|
|
// flashlight on
|
|
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence("SuitFlashlightOn");
|
|
}
|
|
else
|
|
{
|
|
// flashlight off
|
|
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence("SuitFlashlightOff");
|
|
}
|
|
|
|
m_bFlashlightOn = flashlightOn;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: draws the flashlight icon
|
|
//-----------------------------------------------------------------------------
|
|
void CHudFlashlight::Paint()
|
|
{
|
|
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
|
|
if ( !pPlayer )
|
|
return;
|
|
|
|
SetFlashlightState( pPlayer->IsEffectActive( EF_DIMLIGHT ) );
|
|
|
|
// draw our name
|
|
wchar_t *text = L"FLASHLIGHT: ON";
|
|
if (!m_bFlashlightOn)
|
|
{
|
|
text = L"FLASHLIGHT: OFF";
|
|
}
|
|
|
|
surface()->DrawSetTextFont(m_hTextFont);
|
|
surface()->DrawSetTextColor(m_TextColor);
|
|
surface()->DrawSetTextPos(text_xpos, text_ypos);
|
|
surface()->DrawUnicodeString( text );
|
|
}
|
|
|
|
|