AgentIDCardBoundUserInterface.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Content.Shared.Access.Systems;
  2. using Content.Shared.StatusIcon;
  3. using Robust.Client.GameObjects;
  4. using Robust.Client.UserInterface;
  5. using Robust.Shared.Prototypes;
  6. namespace Content.Client.Access.UI
  7. {
  8. /// <summary>
  9. /// Initializes a <see cref="AgentIDCardWindow"/> and updates it when new server messages are received.
  10. /// </summary>
  11. public sealed class AgentIDCardBoundUserInterface : BoundUserInterface
  12. {
  13. private AgentIDCardWindow? _window;
  14. public AgentIDCardBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  15. {
  16. }
  17. protected override void Open()
  18. {
  19. base.Open();
  20. _window = this.CreateWindow<AgentIDCardWindow>();
  21. _window.OnNameChanged += OnNameChanged;
  22. _window.OnJobChanged += OnJobChanged;
  23. _window.OnJobIconChanged += OnJobIconChanged;
  24. }
  25. private void OnNameChanged(string newName)
  26. {
  27. SendMessage(new AgentIDCardNameChangedMessage(newName));
  28. }
  29. private void OnJobChanged(string newJob)
  30. {
  31. SendMessage(new AgentIDCardJobChangedMessage(newJob));
  32. }
  33. public void OnJobIconChanged(ProtoId<JobIconPrototype> newJobIconId)
  34. {
  35. SendMessage(new AgentIDCardJobIconChangedMessage(newJobIconId));
  36. }
  37. /// <summary>
  38. /// Update the UI state based on server-sent info
  39. /// </summary>
  40. /// <param name="state"></param>
  41. protected override void UpdateState(BoundUserInterfaceState state)
  42. {
  43. base.UpdateState(state);
  44. if (_window == null || state is not AgentIDCardBoundUserInterfaceState cast)
  45. return;
  46. _window.SetCurrentName(cast.CurrentName);
  47. _window.SetCurrentJob(cast.CurrentJob);
  48. _window.SetAllowedIcons(cast.CurrentJobIconId);
  49. }
  50. }
  51. }