Fix makeghostrole eui (#19998)
This commit is contained in:
@@ -6,72 +6,70 @@ using Robust.Client.Console;
|
|||||||
using Robust.Client.Player;
|
using Robust.Client.Player;
|
||||||
using Robust.Shared.Utility;
|
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]
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||||
public sealed class MakeGhostRoleEui : BaseEui
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||||
|
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
|
||||||
|
|
||||||
|
private readonly MakeGhostRoleWindow _window;
|
||||||
|
|
||||||
|
public MakeGhostRoleEui()
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
_window = new MakeGhostRoleWindow();
|
||||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
||||||
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
|
|
||||||
|
|
||||||
private readonly MakeGhostRoleWindow _window;
|
_window.OnClose += OnClose;
|
||||||
|
_window.OnMake += OnMake;
|
||||||
|
}
|
||||||
|
|
||||||
public MakeGhostRoleEui()
|
public override void HandleState(EuiStateBase state)
|
||||||
|
{
|
||||||
|
if (state is not MakeGhostRoleEuiState uiState)
|
||||||
{
|
{
|
||||||
_window = new MakeGhostRoleWindow();
|
return;
|
||||||
|
|
||||||
|
|
||||||
_window.OnClose += OnClose;
|
|
||||||
_window.OnMake += OnMake;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void HandleState(EuiStateBase state)
|
_window.SetEntity(_entManager, uiState.Entity);
|
||||||
{
|
}
|
||||||
if (state is not MakeGhostRoleEuiState uiState)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_window.SetEntity(_entManager.GetEntity(uiState.EntityUid));
|
public override void Opened()
|
||||||
|
{
|
||||||
|
base.Opened();
|
||||||
|
_window.OpenCentered();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnMake(NetEntity entity, string name, string description, string rules, bool makeSentient)
|
||||||
|
{
|
||||||
|
var player = _playerManager.LocalPlayer;
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Opened()
|
var makeGhostRoleCommand =
|
||||||
|
$"makeghostrole " +
|
||||||
|
$"\"{CommandParsing.Escape(entity.ToString())}\" " +
|
||||||
|
$"\"{CommandParsing.Escape(name)}\" " +
|
||||||
|
$"\"{CommandParsing.Escape(description)}\" " +
|
||||||
|
$"\"{CommandParsing.Escape(rules)}\"";
|
||||||
|
|
||||||
|
_consoleHost.ExecuteCommand(player.Session, makeGhostRoleCommand);
|
||||||
|
|
||||||
|
if (makeSentient)
|
||||||
{
|
{
|
||||||
base.Opened();
|
var makeSentientCommand = $"makesentient \"{CommandParsing.Escape(entity.ToString())}\"";
|
||||||
_window.OpenCentered();
|
_consoleHost.ExecuteCommand(player.Session, makeSentientCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMake(EntityUid uid, string name, string description, string rules, bool makeSentient)
|
_window.Close();
|
||||||
{
|
}
|
||||||
var player = _playerManager.LocalPlayer;
|
|
||||||
if (player == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var makeGhostRoleCommand =
|
private void OnClose()
|
||||||
$"makeghostrole " +
|
{
|
||||||
$"\"{CommandParsing.Escape(uid.ToString())}\" " +
|
base.Closed();
|
||||||
$"\"{CommandParsing.Escape(name)}\" " +
|
SendMessage(new CloseEuiMessage());
|
||||||
$"\"{CommandParsing.Escape(description)}\" " +
|
|
||||||
$"\"{CommandParsing.Escape(rules)}\"";
|
|
||||||
|
|
||||||
_consoleHost.ExecuteCommand(player.Session, makeGhostRoleCommand);
|
|
||||||
|
|
||||||
if (makeSentient)
|
|
||||||
{
|
|
||||||
var makeSentientCommand = $"makesentient \"{CommandParsing.Escape(uid.ToString())}\"";
|
|
||||||
_consoleHost.ExecuteCommand(player.Session, makeSentientCommand);
|
|
||||||
}
|
|
||||||
|
|
||||||
_window.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnClose()
|
|
||||||
{
|
|
||||||
base.Closed();
|
|
||||||
SendMessage(new CloseEuiMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
|
|||||||
[GenerateTypedNameReferences]
|
[GenerateTypedNameReferences]
|
||||||
public sealed partial class MakeGhostRoleWindow : DefaultWindow
|
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()
|
public MakeGhostRoleWindow()
|
||||||
{
|
{
|
||||||
@@ -27,26 +27,25 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
|
|||||||
MakeButton.OnPressed += OnPressed;
|
MakeButton.OnPressed += OnPressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private EntityUid? EntityUid { get; set; }
|
private NetEntity? Entity { get; set; }
|
||||||
|
|
||||||
public event MakeRole? OnMake;
|
public event MakeRole? OnMake;
|
||||||
|
|
||||||
public void SetEntity(EntityUid uid)
|
public void SetEntity(IEntityManager entManager, NetEntity entity)
|
||||||
{
|
{
|
||||||
EntityUid = uid;
|
Entity = entity;
|
||||||
var entManager = IoCManager.Resolve<IEntityManager>();
|
RoleName.Text = entManager.GetComponent<MetaDataComponent>(entManager.GetEntity(entity)).EntityName;
|
||||||
RoleName.Text = entManager.GetComponent<MetaDataComponent>(uid).EntityName;
|
RoleEntity.Text = $"{entity}";
|
||||||
RoleEntity.Text = $"{uid}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPressed(ButtonEventArgs args)
|
private void OnPressed(ButtonEventArgs args)
|
||||||
{
|
{
|
||||||
if (EntityUid == null)
|
if (Entity == null)
|
||||||
{
|
{
|
||||||
return;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ namespace Content.Server.Ghost.Roles
|
|||||||
if (_openMakeGhostRoleUis.ContainsKey(session))
|
if (_openMakeGhostRoleUis.ContainsKey(session))
|
||||||
CloseEui(session);
|
CloseEui(session);
|
||||||
|
|
||||||
var eui = _openMakeGhostRoleUis[session] = new MakeGhostRoleEui(uid);
|
var eui = _openMakeGhostRoleUis[session] = new MakeGhostRoleEui(EntityManager, GetNetEntity(uid));
|
||||||
_euiManager.OpenEui(eui, session);
|
_euiManager.OpenEui(eui, session);
|
||||||
eui.StateDirty();
|
eui.StateDirty();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,18 +6,19 @@ namespace Content.Server.Ghost.Roles.UI
|
|||||||
{
|
{
|
||||||
public sealed class MakeGhostRoleEui : BaseEui
|
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()
|
public override EuiStateBase GetNewState()
|
||||||
{
|
{
|
||||||
return new MakeGhostRoleEuiState(_entManager.GetNetEntity(EntityUid));
|
return new MakeGhostRoleEuiState(Entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Closed()
|
public override void Closed()
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ namespace Content.Shared.Ghost.Roles
|
|||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class MakeGhostRoleEuiState : EuiStateBase
|
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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user