using Content.Shared.Access.Components; using Content.Shared.Access.Systems; using Content.Shared.StatusIcon; using Robust.Client.UserInterface; using Robust.Shared.Prototypes; namespace Content.Client.Access.UI; /// /// Initializes a and updates it when new server messages are received. /// public sealed class AgentIDCardBoundUserInterface(EntityUid owner, Enum uiKey) : BoundUserInterface(owner, uiKey) { private AgentIDCardWindow? _window; protected override void Open() { base.Open(); if (!EntMan.TryGetComponent(Owner, out AgentIDCardComponent? agent)) return; _window = this.CreateWindow(); _window.OnNameChanged += OnNameChanged; _window.OnJobChanged += OnJobChanged; _window.OnJobIconChanged += OnJobIconChanged; ProtoId currentIcon = default; if (EntMan.TryGetComponent(Owner, out var card)) currentIcon = card.JobIcon; _window.SetAllowedIcons(agent.IconGroups, currentIcon); Update(); } public override void Update() { base.Update(); if (_window == null) return; if (!EntMan.TryGetComponent(Owner, out var card)) return; _window.Update(card); } private void OnNameChanged(string newName) { SendPredictedMessage(new AgentIDCardNameChangedMessage(newName)); } private void OnJobChanged(string newJob) { SendPredictedMessage(new AgentIDCardJobChangedMessage(newJob)); } private void OnJobIconChanged(ProtoId newJobIconId) { SendPredictedMessage(new AgentIDCardJobIconChangedMessage(newJobIconId)); } }