Files
crystall-punk-14/Content.Client/Access/UI/AgentIDCardBoundUserInterface.cs

62 lines
1.9 KiB
C#
Raw Permalink Normal View History

2022-04-15 17:15:25 -04:00
using Content.Shared.Access.Systems;
using Content.Shared.StatusIcon;
2022-04-15 17:15:25 -04:00
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;
2022-04-15 17:15:25 -04:00
namespace Content.Client.Access.UI
{
/// <summary>
/// Initializes a <see cref="AgentIDCardWindow"/> and updates it when new server messages are received.
/// </summary>
public sealed class AgentIDCardBoundUserInterface : BoundUserInterface
{
private AgentIDCardWindow? _window;
2023-07-08 09:02:17 -07:00
public AgentIDCardBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
2022-04-15 17:15:25 -04:00
{
}
protected override void Open()
{
base.Open();
_window = this.CreateWindow<AgentIDCardWindow>();
2022-04-15 17:15:25 -04:00
_window.OnNameChanged += OnNameChanged;
_window.OnJobChanged += OnJobChanged;
_window.OnJobIconChanged += OnJobIconChanged;
2022-04-15 17:15:25 -04:00
}
private void OnNameChanged(string newName)
{
SendMessage(new AgentIDCardNameChangedMessage(newName));
}
private void OnJobChanged(string newJob)
{
SendMessage(new AgentIDCardJobChangedMessage(newJob));
}
public void OnJobIconChanged(ProtoId<JobIconPrototype> newJobIconId)
{
SendMessage(new AgentIDCardJobIconChangedMessage(newJobIconId));
}
2022-04-15 17:15:25 -04:00
/// <summary>
/// Update the UI state based on server-sent info
/// </summary>
/// <param name="state"></param>
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (_window == null || state is not AgentIDCardBoundUserInterfaceState cast)
return;
_window.SetCurrentName(cast.CurrentName);
_window.SetCurrentJob(cast.CurrentJob);
_window.SetAllowedIcons(cast.CurrentJobIconId);
2022-04-15 17:15:25 -04:00
}
}
}