Fix makeghostrole eui (#19998)

This commit is contained in:
metalgearsloth
2023-09-11 14:31:45 +10:00
committed by GitHub
parent 497294219a
commit 3c0439167a
5 changed files with 69 additions and 71 deletions

View File

@@ -6,11 +6,11 @@ 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!;
@@ -21,7 +21,6 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
{
_window = new MakeGhostRoleWindow();
_window.OnClose += OnClose;
_window.OnMake += OnMake;
}
@@ -33,7 +32,7 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
return;
}
_window.SetEntity(_entManager.GetEntity(uiState.EntityUid));
_window.SetEntity(_entManager, uiState.Entity);
}
public override void Opened()
@@ -42,7 +41,7 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
_window.OpenCentered();
}
private void OnMake(EntityUid uid, string name, string description, string rules, bool makeSentient)
private void OnMake(NetEntity entity, string name, string description, string rules, bool makeSentient)
{
var player = _playerManager.LocalPlayer;
if (player == null)
@@ -52,7 +51,7 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
var makeGhostRoleCommand =
$"makeghostrole " +
$"\"{CommandParsing.Escape(uid.ToString())}\" " +
$"\"{CommandParsing.Escape(entity.ToString())}\" " +
$"\"{CommandParsing.Escape(name)}\" " +
$"\"{CommandParsing.Escape(description)}\" " +
$"\"{CommandParsing.Escape(rules)}\"";
@@ -61,7 +60,7 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
if (makeSentient)
{
var makeSentientCommand = $"makesentient \"{CommandParsing.Escape(uid.ToString())}\"";
var makeSentientCommand = $"makesentient \"{CommandParsing.Escape(entity.ToString())}\"";
_consoleHost.ExecuteCommand(player.Session, makeSentientCommand);
}
@@ -73,5 +72,4 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
base.Closed();
SendMessage(new CloseEuiMessage());
}
}
}

View File

@@ -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<IEntityManager>();
RoleName.Text = entManager.GetComponent<MetaDataComponent>(uid).EntityName;
RoleEntity.Text = $"{uid}";
Entity = entity;
RoleName.Text = entManager.GetComponent<MetaDataComponent>(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);
}
}
}

View File

@@ -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();
}

View File

@@ -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()

View File

@@ -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; }
}
}