Make the admin menu openable in the lobby (#15444)
This commit is contained in:
@@ -7,12 +7,13 @@ namespace Content.Client.Administration.UI
|
|||||||
[GenerateTypedNameReferences]
|
[GenerateTypedNameReferences]
|
||||||
public sealed partial class AdminMenuWindow : DefaultWindow
|
public sealed partial class AdminMenuWindow : DefaultWindow
|
||||||
{
|
{
|
||||||
|
public event Action? OnDisposed;
|
||||||
|
|
||||||
public AdminMenuWindow()
|
public AdminMenuWindow()
|
||||||
{
|
{
|
||||||
MinSize = (500, 250);
|
MinSize = (500, 250);
|
||||||
Title = Loc.GetString("admin-menu-title");
|
Title = Loc.GetString("admin-menu-title");
|
||||||
RobustXamlLoader.Load(this);
|
RobustXamlLoader.Load(this);
|
||||||
IoCManager.InjectDependencies(this);
|
|
||||||
MasterTabContainer.SetTabTitle(0, Loc.GetString("admin-menu-admin-tab"));
|
MasterTabContainer.SetTabTitle(0, Loc.GetString("admin-menu-admin-tab"));
|
||||||
MasterTabContainer.SetTabTitle(1, Loc.GetString("admin-menu-adminbus-tab"));
|
MasterTabContainer.SetTabTitle(1, Loc.GetString("admin-menu-adminbus-tab"));
|
||||||
MasterTabContainer.SetTabTitle(2, Loc.GetString("admin-menu-atmos-tab"));
|
MasterTabContainer.SetTabTitle(2, Loc.GetString("admin-menu-atmos-tab"));
|
||||||
@@ -21,5 +22,12 @@ namespace Content.Client.Administration.UI
|
|||||||
MasterTabContainer.SetTabTitle(5, Loc.GetString("admin-menu-players-tab"));
|
MasterTabContainer.SetTabTitle(5, Loc.GetString("admin-menu-players-tab"));
|
||||||
MasterTabContainer.SetTabTitle(6, Loc.GetString("admin-menu-objects-tab"));
|
MasterTabContainer.SetTabTitle(6, Loc.GetString("admin-menu-objects-tab"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
OnDisposed?.Invoke();
|
||||||
|
base.Dispose(disposing);
|
||||||
|
OnDisposed = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,26 @@
|
|||||||
using Content.Client.Administration.Managers;
|
using Content.Client.Administration.Managers;
|
||||||
|
using Content.Client.Administration.Systems;
|
||||||
using Content.Client.Administration.UI;
|
using Content.Client.Administration.UI;
|
||||||
using Content.Client.Administration.UI.Tabs.ObjectsTab;
|
using Content.Client.Administration.UI.Tabs.ObjectsTab;
|
||||||
using Content.Client.Administration.UI.Tabs.PlayerTab;
|
using Content.Client.Administration.UI.Tabs.PlayerTab;
|
||||||
using Content.Client.Gameplay;
|
using Content.Client.Gameplay;
|
||||||
|
using Content.Client.Lobby;
|
||||||
using Content.Client.UserInterface.Controls;
|
using Content.Client.UserInterface.Controls;
|
||||||
using Content.Client.Verbs;
|
|
||||||
using Content.Client.Verbs.UI;
|
using Content.Client.Verbs.UI;
|
||||||
using Content.Shared.Input;
|
using Content.Shared.Input;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.Console;
|
using Robust.Client.Console;
|
||||||
using Robust.Client.Input;
|
using Robust.Client.Input;
|
||||||
using Robust.Client.UserInterface;
|
|
||||||
using Robust.Client.UserInterface.Controllers;
|
using Robust.Client.UserInterface.Controllers;
|
||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Shared.Input;
|
using Robust.Shared.Input;
|
||||||
using Robust.Shared.Input.Binding;
|
using Robust.Shared.Input.Binding;
|
||||||
using Robust.Shared.Utility;
|
|
||||||
using static Robust.Client.UserInterface.Controls.BaseButton;
|
using static Robust.Client.UserInterface.Controls.BaseButton;
|
||||||
|
|
||||||
namespace Content.Client.UserInterface.Systems.Admin;
|
namespace Content.Client.UserInterface.Systems.Admin;
|
||||||
|
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public sealed class AdminUIController : UIController, IOnStateEntered<GameplayState>, IOnStateExited<GameplayState>
|
public sealed class AdminUIController : UIController, IOnStateEntered<GameplayState>, IOnStateEntered<LobbyState>, IOnSystemChanged<AdminSystem>
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IClientAdminManager _admin = default!;
|
[Dependency] private readonly IClientAdminManager _admin = default!;
|
||||||
[Dependency] private readonly IClientConGroupController _conGroups = default!;
|
[Dependency] private readonly IClientConGroupController _conGroups = default!;
|
||||||
@@ -34,7 +33,42 @@ public sealed class AdminUIController : UIController, IOnStateEntered<GameplaySt
|
|||||||
|
|
||||||
public void OnStateEntered(GameplayState state)
|
public void OnStateEntered(GameplayState state)
|
||||||
{
|
{
|
||||||
DebugTools.Assert(_window == null);
|
EnsureWindow();
|
||||||
|
AdminStatusUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnStateEntered(LobbyState state)
|
||||||
|
{
|
||||||
|
EnsureWindow();
|
||||||
|
AdminStatusUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnSystemLoaded(AdminSystem system)
|
||||||
|
{
|
||||||
|
EnsureWindow();
|
||||||
|
|
||||||
|
_admin.AdminStatusUpdated += AdminStatusUpdated;
|
||||||
|
_input.SetInputCommand(ContentKeyFunctions.OpenAdminMenu,
|
||||||
|
InputCmdHandler.FromDelegate(_ => Toggle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnSystemUnloaded(AdminSystem system)
|
||||||
|
{
|
||||||
|
if (_window != null)
|
||||||
|
_window.Dispose();
|
||||||
|
|
||||||
|
_admin.AdminStatusUpdated -= AdminStatusUpdated;
|
||||||
|
|
||||||
|
CommandBinds.Unregister<AdminUIController>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EnsureWindow()
|
||||||
|
{
|
||||||
|
if (_window is { Disposed: false })
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_window?.Disposed ?? false)
|
||||||
|
OnWindowDisposed();
|
||||||
|
|
||||||
_window = UIManager.CreateWindow<AdminMenuWindow>();
|
_window = UIManager.CreateWindow<AdminMenuWindow>();
|
||||||
LayoutContainer.SetAnchorPreset(_window, LayoutContainer.LayoutPreset.Center);
|
LayoutContainer.SetAnchorPreset(_window, LayoutContainer.LayoutPreset.Center);
|
||||||
@@ -43,12 +77,7 @@ public sealed class AdminUIController : UIController, IOnStateEntered<GameplaySt
|
|||||||
_window.ObjectsTabControl.OnEntryPressed += ObjectsTabEntryPressed;
|
_window.ObjectsTabControl.OnEntryPressed += ObjectsTabEntryPressed;
|
||||||
_window.OnOpen += OnWindowOpen;
|
_window.OnOpen += OnWindowOpen;
|
||||||
_window.OnClose += OnWindowClosed;
|
_window.OnClose += OnWindowClosed;
|
||||||
_admin.AdminStatusUpdated += AdminStatusUpdated;
|
_window.OnDisposed += OnWindowDisposed;
|
||||||
|
|
||||||
_input.SetInputCommand(ContentKeyFunctions.OpenAdminMenu,
|
|
||||||
InputCmdHandler.FromDelegate(_ => Toggle()));
|
|
||||||
|
|
||||||
AdminStatusUpdated();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UnloadButton()
|
public void UnloadButton()
|
||||||
@@ -83,27 +112,26 @@ public sealed class AdminUIController : UIController, IOnStateEntered<GameplaySt
|
|||||||
AdminButton.Pressed = false;
|
AdminButton.Pressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnStateExited(GameplayState state)
|
private void OnWindowDisposed()
|
||||||
{
|
{
|
||||||
if (_window != null)
|
if (AdminButton != null)
|
||||||
{
|
AdminButton.Pressed = false;
|
||||||
_window.PlayerTabControl.OnEntryPressed -= PlayerTabEntryPressed;
|
|
||||||
_window.ObjectsTabControl.OnEntryPressed -= ObjectsTabEntryPressed;
|
|
||||||
_window.OnOpen -= OnWindowOpen;
|
|
||||||
_window.OnClose -= OnWindowClosed;
|
|
||||||
|
|
||||||
_window.Dispose();
|
if (_window == null)
|
||||||
_window = null;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
_admin.AdminStatusUpdated -= AdminStatusUpdated;
|
_window.PlayerTabControl.OnEntryPressed -= PlayerTabEntryPressed;
|
||||||
|
_window.ObjectsTabControl.OnEntryPressed -= ObjectsTabEntryPressed;
|
||||||
CommandBinds.Unregister<AdminUIController>();
|
_window.OnOpen -= OnWindowOpen;
|
||||||
|
_window.OnClose -= OnWindowClosed;
|
||||||
|
_window.OnDisposed -= OnWindowDisposed;
|
||||||
|
_window = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AdminStatusUpdated()
|
private void AdminStatusUpdated()
|
||||||
{
|
{
|
||||||
AdminButton!.Visible = _conGroups.CanAdminMenu();
|
if (AdminButton != null)
|
||||||
|
AdminButton.Visible = _conGroups.CanAdminMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AdminButtonPressed(ButtonEventArgs args)
|
private void AdminButtonPressed(ButtonEventArgs args)
|
||||||
|
|||||||
Reference in New Issue
Block a user