Merge more UI refactor stuff (#11277)

* Changelog+options ui controller
* Sandbox UI controller
* Escape menu UI controller
This commit is contained in:
wrexbe
2022-09-14 14:34:48 -07:00
committed by GitHub
parent 8871c445b8
commit 018a96ee88
23 changed files with 591 additions and 573 deletions

View File

@@ -0,0 +1,84 @@
using Content.Client.Decals.UI;
using Content.Client.Gameplay;
using Content.Client.Sandbox;
using Content.Shared.Decals;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controllers;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Client.UserInterface.Systems.DecalPlacer;
public sealed class DecalPlacerUIController : UIController, IOnStateExited<GameplayState>, IOnSystemChanged<SandboxSystem>
{
[Dependency] private readonly IPrototypeManager _prototypes = default!;
[UISystemDependency] private readonly SandboxSystem _sandbox = default!;
private DecalPlacerWindow? _window;
public void ToggleWindow()
{
EnsureWindow();
if (_window!.IsOpen)
{
_window.Close();
}
else if(_sandbox.SandboxAllowed)
{
_window.Open();
}
}
public void OnStateExited(GameplayState state)
{
if (_window == null)
return;
_window.Dispose();
_window = null;
}
public void OnSystemLoaded(SandboxSystem system)
{
_sandbox.SandboxDisabled += CloseWindow;
_prototypes.PrototypesReloaded += OnPrototypesReloaded;
}
public void OnSystemUnloaded(SandboxSystem system)
{
_sandbox.SandboxDisabled -= CloseWindow;
_prototypes.PrototypesReloaded -= OnPrototypesReloaded;
}
private void OnPrototypesReloaded(PrototypesReloadedEventArgs obj)
{
ReloadPrototypes();
}
private void ReloadPrototypes()
{
if (_window == null || _window.Disposed)
return;
var prototypes = _prototypes.EnumeratePrototypes<DecalPrototype>();
_window.Populate(prototypes);
}
private void EnsureWindow()
{
if (_window is { Disposed: false })
return;
_window = UIManager.CreateWindow<DecalPlacerWindow>();
LayoutContainer.SetAnchorPreset(_window, LayoutContainer.LayoutPreset.CenterLeft);
ReloadPrototypes();
}
private void CloseWindow()
{
if (_window == null || _window.Disposed)
return;
_window.Close();
}
}

View File

@@ -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();
}
}
}

View File

@@ -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();
}
}
}

View File

@@ -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();
}
}
}

View File

@@ -0,0 +1,149 @@
using Content.Client.Gameplay;
using Content.Client.HUD;
using Content.Client.Markers;
using Content.Client.Sandbox;
using Content.Client.SubFloor;
using Content.Client.UserInterface.Systems.DecalPlacer;
using Content.Client.UserInterface.Systems.Sandbox.Windows;
using Content.Shared.Input;
using JetBrains.Annotations;
using Robust.Client.Debugging;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controllers;
using Robust.Client.UserInterface.Controllers.Implementations;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Input.Binding;
using Robust.Shared.Map;
using Robust.Shared.Players;
using Robust.Shared.Utility;
namespace Content.Client.UserInterface.Systems.Sandbox;
// TODO hud refactor should part of this be in engine?
[UsedImplicitly]
public sealed class SandboxUIController : UIController, IOnStateChanged<GameplayState>, IOnSystemChanged<SandboxSystem>
{
[Dependency] private readonly IEyeManager _eye = default!;
[Dependency] private readonly IInputManager _input = default!;
[Dependency] private readonly ILightManager _light = default!;
[Dependency] private readonly IGameHud _gameHud = default!;
[UISystemDependency] private readonly DebugPhysicsSystem _debugPhysics = default!;
[UISystemDependency] private readonly MarkerSystem _marker = default!;
[UISystemDependency] private readonly SandboxSystem _sandbox = default!;
[UISystemDependency] private readonly SubFloorHideSystem _subfloorHide = default!;
private SandboxWindow? _window;
// TODO hud refactor cache
private EntitySpawningUIController EntitySpawningController => UIManager.GetUIController<EntitySpawningUIController>();
private TileSpawningUIController TileSpawningController => UIManager.GetUIController<TileSpawningUIController>();
private DecalPlacerUIController DecalPlacerController => UIManager.GetUIController<DecalPlacerUIController>();
public void OnStateEntered(GameplayState state)
{
DebugTools.Assert(_window == null);
EnsureWindow();
_gameHud.SandboxButtonToggled += GameHudOnSandboxButtonToggled;
_input.SetInputCommand(ContentKeyFunctions.OpenEntitySpawnWindow,
InputCmdHandler.FromDelegate(_ => EntitySpawningController.ToggleWindow()));
_input.SetInputCommand(ContentKeyFunctions.OpenSandboxWindow,
InputCmdHandler.FromDelegate(_ => ToggleWindow()));
_input.SetInputCommand(ContentKeyFunctions.OpenTileSpawnWindow,
InputCmdHandler.FromDelegate(_ => TileSpawningController.ToggleWindow()));
_input.SetInputCommand(ContentKeyFunctions.OpenDecalSpawnWindow,
InputCmdHandler.FromDelegate(_ => DecalPlacerController.ToggleWindow()));
CommandBinds.Builder
.Bind(ContentKeyFunctions.EditorCopyObject, new PointerInputCmdHandler(Copy))
.Register<SandboxSystem>();
}
private void EnsureWindow()
{
if(_window is { Disposed: false })
return;
_window = UIManager.CreateWindow<SandboxWindow>();
_window.OnClose += () => { _gameHud.SandboxButtonDown = false; };
_window.OnOpen += () => { _gameHud.SandboxButtonDown = true; };
_window.ToggleLightButton.Pressed = !_light.Enabled;
_window.ToggleFovButton.Pressed = !_eye.CurrentEye.DrawFov;
_window.ToggleShadowsButton.Pressed = !_light.DrawShadows;
_window.ToggleSubfloorButton.Pressed = _subfloorHide.ShowAll;
_window.ShowMarkersButton.Pressed = _marker.MarkersVisible;
_window.ShowBbButton.Pressed = (_debugPhysics.Flags & PhysicsDebugFlags.Shapes) != 0x0;
_window.RespawnButton.OnPressed += _ => _sandbox.Respawn();
_window.SpawnTilesButton.OnPressed += _ => TileSpawningController.ToggleWindow();
_window.SpawnEntitiesButton.OnPressed += _ => EntitySpawningController.ToggleWindow();
_window.SpawnDecalsButton.OnPressed += _ => DecalPlacerController.ToggleWindow();
_window.GiveFullAccessButton.OnPressed += _ => _sandbox.GiveAdminAccess();
_window.GiveAghostButton.OnPressed += _ => _sandbox.GiveAGhost();
_window.ToggleLightButton.OnToggled += _ => _sandbox.ToggleLight();
_window.ToggleFovButton.OnToggled += _ => _sandbox.ToggleFov();
_window.ToggleShadowsButton.OnToggled += _ => _sandbox.ToggleShadows();
_window.SuicideButton.OnPressed += _ => _sandbox.Suicide();
_window.ToggleSubfloorButton.OnPressed += _ => _sandbox.ToggleSubFloor();
_window.ShowMarkersButton.OnPressed += _ => _sandbox.ShowMarkers();
_window.ShowBbButton.OnPressed += _ => _sandbox.ShowBb();
_window.MachineLinkingButton.OnPressed += _ => _sandbox.MachineLinking();
}
private void GameHudOnSandboxButtonToggled(bool pressed)
{
ToggleWindow();
}
public void OnStateExited(GameplayState state)
{
if (_window != null)
{
_window.Dispose();
_window = null;
}
_gameHud.SandboxButtonToggled -= GameHudOnSandboxButtonToggled;
_gameHud.SandboxButtonDown = false;
CommandBinds.Unregister<SandboxSystem>();
}
public void OnSystemLoaded(SandboxSystem system)
{
system.SandboxDisabled += CloseAll;
}
public void OnSystemUnloaded(SandboxSystem system)
{
system.SandboxDisabled -= CloseAll;
}
private void CloseAll()
{
_window?.Close();
EntitySpawningController.CloseWindow();
TileSpawningController.CloseWindow();
}
private bool Copy(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
{
return _sandbox.Copy(session, coords, uid);
}
private void ToggleWindow()
{
if (_window == null)
return;
if (_sandbox.SandboxAllowed && _window.IsOpen != true)
{
_window.OpenCentered();
}
else
{
_window.Close();
}
}
}

View File

@@ -0,0 +1,22 @@
<windows:SandboxWindow
xmlns="https://spacestation14.io"
xmlns:windows="clr-namespace:Content.Client.UserInterface.Systems.Sandbox.Windows"
Title="{Loc sandbox-window-title}"
Resizable="False">
<BoxContainer Orientation="Vertical" SeparationOverride="4">
<Button Name="RespawnButton" Access="Public" Text="{Loc sandbox-window-respawn-button}"/>
<Button Name="SpawnEntitiesButton" Access="Public" Text="{Loc sandbox-window-spawn-entities-button}"/>
<Button Name="SpawnTilesButton" Access="Public" Text="{Loc sandbox-window-spawn-tiles-button}"/>
<Button Name="SpawnDecalsButton" Access="Public" Text="{Loc sandbox-window-spawn-decals-button}"/>
<Button Name="GiveFullAccessButton" Access="Public" Text="{Loc sandbox-window-grant-full-access-button}"/>
<Button Name="GiveAghostButton" Access="Public" Text="{Loc sandbox-window-ghost-button}"/>
<Button Name="ToggleLightButton" Access="Public" Text="{Loc sandbox-window-toggle-lights-button}" ToggleMode="True"/>
<Button Name="ToggleFovButton" Access="Public" Text="{Loc sandbox-window-toggle-fov-button}" ToggleMode="True"/>
<Button Name="ToggleShadowsButton" Access="Public" Text="{Loc sandbox-window-toggle-shadows-button}" ToggleMode="True"/>
<Button Name="ToggleSubfloorButton" Access="Public" Text="{Loc sandbox-window-toggle-subfloor-button}" ToggleMode="True"/>
<Button Name="SuicideButton" Access="Public" Text="{Loc sandbox-window-toggle-suicide-button}" ToggleMode="True"/>
<Button Name="ShowMarkersButton" Access="Public" Text="{Loc sandbox-window-show-spawns-button}" ToggleMode="True"/>
<Button Name="ShowBbButton" Access="Public" Text="{Loc sandbox-window-show-bb-button}" ToggleMode="True"/>
<Button Name="MachineLinkingButton" Access="Public" Text="{Loc sandbox-window-link-machines-button}" ToggleMode="True"/>
</BoxContainer>
</windows:SandboxWindow>

View File

@@ -0,0 +1,14 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
namespace Content.Client.UserInterface.Systems.Sandbox.Windows;
[GenerateTypedNameReferences]
public sealed partial class SandboxWindow : DefaultWindow
{
public SandboxWindow()
{
RobustXamlLoader.Load(this);
}
}