diff --git a/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs b/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs index bdaeedcc82..bc3b6c039b 100644 --- a/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs +++ b/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs @@ -1,7 +1,10 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Content.Client.GameObjects.Components.Clothing; using Content.Shared.GameObjects; +using Content.Shared.GameObjects.Components.Inventory; +using Content.Shared.GameObjects.Components.Storage; using Robust.Client.GameObjects; using Robust.Client.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; @@ -77,15 +80,12 @@ namespace Content.Client.GameObjects foreach (var (slot, entityUid) in cast.Entities) { - if (_slots.ContainsKey(slot)) - { - _slots.Remove(slot); - _clearSlot(slot); - } - var entity = Owner.EntityManager.GetEntity(entityUid); - _slots[slot] = entity; - _setSlot(slot, entity); + if (!_slots.ContainsKey(slot) || _slots[slot] != entity) + { + _slots[slot] = entity; + _setSlot(slot, entity); + } doneSlots.Add(slot); } @@ -139,6 +139,11 @@ namespace Content.Client.GameObjects SendNetworkMessage(equipmessage); } + public void SendOpenStorageUIMessage(Slots slot) + { + SendNetworkMessage(new OpenSlotStorageUIMessage(slot)); + } + public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null) { diff --git a/Content.Client/GameObjects/Components/HUD/Inventory/HumanInventoryInterfaceController.cs b/Content.Client/GameObjects/Components/HUD/Inventory/HumanInventoryInterfaceController.cs index d03851c073..9b23c3ef8d 100644 --- a/Content.Client/GameObjects/Components/HUD/Inventory/HumanInventoryInterfaceController.cs +++ b/Content.Client/GameObjects/Components/HUD/Inventory/HumanInventoryInterfaceController.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System.Collections.Generic; +using Content.Client.GameObjects.Components.Storage; using Content.Client.Utility; using JetBrains.Annotations; using Robust.Client.Interfaces.GameObjects.Components; @@ -52,9 +53,11 @@ namespace Content.Client.GameObjects void AddButton(out InventoryButton variable, Slots slot, string textureName) { var texture = _resourceCache.GetTexture($"/Textures/UserInterface/Inventory/{textureName}.png"); - variable = new InventoryButton(slot, texture) + var storageTexture = _resourceCache.GetTexture($"/Textures/UserInterface/Inventory/back.png"); + variable = new InventoryButton(slot, texture, storageTexture) { - OnPressed = AddToInventory + OnPressed = AddToInventory, + OnStoragePressed = OpenStorage }; _inventoryButtons[slot].Add(variable); } @@ -89,11 +92,13 @@ namespace Content.Client.GameObjects } entity.TryGetComponent(out ISpriteComponent sprite); + var hasInventory = entity.HasComponent(); foreach (var button in buttons) { button.SpriteView.Sprite = sprite; button.OnPressed = RemoveFromInventory; + button.StorageButton.Visible = hasInventory; } } @@ -110,6 +115,7 @@ namespace Content.Client.GameObjects { button.SpriteView.Sprite = null; button.OnPressed = AddToInventory; + button.StorageButton.Visible = false; } } @@ -152,7 +158,8 @@ namespace Content.Client.GameObjects void AddButton(Slots slot, string textureName, Vector2 position) { var texture = resourceCache.GetTexture($"/Textures/UserInterface/Inventory/{textureName}.png"); - var button = new InventoryButton(slot, texture) + var storageTexture = resourceCache.GetTexture($"/Textures/UserInterface/Inventory/back.png"); + var button = new InventoryButton(slot, texture, storageTexture) { Position = position }; diff --git a/Content.Client/GameObjects/Components/HUD/Inventory/InventoryButton.cs b/Content.Client/GameObjects/Components/HUD/Inventory/InventoryButton.cs index ecee121d0b..1bc30aae84 100644 --- a/Content.Client/GameObjects/Components/HUD/Inventory/InventoryButton.cs +++ b/Content.Client/GameObjects/Components/HUD/Inventory/InventoryButton.cs @@ -1,4 +1,4 @@ -using System; +using System; using Content.Shared.GameObjects.Components.Inventory; using Robust.Client.Graphics; using Robust.Client.UserInterface.Controls; @@ -13,10 +13,12 @@ namespace Content.Client.GameObjects public BaseButton Button { get; } public SpriteView SpriteView { get; } + public BaseButton StorageButton { get; } public Action OnPressed { get; set; } + public Action OnStoragePressed { get; set; } - public InventoryButton(EquipmentSlotDefines.Slots slot, Texture texture) + public InventoryButton(EquipmentSlotDefines.Slots slot, Texture texture, Texture storageTexture) { Slot = slot; @@ -25,7 +27,7 @@ namespace Content.Client.GameObjects AddChild(Button = new TextureButton { TextureNormal = texture, - Scale = (2, 2), + Scale = (2, 2) }); Button.OnPressed += e => OnPressed?.Invoke(e); @@ -35,6 +37,17 @@ namespace Content.Client.GameObjects MouseFilter = MouseFilterMode.Ignore, Scale = (2, 2) }); + + AddChild(StorageButton = new TextureButton + { + TextureNormal = storageTexture, + Scale = (0.75f, 0.75f), + SizeFlagsHorizontal = SizeFlags.ShrinkEnd, + SizeFlagsVertical = SizeFlags.ShrinkEnd, + Visible = false + }); + + StorageButton.OnPressed += e => OnStoragePressed?.Invoke(e); } } } diff --git a/Content.Client/GameObjects/Components/HUD/Inventory/InventoryInterfaceController.cs b/Content.Client/GameObjects/Components/HUD/Inventory/InventoryInterfaceController.cs index 9a6187e01c..d085df42de 100644 --- a/Content.Client/GameObjects/Components/HUD/Inventory/InventoryInterfaceController.cs +++ b/Content.Client/GameObjects/Components/HUD/Inventory/InventoryInterfaceController.cs @@ -75,5 +75,13 @@ namespace Content.Client.GameObjects Owner.SendEquipMessage(control.Slot); } + + protected void OpenStorage(BaseButton.ButtonEventArgs args) + { + args.Button.Pressed = false; + var control = (InventoryButton)args.Button.Parent; + + Owner.SendOpenStorageUIMessage(control.Slot); + } } } diff --git a/Content.Client/UserInterface/HandsGui.cs b/Content.Client/UserInterface/HandsGui.cs index 7d54b88c55..7a3dfbbf56 100644 --- a/Content.Client/UserInterface/HandsGui.cs +++ b/Content.Client/UserInterface/HandsGui.cs @@ -60,6 +60,7 @@ namespace Content.Client.UserInterface AddChild(new TextureRect { + MouseFilter = MouseFilterMode.Ignore, Texture = TextureHandLeft, Size = _handL.Size, Position = _handL.TopLeft, @@ -68,6 +69,7 @@ namespace Content.Client.UserInterface AddChild(new TextureRect { + MouseFilter = MouseFilterMode.Ignore, Texture = TextureHandRight, Size = _handR.Size, Position = _handR.TopLeft, @@ -76,6 +78,7 @@ namespace Content.Client.UserInterface AddChild(ActiveHandRect = new TextureRect { + MouseFilter = MouseFilterMode.Ignore, Texture = TextureHandActive, Size = _handL.Size, Position = _handL.TopLeft, diff --git a/Content.Server/GameObjects/Components/GUI/InventoryComponent.cs b/Content.Server/GameObjects/Components/GUI/InventoryComponent.cs index 54b01700b3..0f71bd3b92 100644 --- a/Content.Server/GameObjects/Components/GUI/InventoryComponent.cs +++ b/Content.Server/GameObjects/Components/GUI/InventoryComponent.cs @@ -263,6 +263,12 @@ namespace Content.Server.GameObjects if (playerentity == Owner) HandleInventoryMessage(msg); break; + case OpenSlotStorageUIMessage msg: + ItemComponent item = GetSlotItem(msg.Slot); + ServerStorageComponent storage; + if (item.Owner.TryGetComponent(out storage)) + storage.OpenStorageUI(Owner); + break; } } diff --git a/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs index f03d04cf91..b50a8b9ff4 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs @@ -34,6 +34,7 @@ namespace Content.Server.GameObjects [Dependency] private readonly IMapManager _mapManager; [Dependency] private readonly IPlayerManager _playerManager; [Dependency] private readonly IEntityManager _entityManager; + [Dependency] private readonly IEntitySystemManager _entitySystemManager; #pragma warning restore 649 private Container storage; @@ -174,12 +175,18 @@ namespace Content.Server.GameObjects bool IUse.UseEntity(UseEntityEventArgs eventArgs) { _ensureInitialCalculated(); - var user_session = eventArgs.User.GetComponent().playerSession; + OpenStorageUI(eventArgs.User); + return false; + } + + public void OpenStorageUI(IEntity Character) + { + _ensureInitialCalculated(); + var user_session = Character.GetComponent().playerSession; Logger.DebugS("Storage", "Storage (UID {0}) \"used\" by player session (UID {1}).", Owner.Uid, user_session.AttachedEntityUid); SubscribeSession(user_session); SendNetworkMessage(new OpenStorageUIMessage(), user_session.ConnectedClient); UpdateClientInventory(user_session); - return false; } /// @@ -301,16 +308,15 @@ namespace Content.Server.GameObjects entity.GetComponent().WorldPosition = ourtransform.WorldPosition; } } - } break; - + } case CloseStorageUIMessage _: { var session = _playerManager.GetSessionByChannel(netChannel); UnsubscribeSession(session); - } break; + } } } diff --git a/Content.Shared/GameObjects/Components/Inventory/SharedInventoryComponent.cs b/Content.Shared/GameObjects/Components/Inventory/SharedInventoryComponent.cs index ac97f9a54d..6464f2fbe8 100644 --- a/Content.Shared/GameObjects/Components/Inventory/SharedInventoryComponent.cs +++ b/Content.Shared/GameObjects/Components/Inventory/SharedInventoryComponent.cs @@ -78,5 +78,20 @@ namespace Content.Shared.GameObjects Unequip = 1 } } + + /// + /// Component message for opening the Storage UI of item in Slot + /// + [Serializable, NetSerializable] + public class OpenSlotStorageUIMessage : ComponentMessage + { + public Slots Slot; + + public OpenSlotStorageUIMessage(Slots slot) + { + Directed = true; + Slot = slot; + } + } } }