diff --git a/Content.Client/Interactable/InteractionSystem.cs b/Content.Client/Interactable/InteractionSystem.cs index 2abb966549..bb8ca89576 100644 --- a/Content.Client/Interactable/InteractionSystem.cs +++ b/Content.Client/Interactable/InteractionSystem.cs @@ -1,7 +1,6 @@ using Content.Client.Storage; using Content.Shared.Interaction; using Robust.Shared.Containers; -using Robust.Shared.GameObjects; namespace Content.Client.Interactable { @@ -15,11 +14,12 @@ namespace Content.Client.Interactable if (!target.TryGetContainer(out var container)) return false; - if (!EntityManager.TryGetComponent(container.Owner, out ClientStorageComponent storage)) + if (!TryComp(container.Owner, out ClientStorageComponent? storage)) return false; // we don't check if the user can access the storage entity itself. This should be handed by the UI system. - return storage.UIOpen; + // Need to return if UI is open or not + return true; } } } diff --git a/Content.Client/Storage/ClientStorageComponent.cs b/Content.Client/Storage/ClientStorageComponent.cs index e5eab84e3e..f1042eb90c 100644 --- a/Content.Client/Storage/ClientStorageComponent.cs +++ b/Content.Client/Storage/ClientStorageComponent.cs @@ -1,23 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; using Content.Client.Animations; -using Content.Client.Hands; -using Content.Client.Items.Components; -using Content.Client.Items.Managers; -using Content.Client.UserInterface.Controls; using Content.Shared.DragDrop; using Content.Shared.Storage; -using Robust.Client.GameObjects; -using Robust.Client.Graphics; -using Robust.Client.Player; -using Robust.Client.UserInterface; -using Robust.Client.UserInterface.Controls; -using Robust.Client.UserInterface.CustomControls; -using Robust.Shared.Input; -using static Robust.Client.UserInterface.Control; -using static Robust.Client.UserInterface.Controls.BaseButton; -using static Robust.Client.UserInterface.Controls.BoxContainer; namespace Content.Client.Storage { @@ -27,71 +10,10 @@ namespace Content.Client.Storage [RegisterComponent] public sealed class ClientStorageComponent : SharedStorageComponent, IDraggable { - [Dependency] private readonly IItemSlotManager _itemSlotManager = default!; - [Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly IEntityManager _entityManager = default!; - private List _storedEntities = new(); - private int StorageSizeUsed; - private int StorageCapacityMax; - private StorageWindow? _window; - public bool UIOpen => _window?.IsOpen ?? false; - public override IReadOnlyList StoredEntities => _storedEntities; - private StorageWindow GetOrCreateWindow() - { - if (_window == null) - { - _window = new StorageWindow(this, _playerManager, _entityManager) - { - Title = _entityManager.GetComponent(Owner).EntityName - }; - - _window.EntityList.GenerateItem += GenerateButton; - _window.EntityList.ItemPressed += Interact; - } - - return _window; - } - - protected override void OnRemove() - { - if (_window is { Disposed: false }) - { - _window.EntityList.GenerateItem -= GenerateButton; - _window.EntityList.ItemPressed -= Interact; - _window.Dispose(); - } - - _window = null; - base.OnRemove(); - } - - public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) - { - base.HandleComponentState(curState, nextState); - - if (curState is not StorageComponentState state) - { - return; - } - - _storedEntities = state.StoredEntities.ToList(); - } - - /// - /// Copies received values from server about contents of storage container - /// - /// - public void HandleStorageMessage(StorageHeldItemsEvent storageState) - { - _storedEntities = storageState.StoredEntities.ToList(); - StorageSizeUsed = storageState.StorageSizeUsed; - StorageCapacityMax = storageState.StorageSizeMax; - GetOrCreateWindow().BuildEntityList(storageState.StoredEntities.ToList()); - } - /// /// Animate the newly stored entities in flying towards this storage's position /// @@ -110,190 +32,9 @@ namespace Content.Client.Storage } } - /// - /// Opens the storage UI if closed. Closes it if opened. - /// - public void ToggleUI() - { - var window = GetOrCreateWindow(); - - if (window.IsOpen) - window.Close(); - else - window.OpenCentered(); - } - - public void CloseUI() - { - _window?.Close(); - } - - /// - /// Function for clicking one of the stored entity buttons in the UI, tells server to remove that entity - /// - /// - public void Interact(ButtonEventArgs args, EntityUid entity) - { - if (args.Event.Function == EngineKeyFunctions.UIClick) - { - _entityManager.EntityNetManager?.SendSystemNetworkMessage(new RemoveEntityEvent(Owner, entity)); - args.Event.Handle(); - } - else if (_entityManager.EntityExists(entity)) - { - _itemSlotManager.OnButtonPressed(args.Event, entity); - } - } - public override bool Remove(EntityUid entity) { - if (_storedEntities.Remove(entity)) - { - Dirty(); - return true; - } - return false; } - - /// - /// Button created for each entity that represents that item in the storage UI, with a texture, and name and size label - /// - public void GenerateButton(EntityUid entity, EntityContainerButton button) - { - if (!_entityManager.EntityExists(entity)) - return; - - _entityManager.TryGetComponent(entity, out ISpriteComponent? sprite); - _entityManager.TryGetComponent(entity, out ItemComponent? item); - - button.AddChild(new BoxContainer - { - Orientation = LayoutOrientation.Horizontal, - SeparationOverride = 2, - Children = - { - new SpriteView - { - HorizontalAlignment = HAlignment.Left, - VerticalAlignment = VAlignment.Center, - MinSize = new Vector2(32.0f, 32.0f), - OverrideDirection = Direction.South, - Sprite = sprite - }, - new Label - { - HorizontalExpand = true, - ClipText = true, - Text = _entityManager.GetComponent(entity).EntityName - }, - new Label - { - Align = Label.AlignMode.Right, - Text = item?.Size.ToString() ?? Loc.GetString("no-item-size") - } - } - }); - - button.EnableAllKeybinds = true; - } - - /// - /// GUI class for client storage component - /// - private sealed class StorageWindow : DefaultWindow - { - private Control _vBox; - private readonly Label _information; - public readonly EntityListDisplay EntityList; - public readonly ClientStorageComponent StorageEntity; - - private readonly StyleBoxFlat _hoveredBox = new() { BackgroundColor = Color.Black.WithAlpha(0.35f) }; - private readonly StyleBoxFlat _unHoveredBox = new() { BackgroundColor = Color.Black.WithAlpha(0.0f) }; - - public StorageWindow(ClientStorageComponent storageEntity, IPlayerManager players, IEntityManager entities) - { - StorageEntity = storageEntity; - SetSize = (200, 320); - Title = Loc.GetString("comp-storage-window-title"); - RectClipContent = true; - - var containerButton = new ContainerButton - { - Name = "StorageContainerButton", - MouseFilter = MouseFilterMode.Pass, - }; - Contents.AddChild(containerButton); - - var innerContainerButton = new PanelContainer - { - PanelOverride = _unHoveredBox, - }; - - containerButton.AddChild(innerContainerButton); - containerButton.OnPressed += args => - { - var controlledEntity = players.LocalPlayer?.ControlledEntity; - - if (entities.HasComponent(controlledEntity)) - { - entities.EntityNetManager?.SendSystemNetworkMessage(new InsertEntityEvent(storageEntity.Owner)); - } - }; - - _vBox = new BoxContainer() - { - Orientation = LayoutOrientation.Vertical, - MouseFilter = MouseFilterMode.Ignore, - }; - containerButton.AddChild(_vBox); - _information = new Label - { - Text = Loc.GetString("comp-storage-window-volume", ("itemCount", 0), ("usedVolume", 0), ("maxVolume", 0)), - VerticalAlignment = VAlignment.Center - }; - _vBox.AddChild(_information); - - EntityList = new EntityListDisplay - { - Name = "EntityListContainer", - }; - _vBox.AddChild(EntityList); - EntityList.OnMouseEntered += _ => - { - innerContainerButton.PanelOverride = _hoveredBox; - }; - - EntityList.OnMouseExited += _ => - { - innerContainerButton.PanelOverride = _unHoveredBox; - }; - } - - public override void Close() - { - IoCManager.Resolve().EntityNetManager?.SendSystemNetworkMessage(new CloseStorageUIEvent(StorageEntity.Owner)); - base.Close(); - } - - /// - /// Loops through stored entities creating buttons for each, updates information labels - /// - public void BuildEntityList(List entityUids) - { - EntityList.PopulateList(entityUids); - - //Sets information about entire storage container current capacity - if (StorageEntity.StorageCapacityMax != 0) - { - _information.Text = Loc.GetString("comp-storage-window-volume", ("itemCount", entityUids.Count), - ("usedVolume", StorageEntity.StorageSizeUsed), ("maxVolume", StorageEntity.StorageCapacityMax)); - } - else - { - _information.Text = Loc.GetString("comp-storage-window-volume-unlimited", ("itemCount", entityUids.Count)); - } - } - } } } diff --git a/Content.Client/Storage/StorageBoundUserInterface.cs b/Content.Client/Storage/StorageBoundUserInterface.cs new file mode 100644 index 0000000000..06bd6e277f --- /dev/null +++ b/Content.Client/Storage/StorageBoundUserInterface.cs @@ -0,0 +1,87 @@ +using Content.Client.Storage.UI; +using Robust.Client.GameObjects; +using Robust.Client.UserInterface.Controls; +using Robust.Shared.Input; +using Content.Client.Items.Managers; +using JetBrains.Annotations; +using static Content.Shared.Storage.SharedStorageComponent; + +namespace Content.Client.Storage +{ + [UsedImplicitly] + public sealed class StorageBoundUserInterface : BoundUserInterface + { + [ViewVariables] private StorageWindow? _window; + + public StorageBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) + { + } + + protected override void Open() + { + base.Open(); + + if (_window == null) + { + var entMan = IoCManager.Resolve(); + _window = new StorageWindow(entMan) {Title = entMan.GetComponent(Owner.Owner).EntityName}; + + _window.EntityList.GenerateItem += _window.GenerateButton; + _window.EntityList.ItemPressed += InteractWithItem; + _window.StorageContainerButton.OnPressed += TouchedContainerButton; + + _window.OnClose += Close; + _window.OpenCentered(); + } + else + { + _window.Open(); + } + } + + public void InteractWithItem(BaseButton.ButtonEventArgs args, EntityUid entity) + { + if (args.Event.Function == EngineKeyFunctions.UIClick) + { + SendMessage(new StorageRemoveItemMessage(entity)); + } + else if (IoCManager.Resolve().EntityExists(entity)) + { + IoCManager.Resolve().OnButtonPressed(args.Event, entity); + } + } + + 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); + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + if (!disposing) + return; + + if (_window != null) + { + _window.EntityList.GenerateItem -= _window.GenerateButton; + _window.EntityList.ItemPressed -= InteractWithItem; + _window.StorageContainerButton.OnPressed -= TouchedContainerButton; + _window.OnClose -= Close; + } + + _window?.Dispose(); + _window = null; + } + } +} diff --git a/Content.Client/Storage/StorageSystem.cs b/Content.Client/Storage/StorageSystem.cs index 75ce2fa8c3..ed60a46188 100644 --- a/Content.Client/Storage/StorageSystem.cs +++ b/Content.Client/Storage/StorageSystem.cs @@ -1,4 +1,5 @@ using Content.Shared.Storage; +using Content.Client.Animations; namespace Content.Client.Storage; @@ -9,41 +10,28 @@ public sealed class StorageSystem : EntitySystem { base.Initialize(); - SubscribeNetworkEvent(OnStorageHeldItems); - SubscribeNetworkEvent(OnOpenStorageUI); - SubscribeNetworkEvent(OnCloseStorageUI); - SubscribeNetworkEvent(OnAnimateInsertingEntities); + SubscribeNetworkEvent(HandleAnimatingInsertingEntities); } - private void OnStorageHeldItems(StorageHeldItemsEvent ev) + /// + /// Animate the newly stored entities in flying towards this storage's position + /// + /// + public void HandleAnimatingInsertingEntities(AnimateInsertingEntitiesEvent msg) { - if (TryComp(ev.Storage, out var storage)) - { - storage.HandleStorageMessage(ev); - } - } + if (!TryComp(msg.Storage, out ClientStorageComponent? storage)) + return; - private void OnOpenStorageUI(OpenStorageUIEvent ev) - { - if (TryComp(ev.Storage, out var storage)) - { - storage.ToggleUI(); - } - } + TryComp(msg.Storage, out TransformComponent? transformComp); - private void OnCloseStorageUI(CloseStorageUIEvent ev) - { - if (TryComp(ev.Storage, out var storage)) + for (var i = 0; msg.StoredEntities.Count > i; i++) { - storage.CloseUI(); - } - } - - private void OnAnimateInsertingEntities(AnimateInsertingEntitiesEvent ev) - { - if (TryComp(ev.Storage, out var storage)) - { - storage.HandleAnimatingInsertingEntities(ev); + var entity = msg.StoredEntities[i]; + var initialPosition = msg.EntityPositions[i]; + if (EntityManager.EntityExists(entity) && transformComp != null) + { + ReusableAnimations.AnimateEntityPickup(entity, initialPosition, transformComp.LocalPosition, EntityManager); + } } } } diff --git a/Content.Client/Storage/UI/StorageWindow.cs b/Content.Client/Storage/UI/StorageWindow.cs new file mode 100644 index 0000000000..b8629eaa55 --- /dev/null +++ b/Content.Client/Storage/UI/StorageWindow.cs @@ -0,0 +1,142 @@ +using Robust.Client.GameObjects; +using Robust.Client.Graphics; +using Robust.Client.UserInterface.Controls; +using Robust.Client.UserInterface.CustomControls; +using Content.Client.Items.Components; +using Content.Client.UserInterface.Controls; +using Robust.Client.UserInterface; +using static Robust.Client.UserInterface.Controls.BoxContainer; +using static Content.Shared.Storage.SharedStorageComponent; + +namespace Content.Client.Storage.UI +{ + /// + /// GUI class for client storage component + /// + public sealed class StorageWindow : DefaultWindow + { + private IEntityManager _entityManager; + + private readonly Label _information; + public readonly ContainerButton StorageContainerButton; + public readonly EntityListDisplay EntityList; + private readonly StyleBoxFlat _hoveredBox = new() { BackgroundColor = Color.Black.WithAlpha(0.35f) }; + private readonly StyleBoxFlat _unHoveredBox = new() { BackgroundColor = Color.Black.WithAlpha(0.0f) }; + + public StorageWindow(IEntityManager entityManager) + { + _entityManager = entityManager; + SetSize = (200, 320); + Title = Loc.GetString("comp-storage-window-title"); + RectClipContent = true; + + StorageContainerButton = new ContainerButton + { + Name = "StorageContainerButton", + MouseFilter = MouseFilterMode.Pass, + }; + + Contents.AddChild(StorageContainerButton); + + var innerContainerButton = new PanelContainer + { + PanelOverride = _unHoveredBox, + }; + + StorageContainerButton.AddChild(innerContainerButton); + + Control vBox = new BoxContainer() + { + Orientation = LayoutOrientation.Vertical, + MouseFilter = MouseFilterMode.Ignore, + }; + + StorageContainerButton.AddChild(vBox); + + _information = new Label + { + Text = Loc.GetString("comp-storage-window-volume", ("itemCount", 0), ("usedVolume", 0), ("maxVolume", 0)), + VerticalAlignment = VAlignment.Center + }; + + vBox.AddChild(_information); + + EntityList = new EntityListDisplay + { + Name = "EntityListContainer", + }; + + vBox.AddChild(EntityList); + + EntityList.OnMouseEntered += _ => + { + innerContainerButton.PanelOverride = _hoveredBox; + }; + + EntityList.OnMouseExited += _ => + { + innerContainerButton.PanelOverride = _unHoveredBox; + }; + } + + /// + /// Loops through stored entities creating buttons for each, updates information labels + /// + public void BuildEntityList(StorageBoundUserInterfaceState state) + { + EntityList.PopulateList(state.StoredEntities); + + //Sets information about entire storage container current capacity + if (state.StorageCapacityMax != 0) + { + _information.Text = Loc.GetString("comp-storage-window-volume", ("itemCount", state.StoredEntities.Count), + ("usedVolume", state.StorageSizeUsed), ("maxVolume", state.StorageCapacityMax)); + } + else + { + _information.Text = Loc.GetString("comp-storage-window-volume-unlimited", ("itemCount", state.StoredEntities.Count)); + } + } + + /// + /// Button created for each entity that represents that item in the storage UI, with a texture, and name and size label + /// + public void GenerateButton(EntityUid entity, EntityContainerButton button) + { + if (!_entityManager.EntityExists(entity)) + return; + + _entityManager.TryGetComponent(entity, out ISpriteComponent? sprite); + _entityManager.TryGetComponent(entity, out ItemComponent? item); + + button.AddChild(new BoxContainer + { + Orientation = LayoutOrientation.Horizontal, + SeparationOverride = 2, + Children = + { + new SpriteView + { + HorizontalAlignment = HAlignment.Left, + VerticalAlignment = VAlignment.Center, + MinSize = new Vector2(32.0f, 32.0f), + OverrideDirection = Direction.South, + Sprite = sprite + }, + new Label + { + HorizontalExpand = true, + ClipText = true, + Text = _entityManager.GetComponent(entity).EntityName + }, + new Label + { + Align = Label.AlignMode.Right, + Text = item?.Size.ToString() ?? Loc.GetString("no-item-size") + } + } + }); + button.EnableAllKeybinds = true; + } + } +} diff --git a/Content.Server/Hands/Systems/HandsSystem.cs b/Content.Server/Hands/Systems/HandsSystem.cs index 74401ee403..859bb1883f 100644 --- a/Content.Server/Hands/Systems/HandsSystem.cs +++ b/Content.Server/Hands/Systems/HandsSystem.cs @@ -5,6 +5,7 @@ using Content.Server.Hands.Components; using Content.Server.Popups; using Content.Server.Stack; using Content.Server.Storage.Components; +using Content.Server.Storage.EntitySystems; using Content.Server.Strip; using Content.Server.Stunnable; using Content.Shared.ActionBlocker; @@ -47,6 +48,7 @@ namespace Content.Server.Hands.Systems [Dependency] private readonly SharedHandsSystem _handsSystem = default!; [Dependency] private readonly PullingSystem _pullingSystem = default!; [Dependency] private readonly ThrowingSystem _throwingSystem = default!; + [Dependency] private readonly StorageSystem _storageSystem = default!; public override void Initialize() { @@ -262,7 +264,7 @@ namespace Content.Server.Hands.Systems if (hands.ActiveHand?.HeldEntity != null) { - storageComponent.PlayerInsertHeldEntity(plyEnt); + _storageSystem.PlayerInsertHeldEntity(slotEntity.Value, plyEnt, storageComponent); } else if (storageComponent.StoredEntities != null) { diff --git a/Content.Server/Interaction/InteractionSystem.cs b/Content.Server/Interaction/InteractionSystem.cs index 8b64e8e15f..47cbab8b18 100644 --- a/Content.Server/Interaction/InteractionSystem.cs +++ b/Content.Server/Interaction/InteractionSystem.cs @@ -1,5 +1,3 @@ -using System.Linq; -using System.Threading.Tasks; using Content.Server.Administration.Logs; using Content.Server.CombatMode; using Content.Server.Hands.Components; @@ -12,7 +10,6 @@ using Content.Shared.Input; using Content.Shared.Interaction; using Content.Shared.Item; using Content.Shared.Pulling.Components; -using Content.Shared.Timing; using Content.Shared.Weapons.Melee; using JetBrains.Annotations; using Robust.Server.GameObjects; @@ -20,6 +17,7 @@ using Robust.Shared.Containers; using Robust.Shared.Input.Binding; using Robust.Shared.Map; using Robust.Shared.Players; +using static Content.Shared.Storage.SharedStorageComponent; namespace Content.Server.Interaction { @@ -32,6 +30,7 @@ namespace Content.Server.Interaction [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!; [Dependency] private readonly PullingSystem _pullSystem = default!; [Dependency] private readonly AdminLogSystem _adminLogSystem = default!; + [Dependency] private readonly UserInterfaceSystem _uiSystem = default!; public override void Initialize() { @@ -71,7 +70,7 @@ namespace Content.Server.Interaction return false; // we don't check if the user can access the storage entity itself. This should be handed by the UI system. - return storage.SubscribedSessions.Contains(actor.PlayerSession); + return _uiSystem.SessionHasOpenUi(container.Owner, StorageUiKey.Key, actor.PlayerSession); } #region Drag drop diff --git a/Content.Server/Inventory/ServerInventorySystem.cs b/Content.Server/Inventory/ServerInventorySystem.cs index 8e61bf6d54..03fba80533 100644 --- a/Content.Server/Inventory/ServerInventorySystem.cs +++ b/Content.Server/Inventory/ServerInventorySystem.cs @@ -1,6 +1,6 @@ -using Content.Server.Atmos; using Content.Server.Clothing.Components; using Content.Server.Storage.Components; +using Content.Server.Storage.EntitySystems; using Content.Server.Temperature.Systems; using Content.Shared.Interaction.Events; using Content.Shared.Inventory; @@ -9,8 +9,10 @@ using InventoryComponent = Content.Shared.Inventory.InventoryComponent; namespace Content.Server.Inventory { - sealed class ServerInventorySystem : InventorySystem + public sealed class ServerInventorySystem : InventorySystem { + [Dependency] private readonly StorageSystem _storageSystem = default!; + public override void Initialize() { base.Initialize(); @@ -37,7 +39,7 @@ namespace Content.Server.Inventory if (TryGetSlotEntity(uid, ev.Slot, out var entityUid) && TryComp(entityUid, out var storageComponent)) { - storageComponent.OpenStorageUI(uid); + _storageSystem.OpenStorageUI(entityUid.Value, uid, storageComponent); } } } diff --git a/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs b/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs index 1a3e77d0aa..dc490334c0 100644 --- a/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs +++ b/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs @@ -2,6 +2,7 @@ using System.Linq; using Content.Server.Atmos.Components; using Content.Server.Atmos.EntitySystems; using Content.Server.Nutrition.Components; +using Content.Server.Storage.EntitySystems; using Content.Server.Storage.Components; using Content.Server.Stunnable; using Content.Shared.Camera; @@ -31,6 +32,7 @@ namespace Content.Server.PneumaticCannon [Dependency] private readonly CameraRecoilSystem _cameraRecoil = default!; [Dependency] private readonly SharedHandsSystem _handsSystem = default!; [Dependency] private readonly ThrowingSystem _throwingSystem = default!; + [Dependency] private readonly StorageSystem _storageSystem = default!; private HashSet _currentlyFiring = new(); @@ -133,9 +135,9 @@ namespace Content.Server.PneumaticCannon if (EntityManager.TryGetComponent(args.Used, out var item) && EntityManager.TryGetComponent(component.Owner, out var storage)) { - if (storage.CanInsert(args.Used)) + if (_storageSystem.CanInsert(component.Owner, args.Used, storage)) { - storage.Insert(args.Used); + _storageSystem.Insert(component.Owner, args.Used, storage); args.User.PopupMessage(Loc.GetString("pneumatic-cannon-component-insert-item-success", ("item", args.Used), ("cannon", component.Owner))); } @@ -317,7 +319,7 @@ namespace Content.Server.PneumaticCannon if (component.GasTankSlot.Remove(contained)) { _handsSystem.TryPickupAnyHand(user, contained); - + user.PopupMessage(Loc.GetString("pneumatic-cannon-component-gas-tank-remove", ("tank", contained), ("cannon", component.Owner))); UpdateAppearance(component); diff --git a/Content.Server/Storage/Components/ServerStorageComponent.cs b/Content.Server/Storage/Components/ServerStorageComponent.cs index 8c5014504f..22682b2ee4 100644 --- a/Content.Server/Storage/Components/ServerStorageComponent.cs +++ b/Content.Server/Storage/Components/ServerStorageComponent.cs @@ -1,39 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Content.Server.DoAfter; -using Content.Server.Hands.Components; -using Content.Server.Interaction; -using Content.Shared.Acts; -using Content.Shared.Coordinates; -using Content.Shared.Hands.EntitySystems; -using Content.Shared.Interaction; -using Content.Shared.Interaction.Helpers; -using Content.Shared.Item; -using Content.Shared.Placeable; -using Content.Shared.Popups; using Content.Shared.Sound; -using Content.Shared.Stacks; using Content.Shared.Storage; -using Content.Shared.Storage.Components; using Content.Shared.Whitelist; -using Robust.Server.GameObjects; -using Robust.Server.Player; -using Robust.Shared.Audio; using Robust.Shared.Containers; -using Robust.Shared.Enums; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; -using Robust.Shared.Log; -using Robust.Shared.Map; -using Robust.Shared.Network; -using Robust.Shared.Player; -using Robust.Shared.Players; -using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; -using Robust.Shared.ViewVariables; +using System.Threading; namespace Content.Server.Storage.Components { @@ -41,36 +10,36 @@ namespace Content.Server.Storage.Components /// Storage component for containing entities within this one, matches a UI on the client which shows stored entities /// [RegisterComponent] - [ComponentReference(typeof(IActivate))] - [ComponentReference(typeof(IStorageComponent))] [ComponentReference(typeof(SharedStorageComponent))] - public sealed class ServerStorageComponent : SharedStorageComponent, IInteractUsing, IActivate, IStorageComponent, IDestroyAct, IAfterInteract + public sealed class ServerStorageComponent : SharedStorageComponent { - [Dependency] private readonly IEntityManager _entityManager = default!; - [Dependency] private readonly IEntitySystemManager _sysMan = default!; - - private const string LoggerName = "Storage"; + public string LoggerName = "Storage"; public Container? Storage; - private readonly Dictionary _sizeCache = new(); + public readonly Dictionary SizeCache = new(); - [DataField("occludesLight")] private bool _occludesLight = true; [DataField("quickInsert")] - private bool _quickInsert = false; // Can insert storables by "attacking" them with the storage entity + public bool QuickInsert = false; // Can insert storables by "attacking" them with the storage entity [DataField("clickInsert")] - private bool _clickInsert = true; // Can insert stuff by clicking the storage entity with it + public bool ClickInsert = true; // Can insert stuff by clicking the storage entity with it [DataField("areaInsert")] - private bool _areaInsert = false; // "Attacking" with the storage entity causes it to insert all nearby storables after a delay + public bool AreaInsert = false; // "Attacking" with the storage entity causes it to insert all nearby storables after a delay + + /// + /// Token for interrupting area insert do after. + /// + public CancellationTokenSource? CancelToken; + [DataField("areaInsertRadius")] - private int _areaInsertRadius = 1; + public int AreaInsertRadius = 1; [DataField("whitelist")] - private EntityWhitelist? _whitelist = null; + public EntityWhitelist? Whitelist = null; [DataField("blacklist")] public EntityWhitelist? Blacklist = null; @@ -81,19 +50,30 @@ namespace Content.Server.Storage.Components [DataField("popup")] public bool ShowPopup = true; - private bool _storageInitialCalculated; + /// + /// This storage has an open UI + /// + public bool IsOpen = false; public int StorageUsed; [DataField("capacity")] public int StorageCapacityMax = 10000; - public readonly HashSet SubscribedSessions = new(); - [DataField("storageSoundCollection")] - public SoundSpecifier StorageSoundCollection { get; set; } = new SoundCollectionSpecifier("storageRustle"); + [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? StoredEntities => Storage?.ContainedEntities; [ViewVariables(VVAccess.ReadWrite)] + [DataField("occludesLight")] public bool OccludesLight { get => _occludesLight; @@ -104,567 +84,10 @@ namespace Content.Server.Storage.Components } } - private void UpdateStorageVisualization() - { - if (!_entityManager.TryGetComponent(Owner, out AppearanceComponent appearance)) - return; - - bool open = SubscribedSessions.Count != 0; - - appearance.SetData(StorageVisuals.Open, open); - appearance.SetData(SharedBagOpenVisuals.BagState, open ? SharedBagState.Open : SharedBagState.Closed); - - if (_entityManager.HasComponent(Owner)) - appearance.SetData(StackVisuals.Hide, !open); - } - - private void EnsureInitialCalculated() - { - if (_storageInitialCalculated) - { - return; - } - - RecalculateStorageUsed(); - - _storageInitialCalculated = true; - } - - private void RecalculateStorageUsed() - { - StorageUsed = 0; - _sizeCache.Clear(); - - if (Storage == null) - { - return; - } - - foreach (var entity in Storage.ContainedEntities) - { - var item = _entityManager.GetComponent(entity); - StorageUsed += item.Size; - _sizeCache.Add(entity, item.Size); - } - } - - /// - /// Verifies if an entity can be stored and if it fits - /// - /// The entity to check - /// true if it can be inserted, false otherwise - public bool CanInsert(EntityUid entity) - { - EnsureInitialCalculated(); - - if (_entityManager.TryGetComponent(entity, out ServerStorageComponent? storage) && - storage.StorageCapacityMax >= StorageCapacityMax) - { - return false; - } - - if (_entityManager.TryGetComponent(entity, out SharedItemComponent? store) && - store.Size > StorageCapacityMax - StorageUsed) - { - return false; - } - - if (_whitelist != null && !_whitelist.IsValid(entity)) - { - return false; - } - - if (Blacklist != null && Blacklist.IsValid(entity)) - { - return false; - } - - if (_entityManager.GetComponent(entity).Anchored) - { - return false; - } - - return true; - } - - /// - /// Inserts into the storage container - /// - /// The entity to insert - /// true if the entity was inserted, false otherwise - public bool Insert(EntityUid entity) - { - return CanInsert(entity) && Storage?.Insert(entity) == true; - } - + // neccesary for abstraction, should be deleted on complete storage ECS public override bool Remove(EntityUid entity) { - EnsureInitialCalculated(); - return Storage?.Remove(entity) == true; - } - - public void HandleEntityMaybeInserted(EntInsertedIntoContainerMessage message) - { - if (message.Container != Storage) - { - return; - } - - PlaySoundCollection(); - EnsureInitialCalculated(); - - Logger.DebugS(LoggerName, $"Storage (UID {Owner}) had entity (UID {message.Entity}) inserted into it."); - - var size = 0; - if (_entityManager.TryGetComponent(message.Entity, out SharedItemComponent? storable)) - size = storable.Size; - - StorageUsed += size; - _sizeCache[message.Entity] = size; - - UpdateClientInventories(); - } - - public void HandleEntityMaybeRemoved(EntRemovedFromContainerMessage message) - { - if (message.Container != Storage) - { - return; - } - - EnsureInitialCalculated(); - - Logger.DebugS(LoggerName, $"Storage (UID {Owner}) had entity (UID {message.Entity}) removed from it."); - - if (!_sizeCache.TryGetValue(message.Entity, out var size)) - { - Logger.WarningS(LoggerName, $"Removed entity {_entityManager.ToPrettyString(message.Entity)} without a cached size from storage {_entityManager.ToPrettyString(Owner)} at {_entityManager.GetComponent(Owner).MapPosition}"); - - RecalculateStorageUsed(); - return; - } - - StorageUsed -= size; - - UpdateClientInventories(); - } - - /// - /// Inserts an entity into storage from the player's active hand - /// - /// The player to insert an entity from - /// true if inserted, false otherwise - public bool PlayerInsertHeldEntity(EntityUid player) - { - EnsureInitialCalculated(); - - if (!_entityManager.TryGetComponent(player, out HandsComponent? hands) || - hands.ActiveHandEntity == null) - { - return false; - } - - var toInsert = hands.ActiveHandEntity; - - var handSys = _sysMan.GetEntitySystem(); - - if (!handSys.TryDrop(player, toInsert.Value, handsComp: hands)) - { - Popup(player, "comp-storage-cant-insert"); - return false; - } - - if (!Insert(toInsert.Value)) - { - handSys.PickupOrDrop(player, toInsert.Value, handsComp: hands); - Popup(player, "comp-storage-cant-insert"); - return false; - } - return true; } - - /// - /// Inserts an Entity () in the world into storage, informing if it fails. - /// is *NOT* held, see . - /// - /// The player to insert an entity with - /// true if inserted, false otherwise - public bool PlayerInsertEntityInWorld(EntityUid player, EntityUid toInsert) - { - EnsureInitialCalculated(); - - if (!Insert(toInsert)) - { - Popup(player, "comp-storage-cant-insert"); - return false; - } - return true; - } - - /// - /// Opens the storage UI for an entity - /// - /// The entity to open the UI for - public void OpenStorageUI(EntityUid entity) - { - PlaySoundCollection(); - EnsureInitialCalculated(); - - var userSession = _entityManager.GetComponent(entity).PlayerSession; - - Logger.DebugS(LoggerName, $"Storage (UID {Owner}) \"used\" by player session (UID {userSession.AttachedEntity})."); - - SubscribeSession(userSession); - _entityManager.EntityNetManager?.SendSystemNetworkMessage(new OpenStorageUIEvent(Owner), userSession.ConnectedClient); - UpdateClientInventory(userSession); - } - - /// - /// Updates the storage UI on all subscribed actors, informing them of the state of the container. - /// - private void UpdateClientInventories() - { - foreach (var session in SubscribedSessions) - { - UpdateClientInventory(session); - } - } - - /// - /// Updates storage UI on a client, informing them of the state of the container. - /// - /// The client to be updated - private void UpdateClientInventory(IPlayerSession session) - { - if (session.AttachedEntity == null) - { - Logger.DebugS(LoggerName, $"Storage (UID {Owner}) detected no attached entity in player session (UID {session.AttachedEntity})."); - - UnsubscribeSession(session); - return; - } - - if (Storage == null) - { - Logger.WarningS(LoggerName, $"{nameof(UpdateClientInventory)} called with null {nameof(Storage)}"); - - return; - } - - if (StoredEntities == null) - { - Logger.WarningS(LoggerName, $"{nameof(UpdateClientInventory)} called with null {nameof(StoredEntities)}"); - - return; - } - - var stored = StoredEntities.Select(e => e).ToArray(); - - _entityManager.EntityNetManager?.SendSystemNetworkMessage(new StorageHeldItemsEvent(Owner, StorageCapacityMax,StorageUsed, stored), session.ConnectedClient); - } - - /// - /// Adds a session to the update list. - /// - /// The session to add - private void SubscribeSession(IPlayerSession session) - { - EnsureInitialCalculated(); - - if (!SubscribedSessions.Contains(session)) - { - Logger.DebugS(LoggerName, $"Storage (UID {Owner}) subscribed player session (UID {session.AttachedEntity})."); - - session.PlayerStatusChanged += HandlePlayerSessionChangeEvent; - SubscribedSessions.Add(session); - } - - _entityManager.EnsureComponent(Owner); - if (SubscribedSessions.Count == 1) - UpdateStorageVisualization(); - } - - /// - /// Removes a session from the update list. - /// - /// The session to remove - public void UnsubscribeSession(IPlayerSession session) - { - if (SubscribedSessions.Contains(session)) - { - Logger.DebugS(LoggerName, $"Storage (UID {Owner}) unsubscribed player session (UID {session.AttachedEntity})."); - - SubscribedSessions.Remove(session); - _entityManager.EntityNetManager?.SendSystemNetworkMessage(new CloseStorageUIEvent(Owner), - session.ConnectedClient); - } - - CloseNestedInterfaces(session); - - if (SubscribedSessions.Count == 0) - { - UpdateStorageVisualization(); - - if (_entityManager.HasComponent(Owner)) - { - _entityManager.RemoveComponent(Owner); - } - } - } - - /// - /// If the user has nested-UIs open (e.g., PDA UI open when pda is in a backpack), close them. - /// - /// - public void CloseNestedInterfaces(IPlayerSession session) - { - if (StoredEntities == null) - return; - - foreach (var entity in StoredEntities) - { - if (_entityManager.TryGetComponent(entity, out ServerStorageComponent storageComponent)) - { - DebugTools.Assert(storageComponent != this, $"Storage component contains itself!? Entity: {Owner}"); - storageComponent.UnsubscribeSession(session); - } - - if (_entityManager.TryGetComponent(entity, out ServerUserInterfaceComponent uiComponent)) - { - foreach (var ui in uiComponent.Interfaces) - { - ui.Close(session); - } - } - } - } - - private void HandlePlayerSessionChangeEvent(object? obj, SessionStatusEventArgs sessionStatus) - { - Logger.DebugS(LoggerName, $"Storage (UID {Owner}) handled a status change in player session (UID {sessionStatus.Session.AttachedEntity})."); - - if (sessionStatus.NewStatus != SessionStatus.InGame) - { - UnsubscribeSession(sessionStatus.Session); - } - } - - protected override void Initialize() - { - base.Initialize(); - - // ReSharper disable once StringLiteralTypo - Storage = Owner.EnsureContainer("storagebase"); - Storage.OccludesLight = _occludesLight; - UpdateStorageVisualization(); - EnsureInitialCalculated(); - } - - public void HandleRemoveEntity(RemoveEntityEvent remove, ICommonSession session) - { - EnsureInitialCalculated(); - - if (session.AttachedEntity is not {Valid: true} player) - { - return; - } - - var ownerTransform = _entityManager.GetComponent(Owner); - var playerTransform = _entityManager.GetComponent(player); - - if (!playerTransform.Coordinates.InRange(_entityManager, ownerTransform.Coordinates, 2) || - Owner.IsInContainer() && !playerTransform.ContainsEntity(ownerTransform)) - { - return; - } - - if (!remove.EntityUid.Valid || Storage?.Contains(remove.EntityUid) == false) - { - return; - } - - _sysMan.GetEntitySystem().TryPickupAnyHand(player, remove.EntityUid); - } - - public void HandleInsertEntity(ICommonSession session) - { - EnsureInitialCalculated(); - - if (session.AttachedEntity is not {Valid: true} player) - { - return; - } - - if (!EntitySystem.Get().InRangeUnobstructed(player, Owner, popup: ShowPopup)) - { - return; - } - - PlayerInsertHeldEntity(player); - } - - public void HandleCloseUI(ICommonSession session) - { - if (session is not IPlayerSession playerSession) - { - return; - } - - UnsubscribeSession(playerSession); - } - - /// - /// Inserts storable entities into this storage container if possible, otherwise return to the hand of the user - /// - /// - /// true if inserted, false otherwise - async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) - { - if (!_clickInsert) - return false; - Logger.DebugS(LoggerName, $"Storage (UID {Owner}) attacked by user (UID {eventArgs.User}) with entity (UID {eventArgs.Using})."); - - if (_entityManager.HasComponent(Owner)) - { - return false; - } - - return PlayerInsertHeldEntity(eventArgs.User); - } - - /// - /// Sends a message to open the storage UI - /// - /// - /// - void IActivate.Activate(ActivateEventArgs eventArgs) - { - EnsureInitialCalculated(); - OpenStorageUI(eventArgs.User); - } - - /// - /// Allows a user to pick up entities by clicking them, or pick up all entities in a certain radius - /// arround a click. - /// - /// - /// - async Task IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs) - { - if (!eventArgs.CanReach) return false; - - // 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 (_areaInsert && (eventArgs.Target == null || !_entityManager.HasComponent(eventArgs.Target.Value))) - { - var validStorables = new List(); - foreach (var entity in EntitySystem.Get().GetEntitiesInRange(eventArgs.ClickLocation, _areaInsertRadius, LookupFlags.None)) - { - if (entity.IsInContainer() - || entity == eventArgs.User - || !_entityManager.HasComponent(entity) - || !EntitySystem.Get().InRangeUnobstructed(eventArgs.User, entity)) - continue; - validStorables.Add(entity); - } - - //If there's only one then let's be generous - if (validStorables.Count > 1) - { - var doAfterSystem = EntitySystem.Get(); - var doAfterArgs = new DoAfterEventArgs(eventArgs.User, 0.2f * validStorables.Count, CancellationToken.None, Owner) - { - BreakOnStun = true, - BreakOnDamage = true, - BreakOnUserMove = true, - NeedHand = true, - }; - var result = await doAfterSystem.WaitDoAfter(doAfterArgs); - if (result != DoAfterStatus.Finished) return true; - } - - var successfullyInserted = new List(); - var successfullyInsertedPositions = new List(); - foreach (var entity in validStorables) - { - // Check again, situation may have changed for some entities, but we'll still pick up any that are valid - if (entity.IsInContainer() - || entity == eventArgs.User - || !_entityManager.HasComponent(entity)) - continue; - var position = EntityCoordinates.FromMap(_entityManager.GetComponent(Owner).Parent?.Owner ?? Owner, _entityManager.GetComponent(entity).MapPosition); - if (PlayerInsertEntityInWorld(eventArgs.User, entity)) - { - successfullyInserted.Add(entity); - successfullyInsertedPositions.Add(position); - } - } - - // If we picked up atleast one thing, play a sound and do a cool animation! - if (successfullyInserted.Count > 0) - { - PlaySoundCollection(); - _entityManager.EntityNetManager?.SendSystemNetworkMessage( - new AnimateInsertingEntitiesEvent(Owner, successfullyInserted, successfullyInsertedPositions)); - } - return true; - } - // Pick up the clicked entity - else if (_quickInsert) - { - if (eventArgs.Target is not {Valid: true} target) - { - return false; - } - - if (target.IsInContainer() - || target == eventArgs.User - || !_entityManager.HasComponent(target)) - return false; - var position = EntityCoordinates.FromMap( - _entityManager.GetComponent(Owner).Parent?.Owner ?? Owner, - _entityManager.GetComponent(target).MapPosition); - if (PlayerInsertEntityInWorld(eventArgs.User, target)) - { - _entityManager.EntityNetManager?.SendSystemNetworkMessage(new AnimateInsertingEntitiesEvent(Owner, - new List { target }, - new List { position })); - return true; - } - return true; - } - return false; - } - - void IDestroyAct.OnDestroy(DestructionEventArgs eventArgs) - { - var storedEntities = StoredEntities?.ToList(); - - if (storedEntities == null) - { - return; - } - - foreach (var entity in storedEntities) - { - Remove(entity); - } - } - - private void Popup(EntityUid player, string message) - { - if (!ShowPopup) return; - - Owner.PopupMessage(player, Loc.GetString(message)); - } - - private void PlaySoundCollection() - { - SoundSystem.Play(Filter.Pvs(Owner), StorageSoundCollection.GetSound(), Owner, AudioParams.Default); - } } - - [RegisterComponent] - public sealed class ActiveStorageComponent : Component {} } diff --git a/Content.Server/Storage/EntitySystems/StorageSystem.Fill.cs b/Content.Server/Storage/EntitySystems/StorageSystem.Fill.cs index 3b6e4d57d6..fde7216631 100644 --- a/Content.Server/Storage/EntitySystems/StorageSystem.Fill.cs +++ b/Content.Server/Storage/EntitySystems/StorageSystem.Fill.cs @@ -1,6 +1,4 @@ using Content.Server.Storage.Components; -using Robust.Shared.Random; -using System.Linq; using Content.Shared.Storage; namespace Content.Server.Storage.EntitySystems; @@ -10,8 +8,10 @@ public sealed partial class StorageSystem private void OnStorageFillMapInit(EntityUid uid, StorageFillComponent component, MapInitEvent args) { if (component.Contents.Count == 0) return; - - if (!TryComp(uid, out var storage)) + // ServerStorageComponent needs to rejoin IStorageComponent when other storage components are ECS'd + TryComp(uid, out var storage); + TryComp(uid, out var serverStorageComp); + if (storage == null && serverStorageComp == null) { Logger.Error($"StorageFillComponent couldn't find any StorageComponent ({uid})"); return; @@ -24,7 +24,12 @@ public sealed partial class StorageSystem { var ent = EntityManager.SpawnEntity(item, coordinates); - if (storage.Insert(ent)) continue; + // handle depending on storage component, again this should be unified after ECS + if (storage != null && storage.Insert(ent)) + continue; + + if (serverStorageComp != null && Insert(uid, ent, serverStorageComp)) + continue; Logger.ErrorS("storage", $"Tried to StorageFill {item} inside {uid} but can't."); EntityManager.DeleteEntity(ent); diff --git a/Content.Server/Storage/EntitySystems/StorageSystem.cs b/Content.Server/Storage/EntitySystems/StorageSystem.cs index 5034c1a8df..62e579a5f9 100644 --- a/Content.Server/Storage/EntitySystems/StorageSystem.cs +++ b/Content.Server/Storage/EntitySystems/StorageSystem.cs @@ -14,6 +14,21 @@ using Robust.Shared.Containers; using Robust.Shared.Random; using Robust.Shared.Timing; using Robust.Shared.Utility; +using System.Threading; +using Content.Server.DoAfter; +using Content.Server.Interaction; +using Content.Shared.Acts; +using Content.Shared.Hands.EntitySystems; +using Content.Shared.Item; +using Content.Shared.Placeable; +using Content.Shared.Stacks; +using Content.Shared.Storage.Components; +using Robust.Shared.Audio; +using Robust.Shared.Map; +using Robust.Shared.Player; +using Robust.Server.Containers; +using Content.Server.Popups; +using static Content.Shared.Storage.SharedStorageComponent; namespace Content.Server.Storage.EntitySystems { @@ -22,51 +37,50 @@ namespace Content.Server.Storage.EntitySystems { [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IRobustRandom _random = default!; + [Dependency] private readonly ContainerSystem _containerSystem = default!; [Dependency] private readonly DisposalUnitSystem _disposalSystem = default!; + [Dependency] private readonly DoAfterSystem _doAfterSystem = default!; + [Dependency] private readonly EntityLookupSystem _entityLookupSystem = 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!; /// public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(HandleEntityRemovedFromContainer); - SubscribeLocalEvent(HandleEntityInsertedIntoContainer); + SubscribeLocalEvent(OnComponentInit); + SubscribeLocalEvent>(AddOpenUiVerb); + SubscribeLocalEvent>(AddTransferVerbs); + SubscribeLocalEvent(OnInteractUsing); + SubscribeLocalEvent(OnActivate); + SubscribeLocalEvent(AfterInteract); + SubscribeLocalEvent(OnDestroy); + SubscribeLocalEvent(OnRemoveItemMessage); + SubscribeLocalEvent(OnInsertItemMessage); + SubscribeLocalEvent(OnBoundUIOpen); + SubscribeLocalEvent(OnBoundUIClosed); + SubscribeLocalEvent(OnStorageItemRemoved); SubscribeLocalEvent>(AddToggleOpenVerb); SubscribeLocalEvent(OnRelayMovement); - SubscribeLocalEvent>(AddOpenUiVerb); - SubscribeLocalEvent>(AddTransferVerbs); - SubscribeLocalEvent(OnStorageFillMapInit); - - SubscribeNetworkEvent(OnRemoveEntity); - SubscribeNetworkEvent(OnInsertEntity); - SubscribeNetworkEvent(OnCloseStorageUI); } - private void OnRemoveEntity(RemoveEntityEvent ev, EntitySessionEventArgs args) + private void OnComponentInit(EntityUid uid, ServerStorageComponent storageComp, ComponentInit args) { - if (TryComp(ev.Storage, out var storage)) - { - storage.HandleRemoveEntity(ev, args.SenderSession); - } - } + base.Initialize(); - private void OnInsertEntity(InsertEntityEvent ev, EntitySessionEventArgs args) - { - if (TryComp(ev.Storage, out var storage)) - { - storage.HandleInsertEntity(args.SenderSession); - } - } - - private void OnCloseStorageUI(CloseStorageUIEvent ev, EntitySessionEventArgs args) - { - if (TryComp(ev.Storage, out var storage)) - { - storage.HandleCloseUI(args.SenderSession); - } + // ReSharper disable once StringLiteralTypo + storageComp.Storage = _containerSystem.EnsureContainer(uid, "storagebase"); + storageComp.Storage.OccludesLight = storageComp.OccludesLight; + UpdateStorageVisualization(uid, storageComp); + RecalculateStorageUsed(storageComp); + UpdateStorageUI(uid, storageComp); } private void OnRelayMovement(EntityUid uid, EntityStorageComponent component, RelayMovementEntityEvent args) @@ -76,22 +90,12 @@ namespace Content.Server.Storage.EntitySystems if (_gameTiming.CurTime < component.LastInternalOpenAttempt + EntityStorageComponent.InternalOpenAttemptDelay) - { return; - } component.LastInternalOpenAttempt = _gameTiming.CurTime; component.TryOpenStorage(args.Entity); } - /// - public override void Update(float frameTime) - { - foreach (var (_, component) in EntityManager.EntityQuery()) - { - CheckSubscribedEntities(component); - } - } private void AddToggleOpenVerb(EntityUid uid, EntityStorageComponent component, GetVerbsEvent args) { @@ -121,19 +125,18 @@ namespace Content.Server.Storage.EntitySystems if (!args.CanAccess || !args.CanInteract) return; - if (EntityManager.TryGetComponent(uid, out LockComponent? lockComponent) && lockComponent.Locked) + if (TryComp(uid, out var lockComponent) && lockComponent.Locked) return; // Get the session for the user - var session = EntityManager.GetComponentOrNull(args.User)?.PlayerSession; - if (session == null) + if (!TryComp(args.User, out var actor) || actor?.PlayerSession == null) return; // Does this player currently have the storage UI open? - var uiOpen = component.SubscribedSessions.Contains(session); + bool uiOpen = _uiSystem.SessionHasOpenUi(uid, StorageUiKey.Key, actor.PlayerSession); ActivationVerb verb = new(); - verb.Act = () => component.OpenStorageUI(args.User); + verb.Act = () => OpenStorageUI(uid, args.User, component); if (uiOpen) { verb.Text = Loc.GetString("verb-common-close-ui"); @@ -187,6 +190,236 @@ namespace Content.Server.Storage.EntitySystems args.Verbs.Add(dispose); } + + + /// + /// Inserts storable entities into this storage container if possible, otherwise return to the hand of the user + /// + /// true if inserted, false otherwise + private void OnInteractUsing(EntityUid uid, ServerStorageComponent storageComp, InteractUsingEvent args) + { + if (!storageComp.ClickInsert) + return; + + Logger.DebugS(storageComp.LoggerName, $"Storage (UID {uid}) attacked by user (UID {args.User}) with entity (UID {args.Used})."); + + if (HasComp(uid)) + return; + + PlayerInsertHeldEntity(uid, args.User, storageComp); + } + + /// + /// Sends a message to open the storage UI + /// + /// + private void OnActivate(EntityUid uid, ServerStorageComponent storageComp, ActivateInWorldEvent args) + { + if (!TryComp(args.User, out var actor)) + return; + + OpenStorageUI(uid, args.User, storageComp); + } + + /// + /// Allows a user to pick up entities by clicking them, or pick up all entities in a certain radius + /// around a click. + /// + /// + private async void AfterInteract(EntityUid uid, ServerStorageComponent storageComp, AfterInteractEvent eventArgs) + { + if (!eventArgs.CanReach) return; + + if (storageComp.CancelToken != null) + { + storageComp.CancelToken.Cancel(); + storageComp.CancelToken = null; + 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 && (eventArgs.Target == null || !HasComp(eventArgs.Target.Value))) + { + var validStorables = new List(); + foreach (var entity in _entityLookupSystem.GetEntitiesInRange(eventArgs.ClickLocation, storageComp.AreaInsertRadius, LookupFlags.None)) + { + if (entity == eventArgs.User + || !HasComp(entity) + || !_interactionSystem.InRangeUnobstructed(eventArgs.User, entity)) + continue; + + validStorables.Add(entity); + } + + //If there's only one then let's be generous + if (validStorables.Count > 1) + { + storageComp.CancelToken = new CancellationTokenSource(); + var doAfterArgs = new DoAfterEventArgs(eventArgs.User, 0.2f * validStorables.Count, storageComp.CancelToken.Token, uid) + { + BreakOnStun = true, + BreakOnDamage = true, + BreakOnUserMove = true, + NeedHand = true, + }; + + await _doAfterSystem.WaitDoAfter(doAfterArgs); + } + + // TODO: Make it use the event DoAfter + var successfullyInserted = new List(); + var successfullyInsertedPositions = new List(); + foreach (var entity in validStorables) + { + // Check again, situation may have changed for some entities, but we'll still pick up any that are valid + if (_containerSystem.IsEntityInContainer(entity) + || entity == eventArgs.User + || !HasComp(entity)) + continue; + + if (TryComp(uid, out var transformOwner) && TryComp(entity, out var transformEnt)) + { + var position = EntityCoordinates.FromMap(transformOwner.Parent?.Owner ?? uid, transformEnt.MapPosition); + + if (PlayerInsertEntityInWorld(uid, eventArgs.User, entity, storageComp)) + { + successfullyInserted.Add(entity); + successfullyInsertedPositions.Add(position); + } + } + } + + // If we picked up atleast one thing, play a sound and do a cool animation! + if (successfullyInserted.Count > 0) + { + if (storageComp.StorageInsertSound is not null) + SoundSystem.Play(Filter.Pvs(uid, entityManager: EntityManager), storageComp.StorageInsertSound.GetSound(), uid, AudioParams.Default); + RaiseNetworkEvent(new AnimateInsertingEntitiesEvent(uid, successfullyInserted, successfullyInsertedPositions)); + } + return; + } + // Pick up the clicked entity + else if (storageComp.QuickInsert) + { + if (eventArgs.Target is not {Valid: true} target) + return; + + if (_containerSystem.IsEntityInContainer(target) + || target == eventArgs.User + || !HasComp(target)) + return; + + if (TryComp(uid, out var transformOwner) && TryComp(target, out var transformEnt)) + { + var parent = transformOwner.ParentUid; + + var position = EntityCoordinates.FromMap( + parent.IsValid() ? parent : uid, + transformEnt.MapPosition); + if (PlayerInsertEntityInWorld(uid, eventArgs.User, target, storageComp)) + { + RaiseNetworkEvent(new AnimateInsertingEntitiesEvent(uid, + new List { target }, + new List { position })); + } + } + } + return; + } + + private void OnDestroy(EntityUid uid, ServerStorageComponent storageComp, DestructionEventArgs args) + { + var storedEntities = storageComp.StoredEntities?.ToList(); + + if (storedEntities == null) + return; + + foreach (var entity in storedEntities) + { + RemoveAndDrop(uid, entity, storageComp); + } + } + + private void OnRemoveItemMessage(EntityUid uid, ServerStorageComponent storageComp, StorageRemoveItemMessage args) + { + if (args.Session.AttachedEntity == null) + return; + + HandleRemoveEntity(uid, args.Session.AttachedEntity.Value, args.InteractedItemUID, storageComp); + } + + private void OnInsertItemMessage(EntityUid uid, ServerStorageComponent storageComp, StorageInsertItemMessage args) + { + 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(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) + SoundSystem.Play(Filter.Pvs(uid, entityManager: EntityManager), storageComp.StorageCloseSound.GetSound(), uid, AudioParams.Default); + } + } + + private void OnStorageItemRemoved(EntityUid uid, ServerStorageComponent storageComp, EntRemovedFromContainerMessage args) + { + RecalculateStorageUsed(storageComp); + UpdateStorageUI(uid, storageComp); + } + + private void UpdateStorageVisualization(EntityUid uid, ServerStorageComponent storageComp) + { + if (!TryComp(uid, out var appearance)) + return; + + appearance.SetData(StorageVisuals.Open, storageComp.IsOpen); + appearance.SetData(SharedBagOpenVisuals.BagState, storageComp.IsOpen ? SharedBagState.Open : SharedBagState.Closed); + + if (HasComp(uid)) + appearance.SetData(StackVisuals.Hide, !storageComp.IsOpen); + } + + private void RecalculateStorageUsed(ServerStorageComponent storageComp) + { + storageComp.StorageUsed = 0; + storageComp.SizeCache.Clear(); + + if (storageComp.Storage == null) + return; + + var itemQuery = GetEntityQuery(); + + foreach (var entity in storageComp.Storage.ContainedEntities) + { + if (!itemQuery.TryGetComponent(entity, out var itemComp)) + continue; + + storageComp.StorageUsed += itemComp.Size; + storageComp.SizeCache.Add(entity, itemComp.Size); + } + } + /// /// Move entities from one storage to another. /// @@ -207,8 +440,10 @@ namespace Content.Server.Storage.EntitySystems foreach (var entity in entities.ToList()) { - targetComp.Insert(entity); + Insert(target, entity, targetComp); } + RecalculateStorageUsed(sourceComp); + UpdateStorageUI(source, sourceComp); } /// @@ -236,57 +471,207 @@ namespace Content.Server.Storage.EntitySystems _disposalSystem.AfterInsert(disposalComp, entity); } } + RecalculateStorageUsed(sourceComp); + UpdateStorageUI(source, sourceComp); } - private void HandleEntityRemovedFromContainer(EntRemovedFromContainerMessage message) + public void HandleRemoveEntity(EntityUid uid, EntityUid player, EntityUid itemToRemove, ServerStorageComponent? storageComp = null) { - var oldParentEntity = message.Container.Owner; + if (!Resolve(uid, ref storageComp)) + return; - if (EntityManager.TryGetComponent(oldParentEntity, out ServerStorageComponent? storageComp)) + if (!_containerSystem.ContainsEntity(uid, itemToRemove)) + return; + + // succeeded, remove entity and update UI + _containerSystem.RemoveEntity(uid, itemToRemove, false); + + if (storageComp.StorageRemoveSound is not null) + SoundSystem.Play(Filter.Pvs(uid, entityManager: EntityManager), storageComp.StorageRemoveSound.GetSound(), uid, AudioParams.Default); + + _sharedHandsSystem.TryPickupAnyHand(player, itemToRemove); + } + + /// + /// Verifies if an entity can be stored and if it fits + /// + /// The entity to check + /// true if it can be inserted, false otherwise + public bool CanInsert(EntityUid uid, EntityUid insertEnt, ServerStorageComponent? storageComp = null) + { + if (!Resolve(uid, ref storageComp)) + return false; + + if (TryComp(insertEnt, out ServerStorageComponent? storage) && + storage.StorageCapacityMax >= storageComp.StorageCapacityMax) + return false; + + if (TryComp(insertEnt, out SharedItemComponent? itemComp) && + itemComp.Size > storageComp.StorageCapacityMax - storageComp.StorageUsed) + return false; + + if (storageComp.Whitelist?.IsValid(insertEnt, EntityManager) == false) + return false; + + if (storageComp.Blacklist?.IsValid(insertEnt, EntityManager) == true) + return false; + + if (TryComp(insertEnt, out TransformComponent? transformComp) && transformComp.Anchored) + return false; + + return true; + } + + /// + /// Inserts into the storage container + /// + /// The entity to insert + /// true if the entity was inserted, false otherwise + public bool Insert(EntityUid uid, EntityUid insertEnt, ServerStorageComponent? storageComp = null) + { + if (!Resolve(uid, ref storageComp)) + return false; + + if (!CanInsert(uid, insertEnt, storageComp) || storageComp.Storage?.Insert(insertEnt) == false) + return false; + + if (storageComp.StorageInsertSound is not null) + SoundSystem.Play(Filter.Pvs(uid, entityManager: EntityManager), storageComp.StorageInsertSound.GetSound(), uid, AudioParams.Default); + + RecalculateStorageUsed(storageComp); + UpdateStorageUI(uid, storageComp); + return true; + } + + // REMOVE: remove and drop on the ground + public bool RemoveAndDrop(EntityUid uid, EntityUid removeEnt, ServerStorageComponent? storageComp = null) + { + if (!Resolve(uid, ref storageComp)) + return false; + + var itemRemoved = storageComp.Storage?.Remove(removeEnt) == true; + if (itemRemoved) + RecalculateStorageUsed(storageComp); + + return itemRemoved; + } + + /// + /// Inserts an entity into storage from the player's active hand + /// + /// The player to insert an entity from + /// true if inserted, false otherwise + public bool PlayerInsertHeldEntity(EntityUid uid, EntityUid player, ServerStorageComponent? storageComp = null) + { + if (!Resolve(uid, ref storageComp)) + return false; + + if (!TryComp(player, out HandsComponent? hands) || + hands.ActiveHandEntity == null) + return false; + + var toInsert = hands.ActiveHandEntity; + + if (!_sharedHandsSystem.TryDrop(player, toInsert.Value, handsComp: hands)) { - storageComp.HandleEntityMaybeRemoved(message); + Popup(uid, player, "comp-storage-cant-insert", storageComp); + return false; } + + return PlayerInsertEntityInWorld(uid, player, toInsert.Value, storageComp); } - private void HandleEntityInsertedIntoContainer(EntInsertedIntoContainerMessage message) + /// + /// Inserts an Entity () in the world into storage, informing if it fails. + /// is *NOT* held, see . + /// + /// The player to insert an entity with + /// true if inserted, false otherwise + public bool PlayerInsertEntityInWorld(EntityUid uid, EntityUid player, EntityUid toInsert, ServerStorageComponent? storageComp = null) { - var oldParentEntity = message.Container.Owner; + if (!Resolve(uid, ref storageComp)) + return false; - if (EntityManager.TryGetComponent(oldParentEntity, out ServerStorageComponent? storageComp)) + if (!_sharedInteractionSystem.InRangeUnobstructed(player, uid, popup: storageComp.ShowPopup)) + return false; + + if (!Insert(uid, toInsert, storageComp)) { - storageComp.HandleEntityMaybeInserted(message); + Popup(uid, player, "comp-storage-cant-insert", storageComp); + return false; } + return true; } - private void CheckSubscribedEntities(ServerStorageComponent storageComp) + /// + /// Opens the storage UI for an entity + /// + /// The entity to open the UI for + public void OpenStorageUI(EntityUid uid, EntityUid entity, ServerStorageComponent? storageComp = null) { - var xform = Transform(storageComp.Owner); - var storagePos = xform.WorldPosition; - var storageMap = xform.MapID; + if (!Resolve(uid, ref storageComp)) + return; - var remove = new RemQueue(); + if (!TryComp(entity, out ActorComponent? player)) + return; - foreach (var session in storageComp.SubscribedSessions) + if (storageComp.StorageOpenSound is not null) + SoundSystem.Play(Filter.Pvs(uid, entityManager: EntityManager), storageComp.StorageOpenSound.GetSound(), uid, AudioParams.Default); + + Logger.DebugS(storageComp.LoggerName, $"Storage (UID {uid}) \"used\" by player session (UID {player.PlayerSession.AttachedEntity})."); + + _uiSystem.GetUiOrNull(uid, StorageUiKey.Key)?.Open(player.PlayerSession); + } + + /// + /// If the user has nested-UIs open (e.g., PDA UI open when pda is in a backpack), close them. + /// + /// + public void CloseNestedInterfaces(EntityUid uid, IPlayerSession session, ServerStorageComponent? storageComp = null) + { + if (!Resolve(uid, ref storageComp)) + return; + + if (storageComp.StoredEntities == null) + return; + + // 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) { - // The component manages the set of sessions, so this invalid session should be removed soon. - if (session.AttachedEntity is not {} attachedEntity || !EntityManager.EntityExists(attachedEntity)) - continue; - - var attachedXform = Transform(attachedEntity); - if (storageMap != attachedXform.MapID) - continue; - - var distanceSquared = (storagePos - attachedXform.WorldPosition).LengthSquared; - if (distanceSquared > SharedInteractionSystem.InteractionRangeSquared) + if (TryComp(entity, out ServerStorageComponent? storedStorageComp)) { - remove.Add(session); + DebugTools.Assert(storedStorageComp != storageComp, $"Storage component contains itself!? Entity: {uid}"); + } + + if (TryComp(entity, out ServerUserInterfaceComponent? uiComponent)) + { + foreach (var ui in uiComponent.Interfaces) + { + ui.Close(session); + } } } + } - foreach (var session in remove) - { - storageComp.UnsubscribeSession(session); - } + private void UpdateStorageUI(EntityUid uid, ServerStorageComponent storageComp) + { + if (storageComp.Storage == null) + return; + + var state = new StorageBoundUserInterfaceState((List) storageComp.Storage.ContainedEntities, storageComp.StorageUsed, storageComp.StorageCapacityMax); + + _uiSystem.GetUiOrNull(uid, StorageUiKey.Key)?.SetState(state); + } + + private void Popup(EntityUid uid, EntityUid player, string message, ServerStorageComponent storageComp) + { + if (!storageComp.ShowPopup) return; + + _popupSystem.PopupEntity(Loc.GetString(message), player, Filter.Entities(player)); } } } diff --git a/Content.Shared/Storage/SharedStorageComponent.cs b/Content.Shared/Storage/SharedStorageComponent.cs index 24a3ff9197..8391af9123 100644 --- a/Content.Shared/Storage/SharedStorageComponent.cs +++ b/Content.Shared/Storage/SharedStorageComponent.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; using System.Linq; using Content.Shared.ActionBlocker; using Content.Shared.DragDrop; -using Content.Shared.Interaction.Events; using Content.Shared.Placeable; -using Robust.Shared.GameObjects; using Robust.Shared.GameStates; -using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Serialization; @@ -16,6 +11,42 @@ namespace Content.Shared.Storage [NetworkedComponent()] public abstract class SharedStorageComponent : Component, IDraggable { + [Serializable, NetSerializable] + public sealed class StorageBoundUserInterfaceState : BoundUserInterfaceState + { + public readonly List StoredEntities; + public readonly int StorageSizeUsed; + public readonly int StorageCapacityMax; + + public StorageBoundUserInterfaceState(List storedEntities, int storageSizeUsed, int storageCapacityMax) + { + StoredEntities = storedEntities; + StorageSizeUsed = storageSizeUsed; + StorageCapacityMax = storageCapacityMax; + } + } + + [Serializable, NetSerializable] + public sealed class StorageInsertItemMessage : BoundUserInterfaceMessage + { + } + + [Serializable, NetSerializable] + public sealed class StorageRemoveItemMessage : BoundUserInterfaceMessage + { + public readonly EntityUid InteractedItemUID; + public StorageRemoveItemMessage(EntityUid interactedItemUID) + { + InteractedItemUID = interactedItemUID; + } + } + + [Serializable, NetSerializable] + public enum StorageUiKey + { + Key, + } + [Dependency] private readonly IEntityManager _entMan = default!; public abstract IReadOnlyList? StoredEntities { get; } @@ -35,75 +66,24 @@ namespace Content.Shared.Storage bool IDraggable.Drop(DragDropEvent eventArgs) { if (!EntitySystem.Get().CanInteract(eventArgs.User, eventArgs.Target)) - { return false; - } var storedEntities = StoredEntities?.ToArray(); if (storedEntities == null) - { return false; - } // empty everything out foreach (var storedEntity in storedEntities) { if (Remove(storedEntity)) - { _entMan.GetComponent(storedEntity).WorldPosition = eventArgs.DropLocation.Position; - } } return true; } } - [Serializable, NetSerializable] - public sealed class StorageComponentState : ComponentState - { - public readonly EntityUid[] StoredEntities; - - public StorageComponentState(EntityUid[] storedEntities) - { - StoredEntities = storedEntities; - } - } - - /// - /// Updates the client component about what entities this storage is holding - /// - [Serializable, NetSerializable] - public sealed class StorageHeldItemsEvent : EntityEventArgs - { - public readonly EntityUid Storage; - public readonly int StorageSizeMax; - public readonly int StorageSizeUsed; - public readonly EntityUid[] StoredEntities; - - public StorageHeldItemsEvent(EntityUid storage, int storageSizeMax, int storageSizeUsed, EntityUid[] storedEntities) - { - Storage = storage; - StorageSizeMax = storageSizeMax; - StorageSizeUsed = storageSizeUsed; - StoredEntities = storedEntities; - } - } - - /// - /// Network event for adding an entity to the storage entity. - /// - [Serializable, NetSerializable] - public sealed class InsertEntityEvent : EntityEventArgs - { - public readonly EntityUid Storage; - - public InsertEntityEvent(EntityUid storage) - { - Storage = storage; - } - } - /// /// Network event for displaying an animation of entities flying into a storage entity /// @@ -122,51 +102,6 @@ namespace Content.Shared.Storage } } - /// - /// Network event for removing a contained entity from the storage entity - /// - [Serializable, NetSerializable] - public sealed class RemoveEntityEvent : EntityEventArgs - { - public EntityUid Storage; - public EntityUid EntityUid; - - public RemoveEntityEvent(EntityUid storage, EntityUid entityUid) - { - Storage = storage; - EntityUid = entityUid; - } - } - - /// - /// Network event for opening the storage UI - /// - [Serializable, NetSerializable] - public sealed class OpenStorageUIEvent : EntityEventArgs - { - public readonly EntityUid Storage; - - public OpenStorageUIEvent(EntityUid storage) - { - Storage = storage; - } - } - - /// - /// Network event for closing the storage UI. - /// E.g when the player moves too far away from the container. - /// - [Serializable, NetSerializable] - public sealed class CloseStorageUIEvent : EntityEventArgs - { - public readonly EntityUid Storage; - - public CloseStorageUIEvent(EntityUid storage) - { - Storage = storage; - } - } - [NetSerializable] [Serializable] public enum StorageVisuals diff --git a/Resources/Prototypes/Catalog/Fills/Boxes/general.yml b/Resources/Prototypes/Catalog/Fills/Boxes/general.yml index 778d7c8c73..ba60767bd4 100644 --- a/Resources/Prototypes/Catalog/Fills/Boxes/general.yml +++ b/Resources/Prototypes/Catalog/Fills/Boxes/general.yml @@ -5,8 +5,7 @@ description: A cardboard box for storing things. components: - type: Sprite - layers: - - state: box + state: box - type: entity name: lightbulb box diff --git a/Resources/Prototypes/Entities/Clothing/Back/backpacks.yml b/Resources/Prototypes/Entities/Clothing/Back/backpacks.yml index bbeaaef27d..0cd337a390 100644 --- a/Resources/Prototypes/Entities/Clothing/Back/backpacks.yml +++ b/Resources/Prototypes/Entities/Clothing/Back/backpacks.yml @@ -15,8 +15,10 @@ sprite: Clothing/Back/Backpacks/backpack.rsi - type: Storage capacity: 100 - storageSoundCollection: - collection: storageRustle + - type: UserInterface + interfaces: + - key: enum.StorageUiKey.Key + type: StorageBoundUserInterface - type: entity parent: ClothingBackpack @@ -116,7 +118,7 @@ sprite: Clothing/Back/Backpacks/science.rsi - type: Clothing sprite: Clothing/Back/Backpacks/science.rsi - + - type: entity parent: ClothingBackpack id: ClothingBackpackVirology diff --git a/Resources/Prototypes/Entities/Clothing/Back/duffel.yml b/Resources/Prototypes/Entities/Clothing/Back/duffel.yml index 6b5516840c..2bada5edfd 100644 --- a/Resources/Prototypes/Entities/Clothing/Back/duffel.yml +++ b/Resources/Prototypes/Entities/Clothing/Back/duffel.yml @@ -15,8 +15,10 @@ - back - type: Storage capacity: 100 - storageSoundCollection: - collection: storageRustle + - type: UserInterface + interfaces: + - key: enum.StorageUiKey.Key + type: StorageBoundUserInterface - type: entity parent: ClothingBackpackDuffel diff --git a/Resources/Prototypes/Entities/Clothing/Back/satchel.yml b/Resources/Prototypes/Entities/Clothing/Back/satchel.yml index 1ce0d4dc0c..8b02102527 100644 --- a/Resources/Prototypes/Entities/Clothing/Back/satchel.yml +++ b/Resources/Prototypes/Entities/Clothing/Back/satchel.yml @@ -15,9 +15,11 @@ sprite: Clothing/Back/Satchels/satchel.rsi - type: Storage capacity: 100 - storageSoundCollection: - collection: storageRustle - + - type: UserInterface + interfaces: + - key: enum.StorageUiKey.Key + type: StorageBoundUserInterface + - type: entity parent: ClothingBackpackSatchel id: ClothingBackpackSatchelEngineering diff --git a/Resources/Prototypes/Entities/Clothing/Belt/belts.yml b/Resources/Prototypes/Entities/Clothing/Belt/belts.yml index b53cde45e2..0cb458f1b2 100644 --- a/Resources/Prototypes/Entities/Clothing/Belt/belts.yml +++ b/Resources/Prototypes/Entities/Clothing/Belt/belts.yml @@ -62,6 +62,10 @@ visuals: - type: MappedItemVisualizer sprite: Clothing/Belt/belt_overlay.rsi + - type: UserInterface + interfaces: + - key: enum.StorageUiKey.Key + type: StorageBoundUserInterface - type: entity parent: ClothingBeltBase diff --git a/Resources/Prototypes/Entities/Clothing/OuterClothing/base_clothingouter.yml b/Resources/Prototypes/Entities/Clothing/OuterClothing/base_clothingouter.yml index 877652d0c6..14ddc08051 100644 --- a/Resources/Prototypes/Entities/Clothing/OuterClothing/base_clothingouter.yml +++ b/Resources/Prototypes/Entities/Clothing/OuterClothing/base_clothingouter.yml @@ -9,6 +9,18 @@ - type: Sprite state: icon +- type: entity + abstract: true + parent: ClothingOuterBase + id: ClothingOuterStorageBase + components: + - type: Storage + capacity: 10 + - type: UserInterface + interfaces: + - key: enum.StorageUiKey.Key + type: StorageBoundUserInterface + - type: entity abstract: true parent: ClothingOuterBase diff --git a/Resources/Prototypes/Entities/Clothing/OuterClothing/coats.yml b/Resources/Prototypes/Entities/Clothing/OuterClothing/coats.yml index 7be7400818..322007f5ae 100644 --- a/Resources/Prototypes/Entities/Clothing/OuterClothing/coats.yml +++ b/Resources/Prototypes/Entities/Clothing/OuterClothing/coats.yml @@ -1,5 +1,5 @@ - type: entity - parent: ClothingOuterBase + parent: ClothingOuterStorageBase id: ClothingOuterCoatBomber name: bomber jacket description: A thick, well-worn WW2 leather bomber jacket. @@ -8,11 +8,9 @@ sprite: Clothing/OuterClothing/Coats/bomber.rsi - type: Clothing sprite: Clothing/OuterClothing/Coats/bomber.rsi - - type: Storage - capacity: 10 - type: entity - parent: ClothingOuterBase + parent: ClothingOuterStorageBase id: ClothingOuterCoatDetective name: detective trenchcoat description: A rugged canvas trenchcoat, designed and created by TX Fabrication Corp. The coat is externally impact resistant - perfect for your next act of autodefenestration! @@ -21,8 +19,6 @@ sprite: Clothing/OuterClothing/Coats/detective.rsi - type: Clothing sprite: Clothing/OuterClothing/Coats/detective.rsi - - type: Storage - capacity: 10 - type: Armor modifiers: coefficients: @@ -32,7 +28,7 @@ Heat: 0.9 - type: entity - parent: ClothingOuterBase + parent: ClothingOuterStorageBase id: ClothingOuterCoatGentle name: gentle coat description: A gentle coat for a gentle man, or woman. @@ -41,11 +37,9 @@ sprite: Clothing/OuterClothing/Coats/gentlecoat.rsi - type: Clothing sprite: Clothing/OuterClothing/Coats/gentlecoat.rsi - - type: Storage - capacity: 10 - type: entity - parent: ClothingOuterBase + parent: ClothingOuterStorageBase id: ClothingOuterCoatHoSTrench name: head of security's trenchcoat description: This trenchcoat was specifically designed for asserting superior authority. @@ -54,8 +48,6 @@ sprite: Clothing/OuterClothing/Coats/hos_trenchcoat.rsi - type: Clothing sprite: Clothing/OuterClothing/Coats/hos_trenchcoat.rsi - - type: Storage - capacity: 10 - type: Armor modifiers: coefficients: @@ -65,7 +57,7 @@ Heat: 0.7 - type: entity - parent: ClothingOuterBase + parent: ClothingOuterStorageBase id: ClothingOuterCoatInspector name: inspectors coat description: A strict inspector coat for being intimidating during inspections. @@ -74,11 +66,9 @@ sprite: Clothing/OuterClothing/Coats/insp_coat.rsi - type: Clothing sprite: Clothing/OuterClothing/Coats/insp_coat.rsi - - type: Storage - capacity: 10 - type: entity - parent: ClothingOuterBase + parent: ClothingOuterStorageBase id: ClothingOuterCoatJensen name: jensen coat description: A jensen coat. @@ -87,11 +77,9 @@ sprite: Clothing/OuterClothing/Coats/jensencoat.rsi - type: Clothing sprite: Clothing/OuterClothing/Coats/jensencoat.rsi - - type: Storage - capacity: 10 - type: entity - parent: ClothingOuterBase + parent: ClothingOuterStorageBase id: ClothingOuterCoatLab name: lab coat description: A suit that protects against minor chemical spills. @@ -100,11 +88,9 @@ sprite: Clothing/OuterClothing/Coats/labcoat.rsi - type: Clothing sprite: Clothing/OuterClothing/Coats/labcoat.rsi - - type: Storage - capacity: 10 - type: entity - parent: ClothingOuterBase + parent: ClothingOuterStorageBase id: ClothingOuterCoatLabChem name: lab coat (chem) description: A suit that protects against minor chemical spills. Has an orange stripe on the shoulder. @@ -113,11 +99,9 @@ sprite: Clothing/OuterClothing/Coats/labcoat_chem.rsi - type: Clothing sprite: Clothing/OuterClothing/Coats/labcoat_chem.rsi - - type: Storage - capacity: 10 - type: entity - parent: ClothingOuterBase + parent: ClothingOuterStorageBase id: ClothingOuterCoatLabCmo name: chief medical officer's lab coat description: Bluer than the standard model. @@ -126,11 +110,9 @@ sprite: Clothing/OuterClothing/Coats/labcoat_cmo.rsi - type: Clothing sprite: Clothing/OuterClothing/Coats/labcoat_cmo.rsi - - type: Storage - capacity: 10 - type: entity - parent: ClothingOuterBase + parent: ClothingOuterStorageBase id: ClothingOuterCoatPirate name: pirate garb description: Yarr. @@ -139,11 +121,9 @@ sprite: Clothing/OuterClothing/Coats/pirate.rsi - type: Clothing sprite: Clothing/OuterClothing/Coats/pirate.rsi - - type: Storage - capacity: 10 - type: entity - parent: ClothingOuterBase + parent: ClothingOuterStorageBase id: ClothingOuterCoatWarden name: warden's armored jacket description: A sturdy, utilitarian jacket designed to protect a warden from any brig-bound threats. @@ -152,8 +132,6 @@ sprite: Clothing/OuterClothing/Coats/warden.rsi - type: Clothing sprite: Clothing/OuterClothing/Coats/warden.rsi - - type: Storage - capacity: 10 - type: Armor modifiers: coefficients: diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cans.yml b/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cans.yml index a0164bb597..6973e59c78 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cans.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cans.yml @@ -307,7 +307,7 @@ - type: entity id: DrinkCanPack - parent: BaseItem + parent: BaseStorageItem name: 6pack components: - type: Sprite diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Food/Containers/box.yml b/Resources/Prototypes/Entities/Objects/Consumable/Food/Containers/box.yml index 61aa71ec15..9cd03f6b93 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Food/Containers/box.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Food/Containers/box.yml @@ -6,7 +6,7 @@ # an alpha color which -Y- said he would implement. - type: entity - parent: BaseItem + parent: BoxCardboard id: FoodBoxDonut name: donut box description: Mmm, Donuts. @@ -50,7 +50,7 @@ # Egg - type: entity - parent: BaseItem + parent: BoxCardboard id: FoodContainerEgg name: egg carton description: Don't drop 'em! @@ -66,6 +66,7 @@ - Egg - type: Item sprite: Objects/Consumable/Food/egg.rsi + state: box-closed size: 12 - type: StorageFill contents: @@ -138,7 +139,7 @@ # Since you could open pizza boxes in the stack. - type: entity - parent: BaseItem + parent: BoxCardboard id: FoodBoxPizza name: pizza box components: @@ -219,7 +220,7 @@ # Nugget - type: entity - parent: BaseItem + parent: BoxCardboard id: FoodBoxNugget name: chicken nuggets description: You suddenly have an urge to trade on the intergalactic stock market. @@ -258,7 +259,7 @@ # Donkpocket - type: entity - parent: BaseItem + parent: BoxCardboard id: FoodBoxDonkpocket name: box of donk-pockets description: 'Instructions: Heat in microwave. Product will cool if not eaten within seven minutes.' diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Smokeables/Cigarettes/packs.yml b/Resources/Prototypes/Entities/Objects/Consumable/Smokeables/Cigarettes/packs.yml index 10180f9778..c508333057 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Smokeables/Cigarettes/packs.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Smokeables/Cigarettes/packs.yml @@ -1,6 +1,6 @@ - type: entity id: CigPackBase - parent: BaseItem + parent: BaseStorageItem name: cigarette pack abstract: true components: diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Smokeables/Cigarettes/rolling_paper.yml b/Resources/Prototypes/Entities/Objects/Consumable/Smokeables/Cigarettes/rolling_paper.yml index 32854c776c..d3bcbeea75 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Smokeables/Cigarettes/rolling_paper.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Smokeables/Cigarettes/rolling_paper.yml @@ -1,5 +1,5 @@ - type: entity - parent: BaseItem + parent: BaseStorageItem name: pack of rolling paper id: PackPaperRolling description: A pack of thin pieces of paper used to make fine smokeables. diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Smokeables/Cigars/case.yml b/Resources/Prototypes/Entities/Objects/Consumable/Smokeables/Cigars/case.yml index 7e13720eca..f975439b43 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Smokeables/Cigars/case.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Smokeables/Cigars/case.yml @@ -1,6 +1,6 @@ - type: entity id: CigarCase - parent: BaseItem + parent: BaseStorageItem name: cigar case description: A case for holding your cigars when you are not smoking them. components: diff --git a/Resources/Prototypes/Entities/Objects/Fun/dice_bag.yml b/Resources/Prototypes/Entities/Objects/Fun/dice_bag.yml index ba0c640ccd..b2b61d452a 100644 --- a/Resources/Prototypes/Entities/Objects/Fun/dice_bag.yml +++ b/Resources/Prototypes/Entities/Objects/Fun/dice_bag.yml @@ -1,5 +1,5 @@ - type: entity - parent: BaseItem + parent: BaseStorageItem id: DiceBag name: bag of dice description: Contains all the luck you'll ever need. diff --git a/Resources/Prototypes/Entities/Objects/Misc/box.yml b/Resources/Prototypes/Entities/Objects/Misc/box.yml index 87b472febf..42f17b3509 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/box.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/box.yml @@ -1,6 +1,6 @@ - type: entity id: BoxBase - parent: BaseItem + parent: BaseStorageItem abstract: true components: - type: Sprite diff --git a/Resources/Prototypes/Entities/Objects/Misc/briefcases.yml b/Resources/Prototypes/Entities/Objects/Misc/briefcases.yml index 48167059d7..9aa03af147 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/briefcases.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/briefcases.yml @@ -1,5 +1,5 @@ - type: entity - parent: BaseItem + parent: BaseStorageItem abstract: true id: BriefcaseBase description: Useful for carrying items in your hands. @@ -8,8 +8,6 @@ size: 60 - type: Storage capacity: 60 - storageSoundCollection: - collection: storageRustle - type: entity name: brown briefcase diff --git a/Resources/Prototypes/Entities/Objects/Specific/Chapel/bibles.yml b/Resources/Prototypes/Entities/Objects/Specific/Chapel/bibles.yml index ca86cf3afc..9f0ddce24d 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/Chapel/bibles.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/Chapel/bibles.yml @@ -1,7 +1,7 @@ - type: entity name: bible description: New Interstellar Version 2340 - parent: BaseItem + parent: BaseStorageItem id: Bible components: - type: Bible @@ -31,9 +31,11 @@ - Belt - type: Storage capacity: 10 - storageSoundCollection: - collection: storageRustle - + - type: UserInterface + interfaces: + - key: enum.StorageUiKey.Key + type: StorageBoundUserInterface + - type: entity parent: Bible name: necronomicon diff --git a/Resources/Prototypes/Entities/Objects/Specific/Hydroponics/tools.yml b/Resources/Prototypes/Entities/Objects/Specific/Hydroponics/tools.yml index 5041eb7fc0..b31bb08cf7 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/Hydroponics/tools.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/Hydroponics/tools.yml @@ -109,7 +109,7 @@ - type: entity name: plant bag id: PlantBag - parent: BaseItem + parent: BaseStorageItem description: A bag for botanists to easily move their huge harvests. components: - type: Sprite diff --git a/Resources/Prototypes/Entities/Objects/Specific/Janitorial/janitor.yml b/Resources/Prototypes/Entities/Objects/Specific/Janitorial/janitor.yml index 8971b4382b..a79c23854b 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/Janitorial/janitor.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/Janitorial/janitor.yml @@ -205,6 +205,10 @@ maxFillLevels: 3 fillBaseName: cart_water_ changeColor: false + - type: UserInterface + interfaces: + - key: enum.StorageUiKey.Key + type: StorageBoundUserInterface - type: entity diff --git a/Resources/Prototypes/Entities/Objects/Specific/Janitorial/trashbag.yml b/Resources/Prototypes/Entities/Objects/Specific/Janitorial/trashbag.yml index 2d17ece501..f482a2700d 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/Janitorial/trashbag.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/Janitorial/trashbag.yml @@ -1,7 +1,7 @@ - type: entity name: trash bag id: TrashBag - parent: BaseItem + parent: BaseStorageItem components: - type: Sprite netSync: false @@ -16,7 +16,9 @@ capacity: 125 quickInsert: true areaInsert: true - storageSoundCollection: + storageOpenSound: + collection: trashBagRustle + storageInsertSound: collection: trashBagRustle whitelist: tags: @@ -55,5 +57,3 @@ quickInsert: true areaInsert: true areaInsertRadius: 1000 - storageSoundCollection: - collection: trashBagRustle diff --git a/Resources/Prototypes/Entities/Objects/Specific/Medical/medkits.yml b/Resources/Prototypes/Entities/Objects/Specific/Medical/medkits.yml index 833af1b7f8..bc4cf3eb1c 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/Medical/medkits.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/Medical/medkits.yml @@ -1,7 +1,7 @@ - type: entity name: first aid kit description: It's an emergency medical kit for those serious boo-boos. - parent: BaseItem + parent: BaseStorageItem id: Medkit components: - type: Sprite diff --git a/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml b/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml index 18ccc8b64d..00daaf7be6 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml @@ -279,7 +279,7 @@ - type: entity name: pill canister id: PillCanister - parent: BaseItem + parent: BaseStorageItem description: Holds up to 12 pills. components: - type: Sprite diff --git a/Resources/Prototypes/Entities/Objects/Tools/matches.yml b/Resources/Prototypes/Entities/Objects/Tools/matches.yml index fc426c7e6c..d9a4059772 100644 --- a/Resources/Prototypes/Entities/Objects/Tools/matches.yml +++ b/Resources/Prototypes/Entities/Objects/Tools/matches.yml @@ -1,6 +1,6 @@ - type: entity id: SmallboxItem - parent: BaseItem + parent: BaseStorageItem abstract: true components: - type: Storage diff --git a/Resources/Prototypes/Entities/Objects/Tools/toolbox.yml b/Resources/Prototypes/Entities/Objects/Tools/toolbox.yml index 6a637f1374..56511bb769 100644 --- a/Resources/Prototypes/Entities/Objects/Tools/toolbox.yml +++ b/Resources/Prototypes/Entities/Objects/Tools/toolbox.yml @@ -1,6 +1,6 @@ - type: entity id: ToolboxBase - parent: BaseItem + parent: BaseStorageItem abstract: true components: - type: Sprite diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/pneumatic_cannon.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/pneumatic_cannon.yml index 8071cf9eac..1307c7c447 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/pneumatic_cannon.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/pneumatic_cannon.yml @@ -1,6 +1,6 @@ - type: entity name: improvised pneumatic cannon - parent: BaseItem + parent: BaseStorageItem id: ImprovisedPneumaticCannon description: Improvised using nothing but a pipe, some zipties, and a pneumatic cannon. components: @@ -30,7 +30,7 @@ - type: entity name: pie cannon - parent: BaseItem + parent: BaseStorageItem id: LauncherCreamPie description: Load cream pie for optimal results. components: @@ -43,7 +43,9 @@ components: - CreamPie clickInsert: false - storageSoundCollection: + storageOpenSound: + collection: BikeHorn + storageInsertSound: collection: BikeHorn capacity: 40 - type: PneumaticCannon diff --git a/Resources/Prototypes/Entities/Objects/base_item.yml b/Resources/Prototypes/Entities/Objects/base_item.yml index 5141e9c5bd..5590c32122 100644 --- a/Resources/Prototypes/Entities/Objects/base_item.yml +++ b/Resources/Prototypes/Entities/Objects/base_item.yml @@ -35,3 +35,15 @@ drawdepth: Items noRot: false - type: Pullable + +- type: entity + name: "storage item" + id: BaseStorageItem + parent: BaseItem + abstract: true + components: + - type: Storage + - type: UserInterface + interfaces: + - key: enum.StorageUiKey.Key + type: StorageBoundUserInterface