-
Notifications
You must be signed in to change notification settings - Fork 271
/
Copy pathvgui_baseui_interface.cpp
2381 lines (1952 loc) · 66.1 KB
/
vgui_baseui_interface.cpp
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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Implements all the functions exported by the GameUI dll
//
// $NoKeywords: $
//===========================================================================//
#include "client_pch.h"
#include "tier0/platform.h"
#ifdef IS_WINDOWS_PC
#include "winlite.h"
#endif
#include "appframework/ilaunchermgr.h"
#include <vgui_controls/Panel.h>
#include <vgui_controls/EditablePanel.h>
#include <matsys_controls/matsyscontrols.h>
#include <vgui/Cursor.h>
#include <vgui_controls/PHandle.h>
#include "keys.h"
#include "console.h"
#include "gl_matsysiface.h"
#include "cdll_engine_int.h"
#include "demo.h"
#include "sys_dll.h"
#include "sound.h"
#include "soundflags.h"
#include "filesystem_engine.h"
#include "igame.h"
#include "con_nprint.h"
#include "vgui_DebugSystemPanel.h"
#include "tier0/vprof.h"
#include "cl_demoactionmanager.h"
#include "enginebugreporter.h"
#include "engineperftools.h"
#include "icolorcorrectiontools.h"
#include "tier0/icommandline.h"
#include "client.h"
#include "server.h"
#include "sys.h" // Sys_GetRegKeyValue()
#include "vgui_drawtreepanel.h"
#include "vgui_vprofpanel.h"
#include "vgui/VGUI.h"
#include "vgui/IInput.h"
#include <vgui/IInputInternal.h>
#include "vgui_controls/AnimationController.h"
#include "vgui_vprofgraphpanel.h"
#include "vgui_texturebudgetpanel.h"
#include "vgui_budgetpanel.h"
#include "ivideomode.h"
#include "sourcevr/isourcevirtualreality.h"
#include "cl_pluginhelpers.h"
#include "cl_main.h" // CL_IsHL2Demo()
#include "cl_steamauth.h"
// interface to gameui dll
#include <GameUI/IGameUI.h>
#include <GameUI/IGameConsole.h>
// interface to expose vgui root panels
#include <ienginevgui.h>
#include "VGuiMatSurface/IMatSystemSurface.h"
#include "cl_texturelistpanel.h"
#include "cl_demouipanel.h"
#include "cl_foguipanel.h"
#include "cl_txviewpanel.h"
// vgui2 interface
// note that GameUI project uses ..\public\vgui and ..\public\vgui_controls, not ..\utils\vgui\include
#include <vgui/VGUI.h>
#include <vgui/Cursor.h>
#include <KeyValues.h>
#include <vgui/ILocalize.h>
#include <vgui/IPanel.h>
#include <vgui/IScheme.h>
#include <vgui/IVGui.h>
#include <vgui/ISystem.h>
#include <vgui/ISurface.h>
#include <vgui_controls/EditablePanel.h>
#include <vgui_controls/MenuButton.h>
#include <vgui_controls/Menu.h>
#include <vgui_controls/PHandle.h>
#include "IVguiModule.h"
#include "vgui_baseui_interface.h"
#include "vgui_DebugSystemPanel.h"
#include "toolframework/itoolframework.h"
#include "filesystem/IQueuedLoader.h"
#if defined( _X360 )
#include "xbox/xbox_win32stubs.h"
#endif
#include "vgui_askconnectpanel.h"
#if defined( REPLAY_ENABLED )
#include "replay_internal.h"
#endif
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#ifndef USE_SDL
extern HWND *pmainwindow;
#endif
extern IVEngineClient *engineClient;
extern bool g_bTextMode;
static int g_syncReportLevel = -1;
void VGui_ActivateMouse();
extern CreateInterfaceFn g_AppSystemFactory;
// functions to reference GameUI and GameConsole functions, from GameUI.dll
IGameUI *staticGameUIFuncs = NULL;
IGameConsole *staticGameConsole = NULL;
// cache some of the state we pass through to matsystemsurface, for visibility
bool s_bWindowsInputEnabled = true;
ConVar r_drawvgui( "r_drawvgui", "1", FCVAR_CHEAT, "Enable the rendering of vgui panels" );
ConVar gameui_xbox( "gameui_xbox", "0", 0 );
void Con_CreateConsolePanel( vgui::Panel *parent );
void CL_CreateEntityReportPanel( vgui::Panel *parent );
void ClearIOStates( void );
// turn this on if you're tuning progress bars
//#define ENABLE_LOADING_PROGRESS_PROFILING
//-----------------------------------------------------------------------------
// Purpose: Console command to hide the gameUI, most commonly called from gameUI.dll
//-----------------------------------------------------------------------------
CON_COMMAND( gameui_hide, "Hides the game UI" )
{
EngineVGui()->HideGameUI();
}
//-----------------------------------------------------------------------------
// Purpose: Console command to activate the gameUI, most commonly called from gameUI.dll
//-----------------------------------------------------------------------------
CON_COMMAND( gameui_activate, "Shows the game UI" )
{
EngineVGui()->ActivateGameUI();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CON_COMMAND( gameui_preventescape, "Escape key doesn't hide game UI" )
{
EngineVGui()->SetNotAllowedToHideGameUI( true );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CON_COMMAND( gameui_allowescapetoshow, "Escape key allowed to show game UI" )
{
EngineVGui()->SetNotAllowedToShowGameUI( false );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CON_COMMAND( gameui_preventescapetoshow, "Escape key doesn't show game UI" )
{
EngineVGui()->SetNotAllowedToShowGameUI( true );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CON_COMMAND( gameui_allowescape, "Escape key allowed to hide game UI" )
{
EngineVGui()->SetNotAllowedToHideGameUI( false );
}
//-----------------------------------------------------------------------------
// Purpose: Console command to enable progress bar for next load
//-----------------------------------------------------------------------------
void BaseUI_ProgressEnabled_f()
{
EngineVGui()->EnabledProgressBarForNextLoad();
}
static ConCommand progress_enable("progress_enable", &BaseUI_ProgressEnabled_f );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CEnginePanel : public vgui::EditablePanel
{
typedef vgui::EditablePanel BaseClass;
public:
CEnginePanel( vgui::Panel *pParent, const char *pName ) : BaseClass( pParent, pName )
{
//m_bCanFocus = true;
SetMouseInputEnabled( true );
SetKeyBoardInputEnabled( true );
}
void EnableMouseFocus( bool state )
{
//m_bCanFocus = state;
SetMouseInputEnabled( state );
SetKeyBoardInputEnabled( state );
}
/* virtual vgui::VPANEL IsWithinTraverse(int x, int y, bool traversePopups)
{
if ( !m_bCanFocus )
return NULL;
vgui::VPANEL retval = BaseClass::IsWithinTraverse( x, y, traversePopups );
if ( retval == GetVPanel() )
return NULL;
return retval;
}*/
//private:
// bool m_bCanFocus;
};
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CStaticPanel : public vgui::Panel
{
typedef vgui::Panel BaseClass;
public:
CStaticPanel( vgui::Panel *pParent, const char *pName ) : vgui::Panel( pParent, pName )
{
SetCursor( vgui::dc_none );
SetKeyBoardInputEnabled( false );
SetMouseInputEnabled( false );
}
};
vgui::VPanelHandle g_DrawTreeSelectedPanel;
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CFocusOverlayPanel : public vgui::Panel
{
typedef vgui::Panel BaseClass;
public:
CFocusOverlayPanel( vgui::Panel *pParent, const char *pName );
virtual void PostChildPaint( void );
static void GetColorForSlot( int slot, int& r, int& g, int& b )
{
r = (int)( 124.0 + slot * 47.3 ) & 255;
g = (int)( 63.78 - slot * 71.4 ) & 255;
b = (int)( 188.42 + slot * 13.57 ) & 255;
}
bool DrawTitleSafeOverlay( void );
bool DrawFocusPanelList( void );
};
//-----------------------------------------------------------------------------
//
// Purpose: Centerpoint for handling all user interface in the engine
//
//-----------------------------------------------------------------------------
class CEngineVGui : public IEngineVGuiInternal
{
public:
CEngineVGui();
~CEngineVGui();
// Methods of IEngineVGui
virtual vgui::VPANEL GetPanel( VGuiPanel_t type );
// Methods of IEngineVGuiInternal
virtual void Init();
virtual void Connect();
virtual void Shutdown();
virtual bool SetVGUIDirectories();
virtual bool IsInitialized() const;
virtual bool Key_Event( const InputEvent_t &event );
virtual void UpdateButtonState( const InputEvent_t &event );
virtual void BackwardCompatibility_Paint();
virtual void Paint( PaintMode_t mode );
virtual void PostInit();
CreateInterfaceFn GetGameUIFactory()
{
return m_GameUIFactory;
}
// handlers for game UI (main menu)
virtual void ActivateGameUI();
virtual bool HideGameUI();
virtual bool IsGameUIVisible();
// console
virtual void ShowConsole();
virtual void HideConsole();
virtual bool IsConsoleVisible();
virtual void ClearConsole();
// level loading
virtual void OnLevelLoadingStarted();
virtual void OnLevelLoadingFinished();
virtual void NotifyOfServerConnect(const char *game, int IP, int connectionPort, int queryPort);
virtual void NotifyOfServerDisconnect();
virtual void UpdateProgressBar(LevelLoadingProgress_e progress);
virtual void UpdateCustomProgressBar( float progress, const wchar_t *desc );
virtual void StartCustomProgress();
virtual void FinishCustomProgress();
virtual void EnabledProgressBarForNextLoad()
{
m_bShowProgressDialog = true;
}
// Should pause?
virtual bool ShouldPause();
virtual void ShowErrorMessage();
virtual void SetNotAllowedToHideGameUI( bool bNotAllowedToHide )
{
m_bNotAllowedToHideGameUI = bNotAllowedToHide;
}
virtual void SetNotAllowedToShowGameUI( bool bNotAllowedToShow )
{
m_bNotAllowedToShowGameUI = bNotAllowedToShow;
}
void SetGameDLLPanelsVisible( bool show )
{
if ( !staticGameDLLPanel )
{
return;
}
staticGameDLLPanel->SetVisible( show );
}
virtual void ShowNewGameDialog( int chapter = -1 ); // -1 means just keep the currently select chapter
// Xbox 360
virtual void SessionNotification( const int notification, const int param = 0 );
virtual void SystemNotification( const int notification );
virtual void ShowMessageDialog( const uint nType, vgui::Panel *pOwner = NULL );
virtual void UpdatePlayerInfo( uint64 nPlayerId, const char *pName, int nTeam, byte cVoiceState, int nPlayersNeeded, bool bHost );
virtual void SessionSearchResult( int searchIdx, void *pHostData, XSESSION_SEARCHRESULT *pResult, int ping );
virtual void OnCreditsFinished( void );
// Storage device validation:
// returns true right away if storage device has been previously selected.
// otherwise returns false and will set the variable pointed by pStorageDeviceValidated to 1
// once the storage device is selected by user.
virtual bool ValidateStorageDevice( int *pStorageDeviceValidated );
void SetProgressBias( float bias );
void UpdateProgressBar( float progress );
virtual void ConfirmQuit( void );
private:
vgui::Panel *GetRootPanel( VGuiPanel_t type );
void SetEngineVisible( bool state );
void DrawMouseFocus( void );
void CreateVProfPanels( vgui::Panel *pParent );
void DestroyVProfPanels( );
virtual void Simulate();
// debug overlays
bool IsDebugSystemVisible();
void HideDebugSystem();
bool IsShiftKeyDown();
bool IsAltKeyDown();
bool IsCtrlKeyDown();
CON_COMMAND_MEMBER_F( CEngineVGui, "debugsystemui", ToggleDebugSystemUI, "Show/hide the debug system UI.", FCVAR_CHEAT );
private:
enum { MAX_NUM_FACTORIES = 5 };
CreateInterfaceFn m_FactoryList[MAX_NUM_FACTORIES];
int m_iNumFactories;
CSysModule *m_hStaticGameUIModule;
CreateInterfaceFn m_GameUIFactory;
// top level VGUI2 panel
CStaticPanel *staticPanel;
// base level panels for other subsystems, rooted on staticPanel
CEnginePanel *staticClientDLLPanel;
CEnginePanel *staticClientDLLToolsPanel;
CEnginePanel *staticGameUIPanel;
CEnginePanel *staticGameDLLPanel;
// Want engine tools to be on top of other engine panels
CEnginePanel *staticEngineToolsPanel;
CDebugSystemPanel *staticDebugSystemPanel;
CFocusOverlayPanel *staticFocusOverlayPanel;
#ifdef VPROF_ENABLED
CVProfPanel *m_pVProfPanel;
CBudgetPanelEngine *m_pBudgetPanel;
CTextureBudgetPanel *m_pTextureBudgetPanel;
#endif
// progress bar
bool m_bShowProgressDialog;
LevelLoadingProgress_e m_eLastProgressPoint;
// progress bar debugging
int m_nLastProgressPointRepeatCount;
double m_flLoadingStartTime;
struct LoadingProgressEntry_t
{
double flTime;
LevelLoadingProgress_e eProgress;
};
CUtlVector<LoadingProgressEntry_t> m_LoadingProgress;
bool m_bSaveProgress : 1;
bool m_bNoShaderAPI : 1;
// game ui hiding control
bool m_bNotAllowedToHideGameUI : 1;
bool m_bNotAllowedToShowGameUI : 1;
vgui::IInputInternal *m_pInputInternal;
// used to start the progress from an arbitrary position
float m_ProgressBias;
};
//-----------------------------------------------------------------------------
// Purpose: singleton accessor
//-----------------------------------------------------------------------------
static CEngineVGui g_EngineVGuiImp;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CEngineVGui, IEngineVGui, VENGINE_VGUI_VERSION, g_EngineVGuiImp );
IEngineVGuiInternal *EngineVGui()
{
return &g_EngineVGuiImp;
}
//-----------------------------------------------------------------------------
// The loader progress is updated by the queued loader. It uses an initial
// reserved portion of the bar.
//-----------------------------------------------------------------------------
#define PROGRESS_RESERVE 0.50f
class CLoaderProgress : public ILoaderProgress
{
public:
CLoaderProgress()
{
// initialize to disabled state
m_SnappedProgress = -1;
}
void BeginProgress()
{
g_EngineVGuiImp.SetProgressBias( 0 );
m_SnappedProgress = 0;
}
void UpdateProgress( float progress )
{
if ( m_SnappedProgress == - 1 )
{
// not enabled
return;
}
int snappedProgress = progress * 15;
// Need excessive updates on the 360 to keep the XBox slider inny bar active
if ( !IsX360() && ( snappedProgress <= m_SnappedProgress ) )
{
// prevent excessive updates
return;
}
m_SnappedProgress = snappedProgress;
// up to reserved
g_EngineVGuiImp.UpdateProgressBar( PROGRESS_RESERVE * progress );
}
void EndProgress()
{
// the normal legacy bar now picks up after reserved region
g_EngineVGuiImp.SetProgressBias( PROGRESS_RESERVE );
m_SnappedProgress = -1;
}
private:
int m_SnappedProgress;
};
static CLoaderProgress s_LoaderProgress;
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CEngineVGui::CEngineVGui()
{
staticPanel = NULL;
staticClientDLLToolsPanel = NULL;
staticClientDLLPanel = NULL;
staticGameDLLPanel = NULL;
staticGameUIPanel = NULL;
staticEngineToolsPanel = NULL;
staticDebugSystemPanel = NULL;
staticFocusOverlayPanel = NULL;
m_hStaticGameUIModule = NULL;
m_GameUIFactory = NULL;
#ifdef VPROF_ENABLED
m_pVProfPanel = NULL;
#endif
m_bShowProgressDialog = false;
m_bSaveProgress = false;
m_bNoShaderAPI = false;
m_bNotAllowedToHideGameUI = false;
m_bNotAllowedToShowGameUI = false;
m_pInputInternal = NULL;
m_ProgressBias = 0;
}
//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
CEngineVGui::~CEngineVGui()
{
}
//-----------------------------------------------------------------------------
// add all the base search paths used by VGUI (platform, skins directory, language dirs)
//-----------------------------------------------------------------------------
bool CEngineVGui::SetVGUIDirectories()
{
// Legacy, not supported anymore
return true;
}
//-----------------------------------------------------------------------------
// Setup the base vgui panels
//-----------------------------------------------------------------------------
void CEngineVGui::Init()
{
COM_TimestampedLog( "Loading gameui.dll" );
// load the GameUI dll
const char *szDllName = "GameUI";
m_hStaticGameUIModule = g_pFileSystem->LoadModule(szDllName, "EXECUTABLE_PATH", true); // LoadModule() does a GetLocalCopy() call
m_GameUIFactory = Sys_GetFactory(m_hStaticGameUIModule);
if ( !m_GameUIFactory )
{
Error( "Could not load: %s\n", szDllName );
}
// get the initialization func
staticGameUIFuncs = (IGameUI *)m_GameUIFactory(GAMEUI_INTERFACE_VERSION, NULL);
if (!staticGameUIFuncs )
{
Error( "Could not get IGameUI interface %s from %s\n", GAMEUI_INTERFACE_VERSION, szDllName );
}
if ( IsPC() )
{
staticGameConsole = (IGameConsole *)m_GameUIFactory(GAMECONSOLE_INTERFACE_VERSION, NULL);
if ( !staticGameConsole )
{
Sys_Error( "Could not get IGameConsole interface %s from %s\n", GAMECONSOLE_INTERFACE_VERSION, szDllName );
}
}
vgui::VGui_InitMatSysInterfacesList( "BaseUI", &g_AppSystemFactory, 1 );
// Get our langauge string
char lang[ 64 ];
lang[0] = 0;
engineClient->GetUILanguage( lang, sizeof( lang ) );
if ( lang[0] )
vgui::system()->SetRegistryString( "HKEY_CURRENT_USER\\Software\\Valve\\Source\\Language", lang );
COM_TimestampedLog( "AttachToWindow" );
// Need to be able to play sounds through vgui
g_pMatSystemSurface->InstallPlaySoundFunc( VGui_PlaySound );
COM_TimestampedLog( "Load Scheme File" );
// load scheme
const char *pStr = "Resource/SourceScheme.res";
if ( !vgui::scheme()->LoadSchemeFromFile( pStr, "Tracker" ))
{
Sys_Error( "Error loading file %s\n", pStr );
return;
}
if ( IsX360() || IsGamepadUI() )
{
CCommand ccommand;
if ( CL_ShouldLoadBackgroundLevel( ccommand ) )
{
// Must be before the game ui base panel starts up
// This is a hint to avoid the menu pop due to the impending background map
// that the game ui is not aware of until 1 frame later.
staticGameUIFuncs->SetProgressOnStart();
}
}
COM_TimestampedLog( "vgui::ivgui()->Start()" );
// Start the App running
vgui::ivgui()->Start();
vgui::ivgui()->SetSleep(false);
// setup base panel for the whole VGUI System
// The root panel for everything ( NULL parent makes it a child of the embedded panel )
// Ideal hierarchy:
COM_TimestampedLog( "Building Panels (staticPanel)" );
// Root -- staticPanel
// staticBackgroundImagePanel (from gamui) zpos == 0
// staticClientDLLPanel ( zpos == 25 )
// staticClientDLLToolsPanel ( zpos == 28
// staticGameDLLPanel ( zpos == 30 )
// staticEngineToolsPanel ( zpos == 75 )
// staticGameUIPanel ( GameUI stuff ) ( zpos == 100 )
// staticDebugSystemPanel ( Engine debug stuff ) zpos == 125 )
staticPanel = new CStaticPanel( NULL, "staticPanel" );
staticPanel->SetBounds( 0, 0, videomode->GetModeUIWidth(), videomode->GetModeUIHeight() );
staticPanel->SetPaintBorderEnabled(false);
staticPanel->SetPaintBackgroundEnabled(false);
staticPanel->SetPaintEnabled(false);
staticPanel->SetVisible(true);
staticPanel->SetCursor( vgui::dc_none );
staticPanel->SetZPos(0);
staticPanel->SetVisible(true);
staticPanel->SetParent( vgui::surface()->GetEmbeddedPanel() );
COM_TimestampedLog( "Building Panels (staticClientDLLPanel)" );
staticClientDLLPanel = new CEnginePanel( staticPanel, "staticClientDLLPanel" );
staticClientDLLPanel->SetBounds( 0, 0, videomode->GetModeUIWidth(), videomode->GetModeUIHeight() );
staticClientDLLPanel->SetPaintBorderEnabled(false);
staticClientDLLPanel->SetPaintBackgroundEnabled(false);
staticClientDLLPanel->SetKeyBoardInputEnabled( false ); // popups in the client DLL can enable this.
staticClientDLLPanel->SetPaintEnabled(false);
staticClientDLLPanel->SetVisible( false );
staticClientDLLPanel->SetCursor( vgui::dc_none );
staticClientDLLPanel->SetZPos( 25 );
CreateAskConnectPanel( staticPanel->GetVPanel() );
COM_TimestampedLog( "Building Panels (staticClientDLLToolsPanel)" );
staticClientDLLToolsPanel = new CEnginePanel( staticPanel, "staticClientDLLToolsPanel" );
staticClientDLLToolsPanel->SetBounds( 0, 0, videomode->GetModeUIWidth(), videomode->GetModeUIHeight() );
staticClientDLLToolsPanel->SetPaintBorderEnabled(false);
staticClientDLLToolsPanel->SetPaintBackgroundEnabled(false);
staticClientDLLToolsPanel->SetKeyBoardInputEnabled( false ); // popups in the client DLL can enable this.
staticClientDLLToolsPanel->SetPaintEnabled(false);
staticClientDLLToolsPanel->SetVisible( true );
staticClientDLLToolsPanel->SetCursor( vgui::dc_none );
staticClientDLLToolsPanel->SetZPos( 28 );
staticEngineToolsPanel = new CEnginePanel( staticPanel, "Engine Tools" );
staticEngineToolsPanel->SetBounds( 0, 0, videomode->GetModeUIWidth(), videomode->GetModeUIHeight() );
staticEngineToolsPanel->SetPaintBorderEnabled(false);
staticEngineToolsPanel->SetPaintBackgroundEnabled(false);
staticEngineToolsPanel->SetPaintEnabled(false);
staticEngineToolsPanel->SetVisible( true );
staticEngineToolsPanel->SetCursor( vgui::dc_none );
staticEngineToolsPanel->SetZPos( 75 );
COM_TimestampedLog( "Building Panels (staticGameUIPanel)" );
staticGameUIPanel = new CEnginePanel( staticPanel, "GameUI Panel" );
if(NeedProportional())
staticGameUIPanel->SetProportional(true);
staticGameUIPanel->SetBounds( 0, 0, videomode->GetModeUIWidth(), videomode->GetModeUIHeight() );
staticGameUIPanel->SetPaintBorderEnabled(false);
staticGameUIPanel->SetPaintBackgroundEnabled(false);
staticGameUIPanel->SetPaintEnabled(false);
staticGameUIPanel->SetVisible( true );
staticGameUIPanel->SetCursor( vgui::dc_none );
staticGameUIPanel->SetZPos( 100 );
staticGameDLLPanel = new CEnginePanel( staticPanel, "staticGameDLLPanel" );
staticGameDLLPanel->SetBounds( 0, 0, videomode->GetModeUIWidth(), videomode->GetModeUIHeight() );
staticGameDLLPanel->SetPaintBorderEnabled(false);
staticGameDLLPanel->SetPaintBackgroundEnabled(false);
staticGameDLLPanel->SetKeyBoardInputEnabled( false ); // popups in the game DLL can enable this.
staticGameDLLPanel->SetPaintEnabled(false);
staticGameDLLPanel->SetCursor( vgui::dc_none );
staticGameDLLPanel->SetZPos( 135 );
if ( CommandLine()->CheckParm( "-tools" ) != NULL )
{
staticGameDLLPanel->SetVisible( true );
}
else
{
staticGameDLLPanel->SetVisible( false );
}
if ( IsPC() )
{
COM_TimestampedLog( "Building Panels (staticDebugSystemPanel)" );
staticDebugSystemPanel = new CDebugSystemPanel( staticPanel, "Engine Debug System" );
staticDebugSystemPanel->SetZPos( 125 );
// Install demo playback/editing UI
CDemoUIPanel::InstallDemoUI( staticEngineToolsPanel );
CDemoUIPanel2::Install( staticClientDLLPanel, staticEngineToolsPanel, true );
// Install fog control panel UI
CFogUIPanel::InstallFogUI( staticEngineToolsPanel );
// Install texture view panel
TxViewPanel::Install( staticEngineToolsPanel );
COM_TimestampedLog( "Install bug reporter" );
// Create and initialize bug reporting system
bugreporter->InstallBugReportingUI( staticGameUIPanel, IEngineBugReporter::BR_AUTOSELECT );
bugreporter->Init();
COM_TimestampedLog( "Install perf tools" );
// Create a performance toolkit system
perftools->InstallPerformanceToolsUI( staticEngineToolsPanel );
perftools->Init();
// Create a color correction UI
colorcorrectiontools->InstallColorCorrectionUI( staticEngineToolsPanel );
colorcorrectiontools->Init();
}
// Make sure this is on top of everything
staticFocusOverlayPanel = new CFocusOverlayPanel( staticPanel, "FocusOverlayPanel" );
staticFocusOverlayPanel->SetBounds( 0, 0, videomode->GetModeUIWidth(), videomode->GetModeUIHeight() );
staticFocusOverlayPanel->SetZPos( 150 );
staticFocusOverlayPanel->MoveToFront();
// Create engine vgui panels
if ( IsPC() )
{
Con_CreateConsolePanel( staticEngineToolsPanel );
CL_CreateEntityReportPanel( staticEngineToolsPanel );
VGui_CreateDrawTreePanel( staticEngineToolsPanel );
CL_CreateTextureListPanel( staticEngineToolsPanel );
CreateVProfPanels( staticEngineToolsPanel );
}
staticEngineToolsPanel->LoadControlSettings( "scripts/EngineVGuiLayout.res" );
COM_TimestampedLog( "materials->CacheUsedMaterials()" );
// Make sure that these materials are in the materials cache
materials->CacheUsedMaterials();
COM_TimestampedLog( "g_pVGuiLocalize->AddFile" );
// load the base localization file
g_pVGuiLocalize->AddFile( "Resource/valve_%language%.txt" );
COM_TimestampedLog( "staticGameUIFuncs->Initialize" );
staticGameUIFuncs->Initialize( g_AppSystemFactory );
COM_TimestampedLog( "staticGameUIFuncs->Start" );
staticGameUIFuncs->Start();
// don't need to load the "valve" localization file twice
// Each mod acn have its own language.txt in addition to the valve_%%langauge%%.txt file under defaultgamedir.
// load mod-specific localization file for kb_act.lst, user.scr, settings.scr, etc.
char szFileName[MAX_PATH];
Q_snprintf( szFileName, sizeof( szFileName ) - 1, "resource/%s_%%language%%.txt", GetCurrentMod() );
szFileName[ sizeof( szFileName ) - 1 ] = '\0';
g_pVGuiLocalize->AddFile( szFileName );
// setup console
if ( staticGameConsole )
{
staticGameConsole->Initialize();
staticGameConsole->SetParent(staticGameUIPanel->GetVPanel());
}
if ( IsX360() )
{
// provide an interface for loader to send progress notifications
g_pQueuedLoader->InstallProgress( &s_LoaderProgress );
}
// show the game UI
COM_TimestampedLog( "ActivateGameUI()" );
ActivateGameUI();
if ( staticGameConsole &&
!CommandLine()->CheckParm( "-forcestartupmenu" ) &&
!CommandLine()->CheckParm( "-hideconsole" ) &&
( CommandLine()->FindParm( "-toconsole" ) || CommandLine()->FindParm( "-console" ) || CommandLine()->FindParm( "-rpt" ) || CommandLine()->FindParm( "-allowdebug" ) ) )
{
// activate the console
staticGameConsole->Activate();
}
m_bNoShaderAPI = CommandLine()->FindParm( "-noshaderapi" );
}
void CEngineVGui::PostInit()
{
staticGameUIFuncs->PostInit();
#if defined( _X360 )
g_pMatSystemSurface->ClearTemporaryFontCache();
#endif
}
//-----------------------------------------------------------------------------
// Purpose: connects interfaces in gameui
//-----------------------------------------------------------------------------
void CEngineVGui::Connect()
{
m_pInputInternal = (vgui::IInputInternal *)g_GameSystemFactory( VGUI_INPUTINTERNAL_INTERFACE_VERSION, NULL );
staticGameUIFuncs->Connect( g_GameSystemFactory );
}
//-----------------------------------------------------------------------------
// Create/destroy the vprof panels
//-----------------------------------------------------------------------------
void CEngineVGui::CreateVProfPanels( vgui::Panel *pParent )
{
if ( IsX360() )
return;
#ifdef VPROF_ENABLED
m_pVProfPanel = new CVProfPanel( pParent, "VProfPanel" );
m_pBudgetPanel = new CBudgetPanelEngine( pParent, "BudgetPanel" );
CreateVProfGraphPanel( pParent );
m_pTextureBudgetPanel = new CTextureBudgetPanel( pParent, "TextureBudgetPanel" );
#endif
}
void CEngineVGui::DestroyVProfPanels( )
{
if ( IsX360() )
return;
#ifdef VPROF_ENABLED
if ( m_pVProfPanel )
{
delete m_pVProfPanel;
m_pVProfPanel = NULL;
}
if ( m_pBudgetPanel )
{
delete m_pBudgetPanel;
m_pBudgetPanel = NULL;
}
DestroyVProfGraphPanel();
if ( m_pTextureBudgetPanel )
{
delete m_pTextureBudgetPanel;
m_pTextureBudgetPanel = NULL;
}
#endif
}
//-----------------------------------------------------------------------------
// Are we initialized?
//-----------------------------------------------------------------------------
bool CEngineVGui::IsInitialized() const
{
return staticPanel != NULL;
}
extern bool g_bUsingLegacyAppSystems;
//-----------------------------------------------------------------------------
// Purpose: Called to Shutdown the game UI system
//-----------------------------------------------------------------------------
void CEngineVGui::Shutdown()
{
if ( IsPC() && CL_IsHL2Demo() ) // if they are playing the demo then open the storefront on shutdown
{
vgui::system()->ShellExecute("open", "steam://store_demo/220");
}
if ( IsPC() && CL_IsPortalDemo() ) // if they are playing the demo then open the storefront on shutdown
{
vgui::system()->ShellExecute("open", "steam://store_demo/400");
}
DestroyVProfPanels();
bugreporter->Shutdown();
colorcorrectiontools->Shutdown();
perftools->Shutdown();
demoaction->Shutdown();
if ( g_PluginManager )
{
g_PluginManager->Shutdown();
}
// HACK HACK: There was a bug in the old versions of the viewport which would crash in the case where the client .dll hadn't been fully unloaded, so
// we'll leak this panel here instead!!!
if ( g_bUsingLegacyAppSystems )
{
staticClientDLLPanel->SetParent( (vgui::VPANEL)0 );
}
// This will delete the engine subpanel since it's a child
delete staticPanel;
staticPanel = NULL;
staticClientDLLToolsPanel = NULL;
staticClientDLLPanel = NULL;
staticEngineToolsPanel = NULL;
staticDebugSystemPanel = NULL;
staticFocusOverlayPanel = NULL;
staticGameDLLPanel = NULL;
// Give panels a chance to settle so things
// Marked for deletion will actually get deleted
vgui::ivgui()->RunFrame();
// unload the gameUI
staticGameUIFuncs->Shutdown();
staticGameUIFuncs = NULL;
staticGameConsole = NULL;
staticGameUIPanel = NULL;
// stop the App running
vgui::ivgui()->Stop();
// unload the dll
Sys_UnloadModule(m_hStaticGameUIModule);
m_hStaticGameUIModule = NULL;
m_GameUIFactory = NULL;
m_pInputInternal = NULL;
}
//-----------------------------------------------------------------------------
// Purpose: Retrieve specified root panel
//-----------------------------------------------------------------------------
inline vgui::Panel *CEngineVGui::GetRootPanel( VGuiPanel_t type )
{
if ( sv.IsDedicated() )
{
return NULL;
}
switch ( type )
{
default:
case PANEL_ROOT:
return staticPanel;
case PANEL_CLIENTDLL:
return staticClientDLLPanel;
case PANEL_GAMEUIDLL:
return staticGameUIPanel;
case PANEL_TOOLS:
return staticEngineToolsPanel;
case PANEL_GAMEDLL:
return staticGameDLLPanel;
case PANEL_CLIENTDLL_TOOLS:
return staticClientDLLToolsPanel;
}
}
vgui::VPANEL CEngineVGui::GetPanel( VGuiPanel_t type )
{
return GetRootPanel( type )->GetVPanel();