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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "hud.h"
#include "hudelement.h"
#include "hud_macros.h"
#include "iclientmode.h"
#include "c_basehlplayer.h"
#include "vgui_controls/Panel.h"
#include "vgui_controls/AnimationController.h"
#include "vgui/ISurface.h"
#include <vgui/ILocalize.h>
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
ConVar player_squad_transient_commands( "player_squad_transient_commands", "1", FCVAR_REPLICATED );
//-----------------------------------------------------------------------------
// Purpose: Shows the sprint power bar
//-----------------------------------------------------------------------------
class CHudSquadStatus : public CHudElement, public vgui::Panel
{
DECLARE_CLASS_SIMPLE( CHudSquadStatus, vgui::Panel );
public:
CHudSquadStatus( const char *pElementName );
virtual void Init( void );
virtual void Reset( void );
virtual void OnThink( void );
bool ShouldDraw();
void MsgFunc_SquadMemberDied(bf_read &msg);
protected:
virtual void Paint();
private:
CPanelAnimationVar( vgui::HFont, m_hTextFont, "TextFont", "Default" );
CPanelAnimationVarAliasType( float, text_xpos, "text_xpos", "8", "proportional_float" );
CPanelAnimationVarAliasType( float, text_ypos, "text_ypos", "20", "proportional_float" );
CPanelAnimationVar( vgui::HFont, m_hIconFont, "IconFont", "HudNumbers" );
CPanelAnimationVarAliasType( float, m_flIconInsetX, "IconInsetX", "8", "proportional_float" );
CPanelAnimationVarAliasType( float, m_flIconInsetY, "IconInsetY", "8", "proportional_float" );
CPanelAnimationVarAliasType( float, m_flIconGap, "IconGap", "20", "proportional_float" );
CPanelAnimationVar( Color, m_SquadIconColor, "SquadIconColor", "255 220 0 160" );
CPanelAnimationVar( Color, m_LastMemberColor, "LastMemberColor", "255 220 0 0" );
CPanelAnimationVar( Color, m_SquadTextColor, "SquadTextColor", "255 220 0 160" );
int m_iSquadMembers;
int m_iSquadMedics;
bool m_bSquadMembersFollowing;
bool m_bSquadMemberAdded;
bool m_bSquadMemberJustDied;
};
DECLARE_HUDELEMENT( CHudSquadStatus );
DECLARE_HUD_MESSAGE( CHudSquadStatus, SquadMemberDied );
using namespace vgui;
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CHudSquadStatus::CHudSquadStatus( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "HudSquadStatus" )
{
vgui::Panel *pParent = g_pClientMode->GetViewport();
SetParent( pParent );
SetHiddenBits( HIDEHUD_HEALTH | HIDEHUD_PLAYERDEAD | HIDEHUD_NEEDSUIT );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudSquadStatus::Init( void )
{
HOOK_HUD_MESSAGE( CHudSquadStatus, SquadMemberDied );
m_iSquadMembers = 0;
m_iSquadMedics = 0;
m_bSquadMemberAdded = false;
m_bSquadMembersFollowing = true;
m_bSquadMemberJustDied = false;
SetAlpha( 0 );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudSquadStatus::Reset( void )
{
Init();
}
//-----------------------------------------------------------------------------
// 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 CHudSquadStatus::ShouldDraw( void )
{
bool bNeedsDraw = false;
C_BaseHLPlayer *pPlayer = (C_BaseHLPlayer *)C_BasePlayer::GetLocalPlayer();
if ( !pPlayer )
return false;
bNeedsDraw = ( pPlayer->m_HL2Local.m_iSquadMemberCount > 0 ||
( pPlayer->m_HL2Local.m_iSquadMemberCount != m_iSquadMembers ) ||
( pPlayer->m_HL2Local.m_fSquadInFollowMode != m_bSquadMembersFollowing ) ||
( m_iSquadMembers > 0 ) ||
( m_LastMemberColor[3] > 0 ) );
return ( bNeedsDraw && CHudElement::ShouldDraw() );
}
//-----------------------------------------------------------------------------
// Purpose: updates hud icons
//-----------------------------------------------------------------------------
void CHudSquadStatus::OnThink( void )
{
C_BaseHLPlayer *pPlayer = (C_BaseHLPlayer *)C_BasePlayer::GetLocalPlayer();
if ( !pPlayer )
return;
int squadMembers = pPlayer->m_HL2Local.m_iSquadMemberCount;
bool following = pPlayer->m_HL2Local.m_fSquadInFollowMode;
m_iSquadMedics = pPlayer->m_HL2Local.m_iSquadMedicCount;
// Only update if we've changed vars
if ( squadMembers == m_iSquadMembers && following == m_bSquadMembersFollowing )
return;
// update status display
if ( squadMembers > 0)
{
// we have squad members, show the display
g_pClientMode->GetViewportAnimationController()->RunAnimationCommand( this, "alpha", 255.0f, 0.0f, 0.4f, AnimationController::INTERPOLATOR_LINEAR);
}
else
{
// no squad members, hide the display
g_pClientMode->GetViewportAnimationController()->RunAnimationCommand( this, "alpha", 0.0f, 0.0f, 0.4f, AnimationController::INTERPOLATOR_LINEAR);
}
if ( squadMembers > m_iSquadMembers )
{
// someone is added
// reset the last icon color and animate
m_LastMemberColor = m_SquadIconColor;
m_LastMemberColor[3] = 0;
m_bSquadMemberAdded = true;
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "SquadMemberAdded" );
}
else if ( squadMembers < m_iSquadMembers )
{
// someone has left
// reset the last icon color and animate
m_LastMemberColor = m_SquadIconColor;
m_bSquadMemberAdded = false;
if (m_bSquadMemberJustDied)
{
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "SquadMemberDied" );
m_bSquadMemberJustDied = false;
}
else
{
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "SquadMemberLeft" );
}
}
if ( following != m_bSquadMembersFollowing )
{
if ( following )
{
// flash the squad area to indicate they are following
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "SquadMembersFollowing" );
}
else
{
// flash the crosshair to indicate the targeted order is in effect
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "SquadMembersStationed" );
}
}
m_iSquadMembers = squadMembers;
m_bSquadMembersFollowing = following;
}
//-----------------------------------------------------------------------------
// Purpose: Notification of squad member being killed
//-----------------------------------------------------------------------------
void CHudSquadStatus::MsgFunc_SquadMemberDied(bf_read &msg)
{
m_bSquadMemberJustDied = true;
}
//-----------------------------------------------------------------------------
// Purpose: draws the power bar
//-----------------------------------------------------------------------------
void CHudSquadStatus::Paint()
{
C_BaseHLPlayer *pPlayer = (C_BaseHLPlayer *)C_BasePlayer::GetLocalPlayer();
if ( !pPlayer )
return;
// draw the suit power bar
surface()->DrawSetTextColor( m_SquadIconColor );
surface()->DrawSetTextFont( m_hIconFont );
int xpos = m_flIconInsetX, ypos = m_flIconInsetY;
for (int i = 0; i < m_iSquadMembers; i++)
{
if (m_bSquadMemberAdded && i == m_iSquadMembers - 1)
{
// draw the last added squad member specially
surface()->DrawSetTextColor( m_LastMemberColor );
}
surface()->DrawSetTextPos(xpos, ypos);
if (i < m_iSquadMedics)
{
surface()->DrawUnicodeChar('M');
}
else
{
surface()->DrawUnicodeChar('C');
}
xpos += m_flIconGap;
}
if (!m_bSquadMemberAdded && m_LastMemberColor[3])
{
// draw the last one in the special color
surface()->DrawSetTextColor( m_LastMemberColor );
surface()->DrawSetTextPos(xpos, ypos);
surface()->DrawUnicodeChar('C');
}
// draw our squad status
wchar_t *text = NULL;
if (m_bSquadMembersFollowing)
{
text = g_pVGuiLocalize->Find("#Valve_Hud_SQUAD_FOLLOWING");
if (!text)
{
text = L"SQUAD FOLLOWING";
}
}
else
{
if ( !player_squad_transient_commands.GetBool() )
{
text = g_pVGuiLocalize->Find("#Valve_Hud_SQUAD_STATIONED");
if (!text)
{
text = L"SQUAD STATIONED";
}
}
}
if (text)
{
surface()->DrawSetTextFont(m_hTextFont);
surface()->DrawSetTextColor(m_SquadTextColor);
surface()->DrawSetTextPos(text_xpos, text_ypos);
surface()->DrawPrintText(text, wcslen(text));
}
}
|