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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "cbase.h"
#include "hud.h"
#include "hudelement.h"
#include "iclientmode.h"
#include "engine/IEngineSound.h"
#include "vgui_controls/AnimationController.h"
#include "vgui_controls/Controls.h"
#include "vgui_controls/Panel.h"
#include "vgui/ISurface.h"
#include "c_portal_player.h"
#include "c_weapon_portalgun.h"
#include "IGameUIFuncs.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define HEALTH_WARNING_THRESHOLD 25
static ConVar hud_quickinfo( "hud_quickinfo", "1", FCVAR_ARCHIVE );
static ConVar hud_quickinfo_swap( "hud_quickinfo_swap", "0", FCVAR_ARCHIVE );
extern ConVar crosshair;
#define QUICKINFO_EVENT_DURATION 1.0f
#define QUICKINFO_BRIGHTNESS_FULL 255
#define QUICKINFO_BRIGHTNESS_DIM 64
#define QUICKINFO_FADE_IN_TIME 0.5f
#define QUICKINFO_FADE_OUT_TIME 2.0f
/*
==================================================
CHUDQuickInfo
==================================================
*/
using namespace vgui;
class CHUDQuickInfo : public CHudElement, public vgui::Panel
{
DECLARE_CLASS_SIMPLE( CHUDQuickInfo, vgui::Panel );
public:
CHUDQuickInfo( const char *pElementName );
void Init( void );
void VidInit( void );
bool ShouldDraw( void );
//virtual void OnThink();
virtual void Paint();
virtual void ApplySchemeSettings( IScheme *scheme );
private:
void DrawWarning( int x, int y, CHudTexture *icon, float &time );
void UpdateEventTime( void );
bool EventTimeElapsed( void );
float m_flLastEventTime;
float m_fLastPlacedAlpha[2];
bool m_bLastPlacedAlphaCountingUp[2];
CHudTexture *m_icon_c;
CHudTexture *m_icon_rbn; // right bracket
CHudTexture *m_icon_lbn; // left bracket
CHudTexture *m_icon_rb; // right bracket, full
CHudTexture *m_icon_lb; // left bracket, full
CHudTexture *m_icon_rbe; // right bracket, empty
CHudTexture *m_icon_lbe; // left bracket, empty
CHudTexture *m_icon_rbnone; // right bracket
CHudTexture *m_icon_lbnone; // left bracket
};
DECLARE_HUDELEMENT( CHUDQuickInfo );
CHUDQuickInfo::CHUDQuickInfo( const char *pElementName ) :
CHudElement( pElementName ), BaseClass( NULL, "HUDQuickInfo" )
{
vgui::Panel *pParent = g_pClientMode->GetViewport();
SetParent( pParent );
SetHiddenBits( HIDEHUD_CROSSHAIR );
m_fLastPlacedAlpha[0] = m_fLastPlacedAlpha[1] = 80;
m_bLastPlacedAlphaCountingUp[0] = m_bLastPlacedAlphaCountingUp[1] = true;
}
void CHUDQuickInfo::ApplySchemeSettings( IScheme *scheme )
{
BaseClass::ApplySchemeSettings( scheme );
SetPaintBackgroundEnabled( false );
}
void CHUDQuickInfo::Init( void )
{
m_flLastEventTime = 0.0f;
}
void CHUDQuickInfo::VidInit( void )
{
Init();
m_icon_c = gHUD.GetIcon( "crosshair" );
if ( IsX360() )
{
m_icon_rb = gHUD.GetIcon( "portal_crosshair_right_valid_x360" );
m_icon_lb = gHUD.GetIcon( "portal_crosshair_left_valid_x360" );
m_icon_rbe = gHUD.GetIcon( "portal_crosshair_last_placed_x360" );
m_icon_lbe = gHUD.GetIcon( "portal_crosshair_last_placed_x360" );
m_icon_rbn = gHUD.GetIcon( "portal_crosshair_right_invalid_x360" );
m_icon_lbn = gHUD.GetIcon( "portal_crosshair_left_invalid_x360" );
}
else
{
m_icon_rb = gHUD.GetIcon( "portal_crosshair_right_valid" );
m_icon_lb = gHUD.GetIcon( "portal_crosshair_left_valid" );
m_icon_rbe = gHUD.GetIcon( "portal_crosshair_last_placed" );
m_icon_lbe = gHUD.GetIcon( "portal_crosshair_last_placed" );
m_icon_rbn = gHUD.GetIcon( "portal_crosshair_right_invalid" );
m_icon_lbn = gHUD.GetIcon( "portal_crosshair_left_invalid" );
m_icon_rbnone = gHUD.GetIcon( "crosshair_right" );
m_icon_lbnone = gHUD.GetIcon( "crosshair_left" );
}
}
void CHUDQuickInfo::DrawWarning( int x, int y, CHudTexture *icon, float &time )
{
float scale = (int)( fabs(sin(gpGlobals->curtime*8.0f)) * 128.0);
// Only fade out at the low point of our blink
if ( time <= (gpGlobals->frametime * 200.0f) )
{
if ( scale < 40 )
{
time = 0.0f;
return;
}
else
{
// Counteract the offset below to survive another frame
time += (gpGlobals->frametime * 200.0f);
}
}
// Update our time
time -= (gpGlobals->frametime * 200.0f);
Color caution = gHUD.m_clrCaution;
caution[3] = scale * 255;
icon->DrawSelf( x, y, caution );
}
//-----------------------------------------------------------------------------
// 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 CHUDQuickInfo::ShouldDraw( void )
{
if ( !m_icon_c || !m_icon_rb || !m_icon_rbe || !m_icon_lb || !m_icon_lbe )
return false;
C_Portal_Player *player = ToPortalPlayer(C_BasePlayer::GetLocalPlayer());
if ( player == NULL )
return false;
if ( !crosshair.GetBool() )
return false;
if ( player->IsSuppressingCrosshair() )
return false;
return ( CHudElement::ShouldDraw() && !engine->IsDrawingLoadingImage() );
}
void CHUDQuickInfo::Paint()
{
C_Portal_Player *pPortalPlayer = (C_Portal_Player*)( C_BasePlayer::GetLocalPlayer() );
if ( pPortalPlayer == NULL )
return;
C_BaseCombatWeapon *pWeapon = GetActiveWeapon();
if ( pWeapon == NULL )
return;
int xCenter = ( ScreenWidth() - m_icon_c->Width() ) / 2;
int yCenter = ( ScreenHeight() - m_icon_c->Height() ) / 2;
Color clrNormal = gHUD.m_clrNormal;
clrNormal[3] = 255;
SetActive( true );
m_icon_c->DrawSelf( xCenter, yCenter, clrNormal );
// adjust center for the bigger crosshairs
xCenter = ScreenWidth() / 2;
yCenter = ( ScreenHeight() - m_icon_lb->Height() ) / 2;
C_WeaponPortalgun *pPortalgun = dynamic_cast<C_WeaponPortalgun*>( pWeapon );
bool bPortalPlacability[2];
if ( pPortalgun )
{
bPortalPlacability[0] = pPortalgun->GetPortal1Placablity() > 0.5f;
bPortalPlacability[1] = pPortalgun->GetPortal2Placablity() > 0.5f;
}
if ( !hud_quickinfo.GetInt() || !pPortalgun || ( !pPortalgun->CanFirePortal1() && !pPortalgun->CanFirePortal2() ) )
{
// no quickinfo or we can't fire either portal, just draw the small versions of the crosshairs
clrNormal[3] = 196;
m_icon_lbnone->DrawSelf(xCenter - (m_icon_lbnone->Width() * 2), yCenter, clrNormal);
m_icon_rbnone->DrawSelf(xCenter + m_icon_rbnone->Width(), yCenter, clrNormal);
return;
}
const unsigned char iAlphaStart = 150;
Color portal1Color = UTIL_Portal_Color( 1 );
Color portal2Color = UTIL_Portal_Color( 2 );
portal1Color[ 3 ] = iAlphaStart;
portal2Color[ 3 ] = iAlphaStart;
const int iBaseLastPlacedAlpha = 128;
Color lastPlaced1Color = Color( portal1Color[0], portal1Color[1], portal1Color[2], iBaseLastPlacedAlpha );
Color lastPlaced2Color = Color( portal2Color[0], portal2Color[1], portal2Color[2], iBaseLastPlacedAlpha );
const float fLastPlacedAlphaLerpSpeed = 300.0f;
float fLeftPlaceBarFill = 0.0f;
float fRightPlaceBarFill = 0.0f;
if ( pPortalgun->CanFirePortal1() && pPortalgun->CanFirePortal2() )
{
int iDrawLastPlaced = 0;
//do last placed indicator effects
if ( pPortalgun->GetLastFiredPortal() == 1 )
{
iDrawLastPlaced = 0;
fLeftPlaceBarFill = 1.0f;
}
else if ( pPortalgun->GetLastFiredPortal() == 2 )
{
iDrawLastPlaced = 1;
fRightPlaceBarFill = 1.0f;
}
if( m_bLastPlacedAlphaCountingUp[iDrawLastPlaced] )
{
m_fLastPlacedAlpha[iDrawLastPlaced] += gpGlobals->absoluteframetime * fLastPlacedAlphaLerpSpeed * 2.0f;
if( m_fLastPlacedAlpha[iDrawLastPlaced] > 255.0f )
{
m_bLastPlacedAlphaCountingUp[iDrawLastPlaced] = false;
m_fLastPlacedAlpha[iDrawLastPlaced] = 255.0f - (m_fLastPlacedAlpha[iDrawLastPlaced] - 255.0f);
}
}
else
{
m_fLastPlacedAlpha[iDrawLastPlaced] -= gpGlobals->absoluteframetime * fLastPlacedAlphaLerpSpeed;
if( m_fLastPlacedAlpha[iDrawLastPlaced] < (float)iBaseLastPlacedAlpha )
{
m_fLastPlacedAlpha[iDrawLastPlaced] = (float)iBaseLastPlacedAlpha;
}
}
//reset the last placed indicator on the other side
m_fLastPlacedAlpha[1 - iDrawLastPlaced] -= gpGlobals->absoluteframetime * fLastPlacedAlphaLerpSpeed;
if( m_fLastPlacedAlpha[1 - iDrawLastPlaced] < 0.0f )
{
m_fLastPlacedAlpha[1 - iDrawLastPlaced] = 0.0f;
}
m_bLastPlacedAlphaCountingUp[1 - iDrawLastPlaced] = true;
if ( pPortalgun->GetLastFiredPortal() != 0 )
{
lastPlaced1Color[3] = m_fLastPlacedAlpha[0];
lastPlaced2Color[3] = m_fLastPlacedAlpha[1];
}
else
{
lastPlaced1Color[3] = 0.0f;
lastPlaced2Color[3] = 0.0f;
}
}
//can't fire both portals, and we want the crosshair to remain somewhat symmetrical without being confusing
else if ( !pPortalgun->CanFirePortal1() )
{
// clone portal2 info to portal 1
portal1Color = portal2Color;
lastPlaced1Color[3] = 0.0f;
lastPlaced2Color[3] = 0.0f;
bPortalPlacability[0] = bPortalPlacability[1];
}
else if ( !pPortalgun->CanFirePortal2() )
{
// clone portal1 info to portal 2
portal2Color = portal1Color;
lastPlaced1Color[3] = 0.0f;
lastPlaced2Color[3] = 0.0f;
bPortalPlacability[1] = bPortalPlacability[0];
}
if ( pPortalgun->IsHoldingObject() )
{
// Change the middle to orange
portal1Color = portal2Color = UTIL_Portal_Color( 0 );
bPortalPlacability[0] = bPortalPlacability[1] = false;
}
if ( !hud_quickinfo_swap.GetBool() )
{
if ( bPortalPlacability[0] )
m_icon_lb->DrawSelf(xCenter - (m_icon_lb->Width() * 0.64f ), yCenter - ( m_icon_rb->Height() * 0.17f ), portal1Color);
else
m_icon_lbn->DrawSelf(xCenter - (m_icon_lbn->Width() * 0.64f ), yCenter - ( m_icon_rb->Height() * 0.17f ), portal1Color);
if ( bPortalPlacability[1] )
m_icon_rb->DrawSelf(xCenter + ( m_icon_rb->Width() * -0.35f ), yCenter + ( m_icon_rb->Height() * 0.17f ), portal2Color);
else
m_icon_rbn->DrawSelf(xCenter + ( m_icon_rbn->Width() * -0.35f ), yCenter + ( m_icon_rb->Height() * 0.17f ), portal2Color);
//last placed portal indicator
m_icon_lbe->DrawSelf( xCenter - (m_icon_lbe->Width() * 1.85f), yCenter, lastPlaced1Color );
m_icon_rbe->DrawSelf( xCenter + (m_icon_rbe->Width() * 0.75f), yCenter, lastPlaced2Color );
}
else
{
if ( bPortalPlacability[1] )
m_icon_lb->DrawSelf(xCenter - (m_icon_lb->Width() * 0.64f ), yCenter - ( m_icon_rb->Height() * 0.17f ), portal2Color);
else
m_icon_lbn->DrawSelf(xCenter - (m_icon_lbn->Width() * 0.64f ), yCenter - ( m_icon_rb->Height() * 0.17f ), portal2Color);
if ( bPortalPlacability[0] )
m_icon_rb->DrawSelf(xCenter + ( m_icon_rb->Width() * -0.35f ), yCenter + ( m_icon_rb->Height() * 0.17f ), portal1Color);
else
m_icon_rbn->DrawSelf(xCenter + ( m_icon_rbn->Width() * -0.35f ), yCenter + ( m_icon_rb->Height() * 0.17f ), portal1Color);
//last placed portal indicator
m_icon_lbe->DrawSelf( xCenter - (m_icon_lbe->Width() * 1.85f), yCenter, lastPlaced2Color );
m_icon_rbe->DrawSelf( xCenter + (m_icon_rbe->Width() * 0.75f), yCenter, lastPlaced1Color );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHUDQuickInfo::UpdateEventTime( void )
{
m_flLastEventTime = gpGlobals->curtime;
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CHUDQuickInfo::EventTimeElapsed( void )
{
if (( gpGlobals->curtime - m_flLastEventTime ) > QUICKINFO_EVENT_DURATION )
return true;
return false;
}
|