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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "cbase.h"
#include "hud.h"
#include "hud_macros.h"
#include "view.h"
#include "iclientmode.h"
#include <KeyValues.h>
#include <vgui/ISurface.h>
#include <vgui/ISystem.h>
#include <vgui_controls/Panel.h>
using namespace vgui;
#include "hudelement.h"
#include "hl1_hud_numbers.h"
#include "convar.h"
#define FADE_TIME 100
#define MIN_ALPHA 100
//-----------------------------------------------------------------------------
// Purpose: Health panel
//-----------------------------------------------------------------------------
class CHudBattery : public CHudElement, public CHL1HudNumbers
{
DECLARE_CLASS_SIMPLE( CHudBattery, CHL1HudNumbers );
public:
CHudBattery( const char *pElementName );
void Init( void );
void Reset( void );
void VidInit( void );
void MsgFunc_Battery(bf_read &msg);
private:
void Paint( void );
void ApplySchemeSettings(vgui::IScheme *pScheme);
private:
CHudTexture *icon_suit_empty;
CHudTexture *icon_suit_full;
int m_iBattery;
float m_flFade;
};
DECLARE_HUDELEMENT( CHudBattery );
DECLARE_HUD_MESSAGE( CHudBattery, Battery );
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CHudBattery::CHudBattery( const char *pElementName ) : CHudElement( pElementName ), BaseClass(NULL, "HudSuit")
{
SetHiddenBits( HIDEHUD_HEALTH | HIDEHUD_NEEDSUIT );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudBattery::Init()
{
HOOK_HUD_MESSAGE( CHudBattery, Battery );
Reset();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudBattery::Reset()
{
m_iBattery = 0;
m_flFade = 0;
}
void CHudBattery::VidInit()
{
Reset();
BaseClass::VidInit();
}
void CHudBattery::Paint()
{
Color clrHealth;
int a;
int x;
int y;
BaseClass::Paint();
if ( !icon_suit_empty )
{
icon_suit_empty = gHUD.GetIcon( "suit_empty" );
}
if ( !icon_suit_full )
{
icon_suit_full = gHUD.GetIcon( "suit_full" );
}
if ( !icon_suit_empty || !icon_suit_full )
{
return;
}
// Has health changed? Flash the health #
if ( m_flFade )
{
if (m_flFade > FADE_TIME)
m_flFade = FADE_TIME;
m_flFade -= ( gpGlobals->frametime * 20 );
if ( m_flFade <= 0 )
{
a = 128;
m_flFade = 0;
}
else
{
// Fade the health number back to dim
a = MIN_ALPHA + ( m_flFade / FADE_TIME ) * 128;
}
}
else
{
a = MIN_ALPHA;
}
int r, g, b, nUnused;
(gHUD.m_clrYellowish).GetColor( r, g, b, nUnused );
clrHealth.SetColor( r, g, b, a );
int nFontHeight = GetNumberFontHeight();
int nHudElemWidth, nHudElemHeight;
GetSize( nHudElemWidth, nHudElemHeight );
int iOffset = icon_suit_empty->Height() / 6;
x = nHudElemWidth / 5;
y = nHudElemHeight - ( nFontHeight * 1.5 );
icon_suit_empty->DrawSelf( x, y - iOffset, clrHealth );
if ( m_iBattery > 0 )
{
int nSuitOffset = icon_suit_full->Height() * ((float)(100-(MIN(100,m_iBattery))) * 0.01); // battery can go from 0 to 100 so * 0.01 goes from 0 to 1
icon_suit_full->DrawSelfCropped( x, y - iOffset + nSuitOffset, 0, nSuitOffset, icon_suit_full->Width(), icon_suit_full->Height() - nSuitOffset, clrHealth );
}
x += icon_suit_empty->Width();
DrawHudNumber( x, y, m_iBattery, clrHealth );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudBattery::MsgFunc_Battery( bf_read &msg )
{
int x = msg.ReadShort();
if ( x != m_iBattery )
{
m_flFade = FADE_TIME;
m_iBattery = x;
}
}
void CHudBattery::ApplySchemeSettings(vgui::IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
SetPaintBackgroundEnabled(false);
}
|