Skip to content

Commit 3ddfe25

Browse files
authored
Merge pull request #169 from marchc1/fix-build-and-userinfo-crash
Fix build time issue, userinfo crash, save dialog in singleplayer
2 parents e6d6b24 + a806e5c commit 3ddfe25

9 files changed

Lines changed: 261 additions & 40 deletions

File tree

‎Game.UI/BasePanel.cs‎

Lines changed: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -495,16 +495,77 @@ public override void ApplySchemeSettings(IScheme scheme) {
495495
SetTextInset(0, 0);
496496
}
497497
}
498+
public class SaveBeforeQuitQueryDialog : Frame
499+
{
500+
public SaveBeforeQuitQueryDialog(Panel parent, ReadOnlySpan<char> name) : base(parent, name) {
501+
LoadControlSettings("resource/SaveBeforeQuitDialog.res");
502+
SetDeleteSelfOnClose(true);
503+
SetSizeable(false);
504+
}
505+
506+
public override void DoModal() {
507+
base.Activate();
508+
Input.SetAppModalSurface(this);
509+
MoveToCenterOfScreen();
510+
Surface.RestrictPaintToSinglePanel(this);
511+
512+
gameUI.PreventEngineHideGameUI();
513+
}
514+
515+
public override void OnKeyCodeTyped(ButtonCode code) {
516+
if (code == ButtonCode.KeyEscape)
517+
Close();
518+
else
519+
base.OnKeyCodeTyped(code);
520+
}
521+
522+
public override void OnKeyCodePressed(ButtonCode code) {
523+
switch (code) {
524+
case ButtonCode.KeyXButtonB: Close(); break;
525+
case ButtonCode.KeyXButtonA: OnCommand("SaveAndQuit"); break;
526+
case ButtonCode.KeyXButtonX: OnCommand("Quit"); break;
527+
default: base.OnKeyCodePressed(code); break;
528+
}
529+
}
530+
531+
public override void OnCommand(ReadOnlySpan<char> command) {
532+
if (0 == stricmp(command, "Quit"))
533+
PostMessage(GetParent(), new KeyValues("Command", "command", "QuitNoConfirm"));
534+
else if (0 == stricmp(command, "SaveAndQuit")) {
535+
// find a new name to save
536+
Span<char> saveName= stackalloc char[128];
537+
// TODO: SaveGameDialog.FindSaveSlot(saveName, sizeof(saveName));
538+
// TODO: if (saveName[0] != '\0') {
539+
// TODO: // save the game
540+
// TODO: Span<char> sz = stackalloc char[256];
541+
// TODO: sprintf(sz, "save %s\n").S(saveName);
542+
// TODO: engine.ClientCmd_Unrestricted(sz.SliceNullTerminatedString());
543+
// TODO: }
544+
545+
// quit
546+
PostMessage(GetParent(), new KeyValues("Command", "command", "QuitNoConfirm"));
547+
}
548+
else if (0 == stricmp(command, "Cancel"))
549+
Close();
550+
else
551+
base.OnCommand(command);
552+
}
553+
554+
public override void OnClose() {
555+
base.OnClose();
556+
Surface.RestrictPaintToSinglePanel(null);
557+
gameUI.AllowEngineHideGameUI();
558+
}
559+
}
560+
498561
public class QuitQueryBox : QueryBox
499562
{
500563
public QuitQueryBox(ReadOnlySpan<char> title, ReadOnlySpan<char> queryText, Panel? parent = null) : base(title, queryText, parent) { }
501564

502-
IGameUI GameUI = Singleton<IGameUI>();
503-
504565
public override void DoModal(Frame? frameOver) {
505566
base.DoModal(frameOver);
506567
Surface.RestrictPaintToSinglePanel(this);
507-
GameUI.PreventEngineHideGameUI();
568+
gameUI.PreventEngineHideGameUI();
508569
}
509570
public override void OnKeyCodeTyped(ButtonCode code) {
510571
if (code == ButtonCode.KeyEscape)
@@ -515,15 +576,14 @@ public override void OnKeyCodeTyped(ButtonCode code) {
515576
public override void OnClose() {
516577
base.OnClose();
517578
Surface.RestrictPaintToSinglePanel(null);
518-
GameUI.AllowEngineHideGameUI();
579+
gameUI.AllowEngineHideGameUI();
519580
}
520581
}
521582
public class BasePanel : Panel
522583
{
523584
GameMenu? GameMenu;
524585

525586
readonly public IFileSystem FileSystem = Singleton<IFileSystem>();
526-
readonly public GameUI GameUI;
527587
readonly public IEngineClient engine = Singleton<IEngineClient>();
528588
readonly public ModInfo ModInfo = Singleton<ModInfo>();
529589

@@ -587,7 +647,7 @@ private void RunMenuCommand(ReadOnlySpan<char> command) {
587647
engine.ClientCmd_Unrestricted("quit\n");
588648
break;
589649
case "QuitRestartNoConfirm": break;
590-
case "ResumeGame": GameUI.HideGameUI(); break;
650+
case "ResumeGame": gameUI.HideGameUI(); break;
591651
case "Disconnect": engine.ClientCmd_Unrestricted("disconnect"); break;
592652
case "DisconnectNoConfirm": break;
593653
case "ReleaseModalWindow": Surface.RestrictPaintToSinglePanel(null); break;
@@ -635,12 +695,13 @@ public void PositionDialog(Panel? dialog) {
635695
}
636696

637697
public void OnOpenQuitConfirmationDialog() {
638-
if (GameUI.IsConsoleUI()) {
698+
if (gameUI.IsConsoleUI()) {
639699
throw new NotImplementedException();
640700
}
641701

642-
if (GameUI.IsInLevel() && engine.GetMaxClients() == 1) {
643-
throw new NotImplementedException();
702+
if (gameUI.IsInLevel() && engine.GetMaxClients() == 1) {
703+
SaveBeforeQuitQueryDialog box = new SaveBeforeQuitQueryDialog(this, "SaveBeforeQuitQueryDialog");
704+
box.DoModal();
644705
}
645706
else {
646707
QueryBox box = new QuitQueryBox("#GameUI_QuitConfirmationTitle", "#GameUI_QuitConfirmationText", this);
@@ -660,8 +721,7 @@ static BackgroundMenuButton CreateMenuButton(BasePanel parent, ReadOnlySpan<char
660721
return button;
661722
}
662723

663-
public BasePanel(GameUI gameUI) : base(null, "BaseGameUIPanel") {
664-
GameUI = gameUI;
724+
public BasePanel() : base(null, "BaseGameUIPanel") {
665725
g_BasePanel = this;
666726
CreateGameMenu();
667727
CreateGameLogo();
@@ -677,7 +737,7 @@ public BasePanel(GameUI gameUI) : base(null, "BaseGameUIPanel") {
677737
IFont? FontTest;
678738

679739
public override void PaintBackground() {
680-
if (!GameUI.IsInLevel() || GameUI.LoadingDialog != null || ExitingFrameCount > 0)
740+
if (!gameUI.IsInLevel() || GameUI.LoadingDialog != null || ExitingFrameCount > 0)
681741
DrawBackgroundImage();
682742

683743
if (BackgroundFillAlpha > 0) {
@@ -753,9 +813,9 @@ public void SetBackgroundRenderState(BackgroundState state) {
753813
public void UpdateBackgroundState() {
754814
if (ExitingFrameCount != 0)
755815
SetBackgroundRenderState(BackgroundState.Exiting);
756-
else if (GameUI.IsInLevel())
816+
else if (gameUI.IsInLevel())
757817
SetBackgroundRenderState(BackgroundState.Level);
758-
else if (GameUI.IsInBackgroundLevel() && !LevelLoading)
818+
else if (gameUI.IsInBackgroundLevel() && !LevelLoading)
759819
SetBackgroundRenderState(BackgroundState.MainMenu);
760820
else if (LevelLoading)
761821
SetBackgroundRenderState(BackgroundState.Loading);
@@ -767,7 +827,7 @@ public void UpdateBackgroundState() {
767827

768828
int i;
769829
bool haveActiveDialogs = false;
770-
bool isInLevel = GameUI.IsInLevel();
830+
bool isInLevel = gameUI.IsInLevel();
771831
for (i = 0; i < GetChildCount(); ++i) {
772832
Panel? child = GetChild(i);
773833
if (child != null && child.IsVisible() && child.IsPopup() && child != GameMenu)
@@ -1030,7 +1090,7 @@ internal void OnGameUIActivated() {
10301090

10311091
int LastGameMenuState = -1;
10321092
private void UpdateGameMenus() {
1033-
bool isInGame = GameUI.IsInLevel();
1093+
bool isInGame = gameUI.IsInLevel();
10341094
bool isMulti = isInGame && engine.GetMaxClients() > 1;
10351095

10361096
int state = (isInGame ? 1 : 0) | (isMulti ? 2 : 0);

‎Game.UI/GameUI.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void Initialize(IEngineAPI engineAPI) {
113113
// I have no idea why this one defines needed resource strings... TODO: Is this still needed?
114114
localize.AddFile("Resource/itemtest_%language%.txt", "GAME", true);
115115

116-
staticPanel = new BasePanel(this);
116+
staticPanel = new BasePanel();
117117
staticPanel.SetBounds(0, 0, 400, 300);
118118
staticPanel.SetPaintBorderEnabled(false);
119119
staticPanel.SetPaintBackgroundEnabled(true);
@@ -232,7 +232,7 @@ private bool SetProgressBarStatusText(ReadOnlySpan<char> statusText) {
232232
return true;
233233
}
234234

235-
public LoadingDialog? LoadingDialog;
235+
public static LoadingDialog? LoadingDialog;
236236
string? PreviousStatusText;
237237

238238
public void StartProgressBar() {

‎Game.UI/LoadingDialog.cs‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ namespace Game.UI;
1010

1111
public class LoadingDialog : Frame
1212
{
13-
readonly public IGameUI GameUI = Singleton<IGameUI>();
1413
readonly public ModInfo ModInfo = Singleton<ModInfo>();
15-
readonly IEngineClient engine = Singleton<IEngineClient>();
1614

1715
ProgressBar Progress;
1816
ProgressBar Progress2;
@@ -84,7 +82,7 @@ public override void OnCommand(ReadOnlySpan<char> command) {
8482
public LoadingDialog(Panel? parent) : base(parent, "LoadingDialog") {
8583
SetDeleteSelfOnClose(true);
8684

87-
ConsoleStyle = GameUI.IsConsoleUI();
85+
ConsoleStyle = gameUI.IsConsoleUI();
8886

8987
if (!ConsoleStyle) {
9088
SetSize(416, 100);
@@ -94,7 +92,7 @@ public LoadingDialog(Panel? parent) : base(parent, "LoadingDialog") {
9492
#if GMOD_DLL
9593
Center = false;
9694
#else
97-
Center = !GameUI.HasLoadingBackgroundDialog();
95+
Center = !gameUI.HasLoadingBackgroundDialog();
9896
#endif
9997

10098
ShowingSecondaryProgress = false;
@@ -146,7 +144,7 @@ public LoadingDialog(Panel? parent) : base(parent, "LoadingDialog") {
146144
private void SetupControlSettings(bool forceShowProgressText) {
147145
ShowingVACInfo = false;
148146

149-
if (GameUI.IsConsoleUI()) {
147+
if (gameUI.IsConsoleUI()) {
150148
// KeyValues controlSettings = BasePanel.GetConsoleControlSettings().FindKey("LoadingDialogNoBanner.res");
151149
// LoadControlSettings("null", null, controlSettings);
152150
// return;
@@ -250,17 +248,17 @@ internal void Open() {
250248

251249
private void HideOtherDialogs(bool hide) {
252250
if (hide) {
253-
if (GameUI.HasLoadingBackgroundDialog()) {
254-
GameUI.ShowLoadingBackgroundDialog();
251+
if (gameUI.HasLoadingBackgroundDialog()) {
252+
gameUI.ShowLoadingBackgroundDialog();
255253
MoveToFront();
256254
Input.SetAppModalSurface(this);
257255
}
258256
else
259257
Surface.RestrictPaintToSinglePanel(this);
260258
}
261259
else {
262-
if (GameUI.HasLoadingBackgroundDialog()) {
263-
GameUI.HideLoadingBackgroundDialog();
260+
if (gameUI.HasLoadingBackgroundDialog()) {
261+
gameUI.HideLoadingBackgroundDialog();
264262
Input.SetAppModalSurface(null);
265263
}
266264
else

‎Game.UI/OptionsSubVideo.cs‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ class OptionsSubVideoAdvancedDlg : Frame
4545
int NumAAModes;
4646
AAMode[] AAModes = new AAMode[16];
4747

48-
ICvar cvar = Singleton<ICvar>();
49-
IGameUI GameUI => Singleton<IGameUI>();
50-
5148
public OptionsSubVideoAdvancedDlg(Panel? parent) : base(parent, "OptionsSubVideoAdvancedDlg") {
5249
SetTitle("#GameUI_VideoAdvanced_Title", true);
5350
SetSize(260, 400);
@@ -535,11 +532,11 @@ public override void OnKeyCodeTyped(ButtonCode code) {
535532
}
536533

537534
public bool RequiresRestart() {
538-
if (GameUI.IsInLevel()) {
539-
if (GameUI.IsInBackgroundLevel())
535+
if (gameUI.IsInLevel()) {
536+
if (gameUI.IsInBackgroundLevel())
540537
return false;
541538

542-
// if (!GameUI.IsInMultiplayer()) //todo
539+
// if (!gameUI.IsInMultiplayer()) //todo
543540
// return false;
544541

545542
if (HDR.IsEnabled()) {

‎Game.UI/SourceDllMain.cs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
using Source;
66
using Source.Common;
77
using Source.Common.Client;
8+
using Source.Common.Commands;
89
using Source.Common.Filesystem;
910
using Source.Common.GameUI;
1011
using Source.Common.GUI;
1112
using Source.Common.Input;
1213
using Source.Common.Launcher;
1314
using Source.Common.MaterialSystem;
1415

16+
using System.Runtime.CompilerServices;
17+
18+
using DependencyAttribute = Source.DependencyAttribute;
19+
1520
namespace Game.UI;
1621

1722
[EngineComponent]
@@ -25,8 +30,12 @@ public static class SourceDllMain
2530
[Dependency] public static ISurface Surface { get; private set; } = null!;
2631
[Dependency] public static IVGuiInput Input { get; private set; } = null!;
2732
[Dependency] public static ILocalize Localize { get; private set; } = null!;
33+
[Dependency] public static IGameUI gameUI { get; private set; } = null!;
2834
[Dependency] public static IMaterialSystem Materials { get; private set; } = null!;
2935
[Dependency] public static ISystem system { get; private set; } = null!;
36+
[Dependency] public static ICvar cvar { get; private set; } = null!;
37+
38+
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IGameUI GameUI() => gameUI;
3039

3140
public static void Link(IServiceCollection services) {
3241
services.AddSingleton<IGameConsole, GameConsole>();

‎Source.Engine/Client/ClientState.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,13 @@ public override bool SetSignonState(SignOnState state, int count) {
531531
NetChannel.SetTimeout(Source.Common.Networking.NetChannel.SIGNON_TIME_OUT);
532532
NetChannel.SetMaxBufferSize(true, Protocol.MAX_PAYLOAD);
533533

534+
#if GMOD_DLL
535+
Host.GMOD_BuildConVarUpdateMessage(NetChannel, FCvar.UserInfo, false);
536+
#else
534537
var convars = new NET_SetConVar();
535538
Host.BuildConVarUpdateMessage(convars, FCvar.UserInfo, false);
536539
NetChannel.SendNetMsg(convars);
540+
#endif
537541
break;
538542
case SignOnState.New:
539543
EngineVGui?.UpdateProgressBar(LevelLoadingProgress.SignOnNew);

0 commit comments

Comments
 (0)