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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "hudelement.h"
#include <vgui_controls/Panel.h>
#include <vgui/ISurface.h>
#include "clientmode.h"
#include "c_tf_player.h"
#include "tf_hud_crosshair.h"
#include "hud_crosshair.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/imesh.h"
#include "materialsystem/imaterialvar.h"
#include "VGuiMatSurface/IMatSystemSurface.h"
#include "tf_logic_halloween_2014.h"
#include "tf_gamerules.h"
#include "mathlib/mathlib.h"
ConVar cl_crosshair_red( "cl_crosshair_red", "200", FCVAR_ARCHIVE );
ConVar cl_crosshair_green( "cl_crosshair_green", "200", FCVAR_ARCHIVE );
ConVar cl_crosshair_blue( "cl_crosshair_blue", "200", FCVAR_ARCHIVE );
ConVar cl_crosshair_file( "cl_crosshair_file", "", FCVAR_ARCHIVE );
ConVar cl_crosshair_scale( "cl_crosshair_scale", "32.0", FCVAR_ARCHIVE );
using namespace vgui;
// Everything else is expecting to find "CHudCrosshair"
DECLARE_NAMED_HUDELEMENT( CHudTFCrosshair, CHudCrosshair );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CHudTFCrosshair::CHudTFCrosshair( const char *pName ) :
CHudCrosshair ( pName )
{
m_szPreviousCrosshair[0] = '\0';
m_iCrosshairTextureID = -1;
m_flTimeToHideUntil = -1.f;
ListenForGameEvent( "restart_timer_time" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CHudTFCrosshair::~CHudTFCrosshair( void )
{
if ( vgui::surface() && m_iCrosshairTextureID != -1 )
{
vgui::surface()->DestroyTextureID( m_iCrosshairTextureID );
m_iCrosshairTextureID = -1;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CHudTFCrosshair::ShouldDraw( void )
{
// turn off for the minigames
if ( CTFMinigameLogic::GetMinigameLogic() && CTFMinigameLogic::GetMinigameLogic()->GetActiveMinigame() )
return false;
if ( TFGameRules() && TFGameRules()->ShowMatchSummary() )
return false;
// turn off if the local player is a ghost
C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( pPlayer )
{
if ( pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_GHOST_MODE ) )
return false;
if ( pPlayer->IsTaunting() )
return false;
}
if ( m_flTimeToHideUntil > gpGlobals->curtime )
return false;
return BaseClass::ShouldDraw();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudTFCrosshair::LevelShutdown( void )
{
m_szPreviousCrosshair[0] = '\0';
if ( m_pCrosshairMaterial )
{
delete m_pCrosshairMaterial;
m_pCrosshairMaterial = NULL;
}
m_flTimeToHideUntil = -1.f;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudTFCrosshair::Init()
{
if ( m_iCrosshairTextureID == -1 )
{
m_iCrosshairTextureID = vgui::surface()->CreateNewTextureID();
}
m_flTimeToHideUntil = -1.f;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudTFCrosshair::FireGameEvent( IGameEvent * event )
{
if ( FStrEq( "restart_timer_time", event->GetName() ) )
{
if ( TFGameRules() && TFGameRules()->IsCompetitiveMode() )
{
int nTime = event->GetInt( "time" );
if ( ( nTime <= 10 ) && ( nTime > 0 ) )
{
m_flTimeToHideUntil = gpGlobals->curtime + nTime;
return;
}
}
}
m_flTimeToHideUntil = -1.f;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudTFCrosshair::Paint()
{
C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
if( !pPlayer )
return;
const char *crosshairfile = cl_crosshair_file.GetString();
if ( ( crosshairfile == NULL ) || ( Q_stricmp( m_szPreviousCrosshair, crosshairfile ) != 0 ) )
{
char buf[256];
Q_snprintf( buf, sizeof(buf), "vgui/crosshairs/%s", crosshairfile );
if ( m_iCrosshairTextureID != -1 )
{
vgui::surface()->DrawSetTextureFile( m_iCrosshairTextureID, buf, true, false );
}
if ( m_pCrosshairMaterial )
{
delete m_pCrosshairMaterial;
}
m_pCrosshairMaterial = vgui::surface()->DrawGetTextureMatInfoFactory( m_iCrosshairTextureID );
if ( !m_pCrosshairMaterial )
return;
// save the name to compare with the cvar in the future
Q_strncpy( m_szPreviousCrosshair, crosshairfile, sizeof(m_szPreviousCrosshair) );
}
if ( m_szPreviousCrosshair[0] == '\0' )
{
return BaseClass::Paint();
}
// This is somewhat cut'n'paste from CHudCrosshair::Paint(). Would be nice to unify them some more.
float x, y;
bool bBehindCamera;
GetDrawPosition ( &x, &y, &bBehindCamera );
if( bBehindCamera )
return;
float flWeaponScale = 1.f;
int iTextureW = 32;
int iTextureH = 32;
C_BaseCombatWeapon *pWeapon = pPlayer->GetActiveWeapon();
if ( pWeapon )
{
pWeapon->GetWeaponCrosshairScale( flWeaponScale );
}
float flPlayerScale = 1.0f;
#ifdef TF_CLIENT_DLL
Color clr( cl_crosshair_red.GetInt(), cl_crosshair_green.GetInt(), cl_crosshair_blue.GetInt(), 255 );
flPlayerScale = cl_crosshair_scale.GetFloat() / 32.0f; // the player can change the scale in the options/multiplayer tab
#else
Color clr = m_clrCrosshair;
#endif
float flWidth = flWeaponScale * flPlayerScale * (float)iTextureW;
float flHeight = flWeaponScale * flPlayerScale * (float)iTextureH;
int iWidth = (int)( flWidth + 0.5f );
int iHeight = (int)( flHeight + 0.5f );
int iX = (int)( x + 0.5f );
int iY = (int)( y + 0.5f );
vgui::ISurface *pSurf = vgui::surface();
pSurf->DrawSetColor( clr );
pSurf->DrawSetTexture( m_iCrosshairTextureID );
pSurf->DrawTexturedRect( iX-iWidth, iY-iHeight, iX+iWidth, iY+iHeight );
pSurf->DrawSetTexture(0);
}
|