2021-11-10 13:26:25 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Content.Client.Administration.Managers;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.Administration.UI;
|
2021-12-25 20:10:55 -08:00
|
|
|
using Content.Client.Administration.UI.Tabs.PlayerTab;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.HUD;
|
2021-12-30 14:11:30 -08:00
|
|
|
using Content.Client.Verbs;
|
2020-09-13 14:23:52 +02:00
|
|
|
using Content.Shared.Input;
|
2020-08-25 17:18:32 +02:00
|
|
|
using Robust.Client.Console;
|
2021-10-03 13:34:36 +02:00
|
|
|
using Robust.Client.Graphics;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Client.Input;
|
2021-10-03 13:34:36 +02:00
|
|
|
using Robust.Client.ResourceManagement;
|
2021-12-25 20:10:55 -08:00
|
|
|
using Robust.Client.UserInterface.Controls;
|
2020-08-25 17:18:32 +02:00
|
|
|
using Robust.Client.UserInterface.CustomControls;
|
2021-10-03 13:34:36 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-30 14:11:30 -08:00
|
|
|
using Robust.Shared.Input;
|
2020-08-25 17:18:32 +02:00
|
|
|
using Robust.Shared.Input.Binding;
|
|
|
|
|
using Robust.Shared.IoC;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.Network;
|
2020-08-25 17:18:32 +02:00
|
|
|
|
2021-11-10 13:26:25 +01:00
|
|
|
namespace Content.Client.Administration
|
2020-08-25 17:18:32 +02:00
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed partial class AdminSystem
|
2020-08-25 17:18:32 +02:00
|
|
|
{
|
2020-11-10 16:50:28 +01:00
|
|
|
[Dependency] private readonly INetManager _netManager = default!;
|
2020-08-25 17:18:32 +02:00
|
|
|
[Dependency] private readonly IInputManager _inputManager = default!;
|
2021-01-08 20:40:07 -08:00
|
|
|
[Dependency] private readonly IGameHud _gameHud = default!;
|
|
|
|
|
[Dependency] private readonly IClientAdminManager _clientAdminManager = default!;
|
2020-08-25 17:18:32 +02:00
|
|
|
[Dependency] private readonly IClientConGroupController _clientConGroupController = default!;
|
2021-10-03 13:34:36 +02:00
|
|
|
[Dependency] private readonly IOverlayManager _overlayManager = default!;
|
|
|
|
|
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
|
|
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
2022-03-03 21:18:35 +11:00
|
|
|
[Dependency] private readonly EntityLookupSystem _entityLookup = default!;
|
2021-12-25 20:10:55 -08:00
|
|
|
[Dependency] private readonly IClientConsoleHost _clientConsoleHost = default!;
|
2020-08-25 17:18:32 +02:00
|
|
|
|
2021-12-30 14:11:30 -08:00
|
|
|
[Dependency] private readonly VerbSystem _verbSystem = default!;
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
private AdminMenuWindow? _window;
|
2021-12-30 17:38:12 +01:00
|
|
|
private readonly List<BaseWindow> _commandWindows = new();
|
2020-08-25 17:18:32 +02:00
|
|
|
|
2021-11-10 13:26:25 +01:00
|
|
|
private void InitializeMenu()
|
2020-08-25 17:18:32 +02:00
|
|
|
{
|
|
|
|
|
// Reset the AdminMenu Window on disconnect
|
2021-03-10 14:48:29 +01:00
|
|
|
_netManager.Disconnect += (_, _) => ResetWindow();
|
2020-08-25 17:18:32 +02:00
|
|
|
|
|
|
|
|
_inputManager.SetInputCommand(ContentKeyFunctions.OpenAdminMenu,
|
2021-03-10 14:48:29 +01:00
|
|
|
InputCmdHandler.FromDelegate(_ => Toggle()));
|
2021-01-08 20:40:07 -08:00
|
|
|
|
|
|
|
|
_clientAdminManager.AdminStatusUpdated += () =>
|
|
|
|
|
{
|
|
|
|
|
// when status changes, show the top button if we can open admin menu.
|
|
|
|
|
// if we can't or we lost admin status, close it and hide the button.
|
|
|
|
|
_gameHud.AdminButtonVisible = CanOpen();
|
|
|
|
|
if (!_gameHud.AdminButtonVisible)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
_gameHud.AdminButtonToggled += (open) =>
|
|
|
|
|
{
|
|
|
|
|
if (open)
|
|
|
|
|
{
|
|
|
|
|
TryOpen();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
_gameHud.AdminButtonVisible = CanOpen();
|
|
|
|
|
_gameHud.AdminButtonDown = false;
|
2020-08-25 17:18:32 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-16 09:11:15 +01:00
|
|
|
|
2020-08-25 17:18:32 +02:00
|
|
|
public void ResetWindow()
|
|
|
|
|
{
|
|
|
|
|
_window?.Close();
|
2021-11-10 13:26:25 +01:00
|
|
|
_window?.Dispose();
|
2020-08-25 17:18:32 +02:00
|
|
|
_window = null;
|
|
|
|
|
|
|
|
|
|
foreach (var window in _commandWindows)
|
2021-11-10 13:26:25 +01:00
|
|
|
{
|
|
|
|
|
window.Close();
|
|
|
|
|
window.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-25 17:18:32 +02:00
|
|
|
_commandWindows.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 17:38:12 +01:00
|
|
|
public void OpenCommand(BaseWindow window)
|
2020-08-25 17:18:32 +02:00
|
|
|
{
|
|
|
|
|
_commandWindows.Add(window);
|
|
|
|
|
window.OpenCentered();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Open()
|
|
|
|
|
{
|
2022-01-01 14:10:46 -08:00
|
|
|
if (_window == null)
|
|
|
|
|
{
|
|
|
|
|
_window = new AdminMenuWindow();
|
|
|
|
|
_window.OnClose += Close;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 20:10:55 -08:00
|
|
|
_window.PlayerTabControl.OnEntryPressed += PlayerTabEntryPressed;
|
2020-08-25 17:18:32 +02:00
|
|
|
_window.OpenCentered();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
|
{
|
2021-12-27 19:35:13 -08:00
|
|
|
if (_window != null)
|
|
|
|
|
_window.PlayerTabControl.OnEntryPressed -= PlayerTabEntryPressed;
|
2020-08-25 17:18:32 +02:00
|
|
|
_window?.Close();
|
|
|
|
|
|
|
|
|
|
foreach (var window in _commandWindows)
|
|
|
|
|
window?.Dispose();
|
|
|
|
|
_commandWindows.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the player can open the window
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>True if the player is allowed</returns>
|
|
|
|
|
public bool CanOpen()
|
|
|
|
|
{
|
|
|
|
|
return _clientConGroupController.CanAdminMenu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the player can open the window and tries to open it
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void TryOpen()
|
|
|
|
|
{
|
|
|
|
|
if (CanOpen())
|
|
|
|
|
Open();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Toggle()
|
|
|
|
|
{
|
|
|
|
|
if (_window != null && _window.IsOpen)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TryOpen();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-25 20:10:55 -08:00
|
|
|
|
|
|
|
|
private void PlayerTabEntryPressed(BaseButton.ButtonEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Button is not PlayerTabEntry button
|
|
|
|
|
|| button.PlayerUid == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-12-30 14:11:30 -08:00
|
|
|
var uid = button.PlayerUid.Value;
|
|
|
|
|
var function = args.Event.Function;
|
|
|
|
|
|
|
|
|
|
if (function == EngineKeyFunctions.UIClick)
|
|
|
|
|
_clientConsoleHost.ExecuteCommand($"vv {uid}");
|
|
|
|
|
else if (function == ContentKeyFunctions.OpenContextMenu)
|
|
|
|
|
_verbSystem.VerbMenu.OpenVerbMenu(uid, true);
|
|
|
|
|
else
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
args.Event.Handle();
|
2021-12-25 20:10:55 -08:00
|
|
|
}
|
2020-08-25 17:18:32 +02:00
|
|
|
}
|
|
|
|
|
}
|