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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Client DLL VGUI2 Viewport
//
// $Workfile: $
// $Date: $
//
//-----------------------------------------------------------------------------
// $Log: $
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#pragma warning( disable : 4800 ) // disable forcing int to bool performance warning
// VGUI panel includes
#include <vgui_controls/Panel.h>
#include <vgui/ISurface.h>
#include <KeyValues.h>
#include <vgui/Cursor.h>
#include <vgui/IScheme.h>
#include <vgui/IVGui.h>
#include <vgui/ILocalize.h>
#include <vgui/VGUI.h>
#include "tier0/icommandline.h"
// client dll/engine defines
#include "hud.h"
#include <voice_status.h>
// viewport definitions
#include <baseviewport.h>
#include "tf_viewport.h"
#include "tf_teammenu.h"
#include "vguicenterprint.h"
#include "text_message.h"
#include "tf_classmenu.h"
#include "tf_textwindow.h"
#include "tf_clientscoreboard.h"
#include "tf_spectatorgui.h"
#include "intromenu.h"
#include "tf_intromenu.h"
#include "tf_controls.h"
#include "tf_mapinfomenu.h"
#include "tf_roundinfo.h"
#include "item_pickup_panel.h"
#include "character_info_panel.h"
#include "tf_hud_arena_winpanel.h"
#include "tf_arenateammenu.h"
#include "tf_hud_pve_winpanel.h"
#include "hud_chat.h"
#include "tf_giveawayitempanel.h"
#if defined( REPLAY_ENABLED )
#include "replay/vgui/replaybrowsermainpanel.h"
#endif
#include "clientmode_tf.h"
#include "ienginevgui.h"
#include "tf_hud_mainmenuoverride.h"
#include "c_tf_objective_resource.h"
#include "quest_log_panel.h"
//#include "tf_overview.h"
/*
CON_COMMAND( spec_help, "Show spectator help screen")
{
if ( gViewPortInterface )
gViewPortInterface->ShowPanel( PANEL_INFO, true );
}
CON_COMMAND( spec_menu, "Activates spectator menu")
{
bool bShowIt = true;
C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
if ( pPlayer && !pPlayer->IsObserver() )
return;
if ( args.ArgC() == 2 )
{
bShowIt = atoi( args[ 1 ] ) == 1;
}
if ( gViewPortInterface )
gViewPortInterface->ShowPanel( PANEL_SPECMENU, bShowIt );
}
*/
CON_COMMAND( showmapinfo, "Show map info panel" )
{
if ( !gViewPortInterface )
return;
C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
// don't let the player open the team menu themselves until they're a spectator or they're on a regular team and have picked a class
if ( pPlayer )
{
if ( ( pPlayer->GetTeamNumber() == TEAM_SPECTATOR ) ||
( ( pPlayer->GetTeamNumber() != TEAM_UNASSIGNED ) && ( pPlayer->GetPlayerClass()->GetClassIndex() != TF_CLASS_UNDEFINED ) ) )
{
// close all the other panels that could be open
gViewPortInterface->ShowPanel( PANEL_TEAM, false );
gViewPortInterface->ShowPanel( PANEL_ARENA_TEAM, false );
gViewPortInterface->ShowPanel( PANEL_ARENA_WIN, false );
gViewPortInterface->ShowPanel( PANEL_PVE_WIN, false );
gViewPortInterface->ShowPanel( PANEL_CLASS_RED, false );
gViewPortInterface->ShowPanel( PANEL_CLASS_BLUE, false );
gViewPortInterface->ShowPanel( PANEL_INTRO, false );
gViewPortInterface->ShowPanel( PANEL_ROUNDINFO, false );
gViewPortInterface->ShowPanel( PANEL_MAPINFO, true );
gViewPortInterface->ShowPanel( PANEL_GIVEAWAY_ITEM, false );
}
}
}
CON_COMMAND( changeteam, "Choose a new team" )
{
if ( !gViewPortInterface )
return;
C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
// don't let the player open the team menu themselves until they're on a team
if ( pPlayer && pPlayer->CanShowTeamMenu() )
{
if ( TFGameRules()->IsInArenaMode() == true && tf_arena_use_queue.GetBool() == true )
{
gViewPortInterface->ShowPanel( PANEL_ARENA_TEAM, true );
}
else
{
gViewPortInterface->ShowPanel( PANEL_TEAM, true );
}
}
}
CON_COMMAND( changeclass, "Choose a new class" )
{
if ( !gViewPortInterface )
return;
C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( pPlayer && pPlayer->CanShowClassMenu() )
{
if ( TFGameRules() && TFGameRules()->IsInArenaMode() && pPlayer->IsAlive() == true )
{
if ( pPlayer->GetTeamNumber() > LAST_SHARED_TEAM && ( tf_arena_force_class.GetBool() == true || TFGameRules()->InStalemate() == true ) )
{
CBaseHudChat *pHUDChat = (CBaseHudChat *)GET_HUDELEMENT( CHudChat );
if ( pHUDChat )
{
char szLocalized[100];
g_pVGuiLocalize->ConvertUnicodeToANSI( g_pVGuiLocalize->Find( "#TF_Arena_NoClassChange" ), szLocalized, sizeof(szLocalized) );
pHUDChat->ChatPrintf( pPlayer->entindex(), CHAT_FILTER_NONE, "%s ", szLocalized );
}
return;
}
}
if ( TFGameRules() && TFGameRules()->IsMannVsMachineMode() )
{
if ( !TFGameRules()->InSetup() )
{
CBaseHudChat *pHUDChat = (CBaseHudChat *)GET_HUDELEMENT( CHudChat );
if ( pHUDChat )
{
char szLocalized[100];
g_pVGuiLocalize->ConvertUnicodeToANSI( g_pVGuiLocalize->Find( "#TF_MVM_NoClassChangeAfterSetup" ), szLocalized, sizeof(szLocalized) );
pHUDChat->ChatPrintf( pPlayer->entindex(), CHAT_FILTER_NONE, "%s ", szLocalized );
}
return;
}
}
switch( pPlayer->GetTeamNumber() )
{
case TF_TEAM_RED:
gViewPortInterface->ShowPanel( PANEL_CLASS_RED, true );
break;
case TF_TEAM_BLUE:
gViewPortInterface->ShowPanel( PANEL_CLASS_BLUE, true );
break;
case TEAM_SPECTATOR:
{
if( TFGameRules() && TFGameRules()->IsInArenaMode() == true && tf_arena_use_queue.GetBool() == true )
{
gViewPortInterface->ShowPanel( PANEL_CLASS_BLUE, true );
}
}
break;
default:
break;
}
}
}
CON_COMMAND( togglescores, "Toggles score panel")
{
if ( !gViewPortInterface )
return;
IViewPortPanel *scoreboard = gViewPortInterface->FindPanelByName( PANEL_SCOREBOARD );
if ( !scoreboard )
return;
if ( scoreboard->IsVisible() )
{
gViewPortInterface->ShowPanel( scoreboard, false );
GetClientVoiceMgr()->StopSquelchMode();
}
else
{
gViewPortInterface->ShowPanel( scoreboard, true );
}
}
CON_COMMAND( show_quest_log, "Show the quest log panel" )
{
if ( !gViewPortInterface )
return;
IViewPortPanel *pQuestLog = gViewPortInterface->FindPanelByName( PANEL_QUEST_LOG );
if ( !pQuestLog )
return;
if ( pQuestLog->IsVisible() )
{
gViewPortInterface->ShowPanel( pQuestLog, false );
}
else
{
gViewPortInterface->ShowPanel( pQuestLog, true );
}
}
TFViewport::TFViewport()
{
ivgui()->AddTickSignal( GetVPanel(), 0 );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
TFViewport::~TFViewport()
{
}
//-----------------------------------------------------------------------------
// Purpose: called when the VGUI subsystem starts up
// Creates the sub panels and initialises them
//-----------------------------------------------------------------------------
void TFViewport::Start( IGameUIFuncs *pGameUIFuncs, IGameEventManager2 * pGameEventManager )
{
BaseClass::Start( pGameUIFuncs, pGameEventManager );
}
void TFViewport::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
gHUD.InitColors( pScheme );
SetPaintBackgroundEnabled( false );
// Precache some font characters for the 360
if ( IsX360() || CommandLine()->CheckParm( "-precachefontchars" ) || CommandLine()->CheckParm( "-precachefontintlchars" ) )
{
const wchar_t *pAllChars = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.!:";
const wchar_t *pNumbers = L"0123456789";
// Try some tricky characters and some international characters with accents, etc.
static const wchar_t IntlChars[] = { 'a', 'b', 'c', 'i', 'o', 'y', 'A', 'B', 'C', 0xbf, 0xc1, 0xd1, 0xd3, 0x00 };
if ( CommandLine()->CheckParm( "-precachefontintlchars" ) )
pAllChars = IntlChars;
vgui::surface()->PrecacheFontCharacters( pScheme->GetFont( "ScoreboardTeamName" ), pAllChars );
vgui::surface()->PrecacheFontCharacters( pScheme->GetFont( "ScoreboardMedium" ), pAllChars );
vgui::surface()->PrecacheFontCharacters( pScheme->GetFont( "ScoreboardSmall" ), pAllChars );
vgui::surface()->PrecacheFontCharacters( pScheme->GetFont( "ScoreboardVerySmall" ), pAllChars );
vgui::surface()->PrecacheFontCharacters( pScheme->GetFont( "TFFontMedium" ), pAllChars );
vgui::surface()->PrecacheFontCharacters( pScheme->GetFont( "TFFontSmall" ), pAllChars );
vgui::surface()->PrecacheFontCharacters( pScheme->GetFont( "HudFontMedium" ), pAllChars );
vgui::surface()->PrecacheFontCharacters( pScheme->GetFont( "HudFontMediumSmallSecondary" ), pAllChars );
vgui::surface()->PrecacheFontCharacters( pScheme->GetFont( "HudFontSmall" ), pAllChars );
vgui::surface()->PrecacheFontCharacters( pScheme->GetFont( "DefaultSmall" ), pAllChars );
vgui::surface()->PrecacheFontCharacters( pScheme->GetFont( "ScoreboardTeamScore" ), pNumbers );
}
}
//
// This is the main function of the viewport. Right here is where we create our class menu,
// team menu, and anything else that we want to turn on and off in the UI.
//
IViewPortPanel* TFViewport::CreatePanelByName(const char *szPanelName)
{
IViewPortPanel* newpanel = NULL;
// overwrite MOD specific panel creation
if ( Q_strcmp( PANEL_SCOREBOARD, szPanelName ) == 0 )
{
newpanel = new CTFClientScoreBoardDialog( this );
}
else if ( Q_strcmp( PANEL_SPECGUI, szPanelName ) == 0 )
{
newpanel = new CTFSpectatorGUI( this );
}
else if ( Q_strcmp( PANEL_SPECMENU, szPanelName ) == 0 )
{
// newpanel = new CTFSpectatorGUI( this );
}
else if ( Q_strcmp( PANEL_OVERVIEW, szPanelName ) == 0 )
{
// newpanel = new CTFMapOverview( this );
}
else if ( Q_strcmp( PANEL_INFO, szPanelName ) == 0 )
{
newpanel = new CTFTextWindow( this );
}
else if ( Q_strcmp( PANEL_MAPINFO, szPanelName ) == 0 )
{
newpanel = new CTFMapInfoMenu( this );
}
else if ( Q_strcmp( PANEL_ROUNDINFO, szPanelName ) == 0 )
{
newpanel = new CTFRoundInfo( this );
}
else if ( Q_strcmp( PANEL_TEAM, szPanelName ) == 0 )
{
newpanel = new CTFTeamMenu( this );
}
else if ( Q_strcmp( PANEL_CLASS_RED, szPanelName ) == 0 )
{
newpanel = new CTFClassMenu_Red( this );
}
else if ( Q_strcmp( PANEL_CLASS_BLUE, szPanelName ) == 0 )
{
newpanel = new CTFClassMenu_Blue( this );
}
else if ( Q_strcmp( PANEL_INTRO, szPanelName ) == 0 )
{
newpanel = new CTFIntroMenu( this );
}
else if ( Q_strcmp( PANEL_ARENA_TEAM, szPanelName ) == 0 )
{
newpanel = new CTFArenaTeamMenu( this );
}
else if ( Q_strcmp( PANEL_ARENA_WIN, szPanelName ) == 0 )
{
newpanel = new CTFArenaWinPanel( this );
}
else if ( Q_strcmp( PANEL_PVE_WIN, szPanelName ) == 0 )
{
newpanel = new CTFPVEWinPanel( this );
}
else if ( Q_strcmp( PANEL_GIVEAWAY_ITEM, szPanelName ) == 0 )
{
newpanel = new CTFGiveawayItemPanel( this );
}
else if ( Q_strcmp( PANEL_MAINMENUOVERRIDE, szPanelName ) == 0 )
{
newpanel = new CHudMainMenuOverride( this );
}
else if ( V_strcmp( PANEL_QUEST_LOG, szPanelName ) == 0 )
{
newpanel = new CQuestLogPanel( this );
}
else
{
// create a generic base panel, don't add twice
newpanel = BaseClass::CreatePanelByName( szPanelName );
}
return newpanel;
}
void TFViewport::CreateDefaultPanels( void )
{
AddNewPanel( CreatePanelByName( PANEL_MAPINFO ), "PANEL_MAPINFO" );
AddNewPanel( CreatePanelByName( PANEL_TEAM ), "PANEL_TEAM" );
AddNewPanel( CreatePanelByName( PANEL_CLASS_RED ), "PANEL_CLASS_RED" );
AddNewPanel( CreatePanelByName( PANEL_CLASS_BLUE ), "PANEL_CLASS_BLUE" );
AddNewPanel( CreatePanelByName( PANEL_INTRO ), "PANEL_INTRO" );
AddNewPanel( CreatePanelByName( PANEL_ROUNDINFO ), "PANEL_ROUNDINFO" );
AddNewPanel( CreatePanelByName( PANEL_ARENA_WIN ), "PANEL_ARENA_WIN" );
AddNewPanel( CreatePanelByName( PANEL_ARENA_TEAM ), "PANEL_ARENA_TEAM" );
AddNewPanel( CreatePanelByName( PANEL_PVE_WIN ), "PANEL_PVE_WIN" );
AddNewPanel( CreatePanelByName( PANEL_GIVEAWAY_ITEM ), "PANEL_GIVEAWAY_ITEM" );
AddNewPanel( CreatePanelByName( PANEL_QUEST_LOG ), "PANEL_QUEST_LOG" );
CHudMainMenuOverride *pMMOverride = (CHudMainMenuOverride*)CreatePanelByName( PANEL_MAINMENUOVERRIDE );
if ( pMMOverride )
{
AddNewPanel( pMMOverride, "PANEL_MAINMENUOVERRIDE" );
pMMOverride->AttachToGameUI();
}
BaseClass::CreateDefaultPanels();
}
int TFViewport::GetDeathMessageStartHeight( void )
{
int y = YRES(2);
if ( IsX360() )
{
y = YRES(36);
}
if ( g_pSpectatorGUI && g_pSpectatorGUI->IsVisible() )
{
y = YRES(2) + g_pSpectatorGUI->GetTopBarHeight();
}
return y;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void TFViewport::OnScreenSizeChanged( int iOldWide, int iOldTall )
{
BaseClass::OnScreenSizeChanged( iOldWide, iOldTall );
// we've changed resolution, let's try to figure out if we need to show any of our menus
if ( !gViewPortInterface )
return;
C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( pPlayer )
{
// are we on a team yet?
if ( pPlayer->GetTeamNumber() == TEAM_UNASSIGNED )
{
engine->ClientCmd( "show_motd" );
}
else if ( ( pPlayer->GetTeamNumber() != TEAM_SPECTATOR ) && ( pPlayer->m_Shared.GetDesiredPlayerClassIndex() == TF_CLASS_UNDEFINED ) )
{
if ( tf_arena_force_class.GetBool() == false )
{
switch( pPlayer->GetTeamNumber() )
{
case TF_TEAM_RED:
gViewPortInterface->ShowPanel( PANEL_CLASS_RED, true );
break;
case TF_TEAM_BLUE:
gViewPortInterface->ShowPanel( PANEL_CLASS_BLUE, true );
break;
}
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void TFViewport::OnTick()
{
m_pAnimController->UpdateAnimations( gpGlobals->curtime );
}
|