From d9628d39eb4efa210534d44dba6cd830c5fd8bc9 Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Mon, 29 Jul 2019 13:32:04 -0700 Subject: [PATCH] Implemented storage button on Inventory Adds a small button on the bottom right of Storage items when inside the inventory. When the button is pressed it opens the Storage UI. --- .../HUD/Inventory/ClientInventoryComponent.cs | 5 +++++ .../HumanInventoryInterfaceController.cs | 7 ++++++- .../Components/HUD/Inventory/InventoryButton.cs | 6 +++++- .../Inventory/InventoryInterfaceController.cs | 8 ++++++++ .../Components/GUI/InventoryComponent.cs | 6 ++++++ .../Items/Storage/ServerStorageComponent.cs | 16 +++++++++++----- .../Inventory/SharedInventoryComponent.cs | 15 +++++++++++++++ 7 files changed, 56 insertions(+), 7 deletions(-) diff --git a/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs b/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs index da5613447f..58456557f9 100644 --- a/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs +++ b/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs @@ -138,6 +138,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 bf0e268ee5..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 Content.Client.GameObjects.Components.Storage; using Content.Client.Utility; using JetBrains.Annotations; using Robust.Client.Interfaces.GameObjects.Components; @@ -55,7 +56,8 @@ namespace Content.Client.GameObjects 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); } @@ -90,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; } } @@ -111,6 +115,7 @@ namespace Content.Client.GameObjects { button.SpriteView.Sprite = null; button.OnPressed = AddToInventory; + button.StorageButton.Visible = false; } } diff --git a/Content.Client/GameObjects/Components/HUD/Inventory/InventoryButton.cs b/Content.Client/GameObjects/Components/HUD/Inventory/InventoryButton.cs index 7a4b8eae10..1bc30aae84 100644 --- a/Content.Client/GameObjects/Components/HUD/Inventory/InventoryButton.cs +++ b/Content.Client/GameObjects/Components/HUD/Inventory/InventoryButton.cs @@ -13,8 +13,10 @@ 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, Texture storageTexture) { @@ -36,7 +38,7 @@ namespace Content.Client.GameObjects Scale = (2, 2) }); - AddChild(Button = new TextureButton + AddChild(StorageButton = new TextureButton { TextureNormal = storageTexture, Scale = (0.75f, 0.75f), @@ -44,6 +46,8 @@ namespace Content.Client.GameObjects 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.Server/GameObjects/Components/GUI/InventoryComponent.cs b/Content.Server/GameObjects/Components/GUI/InventoryComponent.cs index 69c14bcb5d..baf092315f 100644 --- a/Content.Server/GameObjects/Components/GUI/InventoryComponent.cs +++ b/Content.Server/GameObjects/Components/GUI/InventoryComponent.cs @@ -262,6 +262,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 f9a4b57b2c..49b3ec9550 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs @@ -33,6 +33,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; @@ -173,12 +174,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; } /// @@ -300,16 +307,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; + } + } } }