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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include <stdio.h>
#include <cdll_client_int.h>
#include "classmenu.h"
#include <vgui/IScheme.h>
#include <vgui/ILocalize.h>
#include <vgui/ISurface.h>
#include <KeyValues.h>
#include <vgui_controls/ImageList.h>
#include <filesystem.h>
#include <vgui_controls/TextEntry.h>
#include <vgui_controls/Button.h>
#include <vgui_controls/Panel.h>
#include "cdll_util.h"
#include "IGameUIFuncs.h" // for key bindings
#ifndef _XBOX
extern IGameUIFuncs *gameuifuncs; // for key binding details
#endif
#include <game/client/iviewport.h>
#include <stdlib.h> // MAX_PATH define
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
#ifdef TF_CLIENT_DLL
#define HUD_CLASSAUTOKILL_FLAGS ( FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_USERINFO )
#else
#define HUD_CLASSAUTOKILL_FLAGS ( FCVAR_CLIENTDLL | FCVAR_ARCHIVE )
#endif // !TF_CLIENT_DLL
ConVar hud_classautokill( "hud_classautokill", "1", HUD_CLASSAUTOKILL_FLAGS, "Automatically kill player after choosing a new playerclass." );
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CClassMenu::CClassMenu(IViewPort *pViewPort) : Frame(NULL, PANEL_CLASS)
{
m_pViewPort = pViewPort;
m_iScoreBoardKey = BUTTON_CODE_INVALID; // this is looked up in Activate()
m_iTeam = 0;
// initialize dialog
SetTitle("", true);
// load the new scheme early!!
SetScheme("ClientScheme");
SetMoveable(false);
SetSizeable(false);
// hide the system buttons
SetTitleBarVisible( false );
SetProportional(true);
// info window about this class
m_pPanel = new EditablePanel( this, "ClassInfo" );
LoadControlSettings( "Resource/UI/ClassMenu.res" );
}
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CClassMenu::CClassMenu(IViewPort *pViewPort, const char *panelName) : Frame(NULL, panelName)
{
m_pViewPort = pViewPort;
m_iScoreBoardKey = BUTTON_CODE_INVALID; // this is looked up in Activate()
m_iTeam = 0;
// initialize dialog
SetTitle("", true);
// load the new scheme early!!
SetScheme("ClientScheme");
SetMoveable(false);
SetSizeable(false);
// hide the system buttons
SetTitleBarVisible( false );
SetProportional(true);
// info window about this class
m_pPanel = new EditablePanel( this, "ClassInfo" );
// Inheriting classes are responsible for calling LoadControlSettings()!
}
//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
CClassMenu::~CClassMenu()
{
}
MouseOverPanelButton* CClassMenu::CreateNewMouseOverPanelButton(EditablePanel *panel)
{
return new MouseOverPanelButton(this, "MouseOverPanelButton", panel);
}
Panel *CClassMenu::CreateControlByName(const char *controlName)
{
if( !Q_stricmp( "MouseOverPanelButton", controlName ) )
{
MouseOverPanelButton *newButton = CreateNewMouseOverPanelButton( m_pPanel );
m_mouseoverButtons.AddToTail( newButton );
return newButton;
}
else
{
return BaseClass::CreateControlByName( controlName );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CClassMenu::Reset()
{
for ( int i = 0 ; i < GetChildCount() ; ++i )
{
// Hide the subpanel for the MouseOverPanelButtons
MouseOverPanelButton *pPanel = dynamic_cast<MouseOverPanelButton *>( GetChild( i ) );
if ( pPanel )
{
pPanel->HidePage();
}
}
// Turn the first button back on again (so we have a default description shown)
Assert( m_mouseoverButtons.Count() );
for ( int i=0; i<m_mouseoverButtons.Count(); ++i )
{
if ( i == 0 )
{
m_mouseoverButtons[i]->ShowPage(); // Show the first page
}
else
{
m_mouseoverButtons[i]->HidePage(); // Hide the rest
}
}
}
//-----------------------------------------------------------------------------
// Purpose: Called when the user picks a class
//-----------------------------------------------------------------------------
void CClassMenu::OnCommand( const char *command )
{
if ( Q_stricmp( command, "vguicancel" ) )
{
engine->ClientCmd( const_cast<char *>( command ) );
#if !defined( CSTRIKE_DLL ) && !defined( TF_CLIENT_DLL )
// They entered a command to change their class, kill them so they spawn with
// the new class right away
if ( hud_classautokill.GetBool() )
{
engine->ClientCmd( "kill" );
}
#endif // !CSTRIKE_DLL && !TF_CLIENT_DLL
}
Close();
gViewPortInterface->ShowBackGround( false );
BaseClass::OnCommand( command );
}
//-----------------------------------------------------------------------------
// Purpose: shows the class menu
//-----------------------------------------------------------------------------
void CClassMenu::ShowPanel(bool bShow)
{
if ( bShow )
{
Activate();
SetMouseInputEnabled( true );
// load a default class page
for ( int i=0; i<m_mouseoverButtons.Count(); ++i )
{
if ( i == 0 )
{
m_mouseoverButtons[i]->ShowPage(); // Show the first page
}
else
{
m_mouseoverButtons[i]->HidePage(); // Hide the rest
}
}
if ( m_iScoreBoardKey == BUTTON_CODE_INVALID )
{
m_iScoreBoardKey = gameuifuncs->GetButtonCodeForBind( "showscores" );
}
}
else
{
SetVisible( false );
SetMouseInputEnabled( false );
}
m_pViewPort->ShowBackGround( bShow );
}
void CClassMenu::SetData(KeyValues *data)
{
m_iTeam = data->GetInt( "team" );
}
//-----------------------------------------------------------------------------
// Purpose: Sets the text of a control by name
//-----------------------------------------------------------------------------
void CClassMenu::SetLabelText(const char *textEntryName, const char *text)
{
Label *entry = dynamic_cast<Label *>(FindChildByName(textEntryName));
if (entry)
{
entry->SetText(text);
}
}
//-----------------------------------------------------------------------------
// Purpose: Sets the visibility of a button by name
//-----------------------------------------------------------------------------
void CClassMenu::SetVisibleButton(const char *textEntryName, bool state)
{
Button *entry = dynamic_cast<Button *>(FindChildByName(textEntryName));
if (entry)
{
entry->SetVisible(state);
}
}
void CClassMenu::OnKeyCodePressed(KeyCode code)
{
int nDir = 0;
switch ( code )
{
case KEY_XBUTTON_UP:
case KEY_XSTICK1_UP:
case KEY_XSTICK2_UP:
case KEY_UP:
case KEY_XBUTTON_LEFT:
case KEY_XSTICK1_LEFT:
case KEY_XSTICK2_LEFT:
case KEY_LEFT:
nDir = -1;
break;
case KEY_XBUTTON_DOWN:
case KEY_XSTICK1_DOWN:
case KEY_XSTICK2_DOWN:
case KEY_DOWN:
case KEY_XBUTTON_RIGHT:
case KEY_XSTICK1_RIGHT:
case KEY_XSTICK2_RIGHT:
case KEY_RIGHT:
nDir = 1;
break;
}
if ( m_iScoreBoardKey != BUTTON_CODE_INVALID && m_iScoreBoardKey == code )
{
gViewPortInterface->ShowPanel( PANEL_SCOREBOARD, true );
gViewPortInterface->PostMessageToPanel( PANEL_SCOREBOARD, new KeyValues( "PollHideCode", "code", code ) );
}
else if ( nDir != 0 )
{
CUtlSortVector< SortedPanel_t, CSortedPanelYLess > vecSortedButtons;
VguiPanelGetSortedChildButtonList( this, (void*)&vecSortedButtons, "&", 0 );
int nNewArmed = VguiPanelNavigateSortedChildButtonList( (void*)&vecSortedButtons, nDir );
if ( nNewArmed != -1 )
{
// Handled!
if ( nNewArmed < m_mouseoverButtons.Count() )
{
m_mouseoverButtons[ nNewArmed ]->OnCursorEntered();
}
return;
}
}
else
{
BaseClass::OnKeyCodePressed( code );
}
}
|