2025-02-17 19:24:34 +11:00
|
|
|
using System.Numerics;
|
2025-02-08 17:17:55 +11:00
|
|
|
using Content.Client.UserInterface.Systems.Storage;
|
|
|
|
|
using Content.Client.UserInterface.Systems.Storage.Controls;
|
2023-09-11 21:20:46 +10:00
|
|
|
using Content.Shared.Storage;
|
2022-09-11 20:42:12 -07:00
|
|
|
using JetBrains.Annotations;
|
2025-02-08 17:17:55 +11:00
|
|
|
using Robust.Client.UserInterface;
|
2025-02-17 19:24:34 +11:00
|
|
|
using Robust.Client.UserInterface.Controls;
|
2022-04-28 06:11:15 -06:00
|
|
|
|
2023-12-04 18:04:39 -05:00
|
|
|
namespace Content.Client.Storage;
|
2023-09-11 21:20:46 +10:00
|
|
|
|
2023-12-04 18:04:39 -05:00
|
|
|
[UsedImplicitly]
|
|
|
|
|
public sealed class StorageBoundUserInterface : BoundUserInterface
|
|
|
|
|
{
|
2025-02-08 17:17:55 +11:00
|
|
|
private StorageWindow? _window;
|
2024-08-28 13:21:52 +10:00
|
|
|
|
2025-02-17 19:24:34 +11:00
|
|
|
public Vector2? Position => _window?.Position;
|
|
|
|
|
|
2023-12-04 18:04:39 -05:00
|
|
|
public StorageBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
|
|
|
|
{
|
|
|
|
|
}
|
2022-10-12 18:35:25 +02:00
|
|
|
|
2024-04-26 18:16:24 +10:00
|
|
|
protected override void Open()
|
|
|
|
|
{
|
|
|
|
|
base.Open();
|
|
|
|
|
|
2025-02-08 17:17:55 +11:00
|
|
|
_window = IoCManager.Resolve<IUserInterfaceManager>()
|
|
|
|
|
.GetUIController<StorageUIController>()
|
2025-02-17 19:24:34 +11:00
|
|
|
.CreateStorageWindow(this);
|
2025-02-08 17:17:55 +11:00
|
|
|
|
|
|
|
|
if (EntMan.TryGetComponent(Owner, out StorageComponent? storage))
|
|
|
|
|
{
|
|
|
|
|
_window.UpdateContainer((Owner, storage));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_window.OnClose += Close;
|
|
|
|
|
_window.FlagDirty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Refresh()
|
|
|
|
|
{
|
|
|
|
|
_window?.FlagDirty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Reclaim()
|
|
|
|
|
{
|
|
|
|
|
if (_window == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_window.OnClose -= Close;
|
|
|
|
|
_window.Orphan();
|
|
|
|
|
_window = null;
|
2024-04-26 18:16:24 +10:00
|
|
|
}
|
|
|
|
|
|
2023-12-04 18:04:39 -05:00
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(disposing);
|
2025-02-08 17:17:55 +11:00
|
|
|
Reclaim();
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-17 19:24:34 +11:00
|
|
|
public void CloseWindow(Vector2 position)
|
|
|
|
|
{
|
|
|
|
|
if (_window == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Update its position before potentially saving.
|
|
|
|
|
// Listen it makes sense okay.
|
|
|
|
|
LayoutContainer.SetPosition(_window, position);
|
|
|
|
|
_window?.Close();
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-08 17:17:55 +11:00
|
|
|
public void Hide()
|
|
|
|
|
{
|
|
|
|
|
if (_window == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_window.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Show()
|
|
|
|
|
{
|
|
|
|
|
if (_window == null)
|
2023-12-04 18:04:39 -05:00
|
|
|
return;
|
2022-04-28 06:11:15 -06:00
|
|
|
|
2025-02-08 17:17:55 +11:00
|
|
|
_window.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-17 19:24:34 +11:00
|
|
|
public void Show(Vector2 position)
|
|
|
|
|
{
|
|
|
|
|
if (_window == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Show();
|
|
|
|
|
LayoutContainer.SetPosition(_window, position);
|
|
|
|
|
}
|
2022-04-28 06:11:15 -06:00
|
|
|
}
|