-
Notifications
You must be signed in to change notification settings - Fork 270
/
Copy pathBasePanel.cpp
4867 lines (4260 loc) · 134 KB
/
BasePanel.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:
//
// $NoKeywords: $
//===========================================================================//
#include <stdio.h>
#include "threadtools.h"
#include "BasePanel.h"
#include "EngineInterface.h"
#include "VGuiSystemModuleLoader.h"
#include "vgui/IInput.h"
#include "vgui/ILocalize.h"
#include "vgui/IPanel.h"
#include "vgui/ISurface.h"
#include "vgui/ISystem.h"
#include "vgui/IVGui.h"
#include "filesystem.h"
#include "GameConsole.h"
#include "GameUI_Interface.h"
#include "vgui_controls/PropertyDialog.h"
#include "vgui_controls/PropertySheet.h"
#include "materialsystem/materialsystem_config.h"
#include "materialsystem/imaterialsystem.h"
#include "sourcevr/isourcevirtualreality.h"
using namespace vgui;
#include "GameConsole.h"
#include "ModInfo.h"
#include "IGameUIFuncs.h"
#include "LoadingDialog.h"
#include "BackgroundMenuButton.h"
#include "vgui_controls/AnimationController.h"
#include "vgui_controls/ImagePanel.h"
#include "vgui_controls/Label.h"
#include "vgui_controls/Menu.h"
#include "vgui_controls/MenuItem.h"
#include "vgui_controls/PHandle.h"
#include "vgui_controls/MessageBox.h"
#include "vgui_controls/QueryBox.h"
#include "vgui_controls/ControllerMap.h"
#include "vgui_controls/KeyRepeat.h"
#include "tier0/icommandline.h"
#include "tier1/convar.h"
#include "NewGameDialog.h"
#include "BonusMapsDialog.h"
#include "LoadGameDialog.h"
#include "SaveGameDialog.h"
#include "OptionsDialog.h"
#include "CreateMultiplayerGameDialog.h"
#include "ChangeGameDialog.h"
#include "BackgroundMenuButton.h"
#include "PlayerListDialog.h"
#include "BenchmarkDialog.h"
#include "LoadCommentaryDialog.h"
#include "ControllerDialog.h"
#include "BonusMapsDatabase.h"
#include "engine/IEngineSound.h"
#include "bitbuf.h"
#include "tier1/fmtstr.h"
#include "inputsystem/iinputsystem.h"
#include "ixboxsystem.h"
#include "matchmaking/matchmakingbasepanel.h"
#include "matchmaking/achievementsdialog.h"
#include "iachievementmgr.h"
#include "UtlSortVector.h"
#include "game/client/IGameClientExports.h"
#include "OptionsSubAudio.h"
#include "hl2orange.spa.h"
#include "CustomTabExplanationDialog.h"
#if defined( _X360 )
#include "xbox/xbox_launch.h"
#else
#include "xbox/xboxstubs.h"
#endif
#include "../engine/imatchmaking.h"
#include "tier1/utlstring.h"
#include "steam/steam_api.h"
#undef MessageBox // Windows helpfully #define's this to MessageBoxA, we're using vgui::MessageBox
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define MAIN_MENU_INDENT_X360 10
ConVar vgui_message_dialog_modal( "vgui_message_dialog_modal", "1", FCVAR_ARCHIVE );
extern vgui::DHANDLE<CLoadingDialog> g_hLoadingDialog;
static CBasePanel *g_pBasePanel = NULL;
static float g_flAnimationPadding = 0.01f;
extern const char *COM_GetModDirectory( void );
extern ConVar x360_audio_english;
extern bool bSteamCommunityFriendsVersion;
static vgui::DHANDLE<vgui::PropertyDialog> g_hOptionsDialog;
//-----------------------------------------------------------------------------
// Purpose: singleton accessor
//-----------------------------------------------------------------------------
CBasePanel *BasePanel()
{
return g_pBasePanel;
}
//-----------------------------------------------------------------------------
// Purpose: hack function to give the module loader access to the main panel handle
// only used in VguiSystemModuleLoader
//-----------------------------------------------------------------------------
VPANEL GetGameUIBasePanel()
{
return BasePanel()->GetVPanel();
}
CGameMenuItem::CGameMenuItem(vgui::Menu *parent, const char *name) : BaseClass(parent, name, "GameMenuItem")
{
m_bRightAligned = false;
}
void CGameMenuItem::ApplySchemeSettings(IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
// make fully transparent
SetFgColor(GetSchemeColor("MainMenu.TextColor", pScheme));
SetBgColor(Color(0, 0, 0, 0));
SetDefaultColor(GetSchemeColor("MainMenu.TextColor", pScheme), Color(0, 0, 0, 0));
SetArmedColor(GetSchemeColor("MainMenu.ArmedTextColor", pScheme), Color(0, 0, 0, 0));
SetDepressedColor(GetSchemeColor("MainMenu.DepressedTextColor", pScheme), Color(0, 0, 0, 0));
SetContentAlignment(Label::a_west);
SetBorder(NULL);
SetDefaultBorder(NULL);
SetDepressedBorder(NULL);
SetKeyFocusBorder(NULL);
vgui::HFont hMainMenuFont = pScheme->GetFont( "MainMenuFont", IsProportional() );
if ( hMainMenuFont )
{
SetFont( hMainMenuFont );
}
else
{
SetFont( pScheme->GetFont( "MenuLarge", IsProportional() ) );
}
SetTextInset(0, 0);
SetArmedSound("UI/buttonrollover.wav");
SetDepressedSound("UI/buttonclick.wav");
SetReleasedSound("UI/buttonclickrelease.wav");
SetButtonActivationType(Button::ACTIVATE_ONPRESSED);
if ( GameUI().IsConsoleUI() )
{
SetArmedColor(GetSchemeColor("MainMenu.ArmedTextColor", pScheme), GetSchemeColor("Button.ArmedBgColor", pScheme));
SetTextInset( MAIN_MENU_INDENT_X360, 0 );
}
if (m_bRightAligned)
{
SetContentAlignment(Label::a_east);
}
}
void CGameMenuItem::PaintBackground()
{
if ( !GameUI().IsConsoleUI() )
{
BaseClass::PaintBackground();
}
else
{
if ( !IsArmed() || !IsVisible() || GetParent()->GetAlpha() < 32 )
return;
int wide, tall;
GetSize( wide, tall );
DrawBoxFade( 0, 0, wide, tall, GetButtonBgColor(), 1.0f, 255, 0, true );
DrawBoxFade( 2, 2, wide - 4, tall - 4, Color( 0, 0, 0, 96 ), 1.0f, 255, 0, true );
}
}
void CGameMenuItem::SetRightAlignedText(bool state)
{
m_bRightAligned = state;
}
//-----------------------------------------------------------------------------
// Purpose: General purpose 1 of N menu
//-----------------------------------------------------------------------------
class CGameMenu : public vgui::Menu
{
public:
DECLARE_CLASS_SIMPLE( CGameMenu, vgui::Menu );
CGameMenu(vgui::Panel *parent, const char *name) : BaseClass(parent, name)
{
if ( GameUI().IsConsoleUI() )
{
// shows graphic button hints
m_pConsoleFooter = new CFooterPanel( parent, "MainMenuFooter" );
int iFixedWidth = 245;
#ifdef _X360
// In low def we need a smaller highlight
XVIDEO_MODE videoMode;
XGetVideoMode( &videoMode );
if ( !videoMode.fIsHiDef )
{
iFixedWidth = 240;
}
else
{
iFixedWidth = 350;
}
#endif
SetFixedWidth( iFixedWidth );
}
else
{
m_pConsoleFooter = NULL;
}
m_hMainMenuOverridePanel = NULL;
}
virtual void ApplySchemeSettings(IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
int height = atoi(pScheme->GetResourceString("MainMenu.MenuItemHeight"));
if( IsProportional() )
height = scheme()->GetProportionalScaledValue( height );
// make fully transparent
SetMenuItemHeight(height);
SetBgColor(Color(0, 0, 0, 0));
SetBorder(NULL);
}
virtual void LayoutMenuBorder()
{
}
void SetMainMenuOverride( vgui::VPANEL panel )
{
m_hMainMenuOverridePanel = panel;
if ( m_hMainMenuOverridePanel )
{
// We've got an override panel. Nuke all our menu items.
DeleteAllItems();
}
}
virtual void SetVisible(bool state)
{
if ( m_hMainMenuOverridePanel )
{
// force to be always visible
ipanel()->SetVisible( m_hMainMenuOverridePanel, true );
// move us to the back instead of going invisible
if ( !state )
{
ipanel()->MoveToBack(m_hMainMenuOverridePanel);
}
}
// force to be always visible
BaseClass::SetVisible(true);
// move us to the back instead of going invisible
if (!state)
{
ipanel()->MoveToBack(GetVPanel());
}
}
virtual int AddMenuItem(const char *itemName, const char *itemText, const char *command, Panel *target, KeyValues *userData = NULL)
{
MenuItem *item = new CGameMenuItem(this, itemName);
item->AddActionSignalTarget(target);
item->SetCommand(command);
item->SetText(itemText);
item->SetUserData(userData);
return BaseClass::AddMenuItem(item);
}
virtual int AddMenuItem(const char *itemName, wchar_t *itemText, const char *command, Panel *target, KeyValues *userData = NULL)
{
MenuItem *item = new CGameMenuItem(this, itemName);
item->AddActionSignalTarget(target);
item->SetCommand(command);
item->SetText(itemText);
item->SetUserData(userData);
return BaseClass::AddMenuItem(item);
}
virtual int AddMenuItem(const char *itemName, const char *itemText, KeyValues *command, Panel *target, KeyValues *userData = NULL)
{
CGameMenuItem *item = new CGameMenuItem(this, itemName);
item->AddActionSignalTarget(target);
item->SetCommand(command);
item->SetText(itemText);
item->SetRightAlignedText(true);
item->SetUserData(userData);
return BaseClass::AddMenuItem(item);
}
virtual void SetMenuItemBlinkingState( const char *itemName, bool state )
{
for (int i = 0; i < GetChildCount(); i++)
{
Panel *child = GetChild(i);
MenuItem *menuItem = dynamic_cast<MenuItem *>(child);
if (menuItem)
{
if ( Q_strcmp( menuItem->GetCommand()->GetString("command", ""), itemName ) == 0 )
{
menuItem->SetBlink( state );
}
}
}
InvalidateLayout();
}
virtual void OnSetFocus()
{
if ( m_hMainMenuOverridePanel )
{
Panel *pMainMenu = ipanel()->GetPanel( m_hMainMenuOverridePanel, "ClientDLL" );
if ( pMainMenu )
{
pMainMenu->PerformLayout();
}
}
BaseClass::OnSetFocus();
}
virtual void OnCommand(const char *command)
{
m_KeyRepeat.Reset();
if (!stricmp(command, "Open"))
{
if ( m_hMainMenuOverridePanel )
{
// force to be always visible
ipanel()->MoveToFront( m_hMainMenuOverridePanel );
ipanel()->RequestFocus( m_hMainMenuOverridePanel );
}
else
{
MoveToFront();
RequestFocus();
}
}
else
{
BaseClass::OnCommand(command);
}
}
virtual void OnKeyCodePressed( KeyCode code )
{
if ( IsX360() )
{
if ( GetAlpha() != 255 )
{
SetEnabled( false );
// inhibit key activity during transitions
return;
}
SetEnabled( true );
if ( code == KEY_XBUTTON_B || code == KEY_XBUTTON_START )
{
if ( GameUI().IsInLevel() )
{
GetParent()->OnCommand( "ResumeGame" );
}
return;
}
}
m_KeyRepeat.KeyDown( code );
int nDir = 0;
switch ( code )
{
case KEY_XBUTTON_UP:
case KEY_XSTICK1_UP:
case KEY_XSTICK2_UP:
case KEY_UP:
case STEAMCONTROLLER_DPAD_UP:
nDir = -1;
break;
case KEY_XBUTTON_DOWN:
case KEY_XSTICK1_DOWN:
case KEY_XSTICK2_DOWN:
case KEY_DOWN:
case STEAMCONTROLLER_DPAD_DOWN:
nDir = 1;
break;
}
if ( nDir != 0 )
{
CUtlSortVector< SortedPanel_t, CSortedPanelYLess > vecSortedButtons;
VguiPanelGetSortedChildButtonList( this, (void*)&vecSortedButtons );
if ( VguiPanelNavigateSortedChildButtonList( (void*)&vecSortedButtons, nDir ) != -1 )
{
// Handled!
return;
}
}
else if ( code == KEY_XBUTTON_A || code == STEAMCONTROLLER_A )
{
CUtlSortVector< SortedPanel_t, CSortedPanelYLess > vecSortedButtons;
VguiPanelGetSortedChildButtonList( this, (void*)&vecSortedButtons );
for ( int i = 0; i < vecSortedButtons.Count(); i++ )
{
if ( vecSortedButtons[ i ].pButton->IsArmed() )
{
vecSortedButtons[ i ].pButton->DoClick();
return;
}
}
}
BaseClass::OnKeyCodePressed( code );
// HACK: Allow F key bindings to operate even here
if ( IsPC() && code >= KEY_F1 && code <= KEY_F12 )
{
// See if there is a binding for the FKey
const char *binding = gameuifuncs->GetBindingForButtonCode( code );
if ( binding && binding[0] )
{
// submit the entry as a console commmand
char szCommand[256];
Q_strncpy( szCommand, binding, sizeof( szCommand ) );
engine->ClientCmd_Unrestricted( szCommand );
}
}
}
void OnKeyCodeReleased( vgui::KeyCode code )
{
m_KeyRepeat.KeyUp( code );
BaseClass::OnKeyCodeReleased( code );
}
void OnThink()
{
vgui::KeyCode code = m_KeyRepeat.KeyRepeated();
if ( code )
{
OnKeyCodeTyped( code );
}
BaseClass::OnThink();
}
virtual void OnKillFocus()
{
BaseClass::OnKillFocus();
if ( m_hMainMenuOverridePanel )
{
// force us to the rear when we lose focus (so it looks like the menu is always on the background)
surface()->MovePopupToBack( m_hMainMenuOverridePanel );
}
else
{
// force us to the rear when we lose focus (so it looks like the menu is always on the background)
surface()->MovePopupToBack(GetVPanel());
}
m_KeyRepeat.Reset();
}
void ShowFooter( bool bShow )
{
if ( m_pConsoleFooter )
{
m_pConsoleFooter->SetVisible( bShow );
}
}
void UpdateMenuItemState( bool isInGame, bool isMultiplayer, bool isInReplay, bool isVREnabled, bool isVRActive )
{
bool isSteam = IsPC() && ( CommandLine()->FindParm("-steam") != 0 );
bool bIsConsoleUI = GameUI().IsConsoleUI();
// disabled save button if we're not in a game
for (int i = 0; i < GetChildCount(); i++)
{
Panel *child = GetChild(i);
MenuItem *menuItem = dynamic_cast<MenuItem *>(child);
if (menuItem)
{
bool shouldBeVisible = true;
// filter the visibility
KeyValues *kv = menuItem->GetUserData();
if (!kv)
continue;
if (!isInGame && kv->GetInt("OnlyInGame") )
{
shouldBeVisible = false;
}
if (!isInReplay && kv->GetInt("OnlyInReplay") )
{
shouldBeVisible = false;
}
else if (!isVREnabled && kv->GetInt("OnlyWhenVREnabled") )
{
shouldBeVisible = false;
}
else if ( ( !isVRActive || ShouldForceVRActive() ) && kv->GetInt( "OnlyWhenVRActive" ) )
{
shouldBeVisible = false;
}
else if (isVRActive && kv->GetInt("OnlyWhenVRInactive") )
{
shouldBeVisible = false;
}
else if (isMultiplayer && kv->GetInt("notmulti"))
{
shouldBeVisible = false;
}
else if (isInGame && !isMultiplayer && kv->GetInt("notsingle"))
{
shouldBeVisible = false;
}
else if (isSteam && kv->GetInt("notsteam"))
{
shouldBeVisible = false;
}
else if ( !bIsConsoleUI && kv->GetInt( "ConsoleOnly" ) )
{
shouldBeVisible = false;
}
// If we're playing back a replay, hide everything else
if ( isInReplay && !kv->GetInt("OnlyInReplay") )
{
shouldBeVisible = false;
}
menuItem->SetVisible( shouldBeVisible );
}
}
if ( !isInGame )
{
// Sort them into their original order
for ( int j = 0; j < GetChildCount() - 2; j++ )
{
MoveMenuItem( j, j + 1 );
}
}
else
{
// Sort them into their in game order
for ( int i = 0; i < GetChildCount(); i++ )
{
for ( int j = i; j < GetChildCount() - 2; j++ )
{
int iID1 = GetMenuID( j );
int iID2 = GetMenuID( j + 1 );
MenuItem *menuItem1 = GetMenuItem( iID1 );
MenuItem *menuItem2 = GetMenuItem( iID2 );
KeyValues *kv1 = menuItem1->GetUserData();
KeyValues *kv2 = menuItem2->GetUserData();
if( !kv1 || !kv2 )
continue;
if ( kv1->GetInt("InGameOrder") > kv2->GetInt("InGameOrder") )
MoveMenuItem( iID2, iID1 );
}
}
}
InvalidateLayout();
if ( m_pConsoleFooter )
{
// update the console footer
const char *pHelpName;
if ( !isInGame )
pHelpName = "MainMenu";
else
pHelpName = "GameMenu";
if ( !m_pConsoleFooter->GetHelpName() || V_stricmp( pHelpName, m_pConsoleFooter->GetHelpName() ) )
{
// game menu must re-establish its own help once it becomes re-active
m_pConsoleFooter->SetHelpNameAndReset( pHelpName );
m_pConsoleFooter->AddNewButtonLabel( "#GameUI_Action", "#GameUI_Icons_A_BUTTON" );
if ( isInGame )
{
m_pConsoleFooter->AddNewButtonLabel( "#GameUI_Close", "#GameUI_Icons_B_BUTTON" );
}
}
}
}
MESSAGE_FUNC_HANDLE( OnCursorEnteredMenuItem, "CursorEnteredMenuItem", menuItem);
private:
CFooterPanel *m_pConsoleFooter;
vgui::CKeyRepeatHandler m_KeyRepeat;
vgui::VPANEL m_hMainMenuOverridePanel;
};
//-----------------------------------------------------------------------------
// Purpose: Respond to cursor entering a menuItem.
//-----------------------------------------------------------------------------
void CGameMenu::OnCursorEnteredMenuItem(VPANEL menuItem)
{
MenuItem *item = static_cast<MenuItem *>(ipanel()->GetPanel(menuItem, GetModuleName()));
KeyValues *pCommand = item->GetCommand();
if ( !pCommand->GetFirstSubKey() )
return;
const char *pszCmd = pCommand->GetFirstSubKey()->GetString();
if ( !pszCmd || !pszCmd[0] )
return;
BaseClass::OnCursorEnteredMenuItem( menuItem );
}
static CBackgroundMenuButton* CreateMenuButton( CBasePanel *parent, const char *panelName, const wchar_t *panelText )
{
CBackgroundMenuButton *pButton = new CBackgroundMenuButton( parent, panelName );
pButton->SetCommand("OpenGameMenu");
pButton->SetText(panelText);
return pButton;
}
bool g_bIsCreatingNewGameMenuForPreFetching = false;
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CBasePanel::CBasePanel() : Panel(NULL, "BaseGameUIPanel")
{
if( NeedProportional() )
SetProportional( true );
g_pBasePanel = this;
m_bLevelLoading = false;
m_eBackgroundState = BACKGROUND_INITIAL;
m_flTransitionStartTime = 0.0f;
m_flTransitionEndTime = 0.0f;
m_flFrameFadeInTime = 0.5f;
m_bRenderingBackgroundTransition = false;
m_bFadingInMenus = false;
m_bEverActivated = false;
m_iGameMenuInset = 24;
m_bPlatformMenuInitialized = false;
m_bHaveDarkenedBackground = false;
m_bHaveDarkenedTitleText = true;
m_bForceTitleTextUpdate = true;
m_BackdropColor = Color(0, 0, 0, 128);
m_pConsoleAnimationController = NULL;
m_pConsoleControlSettings = NULL;
m_bCopyFrameBuffer = false;
m_bUseRenderTargetImage = false;
m_ExitingFrameCount = 0;
m_bXUIVisible = false;
m_bUseMatchmaking = false;
m_bRestartFromInvite = false;
m_bRestartSameGame = false;
m_bUserRefusedSignIn = false;
m_bUserRefusedStorageDevice = false;
m_bWaitingForUserSignIn = false;
m_bWaitingForStorageDeviceHandle = false;
m_bNeedStorageDeviceHandle = false;
m_bStorageBladeShown = false;
m_iStorageID = XBX_INVALID_STORAGE_ID;
m_pAsyncJob = NULL;
m_pStorageDeviceValidatedNotify = NULL;
m_iRenderTargetImageID = -1;
m_iBackgroundImageID = -1;
m_iProductImageID = -1;
m_iLoadingImageID = -1;
if ( GameUI().IsConsoleUI() )
{
m_pConsoleAnimationController = new AnimationController( this );
m_pConsoleAnimationController->SetScriptFile( GetVPanel(), "scripts/GameUIAnimations.txt" );
m_pConsoleAnimationController->SetAutoReloadScript( IsDebug() );
m_pConsoleControlSettings = new KeyValues( "XboxDialogs.res" );
if ( !m_pConsoleControlSettings->LoadFromFile( g_pFullFileSystem, "resource/UI/XboxDialogs.res", "GAME" ) )
{
Error( "Failed to load UI control settings!\n" );
}
else
{
m_pConsoleControlSettings->ProcessResolutionKeys( surface()->GetResolutionKey() );
}
#ifdef _X360
x360_audio_english.SetValue( XboxLaunch()->GetForceEnglish() );
#endif
}
m_pGameMenuButtons.AddToTail( CreateMenuButton( this, "GameMenuButton", ModInfo().GetGameTitle() ) );
m_pGameMenuButtons.AddToTail( CreateMenuButton( this, "GameMenuButton2", ModInfo().GetGameTitle2() ) );
#ifdef CS_BETA
if ( !ModInfo().NoCrosshair() ) // hack to not show the BETA for HL2 or HL1Port
{
m_pGameMenuButtons.AddToTail( CreateMenuButton( this, "BetaButton", L"BETA" ) );
}
#endif // CS_BETA
m_pGameMenu = NULL;
m_pGameLogo = NULL;
m_hMainMenuOverridePanel = NULL;
if ( SteamClient() )
{
HSteamPipe steamPipe = SteamClient()->CreateSteamPipe();
ISteamUtils *pUtils = SteamClient()->GetISteamUtils( steamPipe, "SteamUtils002" );
if ( pUtils )
{
bSteamCommunityFriendsVersion = true;
}
SteamClient()->BReleaseSteamPipe( steamPipe );
}
CreateGameMenu();
CreateGameLogo();
// Bonus maps menu blinks if something has been unlocked since the player last opened the menu
// This is saved as persistant data, and here is where we check for that
CheckBonusBlinkState();
// start the menus fully transparent
SetMenuAlpha( 0 );
if ( GameUI().IsConsoleUI() )
{
// do any costly resource prefetching now....
// force the new dialog to get all of its chapter pics
g_bIsCreatingNewGameMenuForPreFetching = true;
m_hNewGameDialog = new CNewGameDialog( this, false );
m_hNewGameDialog->MarkForDeletion();
g_bIsCreatingNewGameMenuForPreFetching = false;
m_hOptionsDialog_Xbox = new COptionsDialogXbox( this );
m_hOptionsDialog_Xbox->MarkForDeletion();
m_hControllerDialog = new CControllerDialog( this );
m_hControllerDialog->MarkForDeletion();
ArmFirstMenuItem();
m_pConsoleAnimationController->StartAnimationSequence( "InitializeUILayout" );
}
// Record data used for rich presence updates
if ( IsX360() )
{
// Get our active mod directory name
const char *pGameName = CommandLine()->ParmValue( "-game", "hl2" );;
// Set the game we're playing
m_iGameID = CONTEXT_GAME_GAME_HALF_LIFE_2;
m_bSinglePlayer = true;
if ( Q_stristr( pGameName, "episodic" ) )
{
m_iGameID = CONTEXT_GAME_GAME_EPISODE_ONE;
}
else if ( Q_stristr( pGameName, "ep2" ) )
{
m_iGameID = CONTEXT_GAME_GAME_EPISODE_TWO;
}
else if ( Q_stristr( pGameName, "portal" ) )
{
m_iGameID = CONTEXT_GAME_GAME_PORTAL;
}
else if ( Q_stristr( pGameName, "tf" ) )
{
m_iGameID = CONTEXT_GAME_GAME_TEAM_FORTRESS;
m_bSinglePlayer = false;
}
}
}
//-----------------------------------------------------------------------------
// Purpose: Xbox 360 - Get the console UI keyvalues to pass to LoadControlSettings()
//-----------------------------------------------------------------------------
KeyValues *CBasePanel::GetConsoleControlSettings( void )
{
return m_pConsoleControlSettings;
}
//-----------------------------------------------------------------------------
// Purpose: Causes the first menu item to be armed
//-----------------------------------------------------------------------------
void CBasePanel::ArmFirstMenuItem( void )
{
UpdateGameMenus();
// Arm the first item in the menu
for ( int i = 0; i < m_pGameMenu->GetItemCount(); ++i )
{
if ( m_pGameMenu->GetMenuItem( i )->IsVisible() )
{
m_pGameMenu->SetCurrentlyHighlightedItem( i );
break;
}
}
}
CBasePanel::~CBasePanel()
{
g_pBasePanel = NULL;
if ( vgui::surface() )
{
if ( m_iRenderTargetImageID != -1 )
{
vgui::surface()->DestroyTextureID( m_iRenderTargetImageID );
m_iRenderTargetImageID = -1;
}
if ( m_iBackgroundImageID != -1 )
{
vgui::surface()->DestroyTextureID( m_iBackgroundImageID );
m_iBackgroundImageID = -1;
}
if ( m_iProductImageID != -1 )
{
vgui::surface()->DestroyTextureID( m_iProductImageID );
m_iProductImageID = -1;
}
if ( m_iLoadingImageID != -1 )
{
vgui::surface()->DestroyTextureID( m_iLoadingImageID );
m_iLoadingImageID = -1;
}
}
}
static const char *g_rgValidCommands[] =
{
"OpenGameMenu",
"OpenConsole",
"OpenPlayerListDialog",
"OpenNewGameDialog",
"OpenLoadGameDialog",
"OpenSaveGameDialog",
"OpenCustomMapsDialog",
"OpenOptionsDialog",
"OpenBenchmarkDialog",
"OpenServerBrowser",
"OpenFriendsDialog",
"OpenLoadDemoDialog",
"OpenCreateMultiplayerGameDialog",
"OpenChangeGameDialog",
"OpenLoadCommentaryDialog",
"Quit",
"QuitNoConfirm",
"ResumeGame",
"Disconnect",
};
static void CC_GameMenuCommand( const CCommand &args )
{
int c = args.ArgC();
if ( c < 2 )
{
Msg( "Usage: gamemenucommand <commandname>\n" );
return;
}
if ( !g_pBasePanel )
{
return;
}
vgui::ivgui()->PostMessage( g_pBasePanel->GetVPanel(), new KeyValues("Command", "command", args[1] ), NULL);
}
static int CC_GameMenuCompletionFunc( char const *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] )
{
char const *cmdname = "gamemenucommand";
char *substring = (char *)partial;
if ( Q_strstr( partial, cmdname ) )
{
substring = (char *)partial + strlen( cmdname ) + 1;
}
int checklen = Q_strlen( substring );
CUtlRBTree< CUtlString > symbols( 0, 0, UtlStringLessFunc );
int i;
int c = ARRAYSIZE( g_rgValidCommands );
for ( i = 0; i < c; ++i )
{
if ( Q_strnicmp( g_rgValidCommands[ i ], substring, checklen ) )
continue;
CUtlString str;
str = g_rgValidCommands[ i ];
symbols.Insert( str );
// Too many
if ( symbols.Count() >= COMMAND_COMPLETION_MAXITEMS )
break;
}
// Now fill in the results
int slot = 0;
for ( i = symbols.FirstInorder(); i != symbols.InvalidIndex(); i = symbols.NextInorder( i ) )
{
char const *name = symbols[ i ].String();
char buf[ 512 ];
Q_strncpy( buf, name, sizeof( buf ) );
Q_strlower( buf );
Q_snprintf( commands[ slot++ ], COMMAND_COMPLETION_ITEM_LENGTH, "%s %s",
cmdname, buf );
}
return slot;
}
static ConCommand gamemenucommand( "gamemenucommand", CC_GameMenuCommand, "Issue game menu command.", 0, CC_GameMenuCompletionFunc );
//-----------------------------------------------------------------------------
// Purpose: paints the main background image
//-----------------------------------------------------------------------------
void CBasePanel::PaintBackground()
{
if ( !GameUI().IsInLevel() || g_hLoadingDialog.Get() || m_ExitingFrameCount )
{
// not in the game or loading dialog active or exiting, draw the ui background
DrawBackgroundImage();
}
else if ( IsX360() )
{
// only valid during loading from level to level
m_bUseRenderTargetImage = false;
}
if ( m_flBackgroundFillAlpha )
{
int swide, stall;
surface()->GetScreenSize(swide, stall);
surface()->DrawSetColor(0, 0, 0, m_flBackgroundFillAlpha);
surface()->DrawFilledRect(0, 0, swide, stall);
}
}
//-----------------------------------------------------------------------------
// Updates which background state we should be in.
//
// NOTE: These states change at funny times and overlap. They CANNOT be
// used to demarcate exact transitions.