Skip to content

Commit

Permalink
Revert engine reverties (#34968)
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth authored Feb 8, 2025
1 parent 80bd01b commit e971d6e
Show file tree
Hide file tree
Showing 13 changed files with 775 additions and 400 deletions.
65 changes: 53 additions & 12 deletions Content.Client/Storage/StorageBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,80 @@
using Content.Client.Storage.Systems;
using Content.Client.UserInterface.Systems.Storage;
using Content.Client.UserInterface.Systems.Storage.Controls;
using Content.Shared.Storage;
using JetBrains.Annotations;
using Robust.Client.UserInterface;

namespace Content.Client.Storage;

[UsedImplicitly]
public sealed class StorageBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IEntityManager _entManager = default!;

private readonly StorageSystem _storage;

[Obsolete] public override bool DeferredClose => false;
private StorageWindow? _window;

public StorageBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
IoCManager.InjectDependencies(this);
_storage = _entManager.System<StorageSystem>();
}

protected override void Open()
{
base.Open();

if (_entManager.TryGetComponent<StorageComponent>(Owner, out var comp))
_storage.OpenStorageWindow((Owner, comp));
_window = IoCManager.Resolve<IUserInterfaceManager>()
.GetUIController<StorageUIController>()
.CreateStorageWindow(Owner);

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;
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)

Reclaim();
}

public void Hide()
{
if (_window == null)
return;

_window.Visible = false;
}

public void Show()
{
if (_window == null)
return;

_storage.CloseStorageWindow(Owner);
_window.Visible = true;
}

public void ReOpen()
{
_window?.Orphan();
_window = null;
Open();
}
}

134 changes: 58 additions & 76 deletions Content.Client/Storage/Systems/StorageSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
using Content.Shared.Hands;
using Content.Shared.Storage;
using Content.Shared.Storage.EntitySystems;
using Robust.Shared.Collections;
using Robust.Client.Player;
using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Timing;

Expand All @@ -13,114 +14,95 @@ namespace Content.Client.Storage.Systems;
public sealed class StorageSystem : SharedStorageSystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly EntityPickupAnimationSystem _entityPickupAnimation = default!;

private readonly List<Entity<StorageComponent>> _openStorages = new();
public int OpenStorageAmount => _openStorages.Count;

public event Action<Entity<StorageComponent>>? StorageUpdated;
public event Action<Entity<StorageComponent>?>? StorageOrderChanged;
private Dictionary<EntityUid, ItemStorageLocation> _oldStoredItems = new();

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<StorageComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<StorageComponent, ComponentHandleState>(OnStorageHandleState);
SubscribeNetworkEvent<PickupAnimationEvent>(HandlePickupAnimation);
SubscribeAllEvent<AnimateInsertingEntitiesEvent>(HandleAnimatingInsertingEntities);
}

public override void UpdateUI(Entity<StorageComponent?> entity)
private void OnStorageHandleState(EntityUid uid, StorageComponent component, ref ComponentHandleState args)
{
if (Resolve(entity.Owner, ref entity.Comp))
StorageUpdated?.Invoke((entity, entity.Comp));
}
if (args.Current is not StorageComponentState state)
return;

public void OpenStorageWindow(Entity<StorageComponent> entity)
{
if (_openStorages.Contains(entity))
{
if (_openStorages.LastOrDefault() == entity)
{
CloseStorageWindow((entity, entity.Comp));
}
else
{
var storages = new ValueList<Entity<StorageComponent>>(_openStorages);
var reverseStorages = storages.Reverse();
component.Grid.Clear();
component.Grid.AddRange(state.Grid);
component.MaxItemSize = state.MaxItemSize;
component.Whitelist = state.Whitelist;
component.Blacklist = state.Blacklist;

foreach (var storageEnt in reverseStorages)
{
if (storageEnt == entity)
break;
_oldStoredItems.Clear();

CloseStorageBoundUserInterface(storageEnt.Owner);
_openStorages.Remove(entity);
}
}
return;
foreach (var item in component.StoredItems)
{
_oldStoredItems.Add(item.Key, item.Value);
}

ClearNonParentStorages(entity);
_openStorages.Add(entity);
Entity<StorageComponent>? last = _openStorages.LastOrDefault();
StorageOrderChanged?.Invoke(last);
}

public void CloseStorageWindow(Entity<StorageComponent?> entity)
{
if (!Resolve(entity, ref entity.Comp, false))
return;
component.StoredItems.Clear();

if (!_openStorages.Contains((entity, entity.Comp)))
return;
foreach (var (nent, location) in state.StoredItems)
{
var ent = EnsureEntity<StorageComponent>(nent, uid);
component.StoredItems[ent] = location;
}

var storages = new ValueList<Entity<StorageComponent>>(_openStorages);
var reverseStorages = storages.Reverse();
component.SavedLocations.Clear();

foreach (var storage in reverseStorages)
foreach (var loc in state.SavedLocations)
{
CloseStorageBoundUserInterface(storage.Owner);
_openStorages.Remove(storage);
if (storage.Owner == entity.Owner)
break;
component.SavedLocations[loc.Key] = new(loc.Value);
}

Entity<StorageComponent>? last = null;
if (_openStorages.Any())
last = _openStorages.LastOrDefault();
StorageOrderChanged?.Invoke(last);
}
var uiDirty = !component.StoredItems.SequenceEqual(_oldStoredItems);

private void ClearNonParentStorages(EntityUid uid)
{
var storages = new ValueList<Entity<StorageComponent>>(_openStorages);
var reverseStorages = storages.Reverse();

foreach (var storage in reverseStorages)
if (uiDirty && UI.TryGetOpenUi<StorageBoundUserInterface>(uid, StorageComponent.StorageUiKey.Key, out var storageBui))
{
if (storage.Comp.Container.Contains(uid))
break;
storageBui.Refresh();
// Make sure nesting still updated.
var player = _player.LocalEntity;

CloseStorageBoundUserInterface(storage.Owner);
_openStorages.Remove(storage);
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();
}
else
{
storageBui.Show();
}
}
}

private void CloseStorageBoundUserInterface(Entity<UserInterfaceComponent?> entity)
public override void UpdateUI(Entity<StorageComponent?> entity)
{
if (!Resolve(entity, ref entity.Comp, false))
return;

if (entity.Comp.ClientOpenInterfaces.GetValueOrDefault(StorageComponent.StorageUiKey.Key) is not { } bui)
return;
if (UI.TryGetOpenUi<StorageBoundUserInterface>(entity.Owner, StorageComponent.StorageUiKey.Key, out var sBui))
{
sBui.Refresh();
}
}

bui.Close();
protected override void HideStorageWindow(EntityUid uid, EntityUid actor)
{
if (UI.TryGetOpenUi<StorageBoundUserInterface>(uid, StorageComponent.StorageUiKey.Key, out var storageBui))
{
storageBui.Hide();
}
}

private void OnShutdown(Entity<StorageComponent> ent, ref ComponentShutdown args)
protected override void ShowStorageWindow(EntityUid uid, EntityUid actor)
{
CloseStorageWindow((ent, ent.Comp));
if (UI.TryGetOpenUi<StorageBoundUserInterface>(uid, StorageComponent.StorageUiKey.Key, out var storageBui))
{
storageBui.Show();
}
}

/// <inheritdoc />
Expand All @@ -142,7 +124,7 @@ public void PickupAnimation(EntityUid item, EntityCoordinates initialCoords, Ent
{
if (!_timing.IsFirstTimePredicted)
return;

if (TransformSystem.InRange(finalCoords, initialCoords, 0.1f) ||
!Exists(initialCoords.EntityId) || !Exists(finalCoords.EntityId))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ private void OnScreenLoad()
ReloadHotbar();
}

public void Setup(HandsContainer handsContainer, StorageContainer storageContainer)
public void Setup(HandsContainer handsContainer)
{
_inventory = UIManager.GetUIController<InventoryUIController>();
_hands = UIManager.GetUIController<HandsUIController>();
_storage = UIManager.GetUIController<StorageUIController>();
_hands.RegisterHandContainer(handsContainer);
_storage.RegisterStorageContainer(storageContainer);
}

public void ReloadHotbar()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<widgets:HotbarGui
xmlns="https://spacestation14.io"
xmlns:inventory="clr-namespace:Content.Client.UserInterface.Systems.Inventory.Controls"
xmlns:storage="clr-namespace:Content.Client.UserInterface.Systems.Storage.Controls"
xmlns:hands="clr-namespace:Content.Client.UserInterface.Systems.Hands.Controls"
xmlns:widgets="clr-namespace:Content.Client.UserInterface.Systems.Hotbar.Widgets"
Name="HotbarInterface"
Expand All @@ -13,10 +12,8 @@
<BoxContainer Name="StorageContainer"
Access="Public"
HorizontalAlignment="Center"
HorizontalExpand="True"
Margin="10">
<storage:StorageContainer
Name="StoragePanel"
Visible="False"/>
</BoxContainer>
<BoxContainer Orientation="Horizontal" Name="Hotbar" HorizontalAlignment="Center">
<inventory:ItemSlotButtonContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public HotbarGui()
StatusPanelLeft.SetSide(HandUILocation.Left);
var hotbarController = UserInterfaceManager.GetUIController<HotbarUIController>();

hotbarController.Setup(HandContainer, StoragePanel);
hotbarController.Setup(HandContainer);
LayoutContainer.SetGrowVertical(this, LayoutContainer.GrowDirection.Begin);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ItemGridPiece(Entity<ItemComponent> entity, ItemStorageLocation location,
Location = location;

Visible = true;
MouseFilter = MouseFilterMode.Pass;
MouseFilter = MouseFilterMode.Stop;

TooltipSupplier = SupplyTooltip;

Expand Down Expand Up @@ -105,8 +105,11 @@ protected override void Draw(DrawingHandleScreen handle)
return;
}

if (_storageController.IsDragging && _storageController.DraggingGhost?.Entity == Entity && _storageController.DraggingGhost != this)
if (_storageController.IsDragging && _storageController.DraggingGhost?.Entity == Entity &&
_storageController.DraggingGhost != this)
{
return;
}

var adjustedShape = _entityManager.System<ItemSystem>().GetAdjustedItemShape((Entity, itemComponent), Location.Rotation, Vector2i.Zero);
var boundingGrid = adjustedShape.GetBoundingBox();
Expand Down
Loading

0 comments on commit e971d6e

Please sign in to comment.