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,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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user