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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "hudelement.h"
#include <vgui_controls/Panel.h>
#include <vgui/ISurface.h>
#include "clientmode_csnormal.h"
#include "cs_gamerules.h"
#include "hud_basetimer.h"
#include "hud_bitmapnumericdisplay.h"
#include "c_plantedc4.h"
#include <vgui_controls/AnimationController.h>
class CHudRoundTimer : public CHudElement, public vgui::Panel
{
public:
DECLARE_CLASS_SIMPLE( CHudRoundTimer, vgui::Panel );
CHudRoundTimer( const char *name );
protected:
virtual void Paint();
virtual void Think();
virtual bool ShouldDraw();
virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
void PaintTime(HFont font, int xpos, int ypos, int mins, int secs);
private:
float m_flToggleTime;
float m_flNextToggle;
CHudTexture *m_pTimerIcon;
bool m_bFlash;
int m_iAdditiveWhiteID;
CPanelAnimationVar( Color, m_FlashColor, "FlashColor", "Panel.FgColor" );
CPanelAnimationVarAliasType( float, icon_xpos, "icon_xpos", "0", "proportional_float" );
CPanelAnimationVarAliasType( float, icon_ypos, "icon_ypos", "0", "proportional_float" );
CPanelAnimationVar( Color, m_TextColor, "TextColor", "Panel.FgColor" );
CPanelAnimationVar( vgui::HFont, m_hNumberFont, "NumberFont", "HudNumbers" );
CPanelAnimationVarAliasType( float, digit_xpos, "digit_xpos", "50", "proportional_float" );
CPanelAnimationVarAliasType( float, digit_ypos, "digit_ypos", "2", "proportional_float" );
float icon_tall;
float icon_wide;
};
DECLARE_HUDELEMENT( CHudRoundTimer );
CHudRoundTimer::CHudRoundTimer( const char *pName ) :
BaseClass( NULL, "HudRoundTimer" ), CHudElement( pName )
{
m_iAdditiveWhiteID = vgui::surface()->CreateNewTextureID();
vgui::surface()->DrawSetTextureFile( m_iAdditiveWhiteID, "vgui/white_additive" , true, false);
SetHiddenBits( HIDEHUD_PLAYERDEAD );
vgui::Panel *pParent = g_pClientMode->GetViewport();
SetParent( pParent );
}
void CHudRoundTimer::ApplySchemeSettings(vgui::IScheme *pScheme)
{
m_pTimerIcon = gHUD.GetIcon( "timer_icon" );
if( m_pTimerIcon )
{
icon_tall = GetTall() - YRES(2);
float scale = icon_tall / (float)m_pTimerIcon->Height();
icon_wide = ( scale ) * (float)m_pTimerIcon->Width();
}
SetFgColor( m_TextColor );
BaseClass::ApplySchemeSettings( pScheme );
}
bool CHudRoundTimer::ShouldDraw()
{
//necessary?
C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
if ( pPlayer )
{
return !pPlayer->IsObserver();
}
return false;
}
void CHudRoundTimer::Think()
{
C_CSGameRules *pRules = CSGameRules();
if ( !pRules )
return;
int timer = (int)ceil( pRules->GetRoundRemainingTime() );
if ( pRules->IsFreezePeriod() )
{
// in freeze period countdown to round start time
timer = (int)ceil(pRules->GetRoundStartTime()-gpGlobals->curtime);
}
//If the bomb is planted don't draw -- the timer is irrelevant
SetVisible(g_PlantedC4s.Count() == 0);
if(timer > 30)
{
SetFgColor(m_TextColor);
return;
}
if(timer <= 0)
{
timer = 0;
SetFgColor(m_FlashColor);
return;
}
if(gpGlobals->curtime > m_flNextToggle)
{
if( timer <= 0)
{
m_bFlash = true;
}
else if( timer <= 2)
{
m_flToggleTime = gpGlobals->curtime;
m_flNextToggle = gpGlobals->curtime + 0.05;
m_bFlash = !m_bFlash;
}
else if( timer <= 5)
{
m_flToggleTime = gpGlobals->curtime;
m_flNextToggle = gpGlobals->curtime + 0.1;
m_bFlash = !m_bFlash;
}
else if( timer <= 10)
{
m_flToggleTime = gpGlobals->curtime;
m_flNextToggle = gpGlobals->curtime + 0.2;
m_bFlash = !m_bFlash;
}
else if( timer <= 20)
{
m_flToggleTime = gpGlobals->curtime;
m_flNextToggle = gpGlobals->curtime + 0.4;
m_bFlash = !m_bFlash;
}
else if( timer <= 30)
{
m_flToggleTime = gpGlobals->curtime;
m_flNextToggle = gpGlobals->curtime + 0.8;
m_bFlash = !m_bFlash;
}
else
m_bFlash = false;
}
Color startValue, endValue;
Color interp_color;
if( m_bFlash )
{
startValue = m_FlashColor;
endValue = m_TextColor;
}
else
{
startValue = m_TextColor;
endValue = m_FlashColor;
}
float pos = (gpGlobals->curtime - m_flToggleTime) / (m_flNextToggle - m_flToggleTime);
pos = clamp( SimpleSpline( pos ), 0, 1 );
interp_color[0] = ((endValue[0] - startValue[0]) * pos) + startValue[0];
interp_color[1] = ((endValue[1] - startValue[1]) * pos) + startValue[1];
interp_color[2] = ((endValue[2] - startValue[2]) * pos) + startValue[2];
interp_color[3] = ((endValue[3] - startValue[3]) * pos) + startValue[3];
SetFgColor(interp_color);
}
void CHudRoundTimer::Paint()
{
// Update the time.
C_CSGameRules *pRules = CSGameRules();
if ( !pRules )
return;
int timer = (int)ceil( pRules->GetRoundRemainingTime() );
if ( pRules->IsFreezePeriod() )
{
// in freeze period countdown to round start time
timer = (int)ceil(pRules->GetRoundStartTime()-gpGlobals->curtime);
}
if(timer < 0)
timer = 0;
int minutes = timer / 60;
int seconds = timer % 60;
//Draw Timer icon
if( m_pTimerIcon )
{
m_pTimerIcon->DrawSelf( icon_xpos, icon_ypos, icon_wide, icon_tall, GetFgColor() );
}
PaintTime( m_hNumberFont, digit_xpos, digit_ypos, minutes, seconds );
}
void CHudRoundTimer::PaintTime(HFont font, int xpos, int ypos, int mins, int secs)
{
surface()->DrawSetTextFont(font);
wchar_t unicode[6];
V_snwprintf(unicode, ARRAYSIZE(unicode), L"%d:%.2d", mins, secs);
surface()->DrawSetTextPos(xpos, ypos);
surface()->DrawUnicodeString( unicode );
}
|