forked from ReactiveDrop/reactivedrop_public_src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasw_hud_emotes.cpp
More file actions
288 lines (245 loc) · 9.74 KB
/
Copy pathasw_hud_emotes.cpp
File metadata and controls
288 lines (245 loc) · 9.74 KB
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
#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/AnimationController.h>
#include <vgui/ILocalize.h>
#include <filesystem.h>
#include <keyvalues.h>
#include "asw_hudelement.h"
#include "c_asw_marine.h"
#include "asw_marine_profile.h"
#include "c_asw_marine_resource.h"
#include "c_asw_sentry_base.h"
#include "c_asw_game_resource.h"
#include "c_asw_door.h"
#include "c_asw_use_area.h"
#include "asw_input.h"
#include "c_playerresource.h"
#include "ConVar.h"
#include "tier0/vprof.h"
#include "idebugoverlaypanel.h"
#include "engine/IVDebugOverlay.h"
#include "vguimatsurface/imatsystemsurface.h"
#include "tier1/fmtstr.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
extern ConVar asw_draw_hud;
extern ConVar _rd_traitors_challenge_enabled;
//-----------------------------------------------------------------------------
// Purpose: Shows the marines emote graphics
//-----------------------------------------------------------------------------
class CASWHudEmotes : public CASW_HudElement, public vgui::Panel
{
DECLARE_CLASS_SIMPLE( CASWHudEmotes, vgui::Panel );
public:
CASWHudEmotes( const char *pElementName );
~CASWHudEmotes();
virtual void Paint();
virtual void ApplySchemeSettings( IScheme *pScheme );
virtual void PaintEmotes();
virtual void PaintEmotesFor( C_ASW_Marine *pMarine );
virtual void PaintEmote( C_BaseEntity *pEnt, float fTime, int iTexture, float fScale = 1.0f );
virtual bool ShouldDraw( void ) { return asw_draw_hud.GetBool() && CASW_HudElement::ShouldDraw(); }
CPanelAnimationVarAliasType( int, m_nMedicTexture, "MedicEmoteTexture", "vgui/swarm/Emotes/EmoteMedic", "textureid" );
CPanelAnimationVarAliasType( int, m_nAmmoTexture, "AmmoEmoteTexture", "vgui/swarm/Emotes/EmoteAmmo", "textureid" );
CPanelAnimationVarAliasType( int, m_nSmileTexture, "SmileEmoteTexture", "vgui/swarm/Emotes/EmoteSmile", "textureid" );
CPanelAnimationVarAliasType( int, m_nStopTexture, "StopEmoteTexture", "vgui/swarm/Emotes/EmoteStop", "textureid" );
CPanelAnimationVarAliasType( int, m_nGoTexture, "GoEmoteTexture", "vgui/swarm/Emotes/EmoteGo", "textureid" );
CPanelAnimationVarAliasType( int, m_nExclaimTexture, "ExclaimEmoteTexture", "vgui/swarm/Emotes/EmoteExclaim", "textureid" );
CPanelAnimationVarAliasType( int, m_nAnimeTexture, "AnimeEmoteTexture", "vgui/swarm/Emotes/EmoteAnime", "textureid" );
CPanelAnimationVarAliasType( int, m_nQuestionTexture, "QuestionTexture", "vgui/swarm/Emotes/EmoteQuestion", "textureid" );
CPanelAnimationVarAliasType( int, m_nThanksTexture, "ThanksTexture", "vgui/swarm/Emotes/EmoteThanks", "textureid" );
CPanelAnimationVarAliasType( int, m_nWeldEmoteTexture, "WeldEmoteTexture", "vgui/swarm/Emotes/EmoteWelder", "textureid" );
CPanelAnimationVarAliasType( int, m_nWrenchTexture, "WrenchTexture", "vgui/swarm/ClassIcons/EngineerIcon", "textureid" );
CPanelAnimationVarAliasType( int, m_nSentryUpTexture, "SentryUpTexture", "vgui/swarm/ClassIcons/SentryBuild", "textureid" );
CPanelAnimationVarAliasType( int, m_nSentryDnTexture, "SentryDnTexture", "vgui/swarm/ClassIcons/SentryDismantle", "textureid" );
CPanelAnimationVarAliasType( int, m_nHackTexture, "HackTexture", "vgui/swarm/ClassIcons/HackIcon", "textureid" );
CPanelAnimationVarAliasType( int, m_nWeldTexture, "WeldTexture", "vgui/swarm/ClassIcons/WeldIcon", "textureid" );
CPanelAnimationVarAliasType( int, m_nReviveMarineTexture, "ReviveMarineTexture", "vgui/swarm/ClassIcons/revivemarine", "textureid" );
};
DECLARE_HUDELEMENT( CASWHudEmotes );
CASWHudEmotes::CASWHudEmotes( const char *pElementName ) : CASW_HudElement( pElementName ), BaseClass( NULL, "ASWHudEmotes" )
{
vgui::Panel *pParent = GetClientMode()->GetViewport();
SetParent( pParent );
SetHiddenBits( HIDEHUD_REMOTE_TURRET );
vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFile( "resource/SwarmSchemeNew.res", "SwarmSchemeNew" );
SetScheme( scheme );
}
CASWHudEmotes::~CASWHudEmotes()
{
}
void CASWHudEmotes::ApplySchemeSettings( IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
SetBgColor( Color( 0, 0, 0, 0 ) );
SetPaintBackgroundEnabled( false );
}
void CASWHudEmotes::Paint()
{
VPROF_BUDGET( "CASWHudEmotes::Paint", VPROF_BUDGETGROUP_ASW_CLIENT );
BaseClass::Paint();
PaintEmotes();
}
void CASWHudEmotes::PaintEmotes()
{
C_ASW_Game_Resource *pGameResource = ASWGameResource();
if (!pGameResource)
return;
for (int i=0;i<pGameResource->GetMaxMarineResources();i++)
{
C_ASW_Marine_Resource *pMR = pGameResource->GetMarineResource(i);
if (!pMR)
continue;
C_ASW_Marine *marine = pMR->GetMarineEntity();
if ( !marine )
continue;
PaintEmotesFor(marine);
}
}
void CASWHudEmotes::PaintEmotesFor( C_ASW_Marine *pMarine )
{
if ( pMarine->m_iClientEmote & ( 1 << 0 ) )
PaintEmote( pMarine, pMarine->m_fEmoteMedicTime, m_nMedicTexture );
if ( pMarine->m_iClientEmote & ( 1 << 1 ) )
PaintEmote( pMarine, pMarine->m_fEmoteAmmoTime, m_nAmmoTexture );
if ( pMarine->m_iClientEmote & ( 1 << 2 ) )
PaintEmote( pMarine, pMarine->m_fEmoteSmileTime, m_nSmileTexture );
if ( pMarine->m_iClientEmote & ( 1 << 3 ) )
PaintEmote( pMarine, pMarine->m_fEmoteStopTime, m_nStopTexture );
if ( pMarine->m_iClientEmote & ( 1 << 4 ) )
PaintEmote( pMarine, pMarine->m_fEmoteGoTime, m_nGoTexture );
if ( pMarine->m_iClientEmote & ( 1 << 5 ) )
PaintEmote( pMarine, pMarine->m_fEmoteExclaimTime, m_nExclaimTexture );
if ( pMarine->m_iClientEmote & ( 1 << 6 ) )
PaintEmote( pMarine, pMarine->m_fEmoteAnimeSmileTime, m_nAnimeTexture );
if ( pMarine->m_iClientEmote & ( 1 << 7 ) )
PaintEmote( pMarine, pMarine->m_fEmoteQuestionTime, m_nQuestionTexture );
if ( pMarine->m_iClientEmote & ( 1 << 14 ) )
PaintEmote( pMarine, pMarine->m_fEmoteThanksTime, m_nThanksTexture );
if (pMarine->m_iClientEmote & (1 << 15) )
PaintEmote(pMarine, pMarine->m_fEmoteWeldTime, m_nWeldEmoteTexture);
bool bBuildingSentry = false;
bool bWelding = false;
// paint wrench over a sentry gun if a marine is setting one up within an engineer's aura
C_BaseEntity *pUsing = pMarine->m_hUsingEntity.Get();
if ( pUsing )
{
C_ASW_Sentry_Base *pSentry = dynamic_cast< C_ASW_Sentry_Base * >( pUsing );
if ( pSentry )
{
if ( pSentry->IsAssembled() )
PaintEmote( pMarine, 1.5f, m_nSentryDnTexture, 0.9f );
else
PaintEmote( pMarine, 1.5f, m_nSentryUpTexture, 0.9f );
if ( pSentry->m_bSkillMarineHelping )
{
PaintEmote( pSentry, 1.0f, m_nWrenchTexture, 0.4f );
}
bBuildingSentry = true;
}
}
// paint medic icon over a marine if he is reviving another marine
if ( pUsing )
{
if ( pUsing->Classify() == CLASS_ASW_MARINE )
{
C_ASW_Marine *pOtherMarine = assert_cast< C_ASW_Marine * >( pUsing );
if ( pOtherMarine->m_bKnockedOut )
PaintEmote( pMarine, 1.5f, m_nReviveMarineTexture, 0.9f );
}
}
// and a welding door
if ( pMarine->GetMarineResource() )
{
C_ASW_Door *pDoor = pMarine->GetMarineResource()->m_hWeldingDoor.Get();
if ( pDoor )
{
bWelding = true;
if ( pDoor->m_bSkillMarineHelping )
PaintEmote( pDoor, 1.0f, m_nWrenchTexture, 0.4f );
PaintEmote( pMarine, 1.5f, m_nWeldTexture, 0.75f );
}
}
// paint wrench over an engineer if he's boosting a sentry/weld
if ( pMarine->GetMarineResource() )
{
if ( pMarine->GetMarineResource()->m_bUsingEngineeringAura && !bBuildingSentry && !bWelding )
{
PaintEmote( pMarine, 0.9f, m_nWrenchTexture, 0.4f );
}
}
bool bDrawHackIcon = false;
if ( pMarine->IsInhabited() )
{
if ( pMarine->IsHacking() )
bDrawHackIcon = true;
}
else
{
if ( pUsing )
{
C_ASW_Use_Area *pArea = static_cast< C_ASW_Use_Area * >( pUsing );
if ( pArea->Classify() == CLASS_ASW_BUTTON_PANEL )
bDrawHackIcon = true;
}
}
if ( bDrawHackIcon )
PaintEmote( pMarine, 1.0f, m_nHackTexture, 0.75f );
}
void CASWHudEmotes::PaintEmote( C_BaseEntity *pEnt, float fTime, int iTexture, float fEmoteScale )
{
//Msg("PaintEmote scale = %f\n", fEmoteScale);
if ( fEmoteScale < 0 )
fEmoteScale = 0;
Vector screenPos;
Vector vecFacing;
AngleVectors( pEnt->GetRenderAngles(), &vecFacing );
vecFacing *= 5;
// BenLubar: Fix emotes being offset when the camera is rotated
float flYaw = ( ASWInput() ? ASWInput()->ASW_GetCameraYaw() : 90 ) / 180 * M_PI;
Vector vecOffset( cosf( flYaw ) * 40, sinf( flYaw ) * 40, 70 );
if ( !debugoverlay->ScreenPosition( pEnt->GetRenderOrigin() + vecOffset + vecFacing, screenPos ) )
{
//Msg("Emote marinepos: %s\n", VecToString(pEnt->GetRenderOrigin()));
//Msg("Emote marinefacing: %s\n", VecToString(vecFacing));
float xPos = screenPos[0];
float yPos = screenPos[1];
if ( iTexture != -1 )
{
float fAlpha = 0;
float fSize = 0.5 + 0.5 * ( ( 2.0 - fTime ) / 2.0f );
if ( fTime < 1.0f ) // fade in
fAlpha = fTime;
else // fade out
fAlpha = 2.0 - fTime;
float f = clamp( 1.0f - fAlpha, 0.0f, 1.0f );
f = f * f * f;
fAlpha = 1.0f - f;
fSize = ( 0.5f + 0.5f * fAlpha ) * 0.5f;
float fScale = ( ScreenHeight() / 768.0f ) * fEmoteScale;
float HalfW = 128.0f * fScale * fSize * 0.5f;
float HalfH = 128.0f * fScale * fSize * 0.5f;
surface()->DrawSetColor( Color( 255, 255, 255, fAlpha * 255.0f ) );
surface()->DrawSetTexture( iTexture );
//int x = xPos - HalfW;
//int y = yPos - HalfH;
Vertex_t points[4] =
{
Vertex_t( Vector2D( xPos - HalfW, yPos - HalfH ), Vector2D( 0,0 ) ),
Vertex_t( Vector2D( xPos + HalfW, yPos - HalfH ), Vector2D( 1,0 ) ),
Vertex_t( Vector2D( xPos + HalfW, yPos + HalfH ), Vector2D( 1,1 ) ),
Vertex_t( Vector2D( xPos - HalfW, yPos + HalfH ), Vector2D( 0,1 ) )
};
surface()->DrawTexturedPolygon( 4, points );
//surface()->DrawTexturedRect(xPos - HalfW, yPos - HalfH,
//xPos + HalfW, yPos + HalfH);
}
}
}