-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathGameUI_Interface.cpp
More file actions
1124 lines (956 loc) · 33.6 KB
/
Copy pathGameUI_Interface.cpp
File metadata and controls
1124 lines (956 loc) · 33.6 KB
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 © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: Implements all the functions exported by the GameUI dll
//
// $NoKeywords: $
//===========================================================================//
#if !defined( _X360 )
#include <windows.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <io.h>
#include <tier0/dbg.h>
#include <direct.h>
#ifdef SendMessage
#undef SendMessage
#endif
#include "FileSystem.h"
#include "GameUI_Interface.h"
#include "Sys_Utils.h"
#include "string.h"
#include "tier0/icommandline.h"
// interface to engine
#include "EngineInterface.h"
#include "VGuiSystemModuleLoader.h"
#include "bitmap/TGALoader.h"
#include "GameConsole.h"
#include "LoadingDialog.h"
#include "CDKeyEntryDialog.h"
#include "ModInfo.h"
#include "game/client/IGameClientExports.h"
#include "materialsystem/imaterialsystem.h"
#include "engine/imatchmaking.h"
#include "ixboxsystem.h"
#include "iachievementmgr.h"
#include "IGameUIFuncs.h"
#include <IEngineVGUI.h>
#include "steam/steam_api.h"
#include "BonusMapsDatabase.h"
#include "BonusMapsDialog.h"
// vgui2 interface
// note that GameUI project uses ..\vgui2\include, not ..\utils\vgui\include
#include "BasePanel.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/Menu.h>
#include <vgui_controls/PHandle.h>
#include "tier3/tier3.h"
#include "tier0/vcrmode.h"
#if defined( _X360 )
#include "xbox/xbox_win32stubs.h"
#endif
#include "tier0/dbg.h"
#include "engine/IEngineSound.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
IGameUIFuncs *gameuifuncs = NULL;
IEngineVGui *enginevguifuncs = NULL;
IMatchmaking *matchmaking = NULL;
IXboxSystem *xboxsystem = NULL; // 360 only
vgui::ISurface *enginesurfacefuncs = NULL;
IVEngineClient *engine = NULL;
IEngineSound *enginesound = NULL;
IAchievementMgr *achievementmgr = NULL;
static CBasePanel *staticPanel = NULL;
class CGameUI;
CGameUI *g_pGameUI = NULL;
class CLoadingDialog;
vgui::DHANDLE<CLoadingDialog> g_hLoadingDialog;
vgui::VPANEL g_hLoadingBackgroundDialog = NULL;
static CGameUI g_GameUI;
static WHANDLE g_hMutex = NULL;
static WHANDLE g_hWaitMutex = NULL;
static IGameClientExports *g_pGameClientExports = NULL;
IGameClientExports *GameClientExports()
{
return g_pGameClientExports;
}
//-----------------------------------------------------------------------------
// Purpose: singleton accessor
//-----------------------------------------------------------------------------
CGameUI &GameUI()
{
return g_GameUI;
}
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CGameUI, IGameUI, GAMEUI_INTERFACE_VERSION, g_GameUI);
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CGameUI::CGameUI()
{
g_pGameUI = this;
m_bTryingToLoadFriends = false;
m_iFriendsLoadPauseFrames = 0;
m_iGameIP = 0;
m_iGameConnectionPort = 0;
m_iGameQueryPort = 0;
m_bActivatedUI = false;
m_szPreviousStatusText[0] = 0;
m_bIsConsoleUI = false;
m_bHasSavedThisMenuSession = false;
m_bOpenProgressOnStart = false;
}
//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
CGameUI::~CGameUI()
{
g_pGameUI = NULL;
}
//-----------------------------------------------------------------------------
// Purpose: Initialization
//-----------------------------------------------------------------------------
void CGameUI::Initialize( CreateInterfaceFn factory )
{
ConnectTier1Libraries( &factory, 1 );
ConnectTier2Libraries( &factory, 1 );
ConVar_Register( FCVAR_CLIENTDLL );
ConnectTier3Libraries( &factory, 1 );
enginesound = (IEngineSound *)factory(IENGINESOUND_CLIENT_INTERFACE_VERSION, NULL);
engine = (IVEngineClient *)factory( VENGINE_CLIENT_INTERFACE_VERSION, NULL );
ConVarRef var( "gameui_xbox" );
m_bIsConsoleUI = var.IsValid() && var.GetBool();
vgui::VGui_InitInterfacesList( "GameUI", &factory, 1 );
// load localization file
g_pVGuiLocalize->AddFile( "Resource/gameui_%language%.txt", "GAME", true );
// load mod info
ModInfo().LoadCurrentGameInfo();
// load localization file for kb_act.lst
g_pVGuiLocalize->AddFile( "Resource/valve_%language%.txt", "GAME", true );
enginevguifuncs = (IEngineVGui *)factory( VENGINE_VGUI_VERSION, NULL );
enginesurfacefuncs = (vgui::ISurface *)factory(VGUI_SURFACE_INTERFACE_VERSION, NULL);
gameuifuncs = (IGameUIFuncs *)factory( VENGINE_GAMEUIFUNCS_VERSION, NULL );
matchmaking = (IMatchmaking *)factory( VENGINE_MATCHMAKING_VERSION, NULL );
xboxsystem = (IXboxSystem *)factory( XBOXSYSTEM_INTERFACE_VERSION, NULL );
if ( !enginesurfacefuncs || !gameuifuncs || !enginevguifuncs || !xboxsystem || (IsX360() && !matchmaking) )
{
Error( "CGameUI::Initialize() failed to get necessary interfaces\n" );
}
// setup base panel
staticPanel = new CBasePanel();
staticPanel->SetBounds(0, 0, 400, 300 );
staticPanel->SetPaintBorderEnabled( false );
staticPanel->SetPaintBackgroundEnabled( true );
staticPanel->SetPaintEnabled( false );
staticPanel->SetVisible( true );
staticPanel->SetMouseInputEnabled( false );
staticPanel->SetKeyBoardInputEnabled( false );
vgui::VPANEL rootpanel = enginevguifuncs->GetPanel( PANEL_GAMEUIDLL );
staticPanel->SetParent( rootpanel );
}
void CGameUI::PostInit()
{
if ( IsX360() )
{
enginesound->PrecacheSound( "UI/buttonrollover.wav", true, true );
enginesound->PrecacheSound( "UI/buttonclick.wav", true, true );
enginesound->PrecacheSound( "UI/buttonclickrelease.wav", true, true );
enginesound->PrecacheSound( "player/suit_denydevice.wav", true, true );
}
}
//-----------------------------------------------------------------------------
// Purpose: Sets the specified panel as the background panel for the loading
// dialog. If NULL, default background is used. If you set a panel,
// it should be full-screen with an opaque background, and must be a VGUI popup.
//-----------------------------------------------------------------------------
void CGameUI::SetLoadingBackgroundDialog( vgui::VPANEL panel )
{
g_hLoadingBackgroundDialog = panel;
}
void CGameUI::BonusMapUnlock( const char *pchFileName, const char *pchMapName )
{
if ( !pchFileName || pchFileName[ 0 ] == '\0' ||
!pchMapName || pchMapName[ 0 ] == '\0' )
{
if ( !g_pBonusMapsDialog )
return;
g_pBonusMapsDialog->SetSelectedBooleanStatus( "lock", false );
return;
}
if ( BonusMapsDatabase()->SetBooleanStatus( "lock", pchFileName, pchMapName, false ) )
{
BonusMapsDatabase()->RefreshMapData();
if ( !g_pBonusMapsDialog )
{
// It unlocked without the bonus maps menu open, so flash the menu item
CBasePanel *pBasePanel = BasePanel();
if ( pBasePanel )
{
if ( GameUI().IsConsoleUI() )
{
if ( Q_stricmp( pchFileName, "scripts/advanced_chambers" ) == 0 )
{
pBasePanel->SetMenuItemBlinkingState( "OpenNewGameDialog", true );
}
}
else
{
pBasePanel->SetMenuItemBlinkingState( "OpenBonusMapsDialog", true );
}
}
BonusMapsDatabase()->SetBlink( true );
}
else
g_pBonusMapsDialog->RefreshData(); // Update the open dialog
}
}
void CGameUI::BonusMapComplete( const char *pchFileName, const char *pchMapName )
{
if ( !pchFileName || pchFileName[ 0 ] == '\0' ||
!pchMapName || pchMapName[ 0 ] == '\0' )
{
if ( !g_pBonusMapsDialog )
return;
g_pBonusMapsDialog->SetSelectedBooleanStatus( "complete", true );
BonusMapsDatabase()->RefreshMapData();
g_pBonusMapsDialog->RefreshData();
return;
}
if ( BonusMapsDatabase()->SetBooleanStatus( "complete", pchFileName, pchMapName, true ) )
{
BonusMapsDatabase()->RefreshMapData();
// Update the open dialog
if ( g_pBonusMapsDialog )
g_pBonusMapsDialog->RefreshData();
}
}
void CGameUI::BonusMapChallengeUpdate( const char *pchFileName, const char *pchMapName, const char *pchChallengeName, int iBest )
{
if ( !pchFileName || pchFileName[ 0 ] == '\0' ||
!pchMapName || pchMapName[ 0 ] == '\0' ||
!pchChallengeName || pchChallengeName[ 0 ] == '\0' )
{
return;
}
else
{
if ( BonusMapsDatabase()->UpdateChallengeBest( pchFileName, pchMapName, pchChallengeName, iBest ) )
{
// The challenge best changed, so write it to the file
BonusMapsDatabase()->WriteSaveData();
BonusMapsDatabase()->RefreshMapData();
// Update the open dialog
if ( g_pBonusMapsDialog )
g_pBonusMapsDialog->RefreshData();
}
}
}
void CGameUI::BonusMapChallengeNames( char *pchFileName, char *pchMapName, char *pchChallengeName )
{
if ( !pchFileName || !pchMapName || !pchChallengeName )
return;
BonusMapsDatabase()->GetCurrentChallengeNames( pchFileName, pchMapName, pchChallengeName );
}
void CGameUI::BonusMapChallengeObjectives( int &iBronze, int &iSilver, int &iGold )
{
BonusMapsDatabase()->GetCurrentChallengeObjectives( iBronze, iSilver, iGold );
}
void CGameUI::BonusMapDatabaseSave( void )
{
BonusMapsDatabase()->WriteSaveData();
}
int CGameUI::BonusMapNumAdvancedCompleted( void )
{
return BonusMapsDatabase()->NumAdvancedComplete();
}
void CGameUI::BonusMapNumMedals( int piNumMedals[ 3 ] )
{
BonusMapsDatabase()->NumMedals( piNumMedals );
}
//-----------------------------------------------------------------------------
// Purpose: connects to client interfaces
//-----------------------------------------------------------------------------
void CGameUI::Connect( CreateInterfaceFn gameFactory )
{
g_pGameClientExports = (IGameClientExports *)gameFactory(GAMECLIENTEXPORTS_INTERFACE_VERSION, NULL);
achievementmgr = engine->GetAchievementMgr();
if (!g_pGameClientExports)
{
Error("CGameUI::Initialize() failed to get necessary interfaces\n");
}
m_GameFactory = gameFactory;
}
//-----------------------------------------------------------------------------
// Purpose: Callback function; sends platform Shutdown message to specified window
//-----------------------------------------------------------------------------
int __stdcall SendShutdownMsgFunc(WHANDLE hwnd, int lparam)
{
Sys_PostMessage(hwnd, Sys_RegisterWindowMessage("ShutdownValvePlatform"), 0, 1);
return 1;
}
//-----------------------------------------------------------------------------
// Purpose: Searches for GameStartup*.mp3 files in the sound/ui folder and plays one
//-----------------------------------------------------------------------------
void CGameUI::PlayGameStartupSound()
{
if ( IsX360() )
return;
if ( CommandLine()->FindParm( "-nostartupsound" ) )
return;
FileFindHandle_t fh;
CUtlVector<char *> fileNames;
char path[ 512 ];
Q_snprintf( path, sizeof( path ), "sound/ui/gamestartup*.mp3" );
Q_FixSlashes( path );
char const *fn = g_pFullFileSystem->FindFirstEx( path, "MOD", &fh );
if ( fn )
{
do
{
char ext[ 10 ];
Q_ExtractFileExtension( fn, ext, sizeof( ext ) );
if ( !Q_stricmp( ext, "mp3" ) )
{
char temp[ 512 ];
Q_snprintf( temp, sizeof( temp ), "ui/%s", fn );
char *found = new char[ strlen( temp ) + 1 ];
Q_strncpy( found, temp, strlen( temp ) + 1 );
Q_FixSlashes( found );
fileNames.AddToTail( found );
}
fn = g_pFullFileSystem->FindNext( fh );
} while ( fn );
g_pFullFileSystem->FindClose( fh );
}
// did we find any?
if ( fileNames.Count() > 0 )
{
SYSTEMTIME SystemTime;
GetSystemTime( &SystemTime );
int index = SystemTime.wMilliseconds % fileNames.Count();
if ( fileNames.IsValidIndex( index ) && fileNames[index] )
{
char found[ 512 ];
// escape chars "*#" make it stream, and be affected by snd_musicvolume
Q_snprintf( found, sizeof( found ), "play *#%s", fileNames[index] );
engine->ClientCmd_Unrestricted( found );
}
fileNames.PurgeAndDeleteElements();
}
}
//-----------------------------------------------------------------------------
// Purpose: Called to setup the game UI
//-----------------------------------------------------------------------------
void CGameUI::Start()
{
// determine Steam location for configuration
if ( !FindPlatformDirectory( m_szPlatformDir, sizeof( m_szPlatformDir ) ) )
return;
if ( IsPC() )
{
// setup config file directory
char szConfigDir[512];
Q_strncpy( szConfigDir, m_szPlatformDir, sizeof( szConfigDir ) );
Q_strncat( szConfigDir, "config", sizeof( szConfigDir ), COPY_ALL_CHARACTERS );
Msg( "Steam config directory: %s\n", szConfigDir );
g_pFullFileSystem->AddSearchPath(szConfigDir, "CONFIG");
g_pFullFileSystem->CreateDirHierarchy("", "CONFIG");
// user dialog configuration
vgui::system()->SetUserConfigFile("InGameDialogConfig.vdf", "CONFIG");
g_pFullFileSystem->AddSearchPath( "platform", "PLATFORM" );
}
// localization
g_pVGuiLocalize->AddFile( "Resource/platform_%language%.txt");
g_pVGuiLocalize->AddFile( "Resource/vgui_%language%.txt");
Sys_SetLastError( SYS_NO_ERROR );
if ( IsPC() )
{
g_hMutex = Sys_CreateMutex( "ValvePlatformUIMutex" );
g_hWaitMutex = Sys_CreateMutex( "ValvePlatformWaitMutex" );
if ( g_hMutex == NULL || g_hWaitMutex == NULL || Sys_GetLastError() == SYS_ERROR_INVALID_HANDLE )
{
// error, can't get handle to mutex
if (g_hMutex)
{
Sys_ReleaseMutex(g_hMutex);
}
if (g_hWaitMutex)
{
Sys_ReleaseMutex(g_hWaitMutex);
}
g_hMutex = NULL;
g_hWaitMutex = NULL;
Error("Steam Error: Could not access Steam, bad mutex\n");
return;
}
unsigned int waitResult = Sys_WaitForSingleObject(g_hMutex, 0);
if (!(waitResult == SYS_WAIT_OBJECT_0 || waitResult == SYS_WAIT_ABANDONED))
{
// mutex locked, need to deactivate Steam (so we have the Friends/ServerBrowser data files)
// get the wait mutex, so that Steam.exe knows that we're trying to acquire ValveTrackerMutex
waitResult = Sys_WaitForSingleObject(g_hWaitMutex, 0);
if (waitResult == SYS_WAIT_OBJECT_0 || waitResult == SYS_WAIT_ABANDONED)
{
Sys_EnumWindows(SendShutdownMsgFunc, 1);
}
}
// Delay playing the startup music until the first frame
m_bPlayGameStartupSound = true;
// now we are set up to check every frame to see if we can friends/server browser
m_bTryingToLoadFriends = true;
m_iFriendsLoadPauseFrames = 1;
}
}
//-----------------------------------------------------------------------------
// Purpose: Validates the user has a cdkey in the registry
//-----------------------------------------------------------------------------
void CGameUI::ValidateCDKey()
{
// this check is disabled, since we have no plans for an offline version of hl2
#if 0
//!! hack, write out a regkey for now so developers don't have to type it in
//!! undo this before release
vgui::system()->SetRegistryString("HKEY_CURRENT_USER\\Software\\Valve\\Source\\Settings\\EncryptedCDKey", "QOgi:JXrJj<Eb8abkESf4Pg;OfofJwDzRsyH>AdjtyPnV[FB");
// see what's in the registry
if (!CCDKeyEntryDialog::IsValidWeakCDKeyInRegistry())
{
m_hCDKeyEntryDialog = new CCDKeyEntryDialog(NULL, false);
m_hCDKeyEntryDialog->Activate();
}
#endif
}
//-----------------------------------------------------------------------------
// Purpose: Finds which directory the platform resides in
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CGameUI::FindPlatformDirectory(char *platformDir, int bufferSize)
{
platformDir[0] = '\0';
if ( platformDir[0] == '\0' )
{
// we're not under steam, so setup using path relative to game
if ( IsPC() )
{
if ( ::GetModuleFileName( ( HINSTANCE )GetModuleHandle( NULL ), platformDir, bufferSize ) )
{
char *lastslash = strrchr(platformDir, '\\'); // this should be just before the filename
if ( lastslash )
{
*lastslash = 0;
Q_strncat(platformDir, "\\platform\\", bufferSize, COPY_ALL_CHARACTERS );
return true;
}
}
}
else
{
// xbox fetches the platform path from exisiting platform search path
// path to executeable is not correct for xbox remote configuration
if ( g_pFullFileSystem->GetSearchPath( "PLATFORM", false, platformDir, bufferSize ) )
{
char *pSeperator = strchr( platformDir, ';' );
if ( pSeperator )
*pSeperator = '\0';
return true;
}
}
Error( "Unable to determine platform directory\n" );
return false;
}
return (platformDir[0] != 0);
}
//-----------------------------------------------------------------------------
// Purpose: Called to Shutdown the game UI system
//-----------------------------------------------------------------------------
void CGameUI::Shutdown()
{
// notify all the modules of Shutdown
g_VModuleLoader.ShutdownPlatformModules();
// unload the modules them from memory
g_VModuleLoader.UnloadPlatformModules();
ModInfo().FreeModInfo();
#if !defined( NO_STEAM )
SteamAPI_Shutdown();
#endif
// release platform mutex
// close the mutex
if (g_hMutex)
{
Sys_ReleaseMutex(g_hMutex);
}
if (g_hWaitMutex)
{
Sys_ReleaseMutex(g_hWaitMutex);
}
ConVar_Unregister();
DisconnectTier3Libraries();
DisconnectTier2Libraries();
DisconnectTier1Libraries();
}
//-----------------------------------------------------------------------------
// Purpose: just wraps an engine call to activate the gameUI
//-----------------------------------------------------------------------------
void CGameUI::ActivateGameUI()
{
engine->ExecuteClientCmd("gameui_activate");
}
//-----------------------------------------------------------------------------
// Purpose: just wraps an engine call to hide the gameUI
//-----------------------------------------------------------------------------
void CGameUI::HideGameUI()
{
engine->ExecuteClientCmd("gameui_hide");
}
//-----------------------------------------------------------------------------
// Purpose: Toggle allowing the engine to hide the game UI with the escape key
//-----------------------------------------------------------------------------
void CGameUI::PreventEngineHideGameUI()
{
engine->ExecuteClientCmd("gameui_preventescape");
}
//-----------------------------------------------------------------------------
// Purpose: Toggle allowing the engine to hide the game UI with the escape key
//-----------------------------------------------------------------------------
void CGameUI::AllowEngineHideGameUI()
{
engine->ExecuteClientCmd("gameui_allowescape");
}
//-----------------------------------------------------------------------------
// Purpose: Activate the game UI
//-----------------------------------------------------------------------------
void CGameUI::OnGameUIActivated()
{
m_bActivatedUI = true;
// hide/show the main panel to Activate all game ui
staticPanel->SetVisible( true );
// pause the server in single player
if ( engine->GetMaxClients() <= 1 )
{
engine->ClientCmd_Unrestricted( "setpause" );
}
SetSavedThisMenuSession( false );
// notify taskbar
BasePanel()->OnGameUIActivated();
}
//-----------------------------------------------------------------------------
// Purpose: Hides the game ui, in whatever state it's in
//-----------------------------------------------------------------------------
void CGameUI::OnGameUIHidden()
{
// unpause the game when leaving the UI
if ( engine->GetMaxClients() <= 1 )
{
engine->ClientCmd_Unrestricted("unpause");
}
BasePanel()->OnGameUIHidden();
}
//-----------------------------------------------------------------------------
// Purpose: paints all the vgui elements
//-----------------------------------------------------------------------------
void CGameUI::RunFrame()
{
if ( IsX360() && m_bOpenProgressOnStart )
{
StartProgressBar();
m_bOpenProgressOnStart = false;
}
// resize the background panel to the screen size
int wide, tall;
vgui::surface()->GetScreenSize(wide, tall);
staticPanel->SetSize(wide,tall);
// Run frames
g_VModuleLoader.RunFrame();
BasePanel()->RunFrame();
// Play the start-up music the first time we run frame
if ( IsPC() && m_bPlayGameStartupSound )
{
PlayGameStartupSound();
m_bPlayGameStartupSound = false;
}
if ( IsPC() && m_bTryingToLoadFriends && m_iFriendsLoadPauseFrames-- < 1 && g_hMutex && g_hWaitMutex )
{
// try and load Steam platform files
unsigned int waitResult = Sys_WaitForSingleObject(g_hMutex, 0);
if (waitResult == SYS_WAIT_OBJECT_0 || waitResult == SYS_WAIT_ABANDONED)
{
// we got the mutex, so load Friends/Serverbrowser
// clear the loading flag
m_bTryingToLoadFriends = false;
g_VModuleLoader.LoadPlatformModules(&m_GameFactory, 1, false);
// release the wait mutex
Sys_ReleaseMutex(g_hWaitMutex);
// notify the game of our game name
const char *fullGamePath = engine->GetGameDirectory();
const char *pathSep = strrchr( fullGamePath, '/' );
if ( !pathSep )
{
pathSep = strrchr( fullGamePath, '\\' );
}
if ( pathSep )
{
KeyValues *pKV = new KeyValues("ActiveGameName" );
pKV->SetString( "name", pathSep + 1 );
pKV->SetInt( "appid", engine->GetAppID() );
KeyValues *modinfo = new KeyValues("ModInfo");
if ( modinfo->LoadFromFile( g_pFullFileSystem, "gameinfo.txt" ) )
{
pKV->SetString( "game", modinfo->GetString( "game", "" ) );
}
modinfo->deleteThis();
g_VModuleLoader.PostMessageToAllModules( pKV );
}
// notify the ui of a game connect if we're already in a game
if (m_iGameIP)
{
SendConnectedToGameMessage();
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose: Called when the game connects to a server
//-----------------------------------------------------------------------------
void CGameUI::OLD_OnConnectToServer(const char *game, int IP, int port)
{
// Nobody should use this anymore because the query port and the connection port can be different.
// Use OnConnectToServer2 instead.
Assert( false );
OnConnectToServer2( game, IP, port, port );
}
//-----------------------------------------------------------------------------
// Purpose: Called when the game connects to a server
//-----------------------------------------------------------------------------
void CGameUI::OnConnectToServer2(const char *game, int IP, int connectionPort, int queryPort)
{
m_iGameIP = IP;
m_iGameConnectionPort = connectionPort;
m_iGameQueryPort = queryPort;
SendConnectedToGameMessage();
}
void CGameUI::SendConnectedToGameMessage()
{
KeyValues *kv = new KeyValues( "ConnectedToGame" );
kv->SetInt( "ip", m_iGameIP );
kv->SetInt( "connectionport", m_iGameConnectionPort );
kv->SetInt( "queryport", m_iGameQueryPort );
g_VModuleLoader.PostMessageToAllModules( kv );
}
//-----------------------------------------------------------------------------
// Purpose: Called when the game disconnects from a server
//-----------------------------------------------------------------------------
void CGameUI::OnDisconnectFromServer( uint8 eSteamLoginFailure )
{
m_iGameIP = 0;
m_iGameConnectionPort = 0;
m_iGameQueryPort = 0;
g_VModuleLoader.PostMessageToAllModules(new KeyValues("DisconnectedFromGame"));
if ( eSteamLoginFailure == STEAMLOGINFAILURE_BADTICKET )
{
RefreshSteamLogin();
}
else if ( eSteamLoginFailure == STEAMLOGINFAILURE_NOSTEAMLOGIN )
{
if ( g_hLoadingDialog )
{
g_hLoadingDialog->DisplayNoSteamConnectionError();
}
}
else if ( eSteamLoginFailure == STEAMLOGINFAILURE_VACBANNED )
{
if ( g_hLoadingDialog )
{
g_hLoadingDialog->DisplayVACBannedError();
}
}
else if ( eSteamLoginFailure == STEAMLOGINFAILURE_LOGGED_IN_ELSEWHERE )
{
if ( g_hLoadingDialog )
{
g_hLoadingDialog->DisplayLoggedInElsewhereError();
}
}
}
//-----------------------------------------------------------------------------
// Purpose: activates the loading dialog on level load start
//-----------------------------------------------------------------------------
void CGameUI::OnLevelLoadingStarted( bool bShowProgressDialog )
{
g_VModuleLoader.PostMessageToAllModules( new KeyValues( "LoadingStarted" ) );
// notify
BasePanel()->OnLevelLoadingStarted();
if ( bShowProgressDialog )
{
StartProgressBar();
}
// Don't play the start game sound if this happens before we get to the first frame
m_bPlayGameStartupSound = false;
}
//-----------------------------------------------------------------------------
// Purpose: closes any level load dialog
//-----------------------------------------------------------------------------
void CGameUI::OnLevelLoadingFinished(bool bError, const char *failureReason, const char *extendedReason)
{
StopProgressBar( bError, failureReason, extendedReason );
// notify all the modules
g_VModuleLoader.PostMessageToAllModules( new KeyValues( "LoadingFinished" ) );
// hide the UI
HideGameUI();
// notify
BasePanel()->OnLevelLoadingFinished();
}
//-----------------------------------------------------------------------------
// Purpose: Updates progress bar
// Output : Returns true if screen should be redrawn
//-----------------------------------------------------------------------------
bool CGameUI::UpdateProgressBar(float progress, const char *statusText)
{
// if either the progress bar or the status text changes, redraw the screen
bool bRedraw = false;
if ( ContinueProgressBar( progress ) )
{
bRedraw = true;
}
if ( SetProgressBarStatusText( statusText ) )
{
bRedraw = true;
}
return bRedraw;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CGameUI::StartProgressBar()
{
if ( !g_hLoadingDialog.Get() )
{
g_hLoadingDialog = new CLoadingDialog(staticPanel);
}
// open a loading dialog
m_szPreviousStatusText[0] = 0;
g_hLoadingDialog->SetProgressPoint(0.0f);
g_hLoadingDialog->Open();
}
//-----------------------------------------------------------------------------
// Purpose: returns true if the screen should be updated
//-----------------------------------------------------------------------------
bool CGameUI::ContinueProgressBar( float progressFraction )
{
if (!g_hLoadingDialog.Get())
return false;
g_hLoadingDialog->Activate();
return g_hLoadingDialog->SetProgressPoint(progressFraction);
}
//-----------------------------------------------------------------------------
// Purpose: stops progress bar, displays error if necessary
//-----------------------------------------------------------------------------
void CGameUI::StopProgressBar(bool bError, const char *failureReason, const char *extendedReason)
{
if (!g_hLoadingDialog.Get() && bError)
{
g_hLoadingDialog = new CLoadingDialog(staticPanel);
}
if (!g_hLoadingDialog.Get())
return;
if ( !IsX360() && bError )
{
// turn the dialog to error display mode
g_hLoadingDialog->DisplayGenericError(failureReason, extendedReason);
}
else
{
// close loading dialog
g_hLoadingDialog->Close();
g_hLoadingDialog = NULL;
}
// should update the background to be in a transition here
}
//-----------------------------------------------------------------------------
// Purpose: sets loading info text
//-----------------------------------------------------------------------------
bool CGameUI::SetProgressBarStatusText(const char *statusText)
{
if (!g_hLoadingDialog.Get())
return false;
if (!statusText)
return false;
if (!stricmp(statusText, m_szPreviousStatusText))
return false;
g_hLoadingDialog->SetStatusText(statusText);
Q_strncpy(m_szPreviousStatusText, statusText, sizeof(m_szPreviousStatusText));
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CGameUI::SetSecondaryProgressBar(float progress /* range [0..1] */)
{
if (!g_hLoadingDialog.Get())
return;
g_hLoadingDialog->SetSecondaryProgress(progress);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CGameUI::SetSecondaryProgressBarText(const char *statusText)
{
if (!g_hLoadingDialog.Get())
return;
g_hLoadingDialog->SetSecondaryProgressText(statusText);
}
//-----------------------------------------------------------------------------
// Purpose: Returns prev settings
//-----------------------------------------------------------------------------
bool CGameUI::SetShowProgressText( bool show )
{
if (!g_hLoadingDialog.Get())
return false;
return g_hLoadingDialog->SetShowProgressText( show );
}
//-----------------------------------------------------------------------------
// Purpose: brings up a login prompt
//-----------------------------------------------------------------------------
void CGameUI::RefreshSteamLogin()
{
#ifndef NO_STEAM
SteamUser()->RefreshSteam2Login();
#endif
}
//-----------------------------------------------------------------------------
// Purpose: returns true if we're currently playing the game
//-----------------------------------------------------------------------------
bool CGameUI::IsInLevel()
{
const char *levelName = engine->GetLevelName();
if (levelName && levelName[0] && !engine->IsLevelMainMenuBackground())
{
return true;
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose: returns true if we're at the main menu and a background level is loaded
//-----------------------------------------------------------------------------
bool CGameUI::IsInBackgroundLevel()
{