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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "hud.h"
#include "text_message.h"
#include "hud_macros.h"
#include "iclientmode.h"
#include "view.h"
#include <KeyValues.h>
#include <vgui/ISurface.h>
#include <vgui_controls/Panel.h>
#include "VGuiMatSurface/IMatSystemSurface.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/imesh.h"
#include "materialsystem/imaterialvar.h"
#include "IEffects.h"
#include "hudelement.h"
// NVNT damage
#include "haptics/haptic_utils.h"
using namespace vgui;
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Purpose: HDU Damage indication
//-----------------------------------------------------------------------------
class CHudDamageIndicator : public CHudElement, public vgui::Panel
{
DECLARE_CLASS_SIMPLE( CHudDamageIndicator, vgui::Panel );
public:
CHudDamageIndicator( const char *pElementName );
void Init( void );
void Reset( void );
bool ShouldDraw( void );
// Handler for our message
void MsgFunc_Damage( bf_read &msg );
private:
void Paint();
void ApplySchemeSettings(vgui::IScheme *pScheme);
private:
void CalcDamageDirection( const Vector &vecFrom );
void DrawDamageIndicatorFront( float flFade );
void DrawDamageIndicatorRear( float flFade );
void DrawDamageIndicatorLeft( float flFade );
void DrawDamageIndicatorRight( float flFade );
private:
float m_flAttackFront;
float m_flAttackRear;
float m_flAttackLeft;
float m_flAttackRight;
Color m_clrIndicator;
CHudTexture *icon_up;
CHudTexture *icon_down;
CHudTexture *icon_left;
CHudTexture *icon_right;
float m_flFadeCompleteTime; //don't draw past this time
};
DECLARE_HUDELEMENT( CHudDamageIndicator );
DECLARE_HUD_MESSAGE( CHudDamageIndicator, Damage );
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CHudDamageIndicator::CHudDamageIndicator( const char *pElementName ) : CHudElement( pElementName ), BaseClass(NULL, "HudDamageIndicator")
{
vgui::Panel *pParent = g_pClientMode->GetViewport();
SetParent( pParent );
SetHiddenBits( HIDEHUD_HEALTH );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudDamageIndicator::Reset( void )
{
m_flAttackFront = 0.0;
m_flAttackRear = 0.0;
m_flAttackRight = 0.0;
m_flAttackLeft = 0.0;
m_flFadeCompleteTime = 0.0;
m_clrIndicator.SetColor( 250, 0, 0, 255 );
}
void CHudDamageIndicator::Init( void )
{
HOOK_HUD_MESSAGE( CHudDamageIndicator, Damage );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CHudDamageIndicator::ShouldDraw( void )
{
if ( !CHudElement::ShouldDraw() )
return false;
if ( ( m_flAttackFront <= 0.0 ) && ( m_flAttackRear <= 0.0 ) && ( m_flAttackLeft <= 0.0 ) && ( m_flAttackRight <= 0.0 ) )
return false;
return true;
}
void CHudDamageIndicator::DrawDamageIndicatorFront( float flFade )
{
if ( m_flAttackFront > 0.4 )
{
if ( !icon_up )
{
icon_up = gHUD.GetIcon( "pain_up" );
}
if ( !icon_up )
{
return;
}
int x = ( ScreenWidth() / 2 ) - icon_up->Width() / 2;
int y = ( ScreenHeight() / 2 ) - icon_up->Height() * 3;
icon_up->DrawSelf( x, y, m_clrIndicator );
m_flAttackFront = MAX( 0.0, m_flAttackFront - flFade );
}
else
{
m_flAttackFront = 0.0;
}
}
void CHudDamageIndicator::DrawDamageIndicatorRear( float flFade )
{
if ( m_flAttackRear > 0.4 )
{
if ( !icon_down )
{
icon_down = gHUD.GetIcon( "pain_down" );
}
if ( !icon_down )
{
return;
}
int x = ( ScreenWidth() / 2 ) - icon_down->Width() / 2;
int y = ( ScreenHeight() / 2 ) + icon_down->Height() * 2;
icon_down->DrawSelf( x, y, m_clrIndicator );
m_flAttackRear = MAX( 0.0, m_flAttackRear - flFade );
}
else
{
m_flAttackRear = 0.0;
}
}
void CHudDamageIndicator::DrawDamageIndicatorLeft( float flFade )
{
if ( m_flAttackLeft > 0.4 )
{
if ( !icon_left )
{
icon_left = gHUD.GetIcon( "pain_left" );
}
if ( !icon_left )
{
return;
}
int x = ( ScreenWidth() / 2 ) - icon_left->Width() * 3;
int y = ( ScreenHeight() / 2 ) - icon_left->Height() / 2;
icon_left->DrawSelf( x, y, m_clrIndicator );
m_flAttackLeft = MAX( 0.0, m_flAttackLeft - flFade );
}
else
{
m_flAttackLeft = 0.0;
}
}
void CHudDamageIndicator::DrawDamageIndicatorRight( float flFade )
{
if ( m_flAttackRight > 0.4 )
{
if ( !icon_right )
{
icon_right = gHUD.GetIcon( "pain_right" );
}
if ( !icon_right )
{
return;
}
int x = ( ScreenWidth() / 2 ) + icon_right->Width() * 2;
int y = ( ScreenHeight() / 2 ) - icon_right->Height() / 2;
icon_right->DrawSelf( x, y, m_clrIndicator );
m_flAttackRight = MAX( 0.0, m_flAttackRight - flFade );
}
else
{
m_flAttackRight = 0.0;
}
}
//-----------------------------------------------------------------------------
// Purpose: Paints the damage display
//-----------------------------------------------------------------------------
void CHudDamageIndicator::Paint()
{
if( m_flFadeCompleteTime > gpGlobals->curtime )
{
float flFade = gpGlobals->frametime * 2;
// draw damage indicators
DrawDamageIndicatorFront( flFade );
DrawDamageIndicatorRear( flFade );
DrawDamageIndicatorLeft( flFade );
DrawDamageIndicatorRight( flFade );
}
}
// NVNT static to pass damage
static float hap_damage_amount = 0;
//-----------------------------------------------------------------------------
// Purpose: Message handler for Damage message
//-----------------------------------------------------------------------------
void CHudDamageIndicator::MsgFunc_Damage( bf_read &msg )
{
int damageTaken = msg.ReadByte();
Vector vecFrom;
msg.ReadBitVec3Coord( vecFrom );
// NVNT pass damage to static holder
hap_damage_amount = damageTaken;
if ( damageTaken > 0 )
{
m_flFadeCompleteTime = gpGlobals->curtime + 1.0;
CalcDamageDirection( vecFrom );
}
//=============================================================================
// HPE_BEGIN:
// [menglish] Added reads for the added location based parameters to this message
//=============================================================================
msg.ReadLong();
msg.ReadBitVec3Coord( vecFrom );
//=============================================================================
// HPE_END
//=============================================================================
}
void CHudDamageIndicator::CalcDamageDirection( const Vector &vecFrom )
{
if ( vecFrom == vec3_origin )
{
m_flAttackFront = 0.0;
m_flAttackRear = 0.0;
m_flAttackRight = 0.0;
m_flAttackLeft = 0.0;
return;
}
C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();
if ( !pLocalPlayer )
{
return;
}
Vector vecDelta = ( vecFrom - pLocalPlayer->GetRenderOrigin() );
if ( vecDelta.Length() <= 50 )
{
m_flAttackFront = 1.0;
m_flAttackRear = 1.0;
m_flAttackRight = 1.0;
m_flAttackLeft = 1.0;
return;
}
VectorNormalize( vecDelta );
Vector forward;
Vector right;
Vector up;
AngleVectors( MainViewAngles(), &forward, &right, &up );
float flFront = DotProduct( vecDelta, forward );
float flSide = DotProduct( vecDelta, right );
float flUp = DotProduct( vecDelta, up);
if ( flFront > 0 )
{
if ( flFront > 0.3 )
m_flAttackFront = MAX( m_flAttackFront, flFront );
}
else
{
float f = fabs( flFront );
if ( f > 0.3 )
m_flAttackRear = MAX( m_flAttackRear, f );
}
if ( flSide > 0 )
{
if ( flSide > 0.3 )
m_flAttackRight = MAX( m_flAttackRight, flSide );
}
else
{
float f = fabs( flSide );
if ( f > 0.3 )
m_flAttackLeft = MAX( m_flAttackLeft, f );
}
// NVNT pass damage. (use hap_damage amount to apply)
// do rotation
Vector hapDir(-flSide,-flUp,flFront);
if ( haptics )
haptics->ApplyDamageEffect(hap_damage_amount, 0, hapDir);
}
//-----------------------------------------------------------------------------
// Purpose: hud scheme settings
//-----------------------------------------------------------------------------
void CHudDamageIndicator::ApplySchemeSettings(vgui::IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
SetPaintBackgroundEnabled(false);
int wide, tall;
GetHudSize(wide, tall);
SetSize(wide, tall);
}
|