Files
tbd-station-14/Content.Client/UserInterface/Systems/Ghost/Controls/Roles/MakeGhostRoleEui.cs
Pieter-Jan Briers 68ce53ae17 Random spontaneous cleanup PR (#25131)
* Use new Subs.CVar helper

Removes manual config OnValueChanged calls, removes need to remember to manually unsubscribe.

This both reduces boilerplate and fixes many issues where subscriptions weren't removed on entity system shutdown.

* Fix a bunch of warnings

* More warning fixes

* Use new DateTime serializer to get rid of ISerializationHooks in changelog code.

* Get rid of some more ISerializationHooks for enums

* And a little more

* Apply suggestions from code review

Co-authored-by: 0x6273 <0x40@keemail.me>

---------

Co-authored-by: 0x6273 <0x40@keemail.me>
2024-02-13 16:48:39 -05:00

76 lines
2.0 KiB
C#

using Content.Client.Eui;
using Content.Shared.Eui;
using Content.Shared.Ghost.Roles;
using JetBrains.Annotations;
using Robust.Client.Console;
using Robust.Client.Player;
using Robust.Shared.Utility;
namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles;
[UsedImplicitly]
public sealed class MakeGhostRoleEui : BaseEui
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
private readonly MakeGhostRoleWindow _window;
public MakeGhostRoleEui()
{
_window = new MakeGhostRoleWindow();
_window.OnClose += OnClose;
_window.OnMake += OnMake;
}
public override void HandleState(EuiStateBase state)
{
if (state is not MakeGhostRoleEuiState uiState)
{
return;
}
_window.SetEntity(_entManager, uiState.Entity);
}
public override void Opened()
{
base.Opened();
_window.OpenCentered();
}
private void OnMake(NetEntity entity, string name, string description, string rules, bool makeSentient)
{
var session = _playerManager.LocalSession;
if (session == null)
{
return;
}
var makeGhostRoleCommand =
$"makeghostrole " +
$"\"{CommandParsing.Escape(entity.ToString())}\" " +
$"\"{CommandParsing.Escape(name)}\" " +
$"\"{CommandParsing.Escape(description)}\" " +
$"\"{CommandParsing.Escape(rules)}\"";
_consoleHost.ExecuteCommand(session, makeGhostRoleCommand);
if (makeSentient)
{
var makeSentientCommand = $"makesentient \"{CommandParsing.Escape(entity.ToString())}\"";
_consoleHost.ExecuteCommand(session, makeSentientCommand);
}
_window.Close();
}
private void OnClose()
{
base.Closed();
SendMessage(new CloseEuiMessage());
}
}