From 7753ae7c3afbfb023b363d8c1e54e265dfe27e99 Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Wed, 7 Aug 2019 15:56:22 -0700 Subject: [PATCH] Added OpenStorage trigger on ActivateItemInWorld When ActivateItemInWorld is pressed when hovering over a InventoryButton and the InventorySlot contains a storage item, it will open the StorageGUI. --- Content.Client/EscapeMenuOwner.cs | 9 ++-- .../HUD/Inventory/ClientInventoryComponent.cs | 12 ++--- .../HumanInventoryInterfaceController.cs | 2 +- .../HUD/Inventory/InventoryButton.cs | 6 ++- .../Inventory/InventoryInterfaceController.cs | 33 ++++++++++--- Content.Client/UserInterface/GameHud.cs | 2 +- .../Components/GUI/InventoryComponent.cs | 49 +++++++++++++------ .../Components/GUI/ServerHandsComponent.cs | 15 ++++-- .../Inventory/SharedInventoryComponent.cs | 2 +- RobustToolbox | 2 +- 10 files changed, 90 insertions(+), 42 deletions(-) diff --git a/Content.Client/EscapeMenuOwner.cs b/Content.Client/EscapeMenuOwner.cs index 914233839d..54c6f53cb5 100644 --- a/Content.Client/EscapeMenuOwner.cs +++ b/Content.Client/EscapeMenuOwner.cs @@ -1,4 +1,4 @@ -using Content.Client.UserInterface; +using Content.Client.UserInterface; using Robust.Client.Console; using Robust.Client.Interfaces.Input; using Robust.Client.Interfaces.Placement; @@ -49,9 +49,8 @@ namespace Content.Client _escapeMenu.OnClose += () => _gameHud.EscapeButtonDown = false; - var escapeMenuCommand = InputCmdHandler.FromDelegate(Enabled); - - _inputManager.SetInputCommand(EngineKeyFunctions.EscapeMenu, escapeMenuCommand); + _inputManager.SetInputCommand(EngineKeyFunctions.EscapeMenu, + InputCmdHandler.FromDelegate(s => Enabled())); } else if (obj.OldState is GameScreen) { @@ -63,7 +62,7 @@ namespace Content.Client } } - private void Enabled(ICommonSession session) + private void Enabled() { if (_escapeMenu.IsOpen) { diff --git a/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs b/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs index bc3b6c039b..4a7819589e 100644 --- a/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs +++ b/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs @@ -127,18 +127,18 @@ namespace Content.Client.GameObjects _sprite?.LayerSetVisible(slot, false); } - public void SendUnequipMessage(Slots slot) - { - var unequipmessage = new ClientInventoryMessage(slot, ClientInventoryUpdate.Unequip); - SendNetworkMessage(unequipmessage); - } - public void SendEquipMessage(Slots slot) { var equipmessage = new ClientInventoryMessage(slot, ClientInventoryUpdate.Equip); SendNetworkMessage(equipmessage); } + public void SendUseMessage(Slots slot) + { + var equipmessage = new ClientInventoryMessage(slot, ClientInventoryUpdate.Use); + SendNetworkMessage(equipmessage); + } + public void SendOpenStorageUIMessage(Slots slot) { SendNetworkMessage(new OpenSlotStorageUIMessage(slot)); diff --git a/Content.Client/GameObjects/Components/HUD/Inventory/HumanInventoryInterfaceController.cs b/Content.Client/GameObjects/Components/HUD/Inventory/HumanInventoryInterfaceController.cs index 9b23c3ef8d..80fbaf6517 100644 --- a/Content.Client/GameObjects/Components/HUD/Inventory/HumanInventoryInterfaceController.cs +++ b/Content.Client/GameObjects/Components/HUD/Inventory/HumanInventoryInterfaceController.cs @@ -97,7 +97,7 @@ namespace Content.Client.GameObjects foreach (var button in buttons) { button.SpriteView.Sprite = sprite; - button.OnPressed = RemoveFromInventory; + button.OnPressed = HandleInventoryKeybind; button.StorageButton.Visible = hasInventory; } } diff --git a/Content.Client/GameObjects/Components/HUD/Inventory/InventoryButton.cs b/Content.Client/GameObjects/Components/HUD/Inventory/InventoryButton.cs index 1bc30aae84..8f680a23c5 100644 --- a/Content.Client/GameObjects/Components/HUD/Inventory/InventoryButton.cs +++ b/Content.Client/GameObjects/Components/HUD/Inventory/InventoryButton.cs @@ -27,7 +27,8 @@ namespace Content.Client.GameObjects AddChild(Button = new TextureButton { TextureNormal = texture, - Scale = (2, 2) + Scale = (2, 2), + NonFocusKeybinds = true }); Button.OnPressed += e => OnPressed?.Invoke(e); @@ -44,7 +45,8 @@ namespace Content.Client.GameObjects Scale = (0.75f, 0.75f), SizeFlagsHorizontal = SizeFlags.ShrinkEnd, SizeFlagsVertical = SizeFlags.ShrinkEnd, - Visible = false + Visible = false, + NonFocusKeybinds = true }); 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 d085df42de..091e1c46db 100644 --- a/Content.Client/GameObjects/Components/HUD/Inventory/InventoryInterfaceController.cs +++ b/Content.Client/GameObjects/Components/HUD/Inventory/InventoryInterfaceController.cs @@ -1,6 +1,7 @@ -using System; +using System; using Content.Client.UserInterface; using Content.Shared.GameObjects.Components.Inventory; +using Content.Shared.Input; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; using Robust.Shared.Interfaces.GameObjects; @@ -60,24 +61,44 @@ namespace Content.Client.GameObjects { } - protected void RemoveFromInventory(BaseButton.ButtonEventArgs args) + protected void HandleInventoryKeybind(BaseButton.ButtonEventArgs args) { - args.Button.Pressed = false; - var control = (InventoryButton) args.Button.Parent; - - Owner.SendUnequipMessage(control.Slot); + if (args.Event.Function == ContentKeyFunctions.ActivateItemInWorld) + { + OpenStorage(args); + } + else if (args.Event.CanFocus) + { + UseItemOnInventory(args); + } } protected void AddToInventory(BaseButton.ButtonEventArgs args) { + if (!args.Event.CanFocus) + { + return; + } args.Button.Pressed = false; var control = (InventoryButton) args.Button.Parent; Owner.SendEquipMessage(control.Slot); } + protected void UseItemOnInventory(BaseButton.ButtonEventArgs args) + { + args.Button.Pressed = false; + var control = (InventoryButton)args.Button.Parent; + + Owner.SendUseMessage(control.Slot); + } + protected void OpenStorage(BaseButton.ButtonEventArgs args) { + if (!args.Event.CanFocus && args.Event.Function != ContentKeyFunctions.ActivateItemInWorld) + { + return; + } args.Button.Pressed = false; var control = (InventoryButton)args.Button.Parent; diff --git a/Content.Client/UserInterface/GameHud.cs b/Content.Client/UserInterface/GameHud.cs index 4eef7a335f..146449060b 100644 --- a/Content.Client/UserInterface/GameHud.cs +++ b/Content.Client/UserInterface/GameHud.cs @@ -1,4 +1,4 @@ -using System; +using System; using Content.Client.Utility; using Content.Shared.Input; using Robust.Client.Graphics; diff --git a/Content.Server/GameObjects/Components/GUI/InventoryComponent.cs b/Content.Server/GameObjects/Components/GUI/InventoryComponent.cs index 0f71bd3b92..833f06d54f 100644 --- a/Content.Server/GameObjects/Components/GUI/InventoryComponent.cs +++ b/Content.Server/GameObjects/Components/GUI/InventoryComponent.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects; using Robust.Server.GameObjects.Components.Container; using Robust.Server.Interfaces.Player; @@ -19,6 +20,10 @@ namespace Content.Server.GameObjects [RegisterComponent] public class InventoryComponent : SharedInventoryComponent { +#pragma warning disable 649 + [Dependency] private readonly IEntitySystemManager _entitySystemManager; +#pragma warning restore 649 + [ViewVariables] private readonly Dictionary SlotContainers = new Dictionary(); @@ -223,27 +228,41 @@ namespace Content.Server.GameObjects /// private void HandleInventoryMessage(ClientInventoryMessage msg) { - if (msg.Updatetype == ClientInventoryUpdate.Equip) + switch (msg.Updatetype) { - var hands = Owner.GetComponent(); - var activehand = hands.GetActiveHand; - if (activehand != null && activehand.Owner.TryGetComponent(out ClothingComponent clothing)) + case ClientInventoryUpdate.Equip: { - hands.Drop(hands.ActiveIndex); - if (!Equip(msg.Inventoryslot, clothing)) + var hands = Owner.GetComponent(); + var activeHand = hands.GetActiveHand; + if (activeHand != null && activeHand.Owner.TryGetComponent(out ClothingComponent clothing)) { - hands.PutInHand(clothing); + hands.Drop(hands.ActiveIndex); + if (!Equip(msg.Inventoryslot, clothing)) + { + hands.PutInHand(clothing); + } } + break; } - } - else if (msg.Updatetype == ClientInventoryUpdate.Unequip) - { - var hands = Owner.GetComponent(); - var activehand = hands.GetActiveHand; - var itemcontainedinslot = GetSlotItem(msg.Inventoryslot); - if (activehand == null && itemcontainedinslot != null && Unequip(msg.Inventoryslot)) + case ClientInventoryUpdate.Use: { - hands.PutInHand(itemcontainedinslot); + var interactionSystem = _entitySystemManager.GetEntitySystem(); + var hands = Owner.GetComponent(); + var activeHand = hands.GetActiveHand; + var itemContainedInSlot = GetSlotItem(msg.Inventoryslot); + if (itemContainedInSlot != null) + { + if (activeHand != null) + { + interactionSystem.Interaction(Owner, activeHand.Owner, itemContainedInSlot.Owner, + new Robust.Shared.Map.GridCoordinates()); + } + else if (Unequip(msg.Inventoryslot)) + { + hands.PutInHand(itemContainedInSlot); + } + } + break; } } } diff --git a/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs b/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs index 7b42e79451..d38b0efd48 100644 --- a/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs +++ b/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs @@ -472,11 +472,18 @@ namespace Content.Server.GameObjects var playerEntity = session.AttachedEntity; var used = GetActiveHand?.Owner; - if (playerEntity == Owner && used != null && slot.ContainedEntity != null) - { + if (playerEntity == Owner && slot.ContainedEntity != null) + { var interactionSystem = _entitySystemManager.GetEntitySystem(); - interactionSystem.Interaction(Owner, used, slot.ContainedEntity, - GridCoordinates.Nullspace); + if (used != null) + { + interactionSystem.Interaction(Owner, used, slot.ContainedEntity, + GridCoordinates.Nullspace); + } + else + { + interactionSystem.Interaction(Owner, slot.ContainedEntity); + } } break; diff --git a/Content.Shared/GameObjects/Components/Inventory/SharedInventoryComponent.cs b/Content.Shared/GameObjects/Components/Inventory/SharedInventoryComponent.cs index 6464f2fbe8..7dfb88f4d4 100644 --- a/Content.Shared/GameObjects/Components/Inventory/SharedInventoryComponent.cs +++ b/Content.Shared/GameObjects/Components/Inventory/SharedInventoryComponent.cs @@ -75,7 +75,7 @@ namespace Content.Shared.GameObjects public enum ClientInventoryUpdate { Equip = 0, - Unequip = 1 + Use = 1 } } diff --git a/RobustToolbox b/RobustToolbox index f3f317385a..0adcc3c645 160000 --- a/RobustToolbox +++ b/RobustToolbox @@ -1 +1 @@ -Subproject commit f3f317385a542152cf753b5cfc7582e508ec2f57 +Subproject commit 0adcc3c64545e96ca16e7e0e7eeed757dc0262c9