ForensicScannerBoundUserInterface.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Robust.Client.GameObjects;
  2. using Robust.Shared.Timing;
  3. using Content.Shared.Forensics;
  4. using Robust.Client.UserInterface;
  5. namespace Content.Client.Forensics
  6. {
  7. public sealed class ForensicScannerBoundUserInterface : BoundUserInterface
  8. {
  9. [Dependency] private readonly IGameTiming _gameTiming = default!;
  10. [ViewVariables]
  11. private ForensicScannerMenu? _window;
  12. [ViewVariables]
  13. private TimeSpan _printCooldown;
  14. public ForensicScannerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  15. {
  16. }
  17. protected override void Open()
  18. {
  19. base.Open();
  20. _window = this.CreateWindow<ForensicScannerMenu>();
  21. _window.Print.OnPressed += _ => Print();
  22. _window.Clear.OnPressed += _ => Clear();
  23. }
  24. private void Print()
  25. {
  26. SendMessage(new ForensicScannerPrintMessage());
  27. if (_window != null)
  28. _window.UpdatePrinterState(true);
  29. // This UI does not require pinpoint accuracy as to when the Print
  30. // button is available again, so spawning client-side timers is
  31. // fine. The server will make sure the cooldown is honored.
  32. Timer.Spawn(_printCooldown, () =>
  33. {
  34. if (_window != null)
  35. _window.UpdatePrinterState(false);
  36. });
  37. }
  38. private void Clear()
  39. {
  40. SendMessage(new ForensicScannerClearMessage());
  41. }
  42. protected override void UpdateState(BoundUserInterfaceState state)
  43. {
  44. base.UpdateState(state);
  45. if (_window == null)
  46. return;
  47. if (state is not ForensicScannerBoundUserInterfaceState cast)
  48. return;
  49. _printCooldown = cast.PrintCooldown;
  50. // TODO: Fix this
  51. if (cast.PrintReadyAt > _gameTiming.CurTime)
  52. Timer.Spawn(cast.PrintReadyAt - _gameTiming.CurTime, () =>
  53. {
  54. if (_window != null)
  55. _window.UpdatePrinterState(false);
  56. });
  57. _window.UpdateState(cast);
  58. }
  59. }
  60. }