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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: This is a panel which is rendered on top of an entity
//
// $Revision: $
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "vgui_EntityPanel.h"
#include "ienginevgui.h"
#include "c_BaseTFPlayer.h"
#include "clientmode_commander.h"
#include "hud_commander_statuspanel.h"
#include <KeyValues.h>
#include "commanderoverlaypanel.h"
#include <vgui/IVGui.h>
#include "cdll_util.h"
#include "view.h"
//-----------------------------------------------------------------------------
// constructor
//-----------------------------------------------------------------------------
CEntityPanel::CEntityPanel( vgui::Panel *pParent, const char *panelName )
: BaseClass( pParent, panelName )
{
SetPaintBackgroundEnabled( false );
m_pBaseEntity = NULL;
// FIXME: ComputeParent is yucky... can we be rid of it?
if (!pParent)
{
ComputeParent();
}
m_szMouseOverText[ 0 ] = 0;
// Send mouse inputs (but not cursorenter/exit for now) up to parent
SetReflectMouse( true );
m_bShowInNormal = false;
m_flScale = 0;
m_OffsetX = 0;
m_OffsetY = 0;
}
//-----------------------------------------------------------------------------
// Attach to a new entity
//-----------------------------------------------------------------------------
void CEntityPanel::SetEntity( C_BaseEntity* pEntity )
{
m_pBaseEntity = pEntity;
// Recompute position
OnTick();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEntityPanel::ComputeParent( void )
{
vgui::VPANEL parent = NULL;
if ( IsLocalPlayerInTactical() || !m_bShowInNormal )
{
CClientModeCommander *commander = ( CClientModeCommander * )ClientModeCommander();
Assert( commander );
parent = commander->GetCommanderOverlayPanel()->GetVPanel();
}
else
{
parent = enginevgui->GetPanel( PANEL_CLIENTDLL );
}
if ( !GetParent() || ( GetParent()->GetVPanel() != parent ) )
{
SetParent( parent );
}
}
//-----------------------------------------------------------------------------
// Purpose: Compute the size of the panel based upon the commander's zoom level
//-----------------------------------------------------------------------------
void CEntityPanel::ComputeAndSetSize( void )
{
m_flScale = 1.0;
// Scale the image
// Use different scales in tactical / normal
if ( IsLocalPlayerInTactical() )
{
CClientModeCommander *commander = ( CClientModeCommander * )ClientModeCommander();
Assert( commander );
float flZoom = commander->GetCommanderOverlayPanel()->GetZoom();
// Scale our size
m_flScale = 0.75 + (0.25 * (1.0 - flZoom)); // 1/2 size at max zoomed out, full size by half zoomed in
}
else if ( m_pBaseEntity )
{
// Get distance to entity
float flDistance = (m_pBaseEntity->GetRenderOrigin() - MainViewOrigin()).Length();
flDistance *= 2;
m_flScale = 0.25 + MAX( 0, 2.0 - (flDistance / 2048) );
}
// Update the size
int w = m_iOrgWidth * m_flScale;
int h = m_iOrgHeight * m_flScale;
SetSize( w,h );
// Update the offsets too
m_OffsetX = m_iOrgOffsetX * m_flScale;
m_OffsetY = m_iOrgOffsetY * m_flScale;
}
//-----------------------------------------------------------------------------
// initialization
//-----------------------------------------------------------------------------
bool CEntityPanel::Init( ::KeyValues* pInitData, C_BaseEntity* pEntity )
{
Assert( pInitData && pEntity );
m_pBaseEntity = pEntity;
if ( pInitData->GetInt( "showinnormalmode", 0 ) )
{
m_bShowInNormal = true;
}
// get the size...
int w, h;
if (!ParseCoord( pInitData, "offset", m_OffsetX, m_OffsetY ))
return false;
if (!ParseCoord( pInitData, "size", w, h ))
return false;
const char *mouseover = pInitData->GetString( "mousehint", "" );
if ( mouseover && mouseover[ 0 ] )
{
Q_strncpy( m_szMouseOverText, mouseover, sizeof( m_szMouseOverText ) );
}
SetSize( w, h );
m_iOrgWidth = w;
m_iOrgHeight = h;
m_iOrgOffsetX = m_OffsetX;
m_iOrgOffsetY = m_OffsetY;
// we need updating
vgui::ivgui()->AddTickSignal( GetVPanel() );
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Determine where our entity is in screen space.
//-----------------------------------------------------------------------------
void CEntityPanel::GetEntityPosition( int& sx, int& sy )
{
if (!m_pBaseEntity)
{
sx = sy = -1.0f;
return;
}
GetTargetInScreenSpace( m_pBaseEntity, sx, sy );
}
//-----------------------------------------------------------------------------
// Should we draw?.
//-----------------------------------------------------------------------------
bool CEntityPanel::ShouldDraw()
{
return ( ( IsLocalPlayerInTactical() && ClientModeCommander()->ShouldDrawEntity( m_pBaseEntity ) ) ||
( !IsLocalPlayerInTactical() && m_bShowInNormal) );
}
//-----------------------------------------------------------------------------
// called when we're ticked...
//-----------------------------------------------------------------------------
void CEntityPanel::OnTick()
{
// Determine if panel parent should switch
ComputeParent();
// If we should shouldn't draw, don't bother with any of this
if ( !ShouldDraw() )
return;
// Update our current position
int sx, sy;
GetEntityPosition( sx, sy );
// Recalculate our size
ComputeAndSetSize();
// Set the position
SetPos( (int)(sx + m_OffsetX + 0.5f), (int)(sy + m_OffsetY + 0.5f));
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEntityPanel::OnCursorEntered()
{
if ( m_szMouseOverText[ 0 ] )
{
StatusPrint( TYPE_HINT, "%s", m_szMouseOverText );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEntityPanel::OnCursorExited()
{
if ( m_szMouseOverText[ 0 ] )
{
StatusClear();
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : char const
//-----------------------------------------------------------------------------
const char *CEntityPanel::GetMouseOverText( void )
{
return m_szMouseOverText;
}
|