1
0

IdCardConsoleBoundUserInterface.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using Content.Shared.Access;
  2. using Content.Shared.Access.Components;
  3. using Content.Shared.Access.Systems;
  4. using Content.Shared.Containers.ItemSlots;
  5. using Content.Shared.CrewManifest;
  6. using Robust.Shared.Prototypes;
  7. using static Content.Shared.Access.Components.IdCardConsoleComponent;
  8. namespace Content.Client.Access.UI
  9. {
  10. public sealed class IdCardConsoleBoundUserInterface : BoundUserInterface
  11. {
  12. [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
  13. private readonly SharedIdCardConsoleSystem _idCardConsoleSystem = default!;
  14. private IdCardConsoleWindow? _window;
  15. public IdCardConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  16. {
  17. _idCardConsoleSystem = EntMan.System<SharedIdCardConsoleSystem>();
  18. }
  19. protected override void Open()
  20. {
  21. base.Open();
  22. List<ProtoId<AccessLevelPrototype>> accessLevels;
  23. if (EntMan.TryGetComponent<IdCardConsoleComponent>(Owner, out var idCard))
  24. {
  25. accessLevels = idCard.AccessLevels;
  26. }
  27. else
  28. {
  29. accessLevels = new List<ProtoId<AccessLevelPrototype>>();
  30. _idCardConsoleSystem.Log.Error($"No IdCardConsole component found for {EntMan.ToPrettyString(Owner)}!");
  31. }
  32. _window = new IdCardConsoleWindow(this, _prototypeManager, accessLevels)
  33. {
  34. Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName
  35. };
  36. _window.CrewManifestButton.OnPressed += _ => SendMessage(new CrewManifestOpenUiMessage());
  37. _window.PrivilegedIdButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(PrivilegedIdCardSlotId));
  38. _window.TargetIdButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(TargetIdCardSlotId));
  39. _window.OnClose += Close;
  40. _window.OpenCentered();
  41. }
  42. protected override void Dispose(bool disposing)
  43. {
  44. base.Dispose(disposing);
  45. if (!disposing)
  46. return;
  47. _window?.Dispose();
  48. }
  49. protected override void UpdateState(BoundUserInterfaceState state)
  50. {
  51. base.UpdateState(state);
  52. var castState = (IdCardConsoleBoundUserInterfaceState) state;
  53. _window?.UpdateState(castState);
  54. }
  55. public void SubmitData(string newFullName, string newJobTitle, List<ProtoId<AccessLevelPrototype>> newAccessList, string newJobPrototype)
  56. {
  57. if (newFullName.Length > MaxFullNameLength)
  58. newFullName = newFullName[..MaxFullNameLength];
  59. if (newJobTitle.Length > MaxJobTitleLength)
  60. newJobTitle = newJobTitle[..MaxJobTitleLength];
  61. SendMessage(new WriteToTargetIdMessage(
  62. newFullName,
  63. newJobTitle,
  64. newAccessList,
  65. newJobPrototype));
  66. }
  67. }
  68. }