]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Predict StorageComponent (#19682)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Mon, 11 Sep 2023 11:20:46 +0000 (21:20 +1000)
committerGitHub <noreply@github.com>
Mon, 11 Sep 2023 11:20:46 +0000 (21:20 +1000)
68 files changed:
Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs
Content.Client/Atmos/Monitor/UI/AirAlarmBoundUserInterface.cs
Content.Client/Atmos/UI/GasThermomachineBoundUserInterface.cs
Content.Client/Interactable/InteractionSystem.cs
Content.Client/Inventory/ClientInventorySystem.cs
Content.Client/Storage/ClientStorageComponent.cs [deleted file]
Content.Client/Storage/StorageBoundUserInterface.cs
Content.Client/Storage/Systems/StorageSystem.cs
Content.Client/Storage/UI/StorageUIController.cs [new file with mode: 0644]
Content.Client/Storage/UI/StorageWindow.cs
Content.Client/Strip/StrippableSystem.cs
Content.Client/UserInterface/Systems/Inventory/InventoryUIController.cs
Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs
Content.IntegrationTests/Tests/StorageTest.cs
Content.IntegrationTests/Tests/VendingMachineRestockTest.cs
Content.Server/Arcade/BlockGame/BlockGameArcadeSystem.cs
Content.Server/Atmos/Piping/Unary/EntitySystems/GasThermoMachineSystem.cs
Content.Server/Cargo/Systems/CargoSystem.Bounty.cs
Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs
Content.Server/Communications/CommunicationsConsoleComponent.cs
Content.Server/Construction/ConstructionSystem.Initial.cs
Content.Server/Construction/PartExchangerSystem.cs
Content.Server/Crayon/CrayonComponent.cs
Content.Server/Eye/Blinding/ActivatableUIRequiresVisionSystem.cs
Content.Server/Hands/Systems/HandsSystem.cs
Content.Server/Instruments/InstrumentComponent.cs
Content.Server/Interaction/InteractionSystem.cs
Content.Server/Inventory/ServerInventorySystem.cs
Content.Server/Item/ItemSystem.cs
Content.Server/Light/EntitySystems/LightReplacerSystem.cs
Content.Server/Medical/Components/HealthAnalyzerComponent.cs
Content.Server/Nutrition/EntitySystems/FoodSystem.cs
Content.Server/PDA/PdaSystem.cs
Content.Server/Power/EntitySystems/ApcSystem.cs
Content.Server/Resist/EscapeInventorySystem.cs
Content.Server/Salvage/SalvageSystem.ExpeditionConsole.cs
Content.Server/SensorMonitoring/SensorMonitoringConsoleComponent.cs
Content.Server/Solar/EntitySystems/PowerSolarControlConsoleSystem.cs
Content.Server/Stack/StackSystem.cs
Content.Server/Storage/Components/ServerStorageComponent.cs [deleted file]
Content.Server/Storage/Components/StorageFillComponent.cs [deleted file]
Content.Server/Storage/EntitySystems/ItemCounterSystem.cs
Content.Server/Storage/EntitySystems/PickRandomSystem.cs
Content.Server/Storage/EntitySystems/StorageFillVisualizerSystem.cs
Content.Server/Storage/EntitySystems/StorageSystem.Fill.cs
Content.Server/Storage/EntitySystems/StorageSystem.cs
Content.Server/Store/Systems/StoreSystem.Ui.cs
Content.Server/UserInterface/ActivatableUIComponent.cs
Content.Server/UserInterface/ActivatableUISystem.cs
Content.Server/UserInterface/IntrinsicUISystem.cs
Content.Server/UserInterface/UserInterfaceHelpers.cs
Content.Server/Wires/WiresSystem.cs
Content.Shared/Access/SharedAgentIDCardSystem.cs
Content.Shared/Atmos/Piping/Binary/Components/SharedGasCanisterComponent.cs
Content.Shared/Buckle/SharedBuckleSystem.Strap.cs
Content.Shared/Labels/LabelEvents.cs
Content.Shared/Speech/Components/MeleeSpeechComponent.cs
Content.Shared/Storage/Components/StorageFillComponent.cs [new file with mode: 0644]
Content.Shared/Storage/EntitySystems/DumpableSystem.cs
Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs [new file with mode: 0644]
Content.Shared/Storage/SharedStorageComponent.cs [deleted file]
Content.Shared/Storage/StorageComponent.cs [new file with mode: 0644]
Resources/Prototypes/Catalog/Fills/Lockers/service.yml
Resources/Prototypes/Entities/Clothing/Belt/base_clothingbelt.yml
Resources/Prototypes/Entities/Mobs/NPCs/space.yml
Resources/Prototypes/Entities/Objects/Fun/dice_bag.yml
Resources/Prototypes/Entities/Objects/Misc/paper.yml
Resources/Prototypes/Entities/Objects/Specific/Kitchen/foodcarts.yml

index 292759dc878f888ba7cdb2d4f9857fe6b3245200..be45e57c8b1c6c28ba66959074636c6ff3f19ba6 100644 (file)
@@ -5,6 +5,7 @@ using Content.Shared.CrewManifest;
 using Robust.Client.GameObjects;
 using Robust.Shared.Prototypes;
 using static Content.Shared.Access.Components.IdCardConsoleComponent;
+
 namespace Content.Client.Access.UI
 {
     public sealed class IdCardConsoleBoundUserInterface : BoundUserInterface
index 3f7f1e73ee589228026f281c3c46f43906d2f25a..8f3b507c806e7142243cf92ea9167b1943956d68 100644 (file)
@@ -48,7 +48,7 @@ public sealed class AirAlarmBoundUserInterface : BoundUserInterface
     {
         SendMessage(new AirAlarmUpdateDeviceDataMessage(address, data));
     }
-       
+
        private void OnDeviceDataCopied(IAtmosDeviceData data)
     {
         SendMessage(new AirAlarmCopyDeviceDataMessage(data));
index 23850cb25ad94a661cb03f2ee7ffa2c77c551389..1664c8b9d750c320d828d996e95e953239f6de6f 100644 (file)
@@ -19,7 +19,7 @@ namespace Content.Client.Atmos.UI
 
         [ViewVariables]
         private float _maxTemp = 0.0f;
-        
+
         [ViewVariables]
         private bool _isHeater = true;
 
index bb8ca89576b5dc44c03e8ae59789ac7fc2e59471..cdfd3aa54fa83c17b887457ed13efccf6e88e6fb 100644 (file)
@@ -1,5 +1,5 @@
-using Content.Client.Storage;
 using Content.Shared.Interaction;
+using Content.Shared.Storage;
 using Robust.Shared.Containers;
 
 namespace Content.Client.Interactable
@@ -14,7 +14,7 @@ namespace Content.Client.Interactable
             if (!target.TryGetContainer(out var container))
                 return false;
 
-            if (!TryComp(container.Owner, out ClientStorageComponent? storage))
+            if (!TryComp(container.Owner, out StorageComponent? storage))
                 return false;
 
             // we don't check if the user can access the storage entity itself. This should be handed by the UI system.
index e74df5d570d337c815451dcce35807e249112bef..d6a487f3fd5a5b6a46722a07803ecda91f55fb84 100644 (file)
@@ -1,6 +1,5 @@
 using Content.Client.Clothing;
 using Content.Client.Examine;
-using Content.Client.Storage;
 using Content.Client.UserInterface.Controls;
 using Content.Client.Verbs.UI;
 using Content.Shared.Clothing.Components;
@@ -9,6 +8,7 @@ using Content.Shared.Interaction;
 using Content.Shared.Interaction.Events;
 using Content.Shared.Inventory;
 using Content.Shared.Inventory.Events;
+using Content.Shared.Storage;
 using JetBrains.Annotations;
 using Robust.Client.GameObjects;
 using Robust.Client.Player;
@@ -101,7 +101,7 @@ namespace Content.Client.Inventory
             if (args.Equipee != _playerManager.LocalPlayer?.ControlledEntity)
                 return;
             var update = new SlotSpriteUpdate(args.Equipment, args.SlotGroup, args.Slot,
-                HasComp<ClientStorageComponent>(args.Equipment));
+                HasComp<StorageComponent>(args.Equipment));
             OnSpriteUpdate?.Invoke(update);
         }
 
diff --git a/Content.Client/Storage/ClientStorageComponent.cs b/Content.Client/Storage/ClientStorageComponent.cs
deleted file mode 100644 (file)
index 19fa84b..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-using Content.Client.Animations;
-using Content.Shared.DragDrop;
-using Content.Shared.Storage;
-
-namespace Content.Client.Storage
-{
-    /// <summary>
-    /// Client version of item storage containers, contains a UI which displays stored entities and their size
-    /// </summary>
-    [RegisterComponent]
-    [ComponentReference(typeof(SharedStorageComponent))]
-    public sealed partial class ClientStorageComponent : SharedStorageComponent
-    {
-        private List<EntityUid> _storedEntities = new();
-        public override IReadOnlyList<EntityUid> StoredEntities => _storedEntities;
-
-        public override bool Remove(EntityUid entity)
-        {
-            return false;
-        }
-    }
-}
index 25024aa8c5295c880cc1edb95bda39b341b7987a..1842417a6e212a1b3ed20175652a72f36d9ffd42 100644 (file)
@@ -4,12 +4,13 @@ using Content.Client.UserInterface.Controls;
 using Content.Client.Verbs.UI;
 using Content.Shared.Input;
 using Content.Shared.Interaction;
+using Content.Shared.Storage;
 using JetBrains.Annotations;
 using Robust.Client.GameObjects;
 using Robust.Client.UserInterface;
 using Robust.Client.UserInterface.Controls;
 using Robust.Shared.Input;
-using static Content.Shared.Storage.SharedStorageComponent;
+using static Content.Shared.Storage.StorageComponent;
 
 namespace Content.Client.Storage
 {
@@ -19,8 +20,11 @@ namespace Content.Client.Storage
         [ViewVariables]
         private StorageWindow? _window;
 
+        [Dependency] private readonly IEntityManager _entManager = default!;
+
         public StorageBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
         {
+            IoCManager.InjectDependencies(this);
         }
 
         protected override void Open()
@@ -29,17 +33,22 @@ namespace Content.Client.Storage
 
             if (_window == null)
             {
-                _window = new StorageWindow(EntMan)
-                {
-                    Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName
-                };
+                // TODO: This is a bit of a mess but storagecomponent got moved to shared and cleaned up a bit.
+                var controller = IoCManager.Resolve<IUserInterfaceManager>().GetUIController<StorageUIController>();
+                _window = controller.EnsureStorageWindow(Owner);
+                _window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
 
                 _window.EntityList.GenerateItem += _window.GenerateButton;
                 _window.EntityList.ItemPressed += InteractWithItem;
                 _window.StorageContainerButton.OnPressed += TouchedContainerButton;
 
                 _window.OnClose += Close;
-                _window.OpenCenteredLeft();
+
+                if (EntMan.TryGetComponent<StorageComponent>(Owner, out var storageComp))
+                {
+                    BuildEntityList(Owner, storageComp);
+                }
+
             }
             else
             {
@@ -47,6 +56,11 @@ namespace Content.Client.Storage
             }
         }
 
+        public void BuildEntityList(EntityUid uid, StorageComponent component)
+        {
+            _window?.BuildEntityList(uid, component);
+        }
+
         public void InteractWithItem(BaseButton.ButtonEventArgs args, ListData cData)
         {
             if (cData is not EntityListData { Uid: var entity })
@@ -54,7 +68,7 @@ namespace Content.Client.Storage
 
             if (args.Event.Function == EngineKeyFunctions.UIClick)
             {
-                SendMessage(new StorageInteractWithItemEvent(EntMan.GetNetEntity(entity)));
+                SendPredictedMessage(new StorageInteractWithItemEvent(_entManager.GetNetEntity(entity)));
             }
             else if (EntMan.EntityExists(entity))
             {
@@ -92,17 +106,7 @@ namespace Content.Client.Storage
 
         public void TouchedContainerButton(BaseButton.ButtonEventArgs args)
         {
-            SendMessage(new StorageInsertItemMessage());
-        }
-
-        protected override void UpdateState(BoundUserInterfaceState state)
-        {
-            base.UpdateState(state);
-
-            if (_window == null || state is not StorageBoundUserInterfaceState cast)
-                return;
-
-            _window?.BuildEntityList(cast);
+            SendPredictedMessage(new StorageInsertItemMessage());
         }
 
         protected override void Dispose(bool disposing)
@@ -113,14 +117,13 @@ namespace Content.Client.Storage
 
             if (_window != null)
             {
+                _window.Orphan();
                 _window.EntityList.GenerateItem -= _window.GenerateButton;
                 _window.EntityList.ItemPressed -= InteractWithItem;
                 _window.StorageContainerButton.OnPressed -= TouchedContainerButton;
                 _window.OnClose -= Close;
+                _window = null;
             }
-
-            _window?.Dispose();
-            _window = null;
         }
     }
 }
index 27fbfe651e68cd094fffb790f2fb69b3be2e97a3..725c79ffc6623ca65d85d9060a94a4b507ab0cc0 100644 (file)
@@ -1,11 +1,17 @@
 using Content.Client.Animations;
 using Content.Shared.Storage;
+using Content.Shared.Storage.EntitySystems;
+using Robust.Shared.Timing;
 
 namespace Content.Client.Storage.Systems;
 
 // TODO kill this is all horrid.
-public sealed class StorageSystem : EntitySystem
+public sealed class StorageSystem : SharedStorageSystem
 {
+    [Dependency] private readonly IGameTiming _timing = default!;
+
+    public event Action<EntityUid, StorageComponent>? StorageUpdated;
+
     public override void Initialize()
     {
         base.Initialize();
@@ -13,22 +19,24 @@ public sealed class StorageSystem : EntitySystem
         SubscribeNetworkEvent<AnimateInsertingEntitiesEvent>(HandleAnimatingInsertingEntities);
     }
 
+    public override void UpdateUI(EntityUid uid, StorageComponent component)
+    {
+        // Should we wrap this in some prediction call maybe?
+        StorageUpdated?.Invoke(uid, component);
+    }
+
     /// <summary>
     /// Animate the newly stored entities in <paramref name="msg"/> flying towards this storage's position
     /// </summary>
     /// <param name="msg"></param>
     public void HandleAnimatingInsertingEntities(AnimateInsertingEntitiesEvent msg)
     {
-        var store = GetEntity(msg.Storage);
-
-        if (!HasComp<ClientStorageComponent>(store))
-            return;
-
-        TryComp(store, out TransformComponent? transformComp);
+        TryComp(GetEntity(msg.Storage), out TransformComponent? transformComp);
 
         for (var i = 0; msg.StoredEntities.Count > i; i++)
         {
             var entity = GetEntity(msg.StoredEntities[i]);
+
             var initialPosition = msg.EntityPositions[i];
             if (EntityManager.EntityExists(entity) && transformComp != null)
             {
diff --git a/Content.Client/Storage/UI/StorageUIController.cs b/Content.Client/Storage/UI/StorageUIController.cs
new file mode 100644 (file)
index 0000000..9fc7909
--- /dev/null
@@ -0,0 +1,60 @@
+using Content.Client.Storage.Systems;
+using Content.Shared.Storage;
+using Robust.Client.UserInterface.Controllers;
+
+namespace Content.Client.Storage.UI;
+
+public sealed class StorageUIController : UIController, IOnSystemChanged<StorageSystem>
+{
+    // This is mainly to keep legacy functionality for now.
+    private readonly Dictionary<EntityUid, StorageWindow> _storageWindows = new();
+
+    public override void Initialize()
+    {
+        base.Initialize();
+        EntityManager.EventBus.SubscribeLocalEvent<StorageComponent, ComponentShutdown>(OnStorageShutdown);
+    }
+    public StorageWindow EnsureStorageWindow(EntityUid uid)
+    {
+        if (_storageWindows.TryGetValue(uid, out var window))
+        {
+            UIManager.WindowRoot.AddChild(window);
+            return window;
+        }
+
+        window = new StorageWindow(EntityManager);
+        _storageWindows[uid] = window;
+        window.OpenCenteredLeft();
+        return window;
+    }
+
+    private void OnStorageShutdown(EntityUid uid, StorageComponent component, ComponentShutdown args)
+    {
+        if (!_storageWindows.TryGetValue(uid, out var window))
+            return;
+
+        _storageWindows.Remove(uid);
+        window.Dispose();
+    }
+
+    private void OnStorageUpdate(EntityUid uid, StorageComponent component)
+    {
+        if (EntityManager.TryGetComponent<UserInterfaceComponent>(uid, out var uiComp) &&
+            uiComp.OpenInterfaces.TryGetValue(StorageComponent.StorageUiKey.Key, out var bui))
+        {
+            var storageBui = (StorageBoundUserInterface) bui;
+
+            storageBui.BuildEntityList(uid, component);
+        }
+    }
+
+    public void OnSystemLoaded(StorageSystem system)
+    {
+        system.StorageUpdated += OnStorageUpdate;
+    }
+
+    public void OnSystemUnloaded(StorageSystem system)
+    {
+        system.StorageUpdated -= OnStorageUpdate;
+    }
+}
index 9ea60aa03ce9e49b6e19946d6157bec7babfc57a..62c0615a4bece6284715c6144e5807d3a425ac91 100644 (file)
@@ -8,7 +8,9 @@ using Content.Client.UserInterface.Controls;
 using Content.Shared.IdentityManagement;
 using Content.Shared.Item;
 using Content.Shared.Stacks;
+using Content.Shared.Storage;
 using Robust.Client.UserInterface;
+using Robust.Shared.Containers;
 using static Robust.Client.UserInterface.Controls.BoxContainer;
 using static Content.Shared.Storage.SharedStorageComponent;
 using Direction = Robust.Shared.Maths.Direction;
@@ -18,9 +20,9 @@ namespace Content.Client.Storage.UI
     /// <summary>
     /// GUI class for client storage component
     /// </summary>
-    public sealed class StorageWindow : DefaultWindow
+    public sealed class StorageWindow : FancyWindow
     {
-        private IEntityManager _entityManager;
+        private readonly IEntityManager _entityManager;
 
         private readonly Label _information;
         public readonly ContainerButton StorageContainerButton;
@@ -41,7 +43,7 @@ namespace Content.Client.Storage.UI
                 MouseFilter = MouseFilterMode.Pass,
             };
 
-            Contents.AddChild(StorageContainerButton);
+            ContentsContainer.AddChild(StorageContainerButton);
 
             var innerContainerButton = new PanelContainer
             {
@@ -54,6 +56,7 @@ namespace Content.Client.Storage.UI
             {
                 Orientation = LayoutOrientation.Vertical,
                 MouseFilter = MouseFilterMode.Ignore,
+                Margin = new Thickness(5),
             };
 
             StorageContainerButton.AddChild(vBox);
@@ -87,20 +90,27 @@ namespace Content.Client.Storage.UI
         /// <summary>
         /// Loops through stored entities creating buttons for each, updates information labels
         /// </summary>
-        public void BuildEntityList(StorageBoundUserInterfaceState state)
+        public void BuildEntityList(EntityUid entity, StorageComponent component)
         {
-            var list = state.StoredEntities.ConvertAll(nent => new EntityListData(_entityManager.GetEntity(nent)));
+            var storedCount = component.Container.ContainedEntities.Count;
+            var list = new List<EntityListData>(storedCount);
+
+            foreach (var uid in component.Container.ContainedEntities)
+            {
+                list.Add(new EntityListData(uid));
+            }
+
             EntityList.PopulateList(list);
 
-            //Sets information about entire storage container current capacity
-            if (state.StorageCapacityMax != 0)
+            // Sets information about entire storage container current capacity
+            if (component.StorageCapacityMax != 0)
             {
-                _information.Text = Loc.GetString("comp-storage-window-volume", ("itemCount", state.StoredEntities.Count),
-                    ("usedVolume", state.StorageSizeUsed), ("maxVolume", state.StorageCapacityMax));
+                _information.Text = Loc.GetString("comp-storage-window-volume", ("itemCount", storedCount),
+                    ("usedVolume", component.StorageUsed), ("maxVolume", component.StorageCapacityMax));
             }
             else
             {
-                _information.Text = Loc.GetString("comp-storage-window-volume-unlimited", ("itemCount", state.StoredEntities.Count));
+                _information.Text = Loc.GetString("comp-storage-window-volume-unlimited", ("itemCount", storedCount));
             }
         }
 
index 9aefde6211d20b022c05dbf8bfea8df10e36ab0e..c5083d2204670c7c477105a4f8f98280aea09ad8 100644 (file)
@@ -5,7 +5,6 @@ using Content.Shared.Hands;
 using Content.Shared.Inventory.Events;
 using Content.Shared.Strip;
 using Content.Shared.Strip.Components;
-using Robust.Client.GameObjects;
 
 namespace Content.Client.Strip;
 
@@ -33,7 +32,7 @@ public sealed class StrippableSystem : SharedStrippableSystem
 
     public void UpdateUi(EntityUid uid, StrippableComponent? component = null, EntityEventArgs? args = null)
     {
-        if (!TryComp(uid, out ClientUserInterfaceComponent? uiComp))
+        if (!TryComp(uid, out UserInterfaceComponent? uiComp))
             return;
 
         foreach (var ui in uiComp.OpenInterfaces.Values)
index 7b71cc28df389c4c6e86b42522f2b67d32ce87b6..59beaa5a0294ccb1576ab753845347fb427c7744 100644 (file)
@@ -1,12 +1,12 @@
 using Content.Client.Gameplay;
 using Content.Client.Hands.Systems;
 using Content.Client.Inventory;
-using Content.Client.Storage;
 using Content.Client.UserInterface.Controls;
 using Content.Client.UserInterface.Systems.Inventory.Controls;
 using Content.Client.UserInterface.Systems.Inventory.Windows;
 using Content.Shared.Hands.Components;
 using Content.Shared.Input;
+using Content.Shared.Storage;
 using Robust.Client.GameObjects;
 using Robust.Client.UserInterface;
 using Robust.Client.UserInterface.Controllers;
@@ -126,7 +126,7 @@ public sealed class InventoryUIController : UIController, IOnStateEntered<Gamepl
                 container.AddButton(button);
             }
 
-            var showStorage = _entities.HasComponent<ClientStorageComponent>(data.HeldEntity);
+            var showStorage = _entities.HasComponent<StorageComponent>(data.HeldEntity);
             var update = new SlotSpriteUpdate(data.HeldEntity, data.SlotGroup, data.SlotName, showStorage);
             SpriteUpdated(update);
         }
@@ -151,7 +151,7 @@ public sealed class InventoryUIController : UIController, IOnStateEntered<Gamepl
                 _strippingWindow!.InventoryButtons.AddButton(button, data.ButtonOffset);
             }
 
-            var showStorage = _entities.HasComponent<ClientStorageComponent>(data.HeldEntity);
+            var showStorage = _entities.HasComponent<StorageComponent>(data.HeldEntity);
             var update = new SlotSpriteUpdate(data.HeldEntity, data.SlotGroup, data.SlotName, showStorage);
             SpriteUpdated(update);
         }
index 530970407caf6183c3ff3b9d05351f073b07e508..1442c0b6702fcf2fdb7c3e15a314f62b62a4db19 100644 (file)
@@ -18,7 +18,6 @@ using Content.Shared.Construction.Prototypes;
 using Content.Shared.DoAfter;
 using Content.Shared.Gravity;
 using Content.Shared.Item;
-using Robust.Client.GameObjects;
 using Robust.Client.UserInterface;
 using Robust.Client.UserInterface.CustomControls;
 using Robust.Shared.GameObjects;
@@ -785,9 +784,7 @@ public abstract partial class InteractionTest
             return false;
         }
 
-        var clientTarget = CEntMan.GetEntity(target);
-
-        if (!CEntMan.TryGetComponent<ClientUserInterfaceComponent>(clientTarget, out var ui))
+        if (!CEntMan.TryGetComponent<UserInterfaceComponent>(CEntMan.GetEntity(target), out var ui))
         {
             if (shouldSucceed)
                 Assert.Fail($"Entity {SEntMan.ToPrettyString(SEntMan.GetEntity(target.Value))} does not have a bui component");
index 7f8d569d5a0296db558cc8cadb78be160d21b277..ea7f3f5866d25474c6ee3ed6abdd103ee85489b4 100644 (file)
@@ -4,6 +4,7 @@ using System.Linq;
 using Content.Server.Storage.Components;
 using Content.Shared.Item;
 using Content.Shared.Storage;
+using Content.Shared.Storage.Components;
 using Robust.Shared.GameObjects;
 using Robust.Shared.Prototypes;
 using Robust.UnitTesting;
@@ -29,7 +30,7 @@ namespace Content.IntegrationTests.Tests
             {
                 foreach (var proto in protoManager.EnumeratePrototypes<EntityPrototype>())
                 {
-                    if (!proto.TryGetComponent<ServerStorageComponent>("Storage", out var storage) ||
+                    if (!proto.TryGetComponent<StorageComponent>("Storage", out var storage) ||
                         storage.Whitelist != null ||
                         !proto.TryGetComponent<ItemComponent>("Item", out var item)) continue;
 
@@ -84,7 +85,7 @@ namespace Content.IntegrationTests.Tests
                     int capacity;
                     var isEntStorage = false;
 
-                    if (proto.TryGetComponent<ServerStorageComponent>("Storage", out var storage))
+                    if (proto.TryGetComponent<StorageComponent>("Storage", out var storage))
                     {
                         capacity = storage.StorageCapacityMax;
                     }
index e73ffb88cf5929aeedbc63882e2c81179f3fdb3d..7e1de7d0c888afefafac5e03c70fb5d0baf55092 100644 (file)
@@ -12,6 +12,7 @@ using Content.Shared.VendingMachines;
 using Content.Shared.Wires;
 using Content.Server.Wires;
 using Content.Shared.Prototypes;
+using Content.Shared.Storage.Components;
 
 namespace Content.IntegrationTests.Tests
 {
index 06390a42458730338f111ee5c8c44875d74f4bfe..dac29accc968c7d3915ee6428242c43f9f929607 100644 (file)
@@ -30,7 +30,7 @@ public sealed class BlockGameArcadeSystem : EntitySystem
         }
     }
 
-    private void UpdatePlayerStatus(EntityUid uid, IPlayerSession session, BoundUserInterface? bui = null, BlockGameArcadeComponent? blockGame = null)
+    private void UpdatePlayerStatus(EntityUid uid, IPlayerSession session, PlayerBoundUserInterface? bui = null, BlockGameArcadeComponent? blockGame = null)
     {
         if (!Resolve(uid, ref blockGame))
             return;
index 3468310855d75ecf607b62b3ae8601ec3854edf3..7f5f58fe4b78d43b2c4c283caf46090087d59adf 100644 (file)
@@ -150,7 +150,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
             DirtyUI(uid, thermoMachine);
         }
 
-        private void DirtyUI(EntityUid uid, GasThermoMachineComponent? thermoMachine, ServerUserInterfaceComponent? ui=null)
+        private void DirtyUI(EntityUid uid, GasThermoMachineComponent? thermoMachine, UserInterfaceComponent? ui=null)
         {
             if (!Resolve(uid, ref thermoMachine, ref ui, false))
                 return;
index 30c666cdd085747326d21fed76c1557226f08c99..be8f54dfeef5162ac8bb90c31c6c5f9fcadc1fb7 100644 (file)
@@ -9,7 +9,6 @@ using Content.Shared.Cargo.Prototypes;
 using Content.Shared.Database;
 using JetBrains.Annotations;
 using Robust.Server.Containers;
-using Robust.Server.GameObjects;
 using Robust.Shared.Collections;
 using Robust.Shared.Containers;
 using Robust.Shared.Random;
@@ -314,7 +313,7 @@ public sealed partial class CargoSystem
 
     public void UpdateBountyConsoles()
     {
-        var query = EntityQueryEnumerator<CargoBountyConsoleComponent, ServerUserInterfaceComponent>();
+        var query = EntityQueryEnumerator<CargoBountyConsoleComponent, UserInterfaceComponent>();
         while (query.MoveNext(out var uid, out _, out var ui))
         {
             if (_station.GetOwningStation(uid) is not { } station ||
index 3e5250d8bd88bcce89637fac7fc2064909722dc5..5e1baa71bbab8d6b935fdc70fb6f70f8628cf1d6 100644 (file)
@@ -3,7 +3,6 @@ using System.Linq;
 using Content.Server.Chemistry.Components;
 using Content.Server.Labels;
 using Content.Server.Popups;
-using Content.Server.Storage.Components;
 using Content.Server.Storage.EntitySystems;
 using Content.Shared.Administration.Logs;
 using Content.Shared.Chemistry;
@@ -12,6 +11,7 @@ using Content.Shared.Chemistry.Reagent;
 using Content.Shared.Containers.ItemSlots;
 using Content.Shared.Database;
 using Content.Shared.FixedPoint;
+using Content.Shared.Storage;
 using JetBrains.Annotations;
 using Robust.Server.GameObjects;
 using Robust.Shared.Audio;
@@ -174,8 +174,8 @@ namespace Content.Server.Chemistry.EntitySystems
             var user = message.Session.AttachedEntity;
             var maybeContainer = _itemSlotsSystem.GetItemOrNull(chemMaster.Owner, SharedChemMaster.OutputSlotName);
             if (maybeContainer is not { Valid: true } container
-                || !TryComp(container, out ServerStorageComponent? storage)
-                || storage.Storage is null)
+                || !TryComp(container, out StorageComponent? storage)
+                || storage.Container is null)
             {
                 return; // output can't fit pills
             }
@@ -201,7 +201,7 @@ namespace Content.Server.Chemistry.EntitySystems
             for (var i = 0; i < message.Number; i++)
             {
                 var item = Spawn(PillPrototypeId, Transform(container).Coordinates);
-                _storageSystem.Insert(container, item, storage);
+                _storageSystem.Insert(container, item, user, storage);
                 _labelSystem.Label(item, message.Label);
 
                 var itemSolution = _solutionContainerSystem.EnsureSolution(item, SharedChemMaster.PillSolutionName);
@@ -340,10 +340,10 @@ namespace Content.Server.Chemistry.EntitySystems
                 }
             }
 
-            if (!TryComp(container, out ServerStorageComponent? storage))
+            if (!TryComp(container, out StorageComponent? storage))
                 return null;
 
-            var pills = storage.Storage?.ContainedEntities.Select((Func<EntityUid, (string, FixedPoint2 quantity)>) (pill =>
+            var pills = storage.Container?.ContainedEntities.Select((Func<EntityUid, (string, FixedPoint2 quantity)>) (pill =>
             {
                 _solutionContainerSystem.TryGetSolution(pill, SharedChemMaster.PillSolutionName, out var solution);
                 var quantity = solution?.Volume ?? FixedPoint2.Zero;
index 634a87d62791172def9553773e75715d236531d8..e7b5f20cf39258ecb30fb0f35a0e51f636d32024 100644 (file)
@@ -57,6 +57,6 @@ namespace Content.Server.Communications
         [DataField("sound")]
         public SoundSpecifier AnnouncementSound = new SoundPathSpecifier("/Audio/Announcements/announce.ogg");
 
-        public BoundUserInterface? UserInterface => Owner.GetUIOrNull(CommunicationsConsoleUiKey.Key);
+        public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(CommunicationsConsoleUiKey.Key);
     }
 }
index 5c2aecb548aa834747e7e95e5cf1d0663c492b7d..e74edb5da2406d461864b5bbed1a30ab8beb077b 100644 (file)
@@ -2,7 +2,6 @@ using System.IO;
 using System.Linq;
 using System.Threading.Tasks;
 using Content.Server.Construction.Components;
-using Content.Server.Storage.Components;
 using Content.Server.Storage.EntitySystems;
 using Content.Shared.ActionBlocker;
 using Content.Shared.Construction;
@@ -30,7 +29,6 @@ namespace Content.Server.Construction
         [Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
         [Dependency] private readonly SharedHandsSystem _handsSystem = default!;
         [Dependency] private readonly EntityLookupSystem _lookupSystem = default!;
-        [Dependency] private readonly StorageSystem _storageSystem = default!;
 
         // --- WARNING! LEGACY CODE AHEAD! ---
         // This entire file contains the legacy code for initial construction.
@@ -51,9 +49,9 @@ namespace Content.Server.Construction
         {
             foreach (var item in _handsSystem.EnumerateHeld(user))
             {
-                if (TryComp(item, out ServerStorageComponent? storage))
+                if (TryComp(item, out StorageComponent? storage))
                 {
-                    foreach (var storedEntity in storage.StoredEntities!)
+                    foreach (var storedEntity in storage.Container.ContainedEntities!)
                     {
                         yield return storedEntity;
                     }
@@ -66,10 +64,12 @@ namespace Content.Server.Construction
             {
                 while (containerSlotEnumerator.MoveNext(out var containerSlot))
                 {
-                    if(!containerSlot.ContainedEntity.HasValue) continue;
-                    if (EntityManager.TryGetComponent(containerSlot.ContainedEntity.Value, out ServerStorageComponent? storage))
+                    if(!containerSlot.ContainedEntity.HasValue)
+                        continue;
+
+                    if (EntityManager.TryGetComponent(containerSlot.ContainedEntity.Value, out StorageComponent? storage))
                     {
-                        foreach (var storedEntity in storage.StoredEntities!)
+                        foreach (var storedEntity in storage.Container.ContainedEntities)
                         {
                             yield return storedEntity;
                         }
@@ -207,12 +207,9 @@ namespace Content.Server.Construction
                                 continue;
 
                             // Dump out any stored entities in used entity
-                            if (TryComp<ServerStorageComponent>(entity, out var storage) && storage.StoredEntities != null)
+                            if (TryComp<StorageComponent>(entity, out var storage))
                             {
-                                foreach (var storedEntity in storage.StoredEntities.ToList())
-                                {
-                                    _storageSystem.RemoveAndDrop(entity, storedEntity, storage);
-                                }
+                                _container.EmptyContainer(storage.Container);
                             }
 
                             if (string.IsNullOrEmpty(arbitraryStep.Store))
index a4030a70d4cb84dec268487b720b8659fd6a4e99..3f732019651ace4bef49009a6900f46eb3a689dd 100644 (file)
@@ -1,12 +1,12 @@
 using System.Linq;
 using Content.Server.Construction.Components;
-using Content.Server.Storage.Components;
 using Content.Server.Storage.EntitySystems;
 using Content.Shared.DoAfter;
 using Content.Shared.Construction.Components;
 using Content.Shared.Exchanger;
 using Content.Shared.Interaction;
 using Content.Shared.Popups;
+using Content.Shared.Storage;
 using Robust.Shared.Containers;
 using Robust.Shared.Utility;
 using Content.Shared.Wires;
@@ -41,13 +41,13 @@ public sealed class PartExchangerSystem : EntitySystem
         if (args.Handled || args.Args.Target == null)
             return;
 
-        if (!TryComp<ServerStorageComponent>(uid, out var storage) || storage.Storage == null)
+        if (!TryComp<StorageComponent>(uid, out var storage) || storage.Container == null)
             return; //the parts are stored in here
 
         var machinePartQuery = GetEntityQuery<MachinePartComponent>();
         var machineParts = new List<(EntityUid, MachinePartComponent)>();
 
-        foreach (var item in storage.Storage.ContainedEntities) //get parts in RPED
+        foreach (var item in storage.Container.ContainedEntities) //get parts in RPED
         {
             if (machinePartQuery.TryGetComponent(item, out var part))
                 machineParts.Add((item, part));
@@ -96,7 +96,7 @@ public sealed class PartExchangerSystem : EntitySystem
         //put the unused parts back into rped. (this also does the "swapping")
         foreach (var (unused, _) in machineParts)
         {
-            _storage.Insert(storageUid, unused, null, false);
+            _storage.Insert(storageUid, unused, playSound: false);
         }
         _construction.RefreshParts(uid, machine);
     }
@@ -146,7 +146,7 @@ public sealed class PartExchangerSystem : EntitySystem
         //put the unused parts back into rped. (this also does the "swapping")
         foreach (var (unused, _) in machineParts)
         {
-            _storage.Insert(storageEnt, unused, null, false);
+            _storage.Insert(storageEnt, unused, playSound: false);
         }
     }
 
index c1747fc8f1acf99c0eaadd760469e30c6461117c..6f2cd6d397e40298b9e13a7b61c7e3259dc0a215 100644 (file)
@@ -25,6 +25,6 @@ namespace Content.Server.Crayon
         [DataField("deleteEmpty")]
         public bool DeleteEmpty = true;
 
-        [ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(CrayonUiKey.Key);
+        [ViewVariables] public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(CrayonUiKey.Key);
     }
 }
index cbecba701c691cbce1d7c1c80a23f5218db73c46..7bed97db12351d41a6114893c80a69454a0371eb 100644 (file)
@@ -44,7 +44,7 @@ public sealed class ActivatableUIRequiresVisionSystem : EntitySystem
         if (uiList == null)
             return;
 
-        Queue<BoundUserInterface> closeList = new(); // foreach collection modified moment
+        Queue<PlayerBoundUserInterface> closeList = new(); // foreach collection modified moment
 
         foreach (var ui in uiList)
         {
index b746eea6ec0a2f9ce5e37d4f9ca3d93fd23ca068..5a9afe0144426669d48e780b3878b848c93f0dec 100644 (file)
@@ -1,8 +1,8 @@
+using System.Linq;
 using System.Numerics;
 using Content.Server.Popups;
 using Content.Server.Pulling;
 using Content.Server.Stack;
-using Content.Server.Storage.Components;
 using Content.Server.Storage.EntitySystems;
 using Content.Server.Stunnable;
 using Content.Shared.ActionBlocker;
@@ -16,6 +16,7 @@ using Content.Shared.Inventory;
 using Content.Shared.Physics.Pull;
 using Content.Shared.Pulling.Components;
 using Content.Shared.Stacks;
+using Content.Shared.Storage;
 using Content.Shared.Throwing;
 using JetBrains.Annotations;
 using Robust.Server.Player;
@@ -30,8 +31,7 @@ using Robust.Shared.Utility;
 
 namespace Content.Server.Hands.Systems
 {
-    [UsedImplicitly]
-    internal sealed class HandsSystem : SharedHandsSystem
+    public sealed class HandsSystem : SharedHandsSystem
     {
         [Dependency] private readonly InventorySystem _inventorySystem = default!;
         [Dependency] private readonly StackSystem _stackSystem = default!;
@@ -252,7 +252,7 @@ namespace Content.Server.Hands.Systems
                 return;
 
             if (!_inventorySystem.TryGetSlotEntity(plyEnt, equipmentSlot, out var slotEntity) ||
-                !TryComp(slotEntity, out ServerStorageComponent? storageComponent))
+                !TryComp(slotEntity, out StorageComponent? storageComponent))
             {
                 if (_inventorySystem.HasSlot(plyEnt, equipmentSlot))
                 {
@@ -287,16 +287,17 @@ namespace Content.Server.Hands.Systems
             {
                 _storageSystem.PlayerInsertHeldEntity(slotEntity.Value, plyEnt, storageComponent);
             }
-            else if (storageComponent.StoredEntities != null)
+            else
             {
-                if (storageComponent.StoredEntities.Count == 0)
+                if (!storageComponent.Container.ContainedEntities.Any())
                 {
                     _popupSystem.PopupEntity(Loc.GetString("hands-system-empty-equipment-slot", ("slotName", equipmentSlot)), plyEnt,  session);
                 }
                 else
                 {
-                    var lastStoredEntity = storageComponent.StoredEntities[^1];
-                    if (storageComponent.Remove(lastStoredEntity))
+                    var lastStoredEntity = storageComponent.Container.ContainedEntities[^1];
+
+                    if (storageComponent.Container.Remove(lastStoredEntity))
                     {
                         PickupOrDrop(plyEnt, lastStoredEntity, animateUser: true, handsComp: hands);
                     }
index e13302557684228cb63fed14f80e4af70d66bf79..51de0ed35bb1c4d4857970a38ef85a11ea5f5e9f 100644 (file)
@@ -21,7 +21,7 @@ public sealed partial class InstrumentComponent : SharedInstrumentComponent
         _entMan.GetComponentOrNull<ActivatableUIComponent>(Owner)?.CurrentSingleUser
         ?? _entMan.GetComponentOrNull<ActorComponent>(Owner)?.PlayerSession;
 
-    [ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(InstrumentUiKey.Key);
+    [ViewVariables] public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(InstrumentUiKey.Key);
 }
 
 [RegisterComponent]
index 30eeb6e9462dd925a30777b39b4f1bc1ff6ba1a9..c39c086960dfe5cae0f602b6d067722fc98d6c07 100644 (file)
@@ -2,7 +2,6 @@
 
 using Content.Server.Administration.Logs;
 using Content.Server.Pulling;
-using Content.Server.Storage.Components;
 using Content.Shared.ActionBlocker;
 using Content.Shared.DragDrop;
 using Content.Shared.Input;
@@ -46,17 +45,17 @@ namespace Content.Server.Interaction
             if (!_container.TryGetContainingContainer(target, out var container))
                 return false;
 
-            if (!TryComp(container.Owner, out ServerStorageComponent? storage))
+            if (!TryComp(container.Owner, out StorageComponent? storage))
                 return false;
 
-            if (storage.Storage?.ID != container.ID)
+            if (storage.Container?.ID != container.ID)
                 return false;
 
             if (!TryComp(user, out ActorComponent? actor))
                 return false;
 
             // we don't check if the user can access the storage entity itself. This should be handed by the UI system.
-            return _uiSystem.SessionHasOpenUi(container.Owner, SharedStorageComponent.StorageUiKey.Key, actor.PlayerSession);
+            return _uiSystem.SessionHasOpenUi(container.Owner, StorageComponent.StorageUiKey.Key, actor.PlayerSession);
         }
 
         #region Drag drop
index a1cb007d91faf269bc26734c7d315da9e3572867..f80a604ad5da58eb564f791a8f59ae33d91ff3eb 100644 (file)
@@ -1,9 +1,9 @@
-using Content.Server.Storage.Components;
 using Content.Server.Storage.EntitySystems;
 using Content.Shared.Clothing.Components;
 using Content.Shared.Interaction.Events;
 using Content.Shared.Inventory;
 using Content.Shared.Inventory.Events;
+using Content.Shared.Storage;
 
 namespace Content.Server.Inventory
 {
@@ -33,7 +33,7 @@ namespace Content.Server.Inventory
             if (args.SenderSession.AttachedEntity is not { Valid: true } uid)
                     return;
 
-            if (TryGetSlotEntity(uid, ev.Slot, out var entityUid) && TryComp<ServerStorageComponent>(entityUid, out var storageComponent))
+            if (TryGetSlotEntity(uid, ev.Slot, out var entityUid) && TryComp<StorageComponent>(entityUid, out var storageComponent))
             {
                 _storageSystem.OpenStorageUI(entityUid.Value, uid, storageComponent);
             }
index 33c95d3780110fe9ced9fdc25104b3d264e61fed..55fb5aae0913043bc988ae85f0da171da6b73a31 100644 (file)
@@ -1,7 +1,7 @@
-using Content.Server.Storage.Components;
-using Content.Server.Storage.EntitySystems;
+using Content.Server.Storage.EntitySystems;
 using Content.Shared.Item;
 using Content.Shared.Stacks;
+using Content.Shared.Storage;
 
 namespace Content.Server.Item;
 
@@ -14,9 +14,12 @@ public sealed class ItemSystem : SharedItemSystem
         base.OnStackCountChanged(uid, component, args);
 
         if (!Container.TryGetContainingContainer(uid, out var container) ||
-            !TryComp<ServerStorageComponent>(container.Owner, out var storage))
+            !TryComp<StorageComponent>(container.Owner, out var storage))
+        {
             return;
+        }
+
         _storage.RecalculateStorageUsed(storage);
-        _storage.UpdateStorageUI(container.Owner, storage);
+        _storage.UpdateUI(container.Owner, storage);
     }
 }
index e6297eebc546d583a606f3c073e330281cc2512d..d37080a1e10e0db1b418061a0e5dcfb5da4baf55 100644 (file)
@@ -1,6 +1,5 @@
 using System.Linq;
 using Content.Server.Light.Components;
-using Content.Server.Storage.Components;
 using Content.Shared.Examine;
 using Content.Shared.Interaction;
 using Content.Shared.Light.Components;
@@ -101,7 +100,7 @@ public sealed class LightReplacerSystem : EntitySystem
         if (TryComp<LightBulbComponent>(usedUid, out var bulb))
             eventArgs.Handled = TryInsertBulb(uid, usedUid, eventArgs.User, true, component, bulb);
         // add bulbs from storage?
-        else if (TryComp<ServerStorageComponent>(usedUid, out var storage))
+        else if (TryComp<StorageComponent>(usedUid, out var storage))
             eventArgs.Handled = TryInsertBulbsFromStorage(uid, usedUid, eventArgs.User, component, storage);
     }
 
@@ -205,23 +204,23 @@ public sealed class LightReplacerSystem : EntitySystem
     ///     which was successfully inserted inside light replacer
     /// </returns>
     public bool TryInsertBulbsFromStorage(EntityUid replacerUid, EntityUid storageUid, EntityUid? userUid = null,
-        LightReplacerComponent? replacer = null, ServerStorageComponent? storage = null)
+        LightReplacerComponent? replacer = null, StorageComponent? storage = null)
     {
         if (!Resolve(replacerUid, ref replacer))
             return false;
         if (!Resolve(storageUid, ref storage))
             return false;
 
-        if (storage.StoredEntities == null)
-            return false;
-
         var insertedBulbs = 0;
-        var storagedEnts = storage.StoredEntities.ToArray();
+        var storagedEnts = storage.Container.ContainedEntities.ToArray();
+
         foreach (var ent in storagedEnts)
         {
             if (TryComp<LightBulbComponent>(ent, out var bulb) &&
                 TryInsertBulb(replacerUid, ent, userUid, false, replacer, bulb))
+            {
                 insertedBulbs++;
+            }
         }
 
         // show some message if success
index 1148c3afffcf8b1b456e9c581e1dc204764ee6cc..4b0bb5ff1fb7e20a787a16b609ff175b0a0895dd 100644 (file)
@@ -17,7 +17,7 @@ namespace Content.Server.Medical.Components
         [DataField("scanDelay")]
         public float ScanDelay = 0.8f;
 
-        public BoundUserInterface? UserInterface => Owner.GetUIOrNull(HealthAnalyzerUiKey.Key);
+        public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(HealthAnalyzerUiKey.Key);
 
         /// <summary>
         ///     Sound played on scanning begin
index 67e19ae17d604a01b31cf3feff5c4fa6f0f87103..125edd2c4c777918a5cfff28d7c30ed855c6891d 100644 (file)
@@ -28,7 +28,7 @@ using Robust.Shared.Audio;
 using Robust.Shared.Player;
 using Robust.Shared.Utility;
 using Content.Shared.Tag;
-using Content.Server.Storage.Components;
+using Content.Shared.Storage;
 
 namespace Content.Server.Nutrition.EntitySystems
 {
@@ -120,7 +120,7 @@ namespace Content.Server.Nutrition.EntitySystems
             }
 
             // Check for used storage on the food item
-            if (TryComp<ServerStorageComponent>(food, out var storageState) && storageState.StorageUsed != 0)
+            if (TryComp<StorageComponent>(food, out var storageState) && storageState.StorageUsed != 0)
             {
                 _popupSystem.PopupEntity(Loc.GetString("food-has-used-storage", ("food", food)), user, user);
                 return (false, true);
index ae0fc1e1dc530678fa1265f0f2d9b91ca8f60f5c..6c506dc3dd2990f3bc3ce0756d144d3ab943bc33 100644 (file)
@@ -53,7 +53,7 @@ namespace Content.Server.PDA
         {
             base.OnComponentInit(uid, pda, args);
 
-            if (!HasComp<ServerUserInterfaceComponent>(uid))
+            if (!HasComp<UserInterfaceComponent>(uid))
                 return;
 
             UpdateAlertLevel(uid, pda);
index 5356318aaa3fc84c505b99e9ee187038112b07bf..8d9a62cd73d822532d6ff6120dd5c6d4d944c15b 100644 (file)
@@ -40,13 +40,13 @@ public sealed class ApcSystem : EntitySystem
 
     public override void Update(float deltaTime)
     {
-        var query = EntityQueryEnumerator<ApcComponent, PowerNetworkBatteryComponent, ServerUserInterfaceComponent>();
+        var query = EntityQueryEnumerator<ApcComponent, PowerNetworkBatteryComponent, UserInterfaceComponent>();
         while (query.MoveNext(out var uid, out var apc, out var battery, out var ui))
         {
             if (apc.LastUiUpdate + ApcComponent.VisualsChangeDelay < _gameTiming.CurTime)
             {
                 apc.LastUiUpdate = _gameTiming.CurTime;
-                UpdateUIState(uid, apc, battery, ui);
+                UpdateUIState(uid, apc, battery);
             }
         }
     }
@@ -146,7 +146,7 @@ public sealed class ApcSystem : EntitySystem
     public void UpdateUIState(EntityUid uid,
         ApcComponent? apc = null,
         PowerNetworkBatteryComponent? netBat = null,
-        ServerUserInterfaceComponent? ui = null)
+        UserInterfaceComponent? ui = null)
     {
         if (!Resolve(uid, ref apc, ref netBat, ref ui))
             return;
index 64f3baf9c7c233d86deaa19734ab8cecd8e80d20..eb7c4c847866eeebe2ce83e0cfebc0620318b58d 100644 (file)
@@ -60,7 +60,7 @@ public sealed class EscapeInventorySystem : EntitySystem
         }
 
         // Uncontested
-        if (HasComp<SharedStorageComponent>(container.Owner) || HasComp<InventoryComponent>(container.Owner) || HasComp<SecretStashComponent>(container.Owner))
+        if (HasComp<StorageComponent>(container.Owner) || HasComp<InventoryComponent>(container.Owner) || HasComp<SecretStashComponent>(container.Owner))
             AttemptEscape(uid, container.Owner, component);
     }
 
index 324bdf9e01b8ec5ec693c14b9174f750fe6ac3a4..c814e9c36b7c1c1b31c7359f30d078f4b2032451 100644 (file)
@@ -1,6 +1,5 @@
 using Content.Shared.Salvage;
 using Content.Shared.Salvage.Expeditions;
-using Robust.Server.GameObjects;
 
 namespace Content.Server.Salvage;
 
@@ -38,7 +37,7 @@ public sealed partial class SalvageSystem
     {
         var state = GetState(component);
 
-        foreach (var (console, xform, uiComp) in EntityQuery<SalvageExpeditionConsoleComponent, TransformComponent, ServerUserInterfaceComponent>(true))
+        foreach (var (console, xform, uiComp) in EntityQuery<SalvageExpeditionConsoleComponent, TransformComponent, UserInterfaceComponent>(true))
         {
             var station = _station.GetOwningStation(console.Owner, xform);
 
index 64430042d6aef968cf38659d988485070e11dd6e..cd4f2ea23b9dbfd07e368c49ba33cc3197857acc 100644 (file)
@@ -1,6 +1,7 @@
 using Content.Shared.SensorMonitoring;
 using Robust.Server.Player;
 using Robust.Shared.Collections;
+using Robust.Shared.Players;
 
 namespace Content.Server.SensorMonitoring;
 
@@ -26,7 +27,7 @@ public sealed partial class SensorMonitoringConsoleComponent : Component
     public TimeSpan RetentionTime = TimeSpan.FromMinutes(1);
 
     // UI update tracking stuff.
-    public HashSet<IPlayerSession> InitialUIStateSent = new();
+    public HashSet<ICommonSession> InitialUIStateSent = new();
     public TimeSpan LastUIUpdate;
     public ValueList<int> RemovedSensors;
 
index d79f993d87f04b7b175c216b8c0e28da0735e06d..179cadcfbcbc3294a577ccb0a900cc4c39ab0a65 100644 (file)
@@ -34,7 +34,7 @@ namespace Content.Server.Solar.EntitySystems
             {
                 _updateTimer -= 1;
                 var state = new SolarControlConsoleBoundInterfaceState(_powerSolarSystem.TargetPanelRotation, _powerSolarSystem.TargetPanelVelocity, _powerSolarSystem.TotalPanelPower, _powerSolarSystem.TowardsSun);
-                var query = EntityQueryEnumerator<SolarControlConsoleComponent, ServerUserInterfaceComponent>();
+                var query = EntityQueryEnumerator<SolarControlConsoleComponent, UserInterfaceComponent>();
                 while (query.MoveNext(out var uid, out var _, out var uiComp))
                 {
                     _uiSystem.TrySetUiState(uid, SolarControlConsoleUiKey.Key, state, ui: uiComp);
index 12bd2a1bd32bc4f4b6650f5420d556565b84d504..4fc50ce595d4d078f7f4276fc8dfee11a17e1467 100644 (file)
@@ -1,7 +1,7 @@
-using Content.Server.Storage.Components;
 using Content.Server.Storage.EntitySystems;
 using Content.Shared.Popups;
 using Content.Shared.Stacks;
+using Content.Shared.Storage;
 using Content.Shared.Verbs;
 using JetBrains.Annotations;
 using Robust.Server.Containers;
@@ -163,9 +163,9 @@ namespace Content.Server.Stack
                 return;
 
             if (_container.TryGetContainingContainer(uid, out var container) &&
-                TryComp<ServerStorageComponent>(container.Owner, out var storage))
+                TryComp<StorageComponent>(container.Owner, out var storage))
             {
-                _storage.UpdateStorageUI(container.Owner, storage);
+                _storage.UpdateUI(container.Owner, storage);
             }
 
             Hands.PickupOrDrop(userUid, split);
diff --git a/Content.Server/Storage/Components/ServerStorageComponent.cs b/Content.Server/Storage/Components/ServerStorageComponent.cs
deleted file mode 100644 (file)
index bfea401..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-using Content.Shared.Storage;
-using Content.Shared.Whitelist;
-using Robust.Shared.Audio;
-using Robust.Shared.Containers;
-using System.Threading;
-
-namespace Content.Server.Storage.Components
-{
-    /// <summary>
-    /// Storage component for containing entities within this one, matches a UI on the client which shows stored entities
-    /// </summary>
-    [RegisterComponent]
-    [ComponentReference(typeof(SharedStorageComponent))]
-    public sealed partial class ServerStorageComponent : SharedStorageComponent
-    {
-        public string LoggerName = "Storage";
-
-        public Container? Storage;
-
-        public readonly Dictionary<EntityUid, int> SizeCache = new();
-
-        private bool _occludesLight = true;
-
-        [DataField("quickInsert")]
-        public bool QuickInsert = false; // Can insert storables by "attacking" them with the storage entity
-
-        [DataField("clickInsert")]
-        public bool ClickInsert = true; // Can insert stuff by clicking the storage entity with it
-
-        [DataField("areaInsert")]
-        public bool AreaInsert = false;  // "Attacking" with the storage entity causes it to insert all nearby storables after a delay
-
-        [DataField("areaInsertRadius")]
-        public int AreaInsertRadius = 1;
-
-        [DataField("whitelist")]
-        public EntityWhitelist? Whitelist = null;
-        [DataField("blacklist")]
-        public EntityWhitelist? Blacklist = null;
-
-        /// <summary>
-        ///     If true, storage will show popup messages to the player after failed interactions.
-        ///     Usually this is message that item doesn't fit inside container.
-        /// </summary>
-        [DataField("popup")]
-        public bool ShowPopup = true;
-
-        /// <summary>
-        /// This storage has an open UI
-        /// </summary>
-        public bool IsOpen = false;
-        public int StorageUsed;
-        [DataField("capacity")]
-        public int StorageCapacityMax = 10000;
-
-        [DataField("storageOpenSound")]
-        public SoundSpecifier? StorageOpenSound { get; set; } = new SoundCollectionSpecifier("storageRustle");
-
-        [DataField("storageInsertSound")]
-        public SoundSpecifier? StorageInsertSound { get; set; } = new SoundCollectionSpecifier("storageRustle");
-
-        [DataField("storageRemoveSound")]
-        public SoundSpecifier? StorageRemoveSound { get; set; }
-        [DataField("storageCloseSound")]
-        public SoundSpecifier? StorageCloseSound { get; set; }
-
-        [ViewVariables]
-        public override IReadOnlyList<EntityUid>? StoredEntities => Storage?.ContainedEntities;
-
-        [ViewVariables(VVAccess.ReadWrite)]
-        [DataField("occludesLight")]
-        public bool OccludesLight
-        {
-            get => _occludesLight;
-            set
-            {
-                _occludesLight = value;
-                if (Storage != null) Storage.OccludesLight = value;
-            }
-        }
-
-        // neccesary for abstraction, should be deleted on complete storage ECS
-        public override bool Remove(EntityUid entity)
-        {
-            return true;
-        }
-    }
-}
diff --git a/Content.Server/Storage/Components/StorageFillComponent.cs b/Content.Server/Storage/Components/StorageFillComponent.cs
deleted file mode 100644 (file)
index 2c8af28..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-using Content.Server.Storage.EntitySystems;
-using Content.Shared.Storage;
-
-namespace Content.Server.Storage.Components
-{
-    [RegisterComponent, Access(typeof(StorageSystem))]
-    public sealed partial class StorageFillComponent : Component
-    {
-        [DataField("contents")] public List<EntitySpawnEntry> Contents = new();
-    }
-}
index e9c42a401adf251bbc6c2e62b01f3e82aea16dff..415e8d9246711c1400c75074a99d240194a0c867 100644 (file)
@@ -1,4 +1,4 @@
-using Content.Server.Storage.Components;
+using Content.Shared.Storage;
 using Content.Shared.Storage.Components;
 using Content.Shared.Storage.EntitySystems;
 using JetBrains.Annotations;
@@ -11,16 +11,16 @@ namespace Content.Server.Storage.EntitySystems
     {
         protected override int? GetCount(ContainerModifiedMessage msg, ItemCounterComponent itemCounter)
         {
-            if (!EntityManager.TryGetComponent(msg.Container.Owner, out ServerStorageComponent? component)
-                || component.StoredEntities == null)
+            if (!EntityManager.TryGetComponent(msg.Container.Owner, out StorageComponent? component))
             {
                 return null;
             }
 
             var count = 0;
-            foreach (var entity in component.StoredEntities)
+            foreach (var entity in component.Container.ContainedEntities)
             {
-                if (itemCounter.Count.IsValid(entity)) count++;
+                if (itemCounter.Count.IsValid(entity))
+                    count++;
             }
 
             return count;
index 3b73ecb6bb4b92d40dea528b9d44def8fe0a9547..50f6db459c163f8c6588bb5eb8750b4c35316493 100644 (file)
@@ -5,6 +5,7 @@ using Content.Shared.Verbs;
 using Robust.Shared.Containers;
 using Robust.Shared.Random;
 using System.Linq;
+using Content.Shared.Storage;
 
 namespace Content.Server.Storage.EntitySystems;
 
@@ -24,21 +25,20 @@ public sealed class PickRandomSystem : EntitySystem
 
     private void OnGetAlternativeVerbs(EntityUid uid, PickRandomComponent comp, GetVerbsEvent<AlternativeVerb> args)
     {
-        if (!args.CanAccess || !args.CanInteract || !TryComp<ServerStorageComponent>(uid, out var storage))
+        if (!args.CanAccess || !args.CanInteract || !TryComp<StorageComponent>(uid, out var storage))
             return;
 
         var user = args.User;
 
-        var enabled = false;
-        if (storage.StoredEntities != null)
-            enabled = storage.StoredEntities.Any(item => comp.Whitelist?.IsValid(item, EntityManager) ?? true);
+        var enabled = storage.Container.ContainedEntities.Any(item => comp.Whitelist?.IsValid(item, EntityManager) ?? true);
 
         // alt-click / alt-z to pick an item
         args.Verbs.Add(new AlternativeVerb
         {
-            Act = (() => {
+            Act = () =>
+            {
                 TryPick(uid, comp, storage, user);
-            }),
+            },
             Impact = LogImpact.Low,
             Text = Loc.GetString(comp.VerbText),
             Disabled = !enabled,
@@ -46,16 +46,14 @@ public sealed class PickRandomSystem : EntitySystem
         });
     }
 
-    private void TryPick(EntityUid uid, PickRandomComponent comp, ServerStorageComponent storage, EntityUid user)
+    private void TryPick(EntityUid uid, PickRandomComponent comp, StorageComponent storage, EntityUid user)
     {
-        if (storage.StoredEntities == null)
-            return;
+        var entities = storage.Container.ContainedEntities.Where(item => comp.Whitelist?.IsValid(item, EntityManager) ?? true).ToArray();
 
-        var entities = storage.StoredEntities.Where(item => comp.Whitelist?.IsValid(item, EntityManager) ?? true);
         if (!entities.Any())
             return;
 
-        var picked = _random.Pick(entities.ToList());
+        var picked = _random.Pick(entities);
         // if it fails to go into a hand of the user, will be on the storage
         _container.AttachParentToContainerOrGrid(Transform(picked));
 
index 786e0bc93ca8c01948d66816a355350c0480ef61..ed48de2e4501da33b9542aba87be7ed77f0560db 100644 (file)
@@ -1,5 +1,5 @@
-using Content.Server.Storage.Components;
-using Content.Shared.Rounding;
+using Content.Shared.Rounding;
+using Content.Shared.Storage;
 using Content.Shared.Storage.Components;
 using Robust.Server.GameObjects;
 using Robust.Shared.Containers;
@@ -33,7 +33,7 @@ public sealed class StorageFillVisualizerSystem : EntitySystem
         UpdateAppearance(uid, component: component);
     }
 
-    private void UpdateAppearance(EntityUid uid, ServerStorageComponent? storage = null, AppearanceComponent? appearance = null,
+    private void UpdateAppearance(EntityUid uid, StorageComponent? storage = null, AppearanceComponent? appearance = null,
         StorageFillVisualizerComponent? component = null)
     {
         if (!Resolve(uid, ref storage, ref appearance, ref component, false))
index 9a58ff87e88d23068391b997e9e911c12168b102..77c8458b91a5c438565d25fd39eb44ffd210e244 100644 (file)
@@ -1,5 +1,6 @@
 using Content.Server.Storage.Components;
 using Content.Shared.Storage;
+using Content.Shared.Storage.Components;
 
 namespace Content.Server.Storage.EntitySystems;
 
@@ -7,32 +8,33 @@ public sealed partial class StorageSystem
 {
     private void OnStorageFillMapInit(EntityUid uid, StorageFillComponent component, MapInitEvent args)
     {
-        if (component.Contents.Count == 0) return;
+        if (component.Contents.Count == 0)
+            return;
 
-        TryComp<ServerStorageComponent>(uid, out var serverStorageComp);
+        TryComp<StorageComponent>(uid, out var storageComp);
         TryComp<EntityStorageComponent>(uid, out var entityStorageComp);
 
-        if (entityStorageComp == null && serverStorageComp == null)
+        if (entityStorageComp == null && storageComp == null)
         {
-            Logger.Error($"StorageFillComponent couldn't find any StorageComponent ({uid})");
+            Log.Error($"StorageFillComponent couldn't find any StorageComponent ({uid})");
             return;
         }
 
         var coordinates = Transform(uid).Coordinates;
 
-        var spawnItems = EntitySpawnCollection.GetSpawns(component.Contents, _random);
+        var spawnItems = EntitySpawnCollection.GetSpawns(component.Contents, Random);
         foreach (var item in spawnItems)
         {
             var ent = EntityManager.SpawnEntity(item, coordinates);
 
             // handle depending on storage component, again this should be unified after ECS
-            if (entityStorageComp != null && _entityStorage.Insert(ent, uid))
-               continue;
+            if (entityStorageComp != null && EntityStorage.Insert(ent, uid))
+                continue;
 
-            if (serverStorageComp != null && Insert(uid, ent, serverStorageComp, false))
+            if (storageComp != null && Insert(uid, ent, storageComp: storageComp, playSound: false))
                 continue;
 
-            Logger.ErrorS("storage", $"Tried to StorageFill {item} inside {ToPrettyString(uid)} but can't.");
+            Log.Error($"Tried to StorageFill {item} inside {ToPrettyString(uid)} but can't.");
             EntityManager.DeleteEntity(ent);
         }
     }
index 99ed0e17d95bf9eac60eec0592322cda84524bc5..da6a4627520696fc4366f4c465c2b32247c2155c 100644 (file)
-using System.Linq;
 using Content.Server.Administration.Managers;
-using Content.Server.Interaction;
-using Content.Server.Popups;
-using Content.Server.Stack;
-using Content.Server.Storage.Components;
-using Content.Shared.ActionBlocker;
 using Content.Shared.Administration;
-using Content.Shared.CombatMode;
-using Content.Shared.Containers.ItemSlots;
-using Content.Shared.Destructible;
-using Content.Shared.DoAfter;
 using Content.Shared.Ghost;
-using Content.Shared.Hands.Components;
-using Content.Shared.Hands.EntitySystems;
-using Content.Shared.Implants.Components;
-using Content.Shared.Interaction;
-using Content.Shared.Item;
 using Content.Shared.Lock;
-using Content.Shared.Placeable;
-using Content.Shared.Stacks;
 using Content.Shared.Storage;
 using Content.Shared.Storage.Components;
+using Content.Shared.Storage.EntitySystems;
 using Content.Shared.Timing;
 using Content.Shared.Verbs;
-using Robust.Server.Containers;
 using Robust.Server.GameObjects;
 using Robust.Server.Player;
-using Robust.Shared.Audio;
-using Robust.Shared.Containers;
-using Robust.Shared.Map;
-using Robust.Shared.Physics.Systems;
 using Robust.Shared.Player;
-using Robust.Shared.Random;
+using Robust.Shared.Players;
 using Robust.Shared.Utility;
-using static Content.Shared.Storage.SharedStorageComponent;
 
-namespace Content.Server.Storage.EntitySystems
-{
-    public sealed partial class StorageSystem : EntitySystem
-    {
-        [Dependency] private readonly IRobustRandom _random = default!;
-        [Dependency] private readonly IAdminManager _admin = default!;
-        [Dependency] private readonly ILogManager _logManager = default!;
-        [Dependency] private readonly ContainerSystem _containerSystem = default!;
-        [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
-        [Dependency] private readonly EntityLookupSystem _entityLookupSystem = default!;
-        [Dependency] private readonly EntityStorageSystem _entityStorage = default!;
-        [Dependency] private readonly InteractionSystem _interactionSystem = default!;
-        [Dependency] private readonly PopupSystem _popupSystem = default!;
-        [Dependency] private readonly SharedHandsSystem _sharedHandsSystem = default!;
-        [Dependency] private readonly SharedInteractionSystem _sharedInteractionSystem = default!;
-        [Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
-        [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
-        [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
-        [Dependency] private readonly SharedAudioSystem _audio = default!;
-        [Dependency] private readonly SharedCombatModeSystem _combatMode = default!;
-        [Dependency] private readonly SharedTransformSystem _transform = default!;
-        [Dependency] private readonly StackSystem _stack = default!;
-        [Dependency] private readonly UseDelaySystem _useDelay = default!;
-
-        /// <inheritdoc />
-        public override void Initialize()
-        {
-            base.Initialize();
-
-            SubscribeLocalEvent<ServerStorageComponent, ComponentInit>(OnComponentInit);
-            SubscribeLocalEvent<ServerStorageComponent, GetVerbsEvent<ActivationVerb>>(AddOpenUiVerb);
-            SubscribeLocalEvent<ServerStorageComponent, GetVerbsEvent<UtilityVerb>>(AddTransferVerbs);
-            SubscribeLocalEvent<ServerStorageComponent, InteractUsingEvent>(OnInteractUsing, after: new[] { typeof(ItemSlotsSystem) });
-            SubscribeLocalEvent<ServerStorageComponent, ActivateInWorldEvent>(OnActivate);
-            SubscribeLocalEvent<ServerStorageComponent, OpenStorageImplantEvent>(OnImplantActivate);
-            SubscribeLocalEvent<ServerStorageComponent, AfterInteractEvent>(AfterInteract);
-            SubscribeLocalEvent<ServerStorageComponent, DestructionEventArgs>(OnDestroy);
-            SubscribeLocalEvent<ServerStorageComponent, StorageInteractWithItemEvent>(OnInteractWithItem);
-            SubscribeLocalEvent<ServerStorageComponent, StorageInsertItemMessage>(OnInsertItemMessage);
-            SubscribeLocalEvent<ServerStorageComponent, BoundUIOpenedEvent>(OnBoundUIOpen);
-            SubscribeLocalEvent<ServerStorageComponent, BoundUIClosedEvent>(OnBoundUIClosed);
-            SubscribeLocalEvent<ServerStorageComponent, EntRemovedFromContainerMessage>(OnStorageItemRemoved);
-
-            SubscribeLocalEvent<ServerStorageComponent, AreaPickupDoAfterEvent>(OnDoAfter);
-
-            SubscribeLocalEvent<StorageFillComponent, MapInitEvent>(OnStorageFillMapInit);
-        }
-
-        private void OnComponentInit(EntityUid uid, ServerStorageComponent storageComp, ComponentInit args)
-        {
-            base.Initialize();
-
-            // ReSharper disable once StringLiteralTypo
-            storageComp.Storage = _containerSystem.EnsureContainer<Container>(uid, "storagebase");
-            storageComp.Storage.OccludesLight = storageComp.OccludesLight;
-            UpdateStorageVisualization(uid, storageComp);
-            RecalculateStorageUsed(storageComp);
-            UpdateStorageUI(uid, storageComp);
-        }
-
-        private void AddOpenUiVerb(EntityUid uid, ServerStorageComponent component, GetVerbsEvent<ActivationVerb> args)
-        {
-            var silent = false;
-            if (!args.CanAccess || !args.CanInteract || TryComp<LockComponent>(uid, out var lockComponent) && lockComponent.Locked)
-            {
-                // we allow admins to open the storage anyways
-                if (!_admin.HasAdminFlag(args.User, AdminFlags.Admin))
-                    return;
-
-                silent = true;
-            }
-
-            silent |= HasComp<GhostComponent>(args.User);
-
-            // Get the session for the user
-            if (!TryComp<ActorComponent>(args.User, out var actor))
-                return;
-
-            // Does this player currently have the storage UI open?
-            var uiOpen = _uiSystem.SessionHasOpenUi(uid, StorageUiKey.Key, actor.PlayerSession);
-
-            ActivationVerb verb = new()
-            {
-                Act = () => OpenStorageUI(uid, args.User, component, silent)
-            };
-            if (uiOpen)
-            {
-                verb.Text = Loc.GetString("verb-common-close-ui");
-                verb.Icon = new SpriteSpecifier.Texture(
-                    new("/Textures/Interface/VerbIcons/close.svg.192dpi.png"));
-            }
-            else
-            {
-                verb.Text = Loc.GetString("verb-common-open-ui");
-                verb.Icon = new SpriteSpecifier.Texture(
-                    new("/Textures/Interface/VerbIcons/open.svg.192dpi.png"));
-            }
-            args.Verbs.Add(verb);
-        }
-
-        private void AddTransferVerbs(EntityUid uid, ServerStorageComponent component, GetVerbsEvent<UtilityVerb> args)
-        {
-            if (!args.CanAccess || !args.CanInteract)
-                return;
+namespace Content.Server.Storage.EntitySystems;
 
-            var entities = component.Storage?.ContainedEntities;
-            if (entities == null || entities.Count == 0 || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked)
-                return;
+public sealed partial class StorageSystem : SharedStorageSystem
+{
+    [Dependency] private readonly IAdminManager _admin = default!;
+    [Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
 
-            // if the target is storage, add a verb to transfer storage.
-            if (TryComp(args.Target, out ServerStorageComponent? targetStorage)
-                && (!TryComp(uid, out LockComponent? targetLock) || !targetLock.Locked))
-            {
-                UtilityVerb verb = new()
-                {
-                    Text = Loc.GetString("storage-component-transfer-verb"),
-                    IconEntity = GetNetEntity(args.Using),
-                    Act = () => TransferEntities(uid, args.Target, component, lockComponent, targetStorage, targetLock)
-                };
+    public override void Initialize()
+    {
+        base.Initialize();
+        SubscribeLocalEvent<StorageComponent, GetVerbsEvent<ActivationVerb>>(AddUiVerb);
+        SubscribeLocalEvent<StorageComponent, BoundUIClosedEvent>(OnBoundUIClosed);
 
-                args.Verbs.Add(verb);
-            }
-        }
+        SubscribeLocalEvent<StorageFillComponent, MapInitEvent>(OnStorageFillMapInit);
+    }
 
-        /// <summary>
-        /// Inserts storable entities into this storage container if possible, otherwise return to the hand of the user
-        /// </summary>
-        /// <returns>true if inserted, false otherwise</returns>
-        private void OnInteractUsing(EntityUid uid, ServerStorageComponent storageComp, InteractUsingEvent args)
+    private void AddUiVerb(EntityUid uid, StorageComponent component, GetVerbsEvent<ActivationVerb> args)
+    {
+        var silent = false;
+        if (!args.CanAccess || !args.CanInteract || TryComp<LockComponent>(uid, out var lockComponent) && lockComponent.Locked)
         {
-            if (args.Handled || !storageComp.ClickInsert || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked)
-                return;
-
-            _logManager.GetSawmill(storageComp.LoggerName)
-                .Debug($"Storage (UID {uid}) attacked by user (UID {args.User}) with entity (UID {args.Used}).");
-
-            if (HasComp<PlaceableSurfaceComponent>(uid))
+            // we allow admins to open the storage anyways
+            if (!_admin.HasAdminFlag(args.User, AdminFlags.Admin))
                 return;
 
-            PlayerInsertHeldEntity(uid, args.User, storageComp);
-            // Always handle it, even if insertion fails.
-            // We don't want to trigger any AfterInteract logic here.
-            // Example bug: placing wires if item doesn't fit in backpack.
-            args.Handled = true;
+            silent = true;
         }
 
-        /// <summary>
-        /// Sends a message to open the storage UI
-        /// </summary>
-        /// <returns></returns>
-        private void OnActivate(EntityUid uid, ServerStorageComponent storageComp, ActivateInWorldEvent args)
-        {
-            if (args.Handled || _combatMode.IsInCombatMode(args.User) || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked)
-                return;
-
-            OpenStorageUI(uid, args.User, storageComp);
-        }
+        silent |= HasComp<GhostComponent>(args.User);
 
-        /// <summary>
-        /// Specifically for storage implants.
-        /// </summary>
-        private void OnImplantActivate(EntityUid uid, ServerStorageComponent storageComp, OpenStorageImplantEvent args)
-        {
-            if (args.Handled || !TryComp<TransformComponent>(uid, out var xform))
-                return;
+        // Get the session for the user
+        if (!TryComp<ActorComponent>(args.User, out var actor))
+            return;
 
-            OpenStorageUI(uid, xform.ParentUid, storageComp);
-        }
+        // Does this player currently have the storage UI open?
+        var uiOpen = _uiSystem.SessionHasOpenUi(uid, StorageComponent.StorageUiKey.Key, actor.PlayerSession);
 
-        /// <summary>
-        /// Allows a user to pick up entities by clicking them, or pick up all entities in a certain radius
-        /// around a click.
-        /// </summary>
-        /// <returns></returns>
-        private async void AfterInteract(EntityUid uid, ServerStorageComponent storageComp, AfterInteractEvent args)
+        ActivationVerb verb = new()
         {
-            if (!args.CanReach)
-                return;
-
-            // Pick up all entities in a radius around the clicked location.
-            // The last half of the if is because carpets exist and this is terrible
-            if (storageComp.AreaInsert && (args.Target == null || !HasComp<ItemComponent>(args.Target.Value)))
+            Act = () =>
             {
-                var validStorables = new List<NetEntity>();
-                var itemQuery = GetEntityQuery<ItemComponent>();
-
-                foreach (var entity in _entityLookupSystem.GetEntitiesInRange(args.ClickLocation, storageComp.AreaInsertRadius, LookupFlags.Dynamic | LookupFlags.Sundries))
+                if (uiOpen)
                 {
-                    if (entity == args.User
-                        || !itemQuery.HasComponent(entity)
-                        || !CanInsert(uid, entity, out _, storageComp)
-                        || !_interactionSystem.InRangeUnobstructed(args.User, entity))
-                    {
-                        continue;
-                    }
-
-                    validStorables.Add(GetNetEntity(entity));
+                    _uiSystem.TryClose(uid, StorageComponent.StorageUiKey.Key, actor.PlayerSession);
                 }
-
-                //If there's only one then let's be generous
-                if (validStorables.Count > 1)
+                else
                 {
-                    var doAfterArgs = new DoAfterArgs(EntityManager, args.User, 0.2f * validStorables.Count, new AreaPickupDoAfterEvent(validStorables), uid, target: uid)
-                    {
-                        BreakOnDamage = true,
-                        BreakOnUserMove = true,
-                        NeedHand = true
-                    };
-
-                    _doAfterSystem.TryStartDoAfter(doAfterArgs);
+                    OpenStorageUI(uid, args.User, component, silent);
                 }
-
-                return;
             }
-
-            // Pick up the clicked entity
-            if (storageComp.QuickInsert)
-            {
-                if (args.Target is not { Valid: true } target)
-                    return;
-
-                if (_containerSystem.IsEntityInContainer(target)
-                    || target == args.User
-                    || !HasComp<ItemComponent>(target))
-                    return;
-
-                if (TryComp<TransformComponent>(uid, out var transformOwner) && TryComp<TransformComponent>(target, out var transformEnt))
-                {
-                    var parent = transformOwner.ParentUid;
-
-                    var position = EntityCoordinates.FromMap(
-                        parent.IsValid() ? parent : uid,
-                        transformEnt.MapPosition,
-                        _transform
-                    );
-
-                    if (PlayerInsertEntityInWorld(uid, args.User, target, storageComp))
-                    {
-                        RaiseNetworkEvent(new AnimateInsertingEntitiesEvent(GetNetEntity(uid),
-                            new List<NetEntity> { GetNetEntity(target) },
-                            new List<NetCoordinates> { GetNetCoordinates(position) },
-                            new List<Angle> { transformOwner.LocalRotation }));
-                    }
-                }
-            }
-        }
-
-        private void OnDoAfter(EntityUid uid, ServerStorageComponent component, AreaPickupDoAfterEvent args)
+        };
+        if (uiOpen)
         {
-            if (args.Handled || args.Cancelled)
-                return;
-
-            var successfullyInserted = new List<EntityUid>();
-            var successfullyInsertedPositions = new List<EntityCoordinates>();
-            var successfullyInsertedAngles = new List<Angle>();
-            var itemQuery = GetEntityQuery<ItemComponent>();
-            var xformQuery = GetEntityQuery<TransformComponent>();
-            xformQuery.TryGetComponent(uid, out var xform);
-
-            foreach (var nent in args.Entities)
-            {
-                var entity = GetEntity(nent);
-
-                // Check again, situation may have changed for some entities, but we'll still pick up any that are valid
-                if (_containerSystem.IsEntityInContainer(entity)
-                    || entity == args.Args.User
-                    || !itemQuery.HasComponent(entity))
-                    continue;
-
-                if (xform == null ||
-                    !xformQuery.TryGetComponent(entity, out var targetXform) ||
-                    targetXform.MapID != xform.MapID)
-                {
-                    continue;
-                }
-
-                var position = EntityCoordinates.FromMap(
-                    xform.ParentUid.IsValid() ? xform.ParentUid : uid,
-                    new MapCoordinates(_transform.GetWorldPosition(targetXform, xformQuery), targetXform.MapID),
-                    _transform
-                );
-
-                var angle = targetXform.LocalRotation;
-
-                if (PlayerInsertEntityInWorld(uid, args.Args.User, entity, component))
-                {
-                    successfullyInserted.Add(entity);
-                    successfullyInsertedPositions.Add(position);
-                    successfullyInsertedAngles.Add(angle);
-                }
-            }
-
-            // If we picked up atleast one thing, play a sound and do a cool animation!
-            if (successfullyInserted.Count > 0)
-            {
-                _audio.PlayPvs(component.StorageInsertSound, uid);
-                RaiseNetworkEvent(new AnimateInsertingEntitiesEvent(GetNetEntity(uid), GetNetEntityList(successfullyInserted), GetNetCoordinatesList(successfullyInsertedPositions), successfullyInsertedAngles));
-            }
-
-            args.Handled = true;
+            verb.Text = Loc.GetString("verb-common-close-ui");
+            verb.Icon = new SpriteSpecifier.Texture(
+                new("/Textures/Interface/VerbIcons/close.svg.192dpi.png"));
         }
-
-        private void OnDestroy(EntityUid uid, ServerStorageComponent storageComp, DestructionEventArgs args)
+        else
         {
-            var storedEntities = storageComp.StoredEntities?.ToList();
-
-            if (storedEntities == null)
-                return;
-
-            foreach (var entity in storedEntities)
-            {
-                RemoveAndDrop(uid, entity, storageComp);
-            }
+            verb.Text = Loc.GetString("verb-common-open-ui");
+            verb.Icon = new SpriteSpecifier.Texture(
+                new("/Textures/Interface/VerbIcons/open.svg.192dpi.png"));
         }
+        args.Verbs.Add(verb);
+    }
 
-        /// <summary>
-        ///     This function gets called when the user clicked on an item in the storage UI. This will either place the
-        ///     item in the user's hand if it is currently empty, or interact with the item using the user's currently
-        ///     held item.
-        /// </summary>
-        private void OnInteractWithItem(EntityUid uid, ServerStorageComponent storageComp, StorageInteractWithItemEvent args)
-        {
-            // TODO move this to shared for prediction.
-            if (args.Session.AttachedEntity is not EntityUid player)
-                return;
-
-            var interacted = GetEntity(args.InteractedItemUID);
-
-            if (!Exists(interacted))
-            {
-                Log.Error($"Player {args.Session} interacted with non-existent item {interacted} stored in {ToPrettyString(uid)}");
-                return;
-            }
-
-            if (!_actionBlockerSystem.CanInteract(player, interacted) || storageComp.Storage == null || !storageComp.Storage.Contains(interacted))
-                return;
-
-            // Does the player have hands?
-            if (!TryComp(player, out HandsComponent? hands) || hands.Count == 0)
-                return;
-
-            // If the user's active hand is empty, try pick up the item.
-            if (hands.ActiveHandEntity == null)
-            {
-                if (_sharedHandsSystem.TryPickupAnyHand(player, interacted, handsComp: hands)
-                    && storageComp.StorageRemoveSound != null)
-                    _audio.Play(storageComp.StorageRemoveSound, Filter.Pvs(uid, entityManager: EntityManager), uid, true, AudioParams.Default);
-                return;
-            }
-
-            // Else, interact using the held item
-            _interactionSystem.InteractUsing(player, hands.ActiveHandEntity.Value, interacted, Transform(interacted).Coordinates, checkCanInteract: false);
-        }
-
-        private void OnInsertItemMessage(EntityUid uid, ServerStorageComponent storageComp, StorageInsertItemMessage args)
-        {
-            // TODO move this to shared for prediction.
-            if (args.Session.AttachedEntity == null)
-                return;
-
-            PlayerInsertHeldEntity(uid, args.Session.AttachedEntity.Value, storageComp);
-        }
-
-        private void OnBoundUIOpen(EntityUid uid, ServerStorageComponent storageComp, BoundUIOpenedEvent args)
-        {
-            if (!storageComp.IsOpen)
-            {
-                storageComp.IsOpen = true;
-                UpdateStorageVisualization(uid, storageComp);
-            }
-        }
-
-        private void OnBoundUIClosed(EntityUid uid, ServerStorageComponent storageComp, BoundUIClosedEvent args)
-        {
-            if (TryComp<ActorComponent>(args.Session.AttachedEntity, out var actor) && actor?.PlayerSession != null)
-                CloseNestedInterfaces(uid, actor.PlayerSession, storageComp);
-
-            // If UI is closed for everyone
-            if (!_uiSystem.IsUiOpen(uid, args.UiKey))
-            {
-                storageComp.IsOpen = false;
-                UpdateStorageVisualization(uid, storageComp);
-
-                if (storageComp.StorageCloseSound is not null)
-                    _audio.Play(storageComp.StorageCloseSound, Filter.Pvs(uid, entityManager: EntityManager), uid, true, storageComp.StorageCloseSound.Params);
-            }
-        }
-
-        private void OnStorageItemRemoved(EntityUid uid, ServerStorageComponent storageComp, EntRemovedFromContainerMessage args)
-        {
-            RecalculateStorageUsed(storageComp);
-            UpdateStorageUI(uid, storageComp);
-        }
-
-        private void UpdateStorageVisualization(EntityUid uid, ServerStorageComponent storageComp)
-        {
-            if (!TryComp<AppearanceComponent>(uid, out var appearance))
-                return;
-
-            _appearance.SetData(uid, StorageVisuals.Open, storageComp.IsOpen, appearance);
-            _appearance.SetData(uid, SharedBagOpenVisuals.BagState, storageComp.IsOpen ? SharedBagState.Open : SharedBagState.Closed);
-
-            if (HasComp<ItemCounterComponent>(uid))
-                _appearance.SetData(uid, StackVisuals.Hide, !storageComp.IsOpen);
-        }
-
-        public void RecalculateStorageUsed(ServerStorageComponent storageComp)
-        {
-            storageComp.StorageUsed = 0;
-            storageComp.SizeCache.Clear();
-
-            if (storageComp.Storage == null)
-                return;
-
-            var itemQuery = GetEntityQuery<ItemComponent>();
-
-            foreach (var entity in storageComp.Storage.ContainedEntities)
-            {
-                if (!itemQuery.TryGetComponent(entity, out var itemComp))
-                    continue;
-
-                var size = itemComp.Size;
-                storageComp.StorageUsed += size;
-                storageComp.SizeCache.Add(entity, size);
-            }
-        }
-
-        public int GetAvailableSpace(EntityUid uid, ServerStorageComponent? component = null)
-        {
-            if (!Resolve(uid, ref component))
-                return 0;
-
-            return component.StorageCapacityMax - component.StorageUsed;
-        }
-
-        /// <summary>
-        ///     Move entities from one storage to another.
-        /// </summary>
-        public void TransferEntities(EntityUid source, EntityUid target,
-            ServerStorageComponent? sourceComp = null, LockComponent? sourceLock = null,
-            ServerStorageComponent? targetComp = null, LockComponent? targetLock = null)
-        {
-            if (!Resolve(source, ref sourceComp) || !Resolve(target, ref targetComp))
-                return;
-
-            var entities = sourceComp.Storage?.ContainedEntities;
-            if (entities == null || entities.Count == 0)
-                return;
-
-            if (Resolve(source, ref sourceLock, false) && sourceLock.Locked
-                || Resolve(target, ref targetLock, false) && targetLock.Locked)
-                return;
-
-            foreach (var entity in entities.ToList())
-            {
-                Insert(target, entity, targetComp);
-            }
-            RecalculateStorageUsed(sourceComp);
-            UpdateStorageUI(source, sourceComp);
-        }
-
-        /// <summary>
-        ///     Verifies if an entity can be stored and if it fits
-        /// </summary>
-        /// <param name="uid">The entity to check</param>
-        /// <param name="reason">If returning false, the reason displayed to the player</param>
-        /// <returns>true if it can be inserted, false otherwise</returns>
-        public bool CanInsert(EntityUid uid, EntityUid insertEnt, out string? reason, ServerStorageComponent? storageComp = null)
-        {
-            if (!Resolve(uid, ref storageComp))
-            {
-                reason = null;
-                return false;
-            }
-
-            if (TryComp(insertEnt, out TransformComponent? transformComp) && transformComp.Anchored)
-            {
-                reason = "comp-storage-anchored-failure";
-                return false;
-            }
-
-            if (storageComp.Whitelist?.IsValid(insertEnt, EntityManager) == false)
-            {
-                reason = "comp-storage-invalid-container";
-                return false;
-            }
-
-            if (storageComp.Blacklist?.IsValid(insertEnt, EntityManager) == true)
-            {
-                reason = "comp-storage-invalid-container";
-                return false;
-            }
-
-            if (TryComp(insertEnt, out ServerStorageComponent? storage) &&
-                storage.StorageCapacityMax >= storageComp.StorageCapacityMax)
-            {
-                reason = "comp-storage-insufficient-capacity";
-                return false;
-            }
-
-            if (TryComp(insertEnt, out ItemComponent? itemComp) &&
-                itemComp.Size > storageComp.StorageCapacityMax - storageComp.StorageUsed)
-            {
-                reason = "comp-storage-insufficient-capacity";
-                return false;
-            }
-
-            reason = null;
-            return true;
-        }
-
-        /// <summary>
-        ///     Inserts into the storage container
-        /// </summary>
-        /// <returns>true if the entity was inserted, false otherwise</returns>
-        public bool Insert(EntityUid uid, EntityUid insertEnt, ServerStorageComponent? storageComp = null, bool playSound = true)
-        {
-            if (!Resolve(uid, ref storageComp) || !CanInsert(uid, insertEnt, out _, storageComp) || storageComp.Storage == null)
-                return false;
-
-            /*
-             * 1. If the inserted thing is stackable then try to stack it to existing stacks
-             * 2. If anything remains insert whatever is possible.
-             * 3. If insertion is not possible then leave the stack as is.
-             * At either rate still play the insertion sound
-             *
-             * For now we just treat items as always being the same size regardless of stack count.
-             */
-
-            // If it's stackable then prefer to stack it
-            var stackQuery = GetEntityQuery<StackComponent>();
-
-            if (stackQuery.TryGetComponent(insertEnt, out var insertStack))
-            {
-                var toInsertCount = insertStack.Count;
-
-                foreach (var ent in storageComp.Storage.ContainedEntities)
-                {
-                    if (!stackQuery.TryGetComponent(ent, out var containedStack) || !insertStack.StackTypeId.Equals(containedStack.StackTypeId))
-                        continue;
-
-                    if (!_stack.TryAdd(insertEnt, ent, insertStack, containedStack))
-                        continue;
-
-                    var remaining = insertStack.Count;
-                    toInsertCount -= toInsertCount - remaining;
-
-                    if (remaining > 0)
-                        continue;
-
-                    break;
-                }
-
-                // Still stackable remaining
-                if (insertStack.Count > 0)
-                {
-                    // Try to insert it as a new stack.
-                    if (TryComp(insertEnt, out ItemComponent? itemComp) &&
-                        itemComp.Size > storageComp.StorageCapacityMax - storageComp.StorageUsed ||
-                        !storageComp.Storage.Insert(insertEnt))
-                    {
-                        // If we also didn't do any stack fills above then just end
-                        // otherwise play sound and update UI anyway.
-                        if (toInsertCount == insertStack.Count)
-                            return false;
-                    }
-                }
-            }
-            // Non-stackable but no insertion for reasons.
-            else if (!storageComp.Storage.Insert(insertEnt))
-            {
-                return false;
-            }
-
-            if (playSound && storageComp.StorageInsertSound is not null)
-                _audio.PlayPvs(storageComp.StorageInsertSound, uid);
-
-            RecalculateStorageUsed(storageComp);
-            UpdateStorageUI(uid, storageComp);
-            return true;
-        }
+    private void OnBoundUIClosed(EntityUid uid, StorageComponent storageComp, BoundUIClosedEvent args)
+    {
+        if (TryComp<ActorComponent>(args.Session.AttachedEntity, out var actor) && actor?.PlayerSession != null)
+            CloseNestedInterfaces(uid, actor.PlayerSession, storageComp);
 
-        // REMOVE: remove and drop on the ground
-        public bool RemoveAndDrop(EntityUid uid, EntityUid removeEnt, ServerStorageComponent? storageComp = null)
+        // If UI is closed for everyone
+        if (!_uiSystem.IsUiOpen(uid, args.UiKey))
         {
-            if (!Resolve(uid, ref storageComp))
-                return false;
-
-            var itemRemoved = storageComp.Storage?.Remove(removeEnt) == true;
-            if (itemRemoved)
-                RecalculateStorageUsed(storageComp);
+            storageComp.IsUiOpen = false;
+            UpdateStorageVisualization(uid, storageComp);
 
-            return itemRemoved;
+            if (storageComp.StorageCloseSound is not null)
+                Audio.Play(storageComp.StorageCloseSound, Filter.Pvs(uid, entityManager: EntityManager), uid, true, storageComp.StorageCloseSound.Params);
         }
+    }
 
-        /// <summary>
-        ///     Inserts an entity into storage from the player's active hand
-        /// </summary>
-        /// <param name="player">The player to insert an entity from</param>
-        /// <returns>true if inserted, false otherwise</returns>
-        public bool PlayerInsertHeldEntity(EntityUid uid, EntityUid player, ServerStorageComponent? storageComp = null)
-        {
-            if (!Resolve(uid, ref storageComp) || !TryComp(player, out HandsComponent? hands) || hands.ActiveHandEntity == null)
-                return false;
-
-            var toInsert = hands.ActiveHandEntity;
-
-            if (!CanInsert(uid, toInsert.Value, out var reason, storageComp))
-            {
-                Popup(uid, player, reason ?? "comp-storage-cant-insert", storageComp);
-                return false;
-            }
-
-            if (!_sharedHandsSystem.TryDrop(player, toInsert.Value, handsComp: hands))
-            {
-                PopupEnt(uid, player, "comp-storage-cant-drop", toInsert.Value, storageComp);
-                return false;
-            }
-
-            return PlayerInsertEntityInWorld(uid, player, toInsert.Value, storageComp);
-        }
+    /// <summary>
+    ///     Opens the storage UI for an entity
+    /// </summary>
+    /// <param name="entity">The entity to open the UI for</param>
+    public override void OpenStorageUI(EntityUid uid, EntityUid entity, StorageComponent? storageComp = null, bool silent = false)
+    {
+        if (!Resolve(uid, ref storageComp) || !TryComp(entity, out ActorComponent? player))
+            return;
 
-        /// <summary>
-        ///     Inserts an Entity (<paramref name="toInsert"/>) in the world into storage, informing <paramref name="player"/> if it fails.
-        ///     <paramref name="toInsert"/> is *NOT* held, see <see cref="PlayerInsertHeldEntity(Robust.Shared.GameObjects.EntityUid)"/>.
-        /// </summary>
-        /// <param name="player">The player to insert an entity with</param>
-        /// <returns>true if inserted, false otherwise</returns>
-        public bool PlayerInsertEntityInWorld(EntityUid uid, EntityUid player, EntityUid toInsert, ServerStorageComponent? storageComp = null)
+        // prevent spamming bag open / honkerton honk sound
+        silent |= TryComp<UseDelayComponent>(uid, out var useDelay) && UseDelay.ActiveDelay(uid, useDelay);
+        if (!silent)
         {
-            if (!Resolve(uid, ref storageComp) || !_sharedInteractionSystem.InRangeUnobstructed(player, uid, popup: storageComp.ShowPopup))
-                return false;
-
-            if (!Insert(uid, toInsert, storageComp))
-            {
-                Popup(uid, player, "comp-storage-cant-insert", storageComp);
-                return false;
-            }
-            return true;
+            Audio.PlayPvs(storageComp.StorageOpenSound, uid);
+            if (useDelay != null)
+                UseDelay.BeginDelay(uid, useDelay);
         }
 
-        /// <summary>
-        ///     Opens the storage UI for an entity
-        /// </summary>
-        /// <param name="entity">The entity to open the UI for</param>
-        public void OpenStorageUI(EntityUid uid, EntityUid entity, ServerStorageComponent? storageComp = null, bool silent = false)
-        {
-            if (!Resolve(uid, ref storageComp) || !TryComp(entity, out ActorComponent? player))
-                return;
-
-            // prevent spamming bag open / honkerton honk sound
-            silent |= TryComp<UseDelayComponent>(uid, out var useDelay) && _useDelay.ActiveDelay(uid, useDelay);
-            if (!silent)
-            {
-                _audio.PlayPvs(storageComp.StorageOpenSound, uid);
-                if (useDelay != null)
-                    _useDelay.BeginDelay(uid, useDelay);
-            }
+        Log.Debug($"Storage (UID {uid}) \"used\" by player session (UID {player.PlayerSession.AttachedEntity}).");
 
-            _logManager.GetSawmill(storageComp.LoggerName)
-                .Debug($"Storage (UID {uid}) \"used\" by player session (UID {player.PlayerSession.AttachedEntity}).");
+        var bui = _uiSystem.GetUiOrNull(uid, StorageComponent.StorageUiKey.Key);
+        if (bui != null)
+            _uiSystem.OpenUi(bui, player.PlayerSession);
+    }
 
-            var bui = _uiSystem.GetUiOrNull(uid, StorageUiKey.Key);
-            if (bui != null)
-                _uiSystem.OpenUi(bui, player.PlayerSession);
-        }
+    /// <summary>
+    ///     If the user has nested-UIs open (e.g., PDA UI open when pda is in a backpack), close them.
+    /// </summary>
+    /// <param name="session"></param>
+    public void CloseNestedInterfaces(EntityUid uid, IPlayerSession session, StorageComponent? storageComp = null)
+    {
+        if (!Resolve(uid, ref storageComp))
+            return;
 
-        /// <summary>
-        ///     If the user has nested-UIs open (e.g., PDA UI open when pda is in a backpack), close them.
-        /// </summary>
-        /// <param name="session"></param>
-        public void CloseNestedInterfaces(EntityUid uid, IPlayerSession session, ServerStorageComponent? storageComp = null)
+        // for each containing thing
+        // if it has a storage comp
+        // ensure unsubscribe from session
+        // if it has a ui component
+        // close ui
+        foreach (var entity in storageComp.Container.ContainedEntities)
         {
-            if (!Resolve(uid, ref storageComp) || storageComp.StoredEntities == null)
-                return;
+            if (!TryComp(entity, out UserInterfaceComponent? ui))
+                continue;
 
-            // for each containing thing
-            // if it has a storage comp
-            // ensure unsubscribe from session
-            // if it has a ui component
-            // close ui
-            foreach (var entity in storageComp.StoredEntities)
+            foreach (var bui in ui.Interfaces.Values)
             {
-                if (TryComp(entity, out ServerStorageComponent? storedStorageComp))
-                    DebugTools.Assert(storedStorageComp != storageComp, $"Storage component contains itself!? Entity: {uid}");
-
-                if (!TryComp(entity, out ServerUserInterfaceComponent? ui))
-                    continue;
-
-                foreach (var bui in ui.Interfaces.Values)
-                {
-                    _uiSystem.TryClose(entity, bui.UiKey, session, ui);
-                }
+                _uiSystem.TryClose(entity, bui.UiKey, session, ui);
             }
         }
-
-        public void UpdateStorageUI(EntityUid uid, ServerStorageComponent storageComp)
-        {
-            if (storageComp.Storage == null)
-                return;
-
-            var state = new StorageBoundUserInterfaceState(GetNetEntityList(storageComp.Storage.ContainedEntities.ToList()), storageComp.StorageUsed, storageComp.StorageCapacityMax);
-
-            var bui = _uiSystem.GetUiOrNull(uid, StorageUiKey.Key);
-            if (bui != null)
-                _uiSystem.SetUiState(bui, state);
-        }
-
-        private void Popup(EntityUid _, EntityUid player, string message, ServerStorageComponent storageComp)
-        {
-            if (!storageComp.ShowPopup)
-                return;
-
-            _popupSystem.PopupEntity(Loc.GetString(message), player, player);
-        }
-
-        private void PopupEnt(EntityUid _, EntityUid player, string message, EntityUid entityUid, ServerStorageComponent storageComp)
-        {
-            if (!storageComp.ShowPopup)
-                return;
-
-            _popupSystem.PopupEntity(Loc.GetString(message, ("entity", entityUid)), player, player);
-        }
     }
 }
index c5b8761808e8cc7b08916a75d31a54e3a71e044f..d2fccd1b9c327f2bebc1d5aa038d351e8bdb6033 100644 (file)
@@ -67,7 +67,7 @@ public sealed partial class StoreSystem
     /// <param name="store">The store entity itself</param>
     /// <param name="component">The store component being refreshed.</param>
     /// <param name="ui"></param>
-    public void UpdateUserInterface(EntityUid? user, EntityUid store, StoreComponent? component = null, BoundUserInterface? ui = null)
+    public void UpdateUserInterface(EntityUid? user, EntityUid store, StoreComponent? component = null, PlayerBoundUserInterface? ui = null)
     {
         if (!Resolve(store, ref component))
             return;
index 3b61ad6d3ccdfa58fa8c1ef38a2691ff2eb304e4..fe9ae850c8498847d009ecb711375aedfee94fb2 100644 (file)
@@ -12,7 +12,7 @@ namespace Content.Server.UserInterface
         [ViewVariables]
         public Enum? Key { get; set; }
 
-        [ViewVariables] public BoundUserInterface? UserInterface => (Key != null) ? Owner.GetUIOrNull(Key) : null;
+        [ViewVariables] public PlayerBoundUserInterface? UserInterface => (Key != null) ? Owner.GetUIOrNull(Key) : null;
 
         [ViewVariables(VVAccess.ReadWrite)]
         [DataField("inHandsOnly")]
index c7f07c2f7002f41749e855f476096e7148858175..c200d7a3f0045c56ffc2806457435278b882500a 100644 (file)
@@ -33,7 +33,7 @@ public sealed partial class ActivatableUISystem : EntitySystem
 
         SubscribeLocalEvent<ActivatableUIComponent, GetVerbsEvent<ActivationVerb>>(AddOpenUiVerb);
 
-        SubscribeLocalEvent<ServerUserInterfaceComponent, OpenUiActionEvent>(OnActionPerform);
+        SubscribeLocalEvent<UserInterfaceComponent, OpenUiActionEvent>(OnActionPerform);
 
         InitializePower();
     }
@@ -50,7 +50,7 @@ public sealed partial class ActivatableUISystem : EntitySystem
             ev.Cancel();
     }
 
-    private void OnActionPerform(EntityUid uid, ServerUserInterfaceComponent component, OpenUiActionEvent args)
+    private void OnActionPerform(EntityUid uid, UserInterfaceComponent component, OpenUiActionEvent args)
     {
         if (args.Handled || args.Key == null)
             return;
index c7360c15bfcf4c378cfc523d0bfdaa770bfbc002..ce89974f631ef8a4e4b8e98e8998873a1da83172 100644 (file)
@@ -59,7 +59,7 @@ public sealed class IntrinsicUISystem : EntitySystem
         return true;
     }
 
-    private BoundUserInterface? GetUIOrNull(EntityUid uid, Enum? key, IntrinsicUIComponent? component = null)
+    private PlayerBoundUserInterface? GetUIOrNull(EntityUid uid, Enum? key, IntrinsicUIComponent? component = null)
     {
         if (!Resolve(uid, ref component))
             return null;
index 4a0e9d1543827524f04f2142cf5f0a2a4b7d39cf..865772c772cb6971171023141effaf0ae0918ab0 100644 (file)
@@ -5,7 +5,7 @@ namespace Content.Server.UserInterface
     public static class UserInterfaceHelpers
     {
         [Obsolete("Use UserInterfaceSystem")]
-        public static BoundUserInterface? GetUIOrNull(this EntityUid entity, Enum uiKey)
+        public static PlayerBoundUserInterface? GetUIOrNull(this EntityUid entity, Enum uiKey)
         {
             return IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<UserInterfaceSystem>().GetUiOrNull(entity, uiKey);
         }
index 07f0de2ebe7da5e8942ed7c0b63c96dcc57cd68b..0baf0c5c224f05e1178e3eeb3d6b6839fd56c172 100644 (file)
@@ -565,7 +565,7 @@ public sealed class WiresSystem : SharedWiresSystem
         UpdateUserInterface(uid);
     }
 
-    private void UpdateUserInterface(EntityUid uid, WiresComponent? wires = null, ServerUserInterfaceComponent? ui = null)
+    private void UpdateUserInterface(EntityUid uid, WiresComponent? wires = null, UserInterfaceComponent? ui = null)
     {
         if (!Resolve(uid, ref wires, ref ui, false)) // logging this means that we get a bunch of errors
             return;
index d127b326cc7272482cd79290a19d4ff025c0b3dd..ef6690cc356086551bb2ed53a4c8a5fa15a49900 100644 (file)
@@ -8,7 +8,7 @@ namespace Content.Shared.Access.Systems
     }
 
     /// <summary>
-    /// Key representing which <see cref="BoundUserInterface"/> is currently open.
+    /// Key representing which <see cref="PlayerBoundUserInterface"/> is currently open.
     /// Useful when there are multiple UI for an object. Here it's future-proofing only.
     /// </summary>
     [Serializable, NetSerializable]
index c7694aaae772d42b9029dddad0b610c0571c5782..23300cb2a01bc13e824136b9ae1a9104f9b84ff9 100644 (file)
@@ -3,7 +3,7 @@
 namespace Content.Shared.Atmos.Piping.Binary.Components
 {
     /// <summary>
-    /// Key representing which <see cref="BoundUserInterface"/> is currently open.
+    /// Key representing which <see cref="PlayerBoundUserInterface"/> is currently open.
     /// Useful when there are multiple UI for an object. Here it's future-proofing only.
     /// </summary>
     [Serializable, NetSerializable]
index 423a829809d2c3eca3c16b32c865d99febf898a1..c84078baceb485e86f029e401edff65b601f02a6 100644 (file)
@@ -108,7 +108,7 @@ public abstract partial class SharedBuckleSystem
     private void OnStrapContainerGettingInsertedAttempt(EntityUid uid, StrapComponent component, ContainerGettingInsertedAttemptEvent args)
     {
         // If someone is attempting to put this item inside of a backpack, ensure that it has no entities strapped to it.
-        if (HasComp<SharedStorageComponent>(args.Container.Owner) && component.BuckledEntities.Count != 0)
+        if (HasComp<StorageComponent>(args.Container.Owner) && component.BuckledEntities.Count != 0)
             args.Cancel();
     }
 
index c8d6e950efd8febe4c68a18c9211c7d7dfec0fb0..362500b7681a71ae300f8024c1e523be2baf3806 100644 (file)
@@ -3,7 +3,7 @@ using Robust.Shared.Serialization;
 namespace Content.Shared.Labels
 {
     /// <summary>
-    /// Key representing which <see cref="BoundUserInterface"/> is currently open.
+    /// Key representing which <see cref="PlayerBoundUserInterface"/> is currently open.
     /// Useful when there are multiple UI for an object. Here it's future-proofing only.
     /// </summary>
     [Serializable, NetSerializable]
index ca8c7a073b6fd1bdb0a36a5790be5ce082897d42..c457fec43f8cd928a0290459ad08564de62a22cf 100644 (file)
@@ -37,7 +37,7 @@ public sealed partial class MeleeSpeechComponent : Component
 }
 
 /// <summary>
-/// Key representing which <see cref="BoundUserInterface"/> is currently open.
+/// Key representing which <see cref="PlayerBoundUserInterface"/> is currently open.
 /// Useful when there are multiple UI for an object. Here it's future-proofing only.
 /// </summary>
 [Serializable, NetSerializable]
diff --git a/Content.Shared/Storage/Components/StorageFillComponent.cs b/Content.Shared/Storage/Components/StorageFillComponent.cs
new file mode 100644 (file)
index 0000000..e112368
--- /dev/null
@@ -0,0 +1,12 @@
+using Content.Shared.Storage.EntitySystems;
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Storage.Components;
+
+// TODO:
+// REPLACE THIS WITH CONTAINERFILL
+[RegisterComponent, NetworkedComponent, Access(typeof(SharedStorageSystem))]
+public sealed partial class StorageFillComponent : Component
+{
+    [DataField("contents")] public List<EntitySpawnEntry> Contents = new();
+}
index d44cda40f4caa888416d8d52c1bfefb7e5a42e0c..cb53ea829852a007ed62dadb5be0983607f692de 100644 (file)
@@ -1,5 +1,5 @@
+using System.Linq;
 using Content.Shared.Disposal;
-using Content.Shared.Disposal.Components;
 using Content.Shared.DoAfter;
 using Content.Shared.Interaction;
 using Content.Shared.Placeable;
@@ -49,7 +49,7 @@ public sealed class DumpableSystem : EntitySystem
         if (!args.CanAccess || !args.CanInteract)
             return;
 
-        if (!TryComp<SharedStorageComponent>(uid, out var storage) || storage.StoredEntities == null || storage.StoredEntities.Count == 0)
+        if (!TryComp<StorageComponent>(uid, out var storage) || !storage.Container.ContainedEntities.Any())
             return;
 
         AlternativeVerb verb = new()
@@ -69,7 +69,7 @@ public sealed class DumpableSystem : EntitySystem
         if (!args.CanAccess || !args.CanInteract)
             return;
 
-        if (!TryComp<SharedStorageComponent>(uid, out var storage) || storage.StoredEntities == null || storage.StoredEntities.Count == 0)
+        if (!TryComp<StorageComponent>(uid, out var storage) || !storage.Container.ContainedEntities.Any())
             return;
 
         if (_disposalUnitSystem.HasDisposals(args.Target))
@@ -103,10 +103,10 @@ public sealed class DumpableSystem : EntitySystem
 
     public void StartDoAfter(EntityUid storageUid, EntityUid? targetUid, EntityUid userUid, DumpableComponent dumpable)
     {
-        if (!TryComp<SharedStorageComponent>(storageUid, out var storage) || storage.StoredEntities == null)
+        if (!TryComp<StorageComponent>(storageUid, out var storage))
             return;
 
-        float delay = storage.StoredEntities.Count * (float) dumpable.DelayPerItem.TotalSeconds * dumpable.Multiplier;
+        float delay = storage.Container.ContainedEntities.Count * (float) dumpable.DelayPerItem.TotalSeconds * dumpable.Multiplier;
 
         _doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, userUid, delay, new DumpableDoAfterEvent(), storageUid, target: targetUid, used: storageUid)
         {
@@ -118,11 +118,11 @@ public sealed class DumpableSystem : EntitySystem
 
     private void OnDoAfter(EntityUid uid, DumpableComponent component, DoAfterEvent args)
     {
-        if (args.Handled || args.Cancelled || !TryComp<SharedStorageComponent>(uid, out var storage) || storage.StoredEntities == null)
+        if (args.Handled || args.Cancelled || !TryComp<StorageComponent>(uid, out var storage))
             return;
 
         Queue<EntityUid> dumpQueue = new();
-        foreach (var entity in storage.StoredEntities)
+        foreach (var entity in storage.Container.ContainedEntities)
         {
             dumpQueue.Enqueue(entity);
         }
diff --git a/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs
new file mode 100644 (file)
index 0000000..fac7723
--- /dev/null
@@ -0,0 +1,606 @@
+using System.Linq;
+using Content.Shared.ActionBlocker;
+using Content.Shared.CombatMode;
+using Content.Shared.Containers.ItemSlots;
+using Content.Shared.Destructible;
+using Content.Shared.DoAfter;
+using Content.Shared.Hands.Components;
+using Content.Shared.Hands.EntitySystems;
+using Content.Shared.Implants.Components;
+using Content.Shared.Interaction;
+using Content.Shared.Item;
+using Content.Shared.Lock;
+using Content.Shared.Placeable;
+using Content.Shared.Popups;
+using Content.Shared.Stacks;
+using Content.Shared.Storage.Components;
+using Content.Shared.Timing;
+using Content.Shared.Verbs;
+using Robust.Shared.Containers;
+using Robust.Shared.Map;
+using Robust.Shared.Random;
+
+namespace Content.Shared.Storage.EntitySystems;
+
+public abstract class SharedStorageSystem : EntitySystem
+{
+    [Dependency] protected readonly IRobustRandom Random = default!;
+    [Dependency] private   readonly SharedContainerSystem _containerSystem = default!;
+    [Dependency] private   readonly SharedDoAfterSystem _doAfterSystem = default!;
+    [Dependency] private   readonly EntityLookupSystem _entityLookupSystem = default!;
+    [Dependency] protected readonly SharedEntityStorageSystem EntityStorage = default!;
+    [Dependency] private   readonly SharedInteractionSystem _interactionSystem = default!;
+    [Dependency] private   readonly SharedPopupSystem _popupSystem = default!;
+    [Dependency] private   readonly SharedHandsSystem _sharedHandsSystem = default!;
+    [Dependency] private   readonly SharedInteractionSystem _sharedInteractionSystem = default!;
+    [Dependency] private   readonly ActionBlockerSystem _actionBlockerSystem = default!;
+    [Dependency] private   readonly SharedAppearanceSystem _appearance = default!;
+    [Dependency] protected readonly SharedAudioSystem Audio = default!;
+    [Dependency] private   readonly SharedCombatModeSystem _combatMode = default!;
+    [Dependency] private   readonly SharedTransformSystem _transform = default!;
+    [Dependency] private   readonly SharedStackSystem _stack = default!;
+    [Dependency] protected readonly UseDelaySystem UseDelay = default!;
+
+    private EntityQuery<ItemComponent> _itemQuery;
+    private EntityQuery<StackComponent> _stackQuery;
+    private EntityQuery<TransformComponent> _xformQuery;
+
+    /// <inheritdoc />
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        _itemQuery = GetEntityQuery<ItemComponent>();
+        _stackQuery = GetEntityQuery<StackComponent>();
+        _xformQuery = GetEntityQuery<TransformComponent>();
+
+        SubscribeLocalEvent<StorageComponent, ComponentInit>(OnComponentInit, before: new[] { typeof(SharedContainerSystem) });
+        SubscribeLocalEvent<StorageComponent, GetVerbsEvent<UtilityVerb>>(AddTransferVerbs);
+        SubscribeLocalEvent<StorageComponent, InteractUsingEvent>(OnInteractUsing, after: new[] { typeof(ItemSlotsSystem) });
+        SubscribeLocalEvent<StorageComponent, ActivateInWorldEvent>(OnActivate);
+        SubscribeLocalEvent<StorageComponent, OpenStorageImplantEvent>(OnImplantActivate);
+        SubscribeLocalEvent<StorageComponent, AfterInteractEvent>(AfterInteract);
+        SubscribeLocalEvent<StorageComponent, DestructionEventArgs>(OnDestroy);
+        SubscribeLocalEvent<StorageComponent, StorageComponent.StorageInsertItemMessage>(OnInsertItemMessage);
+        SubscribeLocalEvent<StorageComponent, BoundUIOpenedEvent>(OnBoundUIOpen);
+
+        SubscribeLocalEvent<StorageComponent, EntInsertedIntoContainerMessage>(OnStorageItemInserted);
+        SubscribeLocalEvent<StorageComponent, EntRemovedFromContainerMessage>(OnStorageItemRemoved);
+
+        SubscribeLocalEvent<StorageComponent, AreaPickupDoAfterEvent>(OnDoAfter);
+
+        SubscribeLocalEvent<StorageComponent, StorageInteractWithItemEvent>(OnInteractWithItem);
+    }
+
+    private void OnComponentInit(EntityUid uid, StorageComponent storageComp, ComponentInit args)
+    {
+        // ReSharper disable once StringLiteralTypo
+        storageComp.Container = _containerSystem.EnsureContainer<Container>(uid, "storagebase");
+        UpdateStorage(uid, storageComp);
+    }
+
+    /// <summary>
+    /// Updates the storage UI, visualizer, etc.
+    /// </summary>
+    /// <param name="uid"></param>
+    /// <param name="component"></param>
+    private void UpdateStorage(EntityUid uid, StorageComponent component)
+    {
+        // TODO: I had this.
+        // We can get states being applied before the container is ready.
+        if (component.Container == default)
+            return;
+
+        RecalculateStorageUsed(component);
+        UpdateStorageVisualization(uid, component);
+        UpdateUI(uid, component);
+        Dirty(uid, component);
+    }
+
+    public virtual void UpdateUI(EntityUid uid, StorageComponent component) {}
+
+    public virtual void OpenStorageUI(EntityUid uid, EntityUid entity, StorageComponent? storageComp = null, bool silent = false) { }
+
+    private void AddTransferVerbs(EntityUid uid, StorageComponent component, GetVerbsEvent<UtilityVerb> args)
+    {
+        if (!args.CanAccess || !args.CanInteract)
+            return;
+
+        var entities = component.Container.ContainedEntities;
+
+        if (entities.Count == 0 || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked)
+            return;
+
+        // if the target is storage, add a verb to transfer storage.
+        if (TryComp(args.Target, out StorageComponent? targetStorage)
+            && (!TryComp(uid, out LockComponent? targetLock) || !targetLock.Locked))
+        {
+            UtilityVerb verb = new()
+            {
+                Text = Loc.GetString("storage-component-transfer-verb"),
+                IconEntity = GetNetEntity(args.Using),
+                Act = () => TransferEntities(uid, args.Target, args.User, component, lockComponent, targetStorage, targetLock)
+            };
+
+            args.Verbs.Add(verb);
+        }
+    }
+
+    /// <summary>
+    /// Inserts storable entities into this storage container if possible, otherwise return to the hand of the user
+    /// </summary>
+    /// <returns>true if inserted, false otherwise</returns>
+    private void OnInteractUsing(EntityUid uid, StorageComponent storageComp, InteractUsingEvent args)
+    {
+        if (args.Handled || !storageComp.ClickInsert || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked)
+            return;
+
+        Log.Debug($"Storage (UID {uid}) attacked by user (UID {args.User}) with entity (UID {args.Used}).");
+
+        if (HasComp<PlaceableSurfaceComponent>(uid))
+            return;
+
+        PlayerInsertHeldEntity(uid, args.User, storageComp);
+        // Always handle it, even if insertion fails.
+        // We don't want to trigger any AfterInteract logic here.
+        // Example bug: placing wires if item doesn't fit in backpack.
+        args.Handled = true;
+    }
+
+    /// <summary>
+    /// Sends a message to open the storage UI
+    /// </summary>
+    private void OnActivate(EntityUid uid, StorageComponent storageComp, ActivateInWorldEvent args)
+    {
+        if (args.Handled || _combatMode.IsInCombatMode(args.User) || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked)
+            return;
+
+        OpenStorageUI(uid, args.User, storageComp);
+    }
+
+    /// <summary>
+    /// Specifically for storage implants.
+    /// </summary>
+    private void OnImplantActivate(EntityUid uid, StorageComponent storageComp, OpenStorageImplantEvent args)
+    {
+        // TODO: Make this an action or something.
+        if (args.Handled || !_xformQuery.TryGetComponent(uid, out var xform))
+            return;
+
+        OpenStorageUI(uid, xform.ParentUid, storageComp);
+    }
+
+    /// <summary>
+    /// Allows a user to pick up entities by clicking them, or pick up all entities in a certain radius
+    /// around a click.
+    /// </summary>
+    /// <returns></returns>
+    private void AfterInteract(EntityUid uid, StorageComponent storageComp, AfterInteractEvent args)
+    {
+        if (!args.CanReach)
+            return;
+
+        // Pick up all entities in a radius around the clicked location.
+        // The last half of the if is because carpets exist and this is terrible
+        if (storageComp.AreaInsert && (args.Target == null || !HasComp<ItemComponent>(args.Target.Value)))
+        {
+            var validStorables = new List<EntityUid>();
+
+            foreach (var entity in _entityLookupSystem.GetEntitiesInRange(args.ClickLocation, storageComp.AreaInsertRadius, LookupFlags.Dynamic | LookupFlags.Sundries))
+            {
+                if (entity == args.User
+                    || !_itemQuery.HasComponent(entity)
+                    || !CanInsert(uid, entity, out _, storageComp)
+                    || !_interactionSystem.InRangeUnobstructed(args.User, entity))
+                {
+                    continue;
+                }
+
+                validStorables.Add(entity);
+            }
+
+            //If there's only one then let's be generous
+            if (validStorables.Count > 1)
+            {
+                var doAfterArgs = new DoAfterArgs(EntityManager, args.User, 0.2f * validStorables.Count, new AreaPickupDoAfterEvent(GetNetEntityList(validStorables)), uid, target: uid)
+                {
+                    BreakOnDamage = true,
+                    BreakOnUserMove = true,
+                    NeedHand = true
+                };
+
+                _doAfterSystem.TryStartDoAfter(doAfterArgs);
+            }
+
+            return;
+        }
+
+        // Pick up the clicked entity
+        if (storageComp.QuickInsert)
+        {
+            if (args.Target is not { Valid: true } target)
+                return;
+
+            if (_containerSystem.IsEntityInContainer(target)
+                || target == args.User
+                || !HasComp<ItemComponent>(target))
+            {
+                return;
+            }
+
+            if (TryComp<TransformComponent>(uid, out var transformOwner) && TryComp<TransformComponent>(target, out var transformEnt))
+            {
+                var parent = transformOwner.ParentUid;
+
+                var position = EntityCoordinates.FromMap(
+                    parent.IsValid() ? parent : uid,
+                    transformEnt.MapPosition,
+                    _transform
+                );
+
+                if (PlayerInsertEntityInWorld(uid, args.User, target, storageComp))
+                {
+                    RaiseNetworkEvent(new AnimateInsertingEntitiesEvent(GetNetEntity(uid),
+                        new List<NetEntity> { GetNetEntity(target) },
+                        new List<NetCoordinates> { GetNetCoordinates(position) },
+                        new List<Angle> { transformOwner.LocalRotation }));
+                }
+            }
+        }
+    }
+
+    private void OnDoAfter(EntityUid uid, StorageComponent component, AreaPickupDoAfterEvent args)
+    {
+        if (args.Handled || args.Cancelled)
+            return;
+
+        var successfullyInserted = new List<EntityUid>();
+        var successfullyInsertedPositions = new List<EntityCoordinates>();
+        var successfullyInsertedAngles = new List<Angle>();
+        _xformQuery.TryGetComponent(uid, out var xform);
+
+        foreach (var netEntity in args.Entities)
+        {
+            var entity = GetEntity(netEntity);
+
+            // Check again, situation may have changed for some entities, but we'll still pick up any that are valid
+            if (_containerSystem.IsEntityInContainer(entity)
+                || entity == args.Args.User
+                || !_itemQuery.HasComponent(entity))
+                continue;
+
+            if (xform == null ||
+                !_xformQuery.TryGetComponent(entity, out var targetXform) ||
+                targetXform.MapID != xform.MapID)
+            {
+                continue;
+            }
+
+            var position = EntityCoordinates.FromMap(
+                xform.ParentUid.IsValid() ? xform.ParentUid : uid,
+                new MapCoordinates(_transform.GetWorldPosition(targetXform), targetXform.MapID),
+                _transform
+            );
+
+            var angle = targetXform.LocalRotation;
+
+            if (PlayerInsertEntityInWorld(uid, args.Args.User, entity, component))
+            {
+                successfullyInserted.Add(entity);
+                successfullyInsertedPositions.Add(position);
+                successfullyInsertedAngles.Add(angle);
+            }
+        }
+
+        // If we picked up atleast one thing, play a sound and do a cool animation!
+        if (successfullyInserted.Count > 0)
+        {
+            Audio.PlayPvs(component.StorageInsertSound, uid);
+            RaiseNetworkEvent(new AnimateInsertingEntitiesEvent(
+                GetNetEntity(uid),
+                GetNetEntityList(successfullyInserted),
+                GetNetCoordinatesList(successfullyInsertedPositions),
+                successfullyInsertedAngles));
+        }
+
+        args.Handled = true;
+    }
+
+    private void OnDestroy(EntityUid uid, StorageComponent storageComp, DestructionEventArgs args)
+    {
+        var coordinates = _transform.GetMoverCoordinates(uid);
+
+        // Being destroyed so need to recalculate.
+        _containerSystem.EmptyContainer(storageComp.Container, destination: coordinates);
+    }
+
+    /// <summary>
+    ///     This function gets called when the user clicked on an item in the storage UI. This will either place the
+    ///     item in the user's hand if it is currently empty, or interact with the item using the user's currently
+    ///     held item.
+    /// </summary>
+    private void OnInteractWithItem(EntityUid uid, StorageComponent storageComp, StorageInteractWithItemEvent args)
+    {
+        if (args.Session.AttachedEntity is not EntityUid player)
+            return;
+
+        var entity = GetEntity(args.InteractedItemUID);
+
+        if (!Exists(entity))
+        {
+            Log.Error($"Player {args.Session} interacted with non-existent item {args.InteractedItemUID} stored in {ToPrettyString(uid)}");
+            return;
+        }
+
+        if (!_actionBlockerSystem.CanInteract(player, entity) || !storageComp.Container.Contains(entity))
+            return;
+
+        // Does the player have hands?
+        if (!TryComp(player, out HandsComponent? hands) || hands.Count == 0)
+            return;
+
+        // If the user's active hand is empty, try pick up the item.
+        if (hands.ActiveHandEntity == null)
+        {
+            if (_sharedHandsSystem.TryPickupAnyHand(player, entity, handsComp: hands)
+                && storageComp.StorageRemoveSound != null)
+                Audio.PlayPredicted(storageComp.StorageRemoveSound, uid, player);
+            {
+                return;
+            }
+        }
+
+        // Else, interact using the held item
+        _interactionSystem.InteractUsing(player, hands.ActiveHandEntity.Value, entity, Transform(entity).Coordinates, checkCanInteract: false);
+    }
+
+    private void OnInsertItemMessage(EntityUid uid, StorageComponent storageComp, StorageComponent.StorageInsertItemMessage args)
+    {
+        if (args.Session.AttachedEntity == null)
+            return;
+
+        PlayerInsertHeldEntity(uid, args.Session.AttachedEntity.Value, storageComp);
+    }
+
+    private void OnBoundUIOpen(EntityUid uid, StorageComponent storageComp, BoundUIOpenedEvent args)
+    {
+        if (!storageComp.IsUiOpen)
+        {
+            storageComp.IsUiOpen = true;
+            UpdateStorageVisualization(uid, storageComp);
+        }
+    }
+
+    private void OnStorageItemInserted(EntityUid uid, StorageComponent component, EntInsertedIntoContainerMessage args)
+    {
+        UpdateStorage(uid, component);
+    }
+
+    private void OnStorageItemRemoved(EntityUid uid, StorageComponent storageComp, EntRemovedFromContainerMessage args)
+    {
+        UpdateStorage(uid, storageComp);
+    }
+
+    protected void UpdateStorageVisualization(EntityUid uid, StorageComponent storageComp)
+    {
+        if (!TryComp<AppearanceComponent>(uid, out var appearance))
+            return;
+
+        _appearance.SetData(uid, StorageVisuals.Open, storageComp.IsUiOpen, appearance);
+        _appearance.SetData(uid, SharedBagOpenVisuals.BagState, storageComp.IsUiOpen ? SharedBagState.Open : SharedBagState.Closed);
+
+        if (HasComp<ItemCounterComponent>(uid))
+            _appearance.SetData(uid, StackVisuals.Hide, !storageComp.IsUiOpen);
+    }
+
+    public void RecalculateStorageUsed(StorageComponent storageComp)
+    {
+        storageComp.StorageUsed = 0;
+
+        foreach (var entity in storageComp.Container.ContainedEntities)
+        {
+            if (!_itemQuery.TryGetComponent(entity, out var itemComp))
+                continue;
+
+            var size = itemComp.Size;
+            storageComp.StorageUsed += size;
+        }
+    }
+
+    public int GetAvailableSpace(EntityUid uid, StorageComponent? component = null)
+    {
+        if (!Resolve(uid, ref component))
+            return 0;
+
+        return component.StorageCapacityMax - component.StorageUsed;
+    }
+
+    /// <summary>
+    ///     Move entities from one storage to another.
+    /// </summary>
+    public void TransferEntities(EntityUid source, EntityUid target, EntityUid? user = null,
+        StorageComponent? sourceComp = null, LockComponent? sourceLock = null,
+        StorageComponent? targetComp = null, LockComponent? targetLock = null)
+    {
+        if (!Resolve(source, ref sourceComp) || !Resolve(target, ref targetComp))
+            return;
+
+        var entities = sourceComp.Container.ContainedEntities;
+        if (entities.Count == 0)
+            return;
+
+        if (Resolve(source, ref sourceLock, false) && sourceLock.Locked
+            || Resolve(target, ref targetLock, false) && targetLock.Locked)
+            return;
+
+        foreach (var entity in entities.ToArray())
+        {
+            Insert(target, entity, user, targetComp, playSound: false);
+        }
+
+        Audio.PlayPredicted(sourceComp.StorageInsertSound, target, user);
+    }
+
+    /// <summary>
+    ///     Verifies if an entity can be stored and if it fits
+    /// </summary>
+    /// <param name="uid">The entity to check</param>
+    /// <param name="reason">If returning false, the reason displayed to the player</param>
+    /// <returns>true if it can be inserted, false otherwise</returns>
+    public bool CanInsert(EntityUid uid, EntityUid insertEnt, out string? reason, StorageComponent? storageComp = null)
+    {
+        if (!Resolve(uid, ref storageComp))
+        {
+            reason = null;
+            return false;
+        }
+
+        if (TryComp(insertEnt, out TransformComponent? transformComp) && transformComp.Anchored)
+        {
+            reason = "comp-storage-anchored-failure";
+            return false;
+        }
+
+        if (storageComp.Whitelist?.IsValid(insertEnt, EntityManager) == false)
+        {
+            reason = "comp-storage-invalid-container";
+            return false;
+        }
+
+        if (storageComp.Blacklist?.IsValid(insertEnt, EntityManager) == true)
+        {
+            reason = "comp-storage-invalid-container";
+            return false;
+        }
+
+        if (TryComp(insertEnt, out StorageComponent? storage) &&
+            storage.StorageCapacityMax >= storageComp.StorageCapacityMax)
+        {
+            reason = "comp-storage-insufficient-capacity";
+            return false;
+        }
+
+        if (TryComp(insertEnt, out ItemComponent? itemComp) &&
+            itemComp.Size > storageComp.StorageCapacityMax - storageComp.StorageUsed)
+        {
+            reason = "comp-storage-insufficient-capacity";
+            return false;
+        }
+
+        reason = null;
+        return true;
+    }
+
+    /// <summary>
+    ///     Inserts into the storage container
+    /// </summary>
+    /// <returns>true if the entity was inserted, false otherwise</returns>
+    public bool Insert(EntityUid uid, EntityUid insertEnt, EntityUid? user = null, StorageComponent? storageComp = null, bool playSound = true)
+    {
+        if (!Resolve(uid, ref storageComp) || !CanInsert(uid, insertEnt, out _, storageComp))
+            return false;
+
+        /*
+         * 1. If the inserted thing is stackable then try to stack it to existing stacks
+         * 2. If anything remains insert whatever is possible.
+         * 3. If insertion is not possible then leave the stack as is.
+         * At either rate still play the insertion sound
+         *
+         * For now we just treat items as always being the same size regardless of stack count.
+         */
+
+        // If it's stackable then prefer to stack it
+        if (_stackQuery.TryGetComponent(insertEnt, out var insertStack))
+        {
+            var toInsertCount = insertStack.Count;
+
+            foreach (var ent in storageComp.Container.ContainedEntities)
+            {
+                if (!_stackQuery.TryGetComponent(ent, out var containedStack) || !insertStack.StackTypeId.Equals(containedStack.StackTypeId))
+                    continue;
+
+                if (!_stack.TryAdd(insertEnt, ent, insertStack, containedStack))
+                    continue;
+
+                var remaining = insertStack.Count;
+                toInsertCount -= toInsertCount - remaining;
+
+                if (remaining > 0)
+                    continue;
+
+                break;
+            }
+
+            // Still stackable remaining
+            if (insertStack.Count > 0)
+            {
+                // Try to insert it as a new stack.
+                if (TryComp(insertEnt, out ItemComponent? itemComp) &&
+                    itemComp.Size > storageComp.StorageCapacityMax - storageComp.StorageUsed ||
+                    !storageComp.Container.Insert(insertEnt))
+                {
+                    // If we also didn't do any stack fills above then just end
+                    // otherwise play sound and update UI anyway.
+                    if (toInsertCount == insertStack.Count)
+                        return false;
+                }
+            }
+        }
+        // Non-stackable but no insertion for reasons.
+        else if (!storageComp.Container.Insert(insertEnt))
+        {
+            return false;
+        }
+
+        if (playSound && storageComp.StorageInsertSound is not null)
+            Audio.PlayPredicted(storageComp.StorageInsertSound, uid, user);
+
+        return true;
+    }
+
+    /// <summary>
+    ///     Inserts an entity into storage from the player's active hand
+    /// </summary>
+    /// <param name="player">The player to insert an entity from</param>
+    /// <returns>true if inserted, false otherwise</returns>
+    public bool PlayerInsertHeldEntity(EntityUid uid, EntityUid player, StorageComponent? storageComp = null)
+    {
+        if (!Resolve(uid, ref storageComp) || !TryComp(player, out HandsComponent? hands) || hands.ActiveHandEntity == null)
+            return false;
+
+        var toInsert = hands.ActiveHandEntity;
+
+        if (!CanInsert(uid, toInsert.Value, out var reason, storageComp))
+        {
+            _popupSystem.PopupClient(reason ?? Loc.GetString("comp-storage-cant-insert"), uid, player);
+            return false;
+        }
+
+        if (!_sharedHandsSystem.TryDrop(player, toInsert.Value, handsComp: hands))
+        {
+            _popupSystem.PopupClient(Loc.GetString("comp-storage-cant-drop"), uid, player);
+            return false;
+        }
+
+        return PlayerInsertEntityInWorld(uid, player, toInsert.Value, storageComp);
+    }
+
+    /// <summary>
+    ///     Inserts an Entity (<paramref name="toInsert"/>) in the world into storage, informing <paramref name="player"/> if it fails.
+    ///     <paramref name="toInsert"/> is *NOT* held, see <see cref="PlayerInsertHeldEntity(Robust.Shared.GameObjects.EntityUid)"/>.
+    /// </summary>
+    /// <param name="player">The player to insert an entity with</param>
+    /// <returns>true if inserted, false otherwise</returns>
+    public bool PlayerInsertEntityInWorld(EntityUid uid, EntityUid player, EntityUid toInsert, StorageComponent? storageComp = null)
+    {
+        if (!Resolve(uid, ref storageComp) || !_sharedInteractionSystem.InRangeUnobstructed(player, uid))
+            return false;
+
+        if (!Insert(uid, toInsert, player, storageComp))
+        {
+            _popupSystem.PopupClient(Loc.GetString("comp-storage-cant-insert"), uid, player);
+            return false;
+        }
+        return true;
+    }
+}
diff --git a/Content.Shared/Storage/SharedStorageComponent.cs b/Content.Shared/Storage/SharedStorageComponent.cs
deleted file mode 100644 (file)
index 4573af6..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-using Robust.Shared.GameStates;
-using Robust.Shared.Map;
-using Robust.Shared.Serialization;
-
-namespace Content.Shared.Storage
-{
-    [NetworkedComponent()]
-    public abstract partial class SharedStorageComponent : Component
-    {
-        [Serializable, NetSerializable]
-        public sealed class StorageBoundUserInterfaceState : BoundUserInterfaceState
-        {
-            public readonly List<NetEntity> StoredEntities;
-            public readonly int StorageSizeUsed;
-            public readonly int StorageCapacityMax;
-
-            public StorageBoundUserInterfaceState(List<NetEntity> storedEntities, int storageSizeUsed, int storageCapacityMax)
-            {
-                StoredEntities = storedEntities;
-                StorageSizeUsed = storageSizeUsed;
-                StorageCapacityMax = storageCapacityMax;
-            }
-        }
-
-        [Serializable, NetSerializable]
-        public sealed class StorageInsertItemMessage : BoundUserInterfaceMessage
-        {
-        }
-
-        [Serializable, NetSerializable]
-        public sealed class StorageInteractWithItemEvent : BoundUserInterfaceMessage
-        {
-            public readonly NetEntity InteractedItemUID;
-            public StorageInteractWithItemEvent(NetEntity interactedItemUID)
-            {
-                InteractedItemUID = interactedItemUID;
-            }
-        }
-
-        [Serializable, NetSerializable]
-        public enum StorageUiKey
-        {
-            Key,
-        }
-
-        public abstract IReadOnlyList<EntityUid>? StoredEntities { get; }
-
-        /// <summary>
-        ///     Removes from the storage container and updates the stored value
-        /// </summary>
-        /// <param name="entity">The entity to remove</param>
-        /// <returns>True if no longer in storage, false otherwise</returns>
-        public abstract bool Remove(EntityUid entity);
-    }
-
-    /// <summary>
-    /// Network event for displaying an animation of entities flying into a storage entity
-    /// </summary>
-    [Serializable, NetSerializable]
-    public sealed class AnimateInsertingEntitiesEvent : EntityEventArgs
-    {
-        public readonly NetEntity Storage;
-        public readonly List<NetEntity> StoredEntities;
-        public readonly List<NetCoordinates> EntityPositions;
-        public readonly List<Angle> EntityAngles;
-
-        public AnimateInsertingEntitiesEvent(NetEntity storage, List<NetEntity> storedEntities, List<NetCoordinates> entityPositions, List<Angle> entityAngles)
-        {
-            Storage = storage;
-            StoredEntities = storedEntities;
-            EntityPositions = entityPositions;
-            EntityAngles = entityAngles;
-        }
-    }
-
-    [NetSerializable]
-    [Serializable]
-    public enum StorageVisuals : byte
-    {
-        Open,
-        HasContents,
-        CanLock,
-        Locked
-    }
-}
diff --git a/Content.Shared/Storage/StorageComponent.cs b/Content.Shared/Storage/StorageComponent.cs
new file mode 100644 (file)
index 0000000..0a92436
--- /dev/null
@@ -0,0 +1,135 @@
+using Content.Shared.Whitelist;
+using Robust.Shared.Audio;
+using Robust.Shared.Containers;
+using Robust.Shared.GameStates;
+using Robust.Shared.Map;
+using Robust.Shared.Serialization;
+
+namespace Content.Shared.Storage
+{
+    /// <summary>
+    /// Handles generic storage with window, such as backpacks.
+    /// </summary>
+    [RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+    public sealed partial class StorageComponent : Component
+    {
+        // TODO: This fucking sucks
+        [ViewVariables(VVAccess.ReadWrite), DataField("isOpen"), AutoNetworkedField]
+        public bool IsUiOpen;
+
+        [ViewVariables]
+        public Container Container = default!;
+
+        // TODO: Make area insert its own component.
+        [DataField("quickInsert")]
+        public bool QuickInsert; // Can insert storables by "attacking" them with the storage entity
+
+        [DataField("clickInsert")]
+        public bool ClickInsert = true; // Can insert stuff by clicking the storage entity with it
+
+        [DataField("areaInsert")]
+        public bool AreaInsert;  // "Attacking" with the storage entity causes it to insert all nearby storables after a delay
+
+        [DataField("areaInsertRadius")]
+        public int AreaInsertRadius = 1;
+
+        /// <summary>
+        /// Whitelist for entities that can go into the storage.
+        /// </summary>
+        [DataField("whitelist")]
+        public EntityWhitelist? Whitelist;
+
+        /// <summary>
+        /// Blacklist for entities that can go into storage.
+        /// </summary>
+        [DataField("blacklist")]
+        public EntityWhitelist? Blacklist;
+
+        /// <summary>
+        /// How much storage is currently being used by contained entities.
+        /// </summary>
+        [ViewVariables, DataField("storageUsed"), AutoNetworkedField]
+        public int StorageUsed;
+
+        /// <summary>
+        /// Maximum capacity for storage.
+        /// </summary>
+        [DataField("capacity"), AutoNetworkedField]
+        public int StorageCapacityMax = 10000;
+
+        /// <summary>
+        /// Sound played whenever an entity is inserted into storage.
+        /// </summary>
+        [DataField("storageInsertSound")]
+        public SoundSpecifier? StorageInsertSound = new SoundCollectionSpecifier("storageRustle");
+
+        /// <summary>
+        /// Sound played whenever an entity is removed from storage.
+        /// </summary>
+        [DataField("storageRemoveSound")]
+        public SoundSpecifier? StorageRemoveSound;
+
+        /// <summary>
+        /// Sound played whenever the storage window is opened.
+        /// </summary>
+        [DataField("storageOpenSound")]
+        public SoundSpecifier? StorageOpenSound = new SoundCollectionSpecifier("storageRustle");
+
+        /// <summary>
+        /// Sound played whenever the storage window is closed.
+        /// </summary>
+        [DataField("storageCloseSound")]
+        public SoundSpecifier? StorageCloseSound;
+
+        [Serializable, NetSerializable]
+        public sealed class StorageInsertItemMessage : BoundUserInterfaceMessage
+        {
+        }
+
+        [Serializable, NetSerializable]
+        public enum StorageUiKey
+        {
+            Key,
+        }
+    }
+
+    [Serializable, NetSerializable]
+    public sealed class StorageInteractWithItemEvent : BoundUserInterfaceMessage
+    {
+        public readonly NetEntity InteractedItemUID;
+        public StorageInteractWithItemEvent(NetEntity interactedItemUID)
+        {
+            InteractedItemUID = interactedItemUID;
+        }
+    }
+
+    /// <summary>
+    /// Network event for displaying an animation of entities flying into a storage entity
+    /// </summary>
+    [Serializable, NetSerializable]
+    public sealed class AnimateInsertingEntitiesEvent : EntityEventArgs
+    {
+        public readonly NetEntity Storage;
+        public readonly List<NetEntity> StoredEntities;
+        public readonly List<NetCoordinates> EntityPositions;
+        public readonly List<Angle> EntityAngles;
+
+        public AnimateInsertingEntitiesEvent(NetEntity storage, List<NetEntity> storedEntities, List<NetCoordinates> entityPositions, List<Angle> entityAngles)
+        {
+            Storage = storage;
+            StoredEntities = storedEntities;
+            EntityPositions = entityPositions;
+            EntityAngles = entityAngles;
+        }
+    }
+
+    [NetSerializable]
+    [Serializable]
+    public enum StorageVisuals : byte
+    {
+        Open,
+        HasContents,
+        CanLock,
+        Locked
+    }
+}
index 1f669944e1f95d93a2a34ebd60b0ddf5fa328b48..e86c09de2ae632f19c6528daf261a1cd8bf5524a 100644 (file)
@@ -18,7 +18,7 @@
       - id: BoxBeanbag
         amount: 2
       - id: RagItem
-        amound: 2
+        amount: 2
 
 #- type: entity
 #  id: LockerFormalFilled
index 0c400828d812e42d04e00fb173ce4f1c3daf9481..b37d3fd9745f23643f81a519adb6a9640d9740ef 100644 (file)
@@ -23,8 +23,6 @@
   components:
   - type: Storage
     capacity: 40
-    equipSound:
-      path: /Audio/Items/belt_equip.ogg
   - type: ContainerContainer
     containers:
       storagebase: !type:Container
index aaff696c56415abd4ca46f48e2161d9abd9a8a57..62366e0b1420b3aa04cb9c1371ad3f5a9bd9aebb 100644 (file)
     interfaces:
     - key: enum.StrippingUiKey.Key
       type: StrippableBoundUserInterface
-    radius: 1.2
-    energy: 2
-    color: "#4faffb"
   - type: GhostRole
     prob: 0.25
     name: ghost-role-information-space-kangaroo-name
index cac3e0ac580310bde82192266acc556f7ea70222..8c3b5aea8b5d34cd5947ce8ec7c9c2c338b78215 100644 (file)
@@ -19,7 +19,6 @@
   - type: Item
   - type: Storage
     capacity: 18
-    size: 5
     whitelist:
       tags:
         - Dice
index 621018d7f70375a6b2b15a4958a8244dad7a60a9..6a2d569bf46e3a58b8ecc003b0d7e0696722208a 100644 (file)
     size: 5
   - type: Storage
     capacity: 10
-    size: 10
     whitelist:
       tags:
         - Document
index be69667c3de224608718026ab1e37f06dc9c12f4..22faf499f11aacd2a214cd94e80ad22f3b6ed490 100644 (file)
@@ -47,7 +47,6 @@
       - key: enum.StorageUiKey.Key
         type: StorageBoundUserInterface
     - type: Storage
-      popup: false
       capacity: 30
     - type: TileFrictionModifier
       modifier: 0.4 # makes it slide