Merge more UI refactor stuff (#11277)
* Changelog+options ui controller * Sandbox UI controller * Escape menu UI controller
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using Content.Client.Changelog;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.State;
|
||||
using Robust.Client.UserInterface.Controllers;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.EscapeMenu;
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class ChangelogUIController : UIController
|
||||
{
|
||||
private ChangelogWindow _changeLogWindow = default!;
|
||||
|
||||
public void OpenWindow()
|
||||
{
|
||||
EnsureWindow();
|
||||
|
||||
_changeLogWindow.OpenCentered();
|
||||
_changeLogWindow.MoveToFront();
|
||||
}
|
||||
|
||||
private void EnsureWindow()
|
||||
{
|
||||
if (_changeLogWindow is { Disposed: false })
|
||||
return;
|
||||
|
||||
_changeLogWindow = UIManager.CreateWindow<ChangelogWindow>();
|
||||
}
|
||||
|
||||
public void ToggleWindow()
|
||||
{
|
||||
EnsureWindow();
|
||||
|
||||
if (_changeLogWindow.IsOpen)
|
||||
{
|
||||
_changeLogWindow.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
OpenWindow();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
using Content.Client.Gameplay;
|
||||
using Content.Client.HUD;
|
||||
using Content.Client.Info;
|
||||
using Content.Client.Links;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controllers;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.Utility;
|
||||
using static Robust.Client.UserInterface.Controls.BaseButton;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.EscapeMenu;
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class EscapeUIController : UIController, IOnStateEntered<GameplayState>, IOnStateExited<GameplayState>
|
||||
{
|
||||
[Dependency] private readonly IClientConsoleHost _console = default!;
|
||||
[Dependency] private readonly IUriOpener _uri = default!;
|
||||
[Dependency] private readonly IGameHud _gameHud = default!;
|
||||
|
||||
private Options.UI.EscapeMenu? _escapeWindow;
|
||||
|
||||
public void OnStateEntered(GameplayState state)
|
||||
{
|
||||
DebugTools.Assert(_escapeWindow == null);
|
||||
_gameHud.EscapeButtonToggled += GameHudOnEscapeButtonToggled;
|
||||
|
||||
_escapeWindow = UIManager.CreateWindow<Options.UI.EscapeMenu>();
|
||||
_escapeWindow.OnClose += () => { _gameHud.EscapeButtonDown = false; };
|
||||
_escapeWindow.OnOpen += () => { _gameHud.EscapeButtonDown = true; };
|
||||
|
||||
_escapeWindow.ChangelogButton.OnPressed += _ =>
|
||||
{
|
||||
CloseEscapeWindow();
|
||||
UIManager.GetUIController<ChangelogUIController>().ToggleWindow();
|
||||
};
|
||||
|
||||
_escapeWindow.RulesButton.OnPressed += _ =>
|
||||
{
|
||||
CloseEscapeWindow();
|
||||
new RulesAndInfoWindow().Open();
|
||||
};
|
||||
|
||||
_escapeWindow.DisconnectButton.OnPressed += _ =>
|
||||
{
|
||||
CloseEscapeWindow();
|
||||
_console.ExecuteCommand("disconnect");
|
||||
};
|
||||
|
||||
_escapeWindow.OptionsButton.OnPressed += _ =>
|
||||
{
|
||||
CloseEscapeWindow();
|
||||
UIManager.GetUIController<OptionsUIController>().OpenWindow();
|
||||
};
|
||||
|
||||
_escapeWindow.QuitButton.OnPressed += _ =>
|
||||
{
|
||||
CloseEscapeWindow();
|
||||
_console.ExecuteCommand("quit");
|
||||
};
|
||||
|
||||
_escapeWindow.WikiButton.OnPressed += _ =>
|
||||
{
|
||||
_uri.OpenUri(UILinks.Wiki);
|
||||
};
|
||||
|
||||
CommandBinds.Builder
|
||||
.Bind(EngineKeyFunctions.EscapeMenu,
|
||||
InputCmdHandler.FromDelegate(_ => ToggleWindow()))
|
||||
.Register<EscapeUIController>();
|
||||
}
|
||||
|
||||
private void GameHudOnEscapeButtonToggled(bool obj)
|
||||
{
|
||||
ToggleWindow();
|
||||
}
|
||||
|
||||
public void OnStateExited(GameplayState state)
|
||||
{
|
||||
if (_escapeWindow != null)
|
||||
{
|
||||
_escapeWindow.Dispose();
|
||||
_escapeWindow = null;
|
||||
}
|
||||
_gameHud.EscapeButtonToggled -= GameHudOnEscapeButtonToggled;
|
||||
_gameHud.EscapeButtonDown = false;
|
||||
|
||||
CommandBinds.Unregister<EscapeUIController>();
|
||||
}
|
||||
|
||||
private void CloseEscapeWindow()
|
||||
{
|
||||
_escapeWindow?.Close();
|
||||
}
|
||||
|
||||
private void ToggleWindow()
|
||||
{
|
||||
if (_escapeWindow == null)
|
||||
return;
|
||||
|
||||
if (_escapeWindow.IsOpen)
|
||||
{
|
||||
CloseEscapeWindow();
|
||||
}
|
||||
else
|
||||
{
|
||||
_escapeWindow.OpenCentered();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using Content.Client.Options.UI;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.State;
|
||||
using Robust.Client.UserInterface.Controllers;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.EscapeMenu;
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class OptionsUIController : UIController
|
||||
{
|
||||
private OptionsMenu _optionsWindow = default!;
|
||||
|
||||
private void EnsureWindow()
|
||||
{
|
||||
if (_optionsWindow is { Disposed: false })
|
||||
return;
|
||||
|
||||
_optionsWindow = UIManager.CreateWindow<OptionsMenu>();
|
||||
}
|
||||
|
||||
public void OpenWindow()
|
||||
{
|
||||
EnsureWindow();
|
||||
|
||||
_optionsWindow.OpenCentered();
|
||||
_optionsWindow.MoveToFront();
|
||||
}
|
||||
|
||||
public void ToggleWindow()
|
||||
{
|
||||
EnsureWindow();
|
||||
|
||||
if (_optionsWindow.IsOpen)
|
||||
{
|
||||
_optionsWindow.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
OpenWindow();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user