Files
crystall-punk-14/Content.Client/UserInterface/Systems/Ghost/Controls/Roles/MakeGhostRoleEui.cs

76 lines
2.0 KiB
C#
Raw Normal View History

2021-02-16 09:51:27 +01:00
using Content.Client.Eui;
using Content.Shared.Eui;
2021-06-09 22:19:39 +02:00
using Content.Shared.Ghost.Roles;
2021-02-16 09:51:27 +01:00
using JetBrains.Annotations;
using Robust.Client.Console;
using Robust.Client.Player;
using Robust.Shared.Utility;
2023-09-11 14:31:45 +10:00
namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles;
[UsedImplicitly]
public sealed class MakeGhostRoleEui : BaseEui
2021-02-16 09:51:27 +01:00
{
2023-09-11 14:31:45 +10:00
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
2021-02-16 09:51:27 +01:00
2023-09-11 14:31:45 +10:00
private readonly MakeGhostRoleWindow _window;
2021-02-16 09:51:27 +01:00
2023-09-11 14:31:45 +10:00
public MakeGhostRoleEui()
{
_window = new MakeGhostRoleWindow();
2021-02-16 09:51:27 +01:00
2023-09-11 14:31:45 +10:00
_window.OnClose += OnClose;
_window.OnMake += OnMake;
}
2023-09-11 14:31:45 +10:00
public override void HandleState(EuiStateBase state)
{
if (state is not MakeGhostRoleEuiState uiState)
{
return;
2021-02-16 09:51:27 +01:00
}
2023-09-11 14:31:45 +10:00
_window.SetEntity(_entManager, uiState.Entity);
}
2021-02-16 09:51:27 +01:00
2023-09-11 14:31:45 +10:00
public override void Opened()
{
base.Opened();
_window.OpenCentered();
}
2021-02-16 09:51:27 +01:00
2023-09-11 14:31:45 +10:00
private void OnMake(NetEntity entity, string name, string description, string rules, bool makeSentient)
{
var player = _playerManager.LocalPlayer;
if (player == null)
2021-02-16 09:51:27 +01:00
{
2023-09-11 14:31:45 +10:00
return;
2021-02-16 09:51:27 +01:00
}
2023-09-11 14:31:45 +10:00
var makeGhostRoleCommand =
$"makeghostrole " +
$"\"{CommandParsing.Escape(entity.ToString())}\" " +
$"\"{CommandParsing.Escape(name)}\" " +
$"\"{CommandParsing.Escape(description)}\" " +
$"\"{CommandParsing.Escape(rules)}\"";
2021-02-16 09:51:27 +01:00
2023-09-11 14:31:45 +10:00
_consoleHost.ExecuteCommand(player.Session, makeGhostRoleCommand);
2021-02-16 09:51:27 +01:00
2023-09-11 14:31:45 +10:00
if (makeSentient)
2021-02-16 09:51:27 +01:00
{
2023-09-11 14:31:45 +10:00
var makeSentientCommand = $"makesentient \"{CommandParsing.Escape(entity.ToString())}\"";
_consoleHost.ExecuteCommand(player.Session, makeSentientCommand);
2021-02-16 09:51:27 +01:00
}
2023-09-11 14:31:45 +10:00
_window.Close();
}
private void OnClose()
{
base.Closed();
SendMessage(new CloseEuiMessage());
2021-02-16 09:51:27 +01:00
}
}