Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 76 additions & 16 deletions Game.UI/BasePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,16 +495,77 @@ public override void ApplySchemeSettings(IScheme scheme) {
SetTextInset(0, 0);
}
}
public class SaveBeforeQuitQueryDialog : Frame
{
public SaveBeforeQuitQueryDialog(Panel parent, ReadOnlySpan<char> name) : base(parent, name) {
LoadControlSettings("resource/SaveBeforeQuitDialog.res");
SetDeleteSelfOnClose(true);
SetSizeable(false);
}

public override void DoModal() {
base.Activate();
Input.SetAppModalSurface(this);
MoveToCenterOfScreen();
Surface.RestrictPaintToSinglePanel(this);

gameUI.PreventEngineHideGameUI();
}

public override void OnKeyCodeTyped(ButtonCode code) {
if (code == ButtonCode.KeyEscape)
Close();
else
base.OnKeyCodeTyped(code);
}

public override void OnKeyCodePressed(ButtonCode code) {
switch (code) {
case ButtonCode.KeyXButtonB: Close(); break;
case ButtonCode.KeyXButtonA: OnCommand("SaveAndQuit"); break;
case ButtonCode.KeyXButtonX: OnCommand("Quit"); break;
default: base.OnKeyCodePressed(code); break;
}
}

public override void OnCommand(ReadOnlySpan<char> command) {
if (0 == stricmp(command, "Quit"))
PostMessage(GetParent(), new KeyValues("Command", "command", "QuitNoConfirm"));
else if (0 == stricmp(command, "SaveAndQuit")) {
// find a new name to save
Span<char> saveName= stackalloc char[128];
// TODO: SaveGameDialog.FindSaveSlot(saveName, sizeof(saveName));
// TODO: if (saveName[0] != '\0') {
// TODO: // save the game
// TODO: Span<char> sz = stackalloc char[256];
// TODO: sprintf(sz, "save %s\n").S(saveName);
// TODO: engine.ClientCmd_Unrestricted(sz.SliceNullTerminatedString());
// TODO: }

// quit
PostMessage(GetParent(), new KeyValues("Command", "command", "QuitNoConfirm"));
}
else if (0 == stricmp(command, "Cancel"))
Close();
else
base.OnCommand(command);
}

public override void OnClose() {
base.OnClose();
Surface.RestrictPaintToSinglePanel(null);
gameUI.AllowEngineHideGameUI();
}
}

public class QuitQueryBox : QueryBox
{
public QuitQueryBox(ReadOnlySpan<char> title, ReadOnlySpan<char> queryText, Panel? parent = null) : base(title, queryText, parent) { }

IGameUI GameUI = Singleton<IGameUI>();

public override void DoModal(Frame? frameOver) {
base.DoModal(frameOver);
Surface.RestrictPaintToSinglePanel(this);
GameUI.PreventEngineHideGameUI();
gameUI.PreventEngineHideGameUI();
}
public override void OnKeyCodeTyped(ButtonCode code) {
if (code == ButtonCode.KeyEscape)
Expand All @@ -515,15 +576,14 @@ public override void OnKeyCodeTyped(ButtonCode code) {
public override void OnClose() {
base.OnClose();
Surface.RestrictPaintToSinglePanel(null);
GameUI.AllowEngineHideGameUI();
gameUI.AllowEngineHideGameUI();
}
}
public class BasePanel : Panel
{
GameMenu? GameMenu;

readonly public IFileSystem FileSystem = Singleton<IFileSystem>();
readonly public GameUI GameUI;
readonly public IEngineClient engine = Singleton<IEngineClient>();
readonly public ModInfo ModInfo = Singleton<ModInfo>();

Expand Down Expand Up @@ -587,7 +647,7 @@ private void RunMenuCommand(ReadOnlySpan<char> command) {
engine.ClientCmd_Unrestricted("quit\n");
break;
case "QuitRestartNoConfirm": break;
case "ResumeGame": GameUI.HideGameUI(); break;
case "ResumeGame": gameUI.HideGameUI(); break;
case "Disconnect": engine.ClientCmd_Unrestricted("disconnect"); break;
case "DisconnectNoConfirm": break;
case "ReleaseModalWindow": Surface.RestrictPaintToSinglePanel(null); break;
Expand Down Expand Up @@ -635,12 +695,13 @@ public void PositionDialog(Panel? dialog) {
}

public void OnOpenQuitConfirmationDialog() {
if (GameUI.IsConsoleUI()) {
if (gameUI.IsConsoleUI()) {
throw new NotImplementedException();
}

if (GameUI.IsInLevel() && engine.GetMaxClients() == 1) {
throw new NotImplementedException();
if (gameUI.IsInLevel() && engine.GetMaxClients() == 1) {
SaveBeforeQuitQueryDialog box = new SaveBeforeQuitQueryDialog(this, "SaveBeforeQuitQueryDialog");
box.DoModal();
}
else {
QueryBox box = new QuitQueryBox("#GameUI_QuitConfirmationTitle", "#GameUI_QuitConfirmationText", this);
Expand All @@ -660,8 +721,7 @@ static BackgroundMenuButton CreateMenuButton(BasePanel parent, ReadOnlySpan<char
return button;
}

public BasePanel(GameUI gameUI) : base(null, "BaseGameUIPanel") {
GameUI = gameUI;
public BasePanel() : base(null, "BaseGameUIPanel") {
g_BasePanel = this;
CreateGameMenu();
CreateGameLogo();
Expand All @@ -677,7 +737,7 @@ public BasePanel(GameUI gameUI) : base(null, "BaseGameUIPanel") {
IFont? FontTest;

public override void PaintBackground() {
if (!GameUI.IsInLevel() || GameUI.LoadingDialog != null || ExitingFrameCount > 0)
if (!gameUI.IsInLevel() || GameUI.LoadingDialog != null || ExitingFrameCount > 0)
DrawBackgroundImage();

if (BackgroundFillAlpha > 0) {
Expand Down Expand Up @@ -753,9 +813,9 @@ public void SetBackgroundRenderState(BackgroundState state) {
public void UpdateBackgroundState() {
if (ExitingFrameCount != 0)
SetBackgroundRenderState(BackgroundState.Exiting);
else if (GameUI.IsInLevel())
else if (gameUI.IsInLevel())
SetBackgroundRenderState(BackgroundState.Level);
else if (GameUI.IsInBackgroundLevel() && !LevelLoading)
else if (gameUI.IsInBackgroundLevel() && !LevelLoading)
SetBackgroundRenderState(BackgroundState.MainMenu);
else if (LevelLoading)
SetBackgroundRenderState(BackgroundState.Loading);
Expand All @@ -767,7 +827,7 @@ public void UpdateBackgroundState() {

int i;
bool haveActiveDialogs = false;
bool isInLevel = GameUI.IsInLevel();
bool isInLevel = gameUI.IsInLevel();
for (i = 0; i < GetChildCount(); ++i) {
Panel? child = GetChild(i);
if (child != null && child.IsVisible() && child.IsPopup() && child != GameMenu)
Expand Down Expand Up @@ -1030,7 +1090,7 @@ internal void OnGameUIActivated() {

int LastGameMenuState = -1;
private void UpdateGameMenus() {
bool isInGame = GameUI.IsInLevel();
bool isInGame = gameUI.IsInLevel();
bool isMulti = isInGame && engine.GetMaxClients() > 1;

int state = (isInGame ? 1 : 0) | (isMulti ? 2 : 0);
Expand Down
4 changes: 2 additions & 2 deletions Game.UI/GameUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void Initialize(IEngineAPI engineAPI) {
// I have no idea why this one defines needed resource strings... TODO: Is this still needed?
localize.AddFile("Resource/itemtest_%language%.txt", "GAME", true);

staticPanel = new BasePanel(this);
staticPanel = new BasePanel();
staticPanel.SetBounds(0, 0, 400, 300);
staticPanel.SetPaintBorderEnabled(false);
staticPanel.SetPaintBackgroundEnabled(true);
Expand Down Expand Up @@ -232,7 +232,7 @@ private bool SetProgressBarStatusText(ReadOnlySpan<char> statusText) {
return true;
}

public LoadingDialog? LoadingDialog;
public static LoadingDialog? LoadingDialog;
string? PreviousStatusText;

public void StartProgressBar() {
Expand Down
16 changes: 7 additions & 9 deletions Game.UI/LoadingDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ namespace Game.UI;

public class LoadingDialog : Frame
{
readonly public IGameUI GameUI = Singleton<IGameUI>();
readonly public ModInfo ModInfo = Singleton<ModInfo>();
readonly IEngineClient engine = Singleton<IEngineClient>();

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

ConsoleStyle = GameUI.IsConsoleUI();
ConsoleStyle = gameUI.IsConsoleUI();

if (!ConsoleStyle) {
SetSize(416, 100);
Expand All @@ -94,7 +92,7 @@ public LoadingDialog(Panel? parent) : base(parent, "LoadingDialog") {
#if GMOD_DLL
Center = false;
#else
Center = !GameUI.HasLoadingBackgroundDialog();
Center = !gameUI.HasLoadingBackgroundDialog();
#endif

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

if (GameUI.IsConsoleUI()) {
if (gameUI.IsConsoleUI()) {
// KeyValues controlSettings = BasePanel.GetConsoleControlSettings().FindKey("LoadingDialogNoBanner.res");
// LoadControlSettings("null", null, controlSettings);
// return;
Expand Down Expand Up @@ -250,17 +248,17 @@ internal void Open() {

private void HideOtherDialogs(bool hide) {
if (hide) {
if (GameUI.HasLoadingBackgroundDialog()) {
GameUI.ShowLoadingBackgroundDialog();
if (gameUI.HasLoadingBackgroundDialog()) {
gameUI.ShowLoadingBackgroundDialog();
MoveToFront();
Input.SetAppModalSurface(this);
}
else
Surface.RestrictPaintToSinglePanel(this);
}
else {
if (GameUI.HasLoadingBackgroundDialog()) {
GameUI.HideLoadingBackgroundDialog();
if (gameUI.HasLoadingBackgroundDialog()) {
gameUI.HideLoadingBackgroundDialog();
Input.SetAppModalSurface(null);
}
else
Expand Down
9 changes: 3 additions & 6 deletions Game.UI/OptionsSubVideo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ class OptionsSubVideoAdvancedDlg : Frame
int NumAAModes;
AAMode[] AAModes = new AAMode[16];

ICvar cvar = Singleton<ICvar>();
IGameUI GameUI => Singleton<IGameUI>();

public OptionsSubVideoAdvancedDlg(Panel? parent) : base(parent, "OptionsSubVideoAdvancedDlg") {
SetTitle("#GameUI_VideoAdvanced_Title", true);
SetSize(260, 400);
Expand Down Expand Up @@ -535,11 +532,11 @@ public override void OnKeyCodeTyped(ButtonCode code) {
}

public bool RequiresRestart() {
if (GameUI.IsInLevel()) {
if (GameUI.IsInBackgroundLevel())
if (gameUI.IsInLevel()) {
if (gameUI.IsInBackgroundLevel())
return false;

// if (!GameUI.IsInMultiplayer()) //todo
// if (!gameUI.IsInMultiplayer()) //todo
// return false;

if (HDR.IsEnabled()) {
Expand Down
9 changes: 9 additions & 0 deletions Game.UI/SourceDllMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
using Source;
using Source.Common;
using Source.Common.Client;
using Source.Common.Commands;
using Source.Common.Filesystem;
using Source.Common.GameUI;
using Source.Common.GUI;
using Source.Common.Input;
using Source.Common.Launcher;
using Source.Common.MaterialSystem;

using System.Runtime.CompilerServices;

using DependencyAttribute = Source.DependencyAttribute;

namespace Game.UI;

[EngineComponent]
Expand All @@ -25,8 +30,12 @@ public static class SourceDllMain
[Dependency] public static ISurface Surface { get; private set; } = null!;
[Dependency] public static IVGuiInput Input { get; private set; } = null!;
[Dependency] public static ILocalize Localize { get; private set; } = null!;
[Dependency] public static IGameUI gameUI { get; private set; } = null!;
[Dependency] public static IMaterialSystem Materials { get; private set; } = null!;
[Dependency] public static ISystem system { get; private set; } = null!;
[Dependency] public static ICvar cvar { get; private set; } = null!;

[MethodImpl(MethodImplOptions.AggressiveInlining)] public static IGameUI GameUI() => gameUI;

public static void Link(IServiceCollection services) {
services.AddSingleton<IGameConsole, GameConsole>();
Expand Down
4 changes: 4 additions & 0 deletions Source.Engine/Client/ClientState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,13 @@ public override bool SetSignonState(SignOnState state, int count) {
NetChannel.SetTimeout(Source.Common.Networking.NetChannel.SIGNON_TIME_OUT);
NetChannel.SetMaxBufferSize(true, Protocol.MAX_PAYLOAD);

#if GMOD_DLL
Host.GMOD_BuildConVarUpdateMessage(NetChannel, FCvar.UserInfo, false);
#else
var convars = new NET_SetConVar();
Host.BuildConVarUpdateMessage(convars, FCvar.UserInfo, false);
NetChannel.SendNetMsg(convars);
#endif
break;
case SignOnState.New:
EngineVGui?.UpdateProgressBar(LevelLoadingProgress.SignOnNew);
Expand Down
Loading
Loading