1
0

StorageBoundUserInterface.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System.Numerics;
  2. using Content.Client.UserInterface.Systems.Storage;
  3. using Content.Client.UserInterface.Systems.Storage.Controls;
  4. using Content.Shared.Storage;
  5. using JetBrains.Annotations;
  6. using Robust.Client.UserInterface;
  7. using Robust.Client.UserInterface.Controls;
  8. namespace Content.Client.Storage;
  9. [UsedImplicitly]
  10. public sealed class StorageBoundUserInterface : BoundUserInterface
  11. {
  12. private StorageWindow? _window;
  13. public Vector2? Position => _window?.Position;
  14. public StorageBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  15. {
  16. }
  17. protected override void Open()
  18. {
  19. base.Open();
  20. _window = IoCManager.Resolve<IUserInterfaceManager>()
  21. .GetUIController<StorageUIController>()
  22. .CreateStorageWindow(this);
  23. if (EntMan.TryGetComponent(Owner, out StorageComponent? storage))
  24. {
  25. _window.UpdateContainer((Owner, storage));
  26. }
  27. _window.OnClose += Close;
  28. _window.FlagDirty();
  29. }
  30. public void Refresh()
  31. {
  32. _window?.FlagDirty();
  33. }
  34. public void Reclaim()
  35. {
  36. if (_window == null)
  37. return;
  38. _window.OnClose -= Close;
  39. _window.Orphan();
  40. _window = null;
  41. }
  42. protected override void Dispose(bool disposing)
  43. {
  44. base.Dispose(disposing);
  45. Reclaim();
  46. }
  47. public void CloseWindow(Vector2 position)
  48. {
  49. if (_window == null)
  50. return;
  51. // Update its position before potentially saving.
  52. // Listen it makes sense okay.
  53. LayoutContainer.SetPosition(_window, position);
  54. _window?.Close();
  55. }
  56. public void Hide()
  57. {
  58. if (_window == null)
  59. return;
  60. _window.Visible = false;
  61. }
  62. public void Show()
  63. {
  64. if (_window == null)
  65. return;
  66. _window.Visible = true;
  67. }
  68. public void Show(Vector2 position)
  69. {
  70. if (_window == null)
  71. return;
  72. Show();
  73. LayoutContainer.SetPosition(_window, position);
  74. }
  75. }