Revert engine reverties (#34968)
This commit is contained in:
@@ -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;
|
||||
|
||||
_storage.CloseStorageWindow(Owner);
|
||||
_window.Visible = false;
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
if (_window == null)
|
||||
return;
|
||||
|
||||
_window.Visible = true;
|
||||
}
|
||||
|
||||
public void ReOpen()
|
||||
{
|
||||
_window?.Orphan();
|
||||
_window = null;
|
||||
Open();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@ using Content.Client.Animations;
|
||||
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;
|
||||
|
||||
@@ -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))
|
||||
component.Grid.Clear();
|
||||
component.Grid.AddRange(state.Grid);
|
||||
component.MaxItemSize = state.MaxItemSize;
|
||||
component.Whitelist = state.Whitelist;
|
||||
component.Blacklist = state.Blacklist;
|
||||
|
||||
_oldStoredItems.Clear();
|
||||
|
||||
foreach (var item in component.StoredItems)
|
||||
{
|
||||
if (_openStorages.LastOrDefault() == entity)
|
||||
_oldStoredItems.Add(item.Key, item.Value);
|
||||
}
|
||||
|
||||
component.StoredItems.Clear();
|
||||
|
||||
foreach (var (nent, location) in state.StoredItems)
|
||||
{
|
||||
var ent = EnsureEntity<StorageComponent>(nent, uid);
|
||||
component.StoredItems[ent] = location;
|
||||
}
|
||||
|
||||
component.SavedLocations.Clear();
|
||||
|
||||
foreach (var loc in state.SavedLocations)
|
||||
{
|
||||
component.SavedLocations[loc.Key] = new(loc.Value);
|
||||
}
|
||||
|
||||
var uiDirty = !component.StoredItems.SequenceEqual(_oldStoredItems);
|
||||
|
||||
if (uiDirty && UI.TryGetOpenUi<StorageBoundUserInterface>(uid, StorageComponent.StorageUiKey.Key, out var storageBui))
|
||||
{
|
||||
storageBui.Refresh();
|
||||
// Make sure nesting still updated.
|
||||
var player = _player.LocalEntity;
|
||||
|
||||
if (NestedStorage && player != null && ContainerSystem.TryGetContainingContainer((uid, null, null), out var container) &&
|
||||
UI.TryGetOpenUi<StorageBoundUserInterface>(container.Owner, StorageComponent.StorageUiKey.Key, out var containerBui))
|
||||
{
|
||||
CloseStorageWindow((entity, entity.Comp));
|
||||
containerBui.Hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
var storages = new ValueList<Entity<StorageComponent>>(_openStorages);
|
||||
var reverseStorages = storages.Reverse();
|
||||
|
||||
foreach (var storageEnt in reverseStorages)
|
||||
{
|
||||
if (storageEnt == entity)
|
||||
break;
|
||||
|
||||
CloseStorageBoundUserInterface(storageEnt.Owner);
|
||||
_openStorages.Remove(entity);
|
||||
}
|
||||
storageBui.Show();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ClearNonParentStorages(entity);
|
||||
_openStorages.Add(entity);
|
||||
Entity<StorageComponent>? last = _openStorages.LastOrDefault();
|
||||
StorageOrderChanged?.Invoke(last);
|
||||
}
|
||||
|
||||
public void CloseStorageWindow(Entity<StorageComponent?> entity)
|
||||
public override void UpdateUI(Entity<StorageComponent?> entity)
|
||||
{
|
||||
if (!Resolve(entity, ref entity.Comp, false))
|
||||
return;
|
||||
|
||||
if (!_openStorages.Contains((entity, entity.Comp)))
|
||||
return;
|
||||
|
||||
var storages = new ValueList<Entity<StorageComponent>>(_openStorages);
|
||||
var reverseStorages = storages.Reverse();
|
||||
|
||||
foreach (var storage in reverseStorages)
|
||||
if (UI.TryGetOpenUi<StorageBoundUserInterface>(entity.Owner, StorageComponent.StorageUiKey.Key, out var sBui))
|
||||
{
|
||||
CloseStorageBoundUserInterface(storage.Owner);
|
||||
_openStorages.Remove(storage);
|
||||
if (storage.Owner == entity.Owner)
|
||||
break;
|
||||
sBui.Refresh();
|
||||
}
|
||||
|
||||
Entity<StorageComponent>? last = null;
|
||||
if (_openStorages.Any())
|
||||
last = _openStorages.LastOrDefault();
|
||||
StorageOrderChanged?.Invoke(last);
|
||||
}
|
||||
|
||||
private void ClearNonParentStorages(EntityUid uid)
|
||||
protected override void HideStorageWindow(EntityUid uid, EntityUid actor)
|
||||
{
|
||||
var storages = new ValueList<Entity<StorageComponent>>(_openStorages);
|
||||
var reverseStorages = storages.Reverse();
|
||||
|
||||
foreach (var storage in reverseStorages)
|
||||
if (UI.TryGetOpenUi<StorageBoundUserInterface>(uid, StorageComponent.StorageUiKey.Key, out var storageBui))
|
||||
{
|
||||
if (storage.Comp.Container.Contains(uid))
|
||||
break;
|
||||
|
||||
CloseStorageBoundUserInterface(storage.Owner);
|
||||
_openStorages.Remove(storage);
|
||||
storageBui.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseStorageBoundUserInterface(Entity<UserInterfaceComponent?> entity)
|
||||
protected override void ShowStorageWindow(EntityUid uid, EntityUid actor)
|
||||
{
|
||||
if (!Resolve(entity, ref entity.Comp, false))
|
||||
return;
|
||||
|
||||
if (entity.Comp.ClientOpenInterfaces.GetValueOrDefault(StorageComponent.StorageUiKey.Key) is not { } bui)
|
||||
return;
|
||||
|
||||
bui.Close();
|
||||
}
|
||||
|
||||
private void OnShutdown(Entity<StorageComponent> ent, ref ComponentShutdown args)
|
||||
{
|
||||
CloseStorageWindow((ent, ent.Comp));
|
||||
if (UI.TryGetOpenUi<StorageBoundUserInterface>(uid, StorageComponent.StorageUiKey.Key, out var storageBui))
|
||||
{
|
||||
storageBui.Show();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -142,7 +124,7 @@ public sealed class StorageSystem : SharedStorageSystem
|
||||
{
|
||||
if (!_timing.IsFirstTimePredicted)
|
||||
return;
|
||||
|
||||
|
||||
if (TransformSystem.InRange(finalCoords, initialCoords, 0.1f) ||
|
||||
!Exists(initialCoords.EntityId) || !Exists(finalCoords.EntityId))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user