CriminalRecordsConsoleBoundUserInterface.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using Content.Shared.Access.Systems;
  2. using Content.Shared.CriminalRecords;
  3. using Content.Shared.CriminalRecords.Components;
  4. using Content.Shared.Security;
  5. using Content.Shared.StationRecords;
  6. using Robust.Client.Player;
  7. using Robust.Shared.Prototypes;
  8. using Robust.Shared.Random;
  9. namespace Content.Client.CriminalRecords;
  10. public sealed class CriminalRecordsConsoleBoundUserInterface : BoundUserInterface
  11. {
  12. [Dependency] private readonly IPrototypeManager _proto = default!;
  13. [Dependency] private readonly IRobustRandom _random = default!;
  14. [Dependency] private readonly IPlayerManager _playerManager = default!;
  15. private readonly AccessReaderSystem _accessReader;
  16. private CriminalRecordsConsoleWindow? _window;
  17. private CrimeHistoryWindow? _historyWindow;
  18. public CriminalRecordsConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  19. {
  20. _accessReader = EntMan.System<AccessReaderSystem>();
  21. }
  22. protected override void Open()
  23. {
  24. base.Open();
  25. var comp = EntMan.GetComponent<CriminalRecordsConsoleComponent>(Owner);
  26. _window = new(Owner, comp.MaxStringLength, _playerManager, _proto, _random, _accessReader);
  27. _window.OnKeySelected += key =>
  28. SendMessage(new SelectStationRecord(key));
  29. _window.OnFiltersChanged += (type, filterValue) =>
  30. SendMessage(new SetStationRecordFilter(type, filterValue));
  31. _window.OnStatusSelected += status =>
  32. SendMessage(new CriminalRecordChangeStatus(status, null));
  33. _window.OnDialogConfirmed += (status, reason) =>
  34. SendMessage(new CriminalRecordChangeStatus(status, reason));
  35. _window.OnStatusFilterPressed += (statusFilter) =>
  36. SendMessage(new CriminalRecordSetStatusFilter(statusFilter));
  37. _window.OnHistoryUpdated += UpdateHistory;
  38. _window.OnHistoryClosed += () => _historyWindow?.Close();
  39. _window.OnClose += Close;
  40. _historyWindow = new(comp.MaxStringLength);
  41. _historyWindow.OnAddHistory += line => SendMessage(new CriminalRecordAddHistory(line));
  42. _historyWindow.OnDeleteHistory += index => SendMessage(new CriminalRecordDeleteHistory(index));
  43. _historyWindow.Close(); // leave closed until user opens it
  44. }
  45. /// <summary>
  46. /// Updates or opens a new history window.
  47. /// </summary>
  48. private void UpdateHistory(CriminalRecord record, bool access, bool open)
  49. {
  50. _historyWindow!.UpdateHistory(record, access);
  51. if (open)
  52. _historyWindow.OpenCentered();
  53. }
  54. protected override void UpdateState(BoundUserInterfaceState state)
  55. {
  56. base.UpdateState(state);
  57. if (state is not CriminalRecordsConsoleState cast)
  58. return;
  59. _window?.UpdateState(cast);
  60. }
  61. protected override void Dispose(bool disposing)
  62. {
  63. base.Dispose(disposing);
  64. _window?.Close();
  65. _historyWindow?.Close();
  66. }
  67. }