diff --git a/Content.Client/GameObjects/Components/Inventory/ClientInventoryComponent.cs b/Content.Client/GameObjects/Components/Inventory/ClientInventoryComponent.cs index 86c4ffdba3..44c5f8e848 100644 --- a/Content.Client/GameObjects/Components/Inventory/ClientInventoryComponent.cs +++ b/Content.Client/GameObjects/Components/Inventory/ClientInventoryComponent.cs @@ -1,5 +1,7 @@ using Content.Shared.GameObjects; +using Content.Shared.Input; using SS14.Client.GameObjects; +using SS14.Client.Interfaces.Input; using SS14.Client.UserInterface; using SS14.Client.UserInterface.Controls; using SS14.Client.UserInterface.CustomControls; @@ -25,7 +27,8 @@ namespace Content.Client.GameObjects { private InventoryWindow Window; private string TemplateName = "HumanInventory"; //stored for serialization purposes - public event EventHandler OnCharacterMenuKey; + + private InputCommand OpenMenuCommand; public override void OnRemove() { @@ -39,12 +42,14 @@ namespace Content.Client.GameObjects base.ExposeData(serializer); Window = new InventoryWindow(this); + OpenMenuCommand = InputCommand.FromDelegate(() => { Window.AddToScreen(); Window.Open(); }); serializer.DataField(ref TemplateName, "Template", "HumanInventory"); Window.CreateInventory(TemplateName); } public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null) { + var inputMgr = IoCManager.Resolve(); switch (message) { //Updates what we are storing in UI slots @@ -58,30 +63,14 @@ namespace Content.Client.GameObjects Window.RemoveFromSlot(msg); } break; - } - } - /// - /// Register a hotkey to open the character menu with - /// - public override void Initialize() - { - base.Initialize(); - OnCharacterMenuKey += OpenMenu; - IoCManager.Resolve().SubscribeEvent(OnCharacterMenuKey, this); - } + case PlayerAttachedMsg _: + inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, OpenMenuCommand); + break; - /// - /// Hotkey opens the character menu window - /// - /// - /// - private void OpenMenu(object sender, BoundKeyChangedMessage message) - { - if (message.Function == BoundKeyFunctions.OpenCharacterMenu && message.State == BoundKeyState.Down) - { - Window.AddToScreen(); - Window.Open(); + case PlayerDetachedMsg _: + inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, null); + break; } } diff --git a/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs b/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs index b3fbf04083..ab9bf5f859 100644 --- a/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs +++ b/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces.GameObjects; using Content.Shared.GameObjects; +using Content.Shared.Input; using SS14.Server.GameObjects; using SS14.Server.GameObjects.Components.Container; using SS14.Server.Interfaces.Player; @@ -40,6 +41,10 @@ namespace Content.Server.GameObjects // Mostly arbitrary. public const float PICKUP_RANGE = 2; + private InputCommand SwapHandsCommand; + private InputCommand DropCommand; + private InputCommand ActivateItemInHandCommand; + public override void ExposeData(EntitySerializer serializer) { base.ExposeData(serializer); @@ -256,6 +261,7 @@ namespace Content.Server.GameObjects { base.HandleMessage(message, netChannel, component); + IPlayerInput input; switch (message) { case ClientChangedHandMsg msg: @@ -284,27 +290,40 @@ namespace Content.Server.GameObjects } //Boundkeychangedmsg only works for the player entity and doesn't need any extra verification - case BoundKeyChangedMsg msg: - if (msg.State != BoundKeyState.Down) - return; - switch (msg.Function) - { - case BoundKeyFunctions.SwitchHands: - SwapHands(); - break; - case BoundKeyFunctions.Drop: - Drop(ActiveIndex); - break; - case BoundKeyFunctions.ActivateItemInHand: - var used = GetActiveHand?.Owner; - if (used != null) - { - InteractionSystem.TryUseInteraction(Owner, used); - } - break; - } + case PlayerAttachedMsg msg: + InitInputCommands(); + input = msg.NewPlayer.Input; + input.SetCommand(ContentKeyFunctions.SwapHands, SwapHandsCommand); + input.SetCommand(ContentKeyFunctions.Drop, DropCommand); + input.SetCommand(ContentKeyFunctions.ActivateItemInHand, ActivateItemInHandCommand); + break; + + case PlayerDetachedMsg msg: + input = msg.OldPlayer.Input; + input.SetCommand(ContentKeyFunctions.SwapHands, null); + input.SetCommand(ContentKeyFunctions.Drop, null); + input.SetCommand(ContentKeyFunctions.ActivateItemInHand, null); break; } } + + private void InitInputCommands() + { + if (SwapHandsCommand != null) + { + return; + } + + SwapHandsCommand = InputCommand.FromDelegate(SwapHands); + DropCommand = InputCommand.FromDelegate(() => Drop(ActiveIndex)); + ActivateItemInHandCommand = InputCommand.FromDelegate(() => + { + var used = GetActiveHand?.Owner; + if (used != null) + { + InteractionSystem.TryUseInteraction(Owner, used); + } + }); + } } } diff --git a/Content.Shared/Content.Shared.csproj b/Content.Shared/Content.Shared.csproj index 9701eb566b..c1a950de18 100644 --- a/Content.Shared/Content.Shared.csproj +++ b/Content.Shared/Content.Shared.csproj @@ -98,6 +98,7 @@ + - + \ No newline at end of file diff --git a/Content.Shared/GameObjects/Components/Items/SharedHandsComponent.cs b/Content.Shared/GameObjects/Components/Items/SharedHandsComponent.cs index fff822da7b..788b39ffef 100644 --- a/Content.Shared/GameObjects/Components/Items/SharedHandsComponent.cs +++ b/Content.Shared/GameObjects/Components/Items/SharedHandsComponent.cs @@ -13,7 +13,7 @@ namespace Content.Shared.GameObjects } // The IDs of the items get synced over the network. - [Serializable] + [Serializable, NetSerializable] public class HandsComponentState : ComponentState { public readonly Dictionary Hands; diff --git a/Content.Shared/Input/ContentKeyFunctions.cs b/Content.Shared/Input/ContentKeyFunctions.cs new file mode 100644 index 0000000000..893c3bb6ed --- /dev/null +++ b/Content.Shared/Input/ContentKeyFunctions.cs @@ -0,0 +1,13 @@ +using SS14.Shared.Input; + +namespace Content.Shared.Input +{ + [KeyFunctions] + public static class ContentKeyFunctions + { + public static readonly BoundKeyFunction SwapHands = "SwapHands"; + public static readonly BoundKeyFunction Drop = "Drop"; + public static readonly BoundKeyFunction ActivateItemInHand = "ActivateItemInHand"; + public static readonly BoundKeyFunction OpenCharacterMenu = "OpenCharacterMenu"; + } +} diff --git a/Resources/keybinds_content.yml b/Resources/keybinds_content.yml new file mode 100644 index 0000000000..626c3b988e --- /dev/null +++ b/Resources/keybinds_content.yml @@ -0,0 +1,14 @@ +version: 1 # Not used right now, whatever. +binds: +- function: SwapHands + key: Tab + type: State +- function: Drop + key: Q + type: State +- function: ActivateItemInHand + key: F + type: State +- function: OpenCharacterMenu + key: C + type: State diff --git a/engine b/engine index 909bb5936f..dc80060757 160000 --- a/engine +++ b/engine @@ -1 +1 @@ -Subproject commit 909bb5936f40ef0dbcfcc5e63db262f508252f5b +Subproject commit dc80060757a740260af0b4e63ed6ff7591947812