blob: c07943c10384932e0fbe2d2f25cd388f5ff387a7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
//
// battery.cpp
//
// implementation of CHudBattery class
//
#include "cbase.h"
#include "hud.h"
#include "hudelement.h"
#include "hud_macros.h"
#include "hud_numericdisplay.h"
#include "iclientmode.h"
#include "vgui_controls/AnimationController.h"
#include "vgui/ILocalize.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define INIT_BAT -1
//-----------------------------------------------------------------------------
// Purpose: Displays suit power (armor) on hud
//-----------------------------------------------------------------------------
class CHudBattery : public CHudNumericDisplay, public CHudElement
{
DECLARE_CLASS_SIMPLE( CHudBattery, CHudNumericDisplay );
public:
CHudBattery( const char *pElementName );
void Init( void );
void Reset( void );
void VidInit( void );
void OnThink( void );
void MsgFunc_Battery(bf_read &msg );
bool ShouldDraw();
private:
int m_iBat;
int m_iNewBat;
};
DECLARE_HUDELEMENT( CHudBattery );
DECLARE_HUD_MESSAGE( CHudBattery, Battery );
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CHudBattery::CHudBattery( const char *pElementName ) : BaseClass(NULL, "HudSuit"), CHudElement( pElementName )
{
SetHiddenBits( HIDEHUD_HEALTH | HIDEHUD_NEEDSUIT );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudBattery::Init( void )
{
HOOK_HUD_MESSAGE( CHudBattery, Battery);
Reset();
m_iBat = INIT_BAT;
m_iNewBat = 0;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudBattery::Reset( void )
{
SetLabelText(g_pVGuiLocalize->Find("#Valve_Hud_SUIT"));
SetDisplayValue(m_iBat);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudBattery::VidInit( void )
{
Reset();
}
//-----------------------------------------------------------------------------
// Purpose: Save CPU cycles by letting the HUD system early cull
// costly traversal. Called per frame, return true if thinking and
// painting need to occur.
//-----------------------------------------------------------------------------
bool CHudBattery::ShouldDraw( void )
{
bool bNeedsDraw = ( m_iBat != m_iNewBat ) || ( GetAlpha() > 0 );
return ( bNeedsDraw && CHudElement::ShouldDraw() );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudBattery::OnThink( void )
{
if ( m_iBat == m_iNewBat )
return;
if ( !m_iNewBat )
{
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence("SuitPowerZero");
}
else if ( m_iNewBat < m_iBat )
{
// battery power has decreased, so play the damaged animation
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence("SuitDamageTaken");
// play an extra animation if we're super low
if ( m_iNewBat < 20 )
{
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence("SuitArmorLow");
}
}
else
{
// battery power has increased (if we had no previous armor, or if we just loaded the game, don't use alert state)
if ( m_iBat == INIT_BAT || m_iBat == 0 || m_iNewBat >= 20)
{
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence("SuitPowerIncreasedAbove20");
}
else
{
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence("SuitPowerIncreasedBelow20");
}
}
m_iBat = m_iNewBat;
SetDisplayValue(m_iBat);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudBattery::MsgFunc_Battery( bf_read &msg )
{
m_iNewBat = msg.ReadShort();
}
|