From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Mon, 11 Sep 2023 04:31:45 +0000 (+1000) Subject: Fix makeghostrole eui (#19998) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=3c0439167a0fc3d4eced11312d534499e9e5b5df;p=space-station-14.git Fix makeghostrole eui (#19998) --- diff --git a/Content.Client/UserInterface/Systems/Ghost/Controls/Roles/MakeGhostRoleEui.cs b/Content.Client/UserInterface/Systems/Ghost/Controls/Roles/MakeGhostRoleEui.cs index 1f41edb931..926a830e71 100644 --- a/Content.Client/UserInterface/Systems/Ghost/Controls/Roles/MakeGhostRoleEui.cs +++ b/Content.Client/UserInterface/Systems/Ghost/Controls/Roles/MakeGhostRoleEui.cs @@ -6,72 +6,70 @@ using Robust.Client.Console; using Robust.Client.Player; using Robust.Shared.Utility; -namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles +namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles; + +[UsedImplicitly] +public sealed class MakeGhostRoleEui : BaseEui { - [UsedImplicitly] - public sealed class MakeGhostRoleEui : BaseEui - { - [Dependency] private readonly IEntityManager _entManager = default!; - [Dependency] private readonly IPlayerManager _playerManager = default!; - [Dependency] private readonly IClientConsoleHost _consoleHost = default!; + [Dependency] private readonly IEntityManager _entManager = default!; + [Dependency] private readonly IPlayerManager _playerManager = default!; + [Dependency] private readonly IClientConsoleHost _consoleHost = default!; - private readonly MakeGhostRoleWindow _window; + private readonly MakeGhostRoleWindow _window; - public MakeGhostRoleEui() - { - _window = new MakeGhostRoleWindow(); + public MakeGhostRoleEui() + { + _window = new MakeGhostRoleWindow(); + _window.OnClose += OnClose; + _window.OnMake += OnMake; + } - _window.OnClose += OnClose; - _window.OnMake += OnMake; + public override void HandleState(EuiStateBase state) + { + if (state is not MakeGhostRoleEuiState uiState) + { + return; } - public override void HandleState(EuiStateBase state) - { - if (state is not MakeGhostRoleEuiState uiState) - { - return; - } + _window.SetEntity(_entManager, uiState.Entity); + } - _window.SetEntity(_entManager.GetEntity(uiState.EntityUid)); - } + public override void Opened() + { + base.Opened(); + _window.OpenCentered(); + } - public override void Opened() + private void OnMake(NetEntity entity, string name, string description, string rules, bool makeSentient) + { + var player = _playerManager.LocalPlayer; + if (player == null) { - base.Opened(); - _window.OpenCentered(); + return; } - private void OnMake(EntityUid uid, string name, string description, string rules, bool makeSentient) - { - var player = _playerManager.LocalPlayer; - if (player == null) - { - return; - } - - var makeGhostRoleCommand = - $"makeghostrole " + - $"\"{CommandParsing.Escape(uid.ToString())}\" " + - $"\"{CommandParsing.Escape(name)}\" " + - $"\"{CommandParsing.Escape(description)}\" " + - $"\"{CommandParsing.Escape(rules)}\""; - - _consoleHost.ExecuteCommand(player.Session, makeGhostRoleCommand); + var makeGhostRoleCommand = + $"makeghostrole " + + $"\"{CommandParsing.Escape(entity.ToString())}\" " + + $"\"{CommandParsing.Escape(name)}\" " + + $"\"{CommandParsing.Escape(description)}\" " + + $"\"{CommandParsing.Escape(rules)}\""; - if (makeSentient) - { - var makeSentientCommand = $"makesentient \"{CommandParsing.Escape(uid.ToString())}\""; - _consoleHost.ExecuteCommand(player.Session, makeSentientCommand); - } + _consoleHost.ExecuteCommand(player.Session, makeGhostRoleCommand); - _window.Close(); - } - - private void OnClose() + if (makeSentient) { - base.Closed(); - SendMessage(new CloseEuiMessage()); + var makeSentientCommand = $"makesentient \"{CommandParsing.Escape(entity.ToString())}\""; + _consoleHost.ExecuteCommand(player.Session, makeSentientCommand); } + + _window.Close(); + } + + private void OnClose() + { + base.Closed(); + SendMessage(new CloseEuiMessage()); } } diff --git a/Content.Client/UserInterface/Systems/Ghost/Controls/Roles/MakeGhostRoleWindow.xaml.cs b/Content.Client/UserInterface/Systems/Ghost/Controls/Roles/MakeGhostRoleWindow.xaml.cs index 6ce3d7da6b..0839510970 100644 --- a/Content.Client/UserInterface/Systems/Ghost/Controls/Roles/MakeGhostRoleWindow.xaml.cs +++ b/Content.Client/UserInterface/Systems/Ghost/Controls/Roles/MakeGhostRoleWindow.xaml.cs @@ -9,7 +9,7 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles [GenerateTypedNameReferences] public sealed partial class MakeGhostRoleWindow : DefaultWindow { - public delegate void MakeRole(EntityUid uid, string name, string description, string rules, bool makeSentient); + public delegate void MakeRole(NetEntity uid, string name, string description, string rules, bool makeSentient); public MakeGhostRoleWindow() { @@ -27,26 +27,25 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles MakeButton.OnPressed += OnPressed; } - private EntityUid? EntityUid { get; set; } + private NetEntity? Entity { get; set; } public event MakeRole? OnMake; - public void SetEntity(EntityUid uid) + public void SetEntity(IEntityManager entManager, NetEntity entity) { - EntityUid = uid; - var entManager = IoCManager.Resolve(); - RoleName.Text = entManager.GetComponent(uid).EntityName; - RoleEntity.Text = $"{uid}"; + Entity = entity; + RoleName.Text = entManager.GetComponent(entManager.GetEntity(entity)).EntityName; + RoleEntity.Text = $"{entity}"; } private void OnPressed(ButtonEventArgs args) { - if (EntityUid == null) + if (Entity == null) { return; } - OnMake?.Invoke(EntityUid.Value, RoleName.Text, RoleDescription.Text, RoleRules.Text, MakeSentientCheckbox.Pressed); + OnMake?.Invoke(Entity.Value, RoleName.Text, RoleDescription.Text, RoleRules.Text, MakeSentientCheckbox.Pressed); } } } diff --git a/Content.Server/Ghost/Roles/GhostRoleSystem.cs b/Content.Server/Ghost/Roles/GhostRoleSystem.cs index 90bcc1a584..38be308379 100644 --- a/Content.Server/Ghost/Roles/GhostRoleSystem.cs +++ b/Content.Server/Ghost/Roles/GhostRoleSystem.cs @@ -119,7 +119,7 @@ namespace Content.Server.Ghost.Roles if (_openMakeGhostRoleUis.ContainsKey(session)) CloseEui(session); - var eui = _openMakeGhostRoleUis[session] = new MakeGhostRoleEui(uid); + var eui = _openMakeGhostRoleUis[session] = new MakeGhostRoleEui(EntityManager, GetNetEntity(uid)); _euiManager.OpenEui(eui, session); eui.StateDirty(); } diff --git a/Content.Server/Ghost/Roles/UI/MakeGhostRoleEui.cs b/Content.Server/Ghost/Roles/UI/MakeGhostRoleEui.cs index ff1967f966..c2dce9c563 100644 --- a/Content.Server/Ghost/Roles/UI/MakeGhostRoleEui.cs +++ b/Content.Server/Ghost/Roles/UI/MakeGhostRoleEui.cs @@ -6,18 +6,19 @@ namespace Content.Server.Ghost.Roles.UI { public sealed class MakeGhostRoleEui : BaseEui { - [Dependency] private readonly IEntityManager _entManager = default!; + private IEntityManager _entManager; - public MakeGhostRoleEui(EntityUid entityUid) + public MakeGhostRoleEui(IEntityManager entManager, NetEntity entity) { - EntityUid = entityUid; + _entManager = entManager; + Entity = entity; } - public EntityUid EntityUid { get; } + public NetEntity Entity { get; } public override EuiStateBase GetNewState() { - return new MakeGhostRoleEuiState(_entManager.GetNetEntity(EntityUid)); + return new MakeGhostRoleEuiState(Entity); } public override void Closed() diff --git a/Content.Shared/Ghost/Roles/MakeGhostRoleEuiState.cs b/Content.Shared/Ghost/Roles/MakeGhostRoleEuiState.cs index 8dd05e62f3..e17ab4aab3 100644 --- a/Content.Shared/Ghost/Roles/MakeGhostRoleEuiState.cs +++ b/Content.Shared/Ghost/Roles/MakeGhostRoleEuiState.cs @@ -6,11 +6,11 @@ namespace Content.Shared.Ghost.Roles [Serializable, NetSerializable] public sealed class MakeGhostRoleEuiState : EuiStateBase { - public MakeGhostRoleEuiState(NetEntity entityUid) + public MakeGhostRoleEuiState(NetEntity entity) { - EntityUid = entityUid; + Entity = entity; } - public NetEntity EntityUid { get; } + public NetEntity Entity { get; } } }