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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "c_baseobject.h"
#include "ObjectControlPanel.h"
#include "hud_minimap.h"
#include "vgui_bitmapimage.h"
#include "c_vehicle_teleport_station.h"
#include <vgui/MouseCode.h>
class C_ObjMCVSelectionPanel;
CUtlLinkedList<C_ObjMCVSelectionPanel*,int> g_SelectionPanels;
// ------------------------------------------------------------------------------------------------ //
// C_ObjMCVSelectionPanel
// ------------------------------------------------------------------------------------------------ //
class C_ObjMCVSelectionPanel : public C_BaseObject
{
public:
DECLARE_CLASS( C_ObjMCVSelectionPanel, C_BaseObject );
DECLARE_CLIENTCLASS();
C_ObjMCVSelectionPanel();
~C_ObjMCVSelectionPanel();
typedef CHandle<C_VehicleTeleportStation> VehicleTeleportStationHandle;
CUtlVector<VehicleTeleportStationHandle> m_DeployedTeleportStations;
private:
static C_ObjMCVSelectionPanel *s_pSelectionPanel;
friend void RecvProxy_TeleportStationCount( void *pStruct, int objectID, int currentArrayLength );
friend void RecvProxy_TeleportStationElement( const CRecvProxyData *pData, void *pStruct, void *pOut );
C_ObjMCVSelectionPanel( const C_ObjMCVSelectionPanel & );
};
void RecvProxy_TeleportStationCount( void *pStruct, int objectID, int currentArrayLength )
{
C_ObjMCVSelectionPanel *pPanel = (C_ObjMCVSelectionPanel*)pStruct;
if ( pPanel->m_DeployedTeleportStations.Count() != currentArrayLength )
{
pPanel->m_DeployedTeleportStations.SetSize( currentArrayLength );
}
}
void RecvProxy_TeleportStationElement( const CRecvProxyData *pData, void *pStruct, void *pOut )
{
C_ObjMCVSelectionPanel *pPanel = (C_ObjMCVSelectionPanel*)pStruct;
Assert( pData->m_iElement < pPanel->m_DeployedTeleportStations.Count() );
RecvProxy_IntToEHandle( pData, pStruct, &pPanel->m_DeployedTeleportStations[pData->m_iElement] );
}
IMPLEMENT_CLIENTCLASS_DT( C_ObjMCVSelectionPanel, DT_MCVSelectionPanel, CObjMCVSelectionPanel )
RecvPropVirtualArray(
RecvProxy_TeleportStationCount,
32,
RecvPropEHandle( "teleport_station_element", 0, 0, RecvProxy_TeleportStationElement ),
"teleport_stations" )
END_RECV_TABLE()
C_ObjMCVSelectionPanel::C_ObjMCVSelectionPanel()
{
g_SelectionPanels.AddToTail( this );
}
C_ObjMCVSelectionPanel::~C_ObjMCVSelectionPanel()
{
g_SelectionPanels.FindAndRemove( this );
}
//-----------------------------------------------------------------------------
// CMCVMinimapPanel
//-----------------------------------------------------------------------------
class CMCVMinimapPanel : public CMinimapPanel
{
public:
DECLARE_CLASS( CMCVMinimapPanel, CMinimapPanel );
CMCVMinimapPanel( vgui::Panel *pParent, const char *pElementName );
virtual ~CMCVMinimapPanel();
virtual void Paint();
virtual void OnMousePressed( vgui::MouseCode code );
virtual void OnCursorMoved( int x, int y );
private:
BitmapImage m_MCVImage;
BitmapImage m_SelectedMCVImage;
int m_LastX, m_LastY;
};
CMCVMinimapPanel::CMCVMinimapPanel( vgui::Panel *pParent, const char *pElementName )
: CMinimapPanel( pElementName )
{
SetParent( pParent );
m_MCVImage.Init( GetVPanel(), "hud/minimap/icon_mcv_unselected" );
m_SelectedMCVImage.Init( GetVPanel(), "hud/minimap/icon_mcv_selected" );
m_LastX = m_LastY = 0;
}
CMCVMinimapPanel::~CMCVMinimapPanel()
{
}
void CMCVMinimapPanel::Paint()
{
// Draw the minimap.
BaseClass::Paint();
// Now draw the MCVs.
if ( g_SelectionPanels.Count() > 0 )
{
C_ObjMCVSelectionPanel *pPanel = g_SelectionPanels[ g_SelectionPanels.Head() ];
C_BaseEntity *pSelectedMCV = C_BaseTFPlayer::GetLocalPlayer()->GetSelectedMCV();
for ( int i=0; i < pPanel->m_DeployedTeleportStations.Count(); i++ )
{
C_VehicleTeleportStation *pStation = pPanel->m_DeployedTeleportStations[i];
if ( pStation )
{
float x, y;
if ( WorldToMinimap( MINIMAP_CLAMP, pStation->GetAbsOrigin(), x, y ) )
{
int size = 20;
if ( pStation == pSelectedMCV )
m_SelectedMCVImage.DoPaint( x-size/2, y-size/2, size, size );
else
m_MCVImage.DoPaint( x-size/2, y-size/2, size, size );
}
}
}
}
}
void CMCVMinimapPanel::OnMousePressed( vgui::MouseCode code )
{
BaseClass::OnMousePressed( code );
if ( code != vgui::MOUSE_LEFT )
return;
// Now draw the MCVs.
if ( g_SelectionPanels.Count() > 0 )
{
C_ObjMCVSelectionPanel *pPanel = g_SelectionPanels[ g_SelectionPanels.Head() ];
// Find the closest MCV to their mouse press.
int iClosest = -1;
float flClosest = 1e24;
Vector2D curMousePos( m_LastX, m_LastY );
for ( int i=0; i < pPanel->m_DeployedTeleportStations.Count(); i++ )
{
C_VehicleTeleportStation *pStation = pPanel->m_DeployedTeleportStations[i];
if ( pStation )
{
Vector2D mcvPos;
if ( WorldToMinimap( MINIMAP_CLAMP, pStation->GetAbsOrigin(), mcvPos.x, mcvPos.y ) )
{
float flTestDist = mcvPos.DistTo( curMousePos );
if ( flTestDist < flClosest )
{
flClosest = flTestDist;
iClosest = i;
}
}
}
}
if ( iClosest != -1 && flClosest < 10 )
{
C_VehicleTeleportStation *pClosest = pPanel->m_DeployedTeleportStations[iClosest];
char str[512];
Q_snprintf( str, sizeof( str ), "SelectMCV %d", pClosest->entindex() );
pPanel->SendClientCommand( str );
}
}
}
void CMCVMinimapPanel::OnCursorMoved( int x, int y )
{
BaseClass::OnCursorMoved( x, y );
m_LastX = x;
m_LastY = y;
}
// ------------------------------------------------------------------------------------------------ //
// CMCVSelectionPanel
// ------------------------------------------------------------------------------------------------ //
class CMCVSelectionPanel : public CObjectControlPanel
{
DECLARE_CLASS( CMCVSelectionPanel, CObjectControlPanel );
public:
CMCVSelectionPanel( vgui::Panel *parent, const char *panelName );
virtual ~CMCVSelectionPanel();
virtual bool Init( KeyValues* pKeyValues, VGuiScreenInitData_t* pInitData );
virtual void OnCommand( const char *command );
private:
CMCVMinimapPanel *m_pMinimapPanel;
};
DECLARE_VGUI_SCREEN_FACTORY( CMCVSelectionPanel, "mcv_selection_panel" );
CMCVSelectionPanel::CMCVSelectionPanel( vgui::Panel *parent, const char *panelName )
: BaseClass( parent, "CMCVSelectionPanel" )
{
m_pMinimapPanel = new CMCVMinimapPanel( this, "MinimapPanel" );
m_pMinimapPanel->SetZPos( 10 );
m_pMinimapPanel->Init( NULL );
}
CMCVSelectionPanel::~CMCVSelectionPanel()
{
delete m_pMinimapPanel;
}
bool CMCVSelectionPanel::Init( KeyValues* pKeyValues, VGuiScreenInitData_t* pInitData )
{
if ( !BaseClass::Init( pKeyValues, pInitData ) )
return false;
m_pMinimapPanel->LevelInit( engine->GetLevelName() );
m_pMinimapPanel->SetVisible( true );
return true;
}
void CMCVSelectionPanel::OnCommand( const char *command )
{
BaseClass::OnCommand( command );
}
|