General storage fixes (#34845)

* Fix storage stars

* Fix some more storage bugs

- Fix positions not saving.
- Fix the 1-tick delay between parent and child storage UIs opening / closing.
- Fix BackButton being visible sometimes when it shouldn't be.

* milon is a furry
This commit is contained in:
metalgearsloth
2025-02-17 19:24:34 +11:00
committed by GitHub
parent b55ef7dd56
commit cf38814515
6 changed files with 143 additions and 37 deletions

View File

@@ -1,8 +1,10 @@
using System.Numerics;
using Content.Client.UserInterface.Systems.Storage;
using Content.Client.UserInterface.Systems.Storage.Controls;
using Content.Shared.Storage;
using JetBrains.Annotations;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.Storage;
@@ -11,6 +13,8 @@ public sealed class StorageBoundUserInterface : BoundUserInterface
{
private StorageWindow? _window;
public Vector2? Position => _window?.Position;
public StorageBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
@@ -21,7 +25,7 @@ public sealed class StorageBoundUserInterface : BoundUserInterface
_window = IoCManager.Resolve<IUserInterfaceManager>()
.GetUIController<StorageUIController>()
.CreateStorageWindow(Owner);
.CreateStorageWindow(this);
if (EntMan.TryGetComponent(Owner, out StorageComponent? storage))
{
@@ -50,10 +54,20 @@ public sealed class StorageBoundUserInterface : BoundUserInterface
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
Reclaim();
}
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();
}
public void Hide()
{
if (_window == null)
@@ -70,6 +84,15 @@ public sealed class StorageBoundUserInterface : BoundUserInterface
_window.Visible = true;
}
public void Show(Vector2 position)
{
if (_window == null)
return;
Show();
LayoutContainer.SetPosition(_window, position);
}
public void ReOpen()
{
_window?.Orphan();

View File

@@ -19,6 +19,8 @@ public sealed class StorageSystem : SharedStorageSystem
private Dictionary<EntityUid, ItemStorageLocation> _oldStoredItems = new();
private List<(StorageBoundUserInterface Bui, bool Value)> _queuedBuis = new();
public override void Initialize()
{
base.Initialize();
@@ -72,7 +74,7 @@ public sealed class StorageSystem : SharedStorageSystem
if (NestedStorage && player != null && ContainerSystem.TryGetContainingContainer((uid, null, null), out var container) &&
UI.TryGetOpenUi<StorageBoundUserInterface>(container.Owner, StorageComponent.StorageUiKey.Key, out var containerBui))
{
containerBui.Hide();
_queuedBuis.Add((containerBui, false));
}
}
}
@@ -89,7 +91,7 @@ public sealed class StorageSystem : SharedStorageSystem
{
if (UI.TryGetOpenUi<StorageBoundUserInterface>(uid, StorageComponent.StorageUiKey.Key, out var storageBui))
{
storageBui.Hide();
_queuedBuis.Add((storageBui, false));
}
}
@@ -97,7 +99,7 @@ public sealed class StorageSystem : SharedStorageSystem
{
if (UI.TryGetOpenUi<StorageBoundUserInterface>(uid, StorageComponent.StorageUiKey.Key, out var storageBui))
{
storageBui.Show();
_queuedBuis.Add((storageBui, true));
}
}
@@ -152,4 +154,30 @@ public sealed class StorageSystem : SharedStorageSystem
}
}
}
public override void Update(float frameTime)
{
base.Update(frameTime);
if (!_timing.IsFirstTimePredicted)
{
return;
}
// This update loop exists just to synchronize with UISystem and avoid 1-tick delays.
// If deferred opens / closes ever get removed you can dump this.
foreach (var (bui, open) in _queuedBuis)
{
if (open)
{
bui.Show();
}
else
{
bui.Hide();
}
}
_queuedBuis.Clear();
}
}