From 12f3b6bb7b14610e8eae116f056f8115c41af647 Mon Sep 17 00:00:00 2001 From: chairbender Date: Sun, 31 May 2020 14:32:05 -0700 Subject: [PATCH] Use new command binding system supporting multiple bindings (#1043) Co-authored-by: Pieter-Jan Briers --- .../EntitySystems/CharacterInterfaceSystem.cs | 14 +++++++--- .../EntitySystems/ClientInventorySystem.cs | 14 +++++++--- .../EntitySystems/CombatModeSystem.cs | 16 ++++++++---- .../EntitySystems/ConstructorSystem.cs | 17 +++++++++--- .../EntitySystems/ExamineSystem.cs | 12 +++++++-- .../GameObjects/EntitySystems/VerbSystem.cs | 14 +++++++--- .../EntitySystems/Click/InteractionSystem.cs | 26 ++++++++++--------- .../GameObjects/EntitySystems/HandsSystem.cs | 25 +++++++----------- .../GameObjects/EntitySystems/MoverSystem.cs | 24 +++++++---------- RobustToolbox | 2 +- 10 files changed, 102 insertions(+), 62 deletions(-) diff --git a/Content.Client/GameObjects/EntitySystems/CharacterInterfaceSystem.cs b/Content.Client/GameObjects/EntitySystems/CharacterInterfaceSystem.cs index 9a061cf26a..9b66217612 100644 --- a/Content.Client/GameObjects/EntitySystems/CharacterInterfaceSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/CharacterInterfaceSystem.cs @@ -6,6 +6,7 @@ using Robust.Client.Player; using Robust.Client.UserInterface.CustomControls; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Input; +using Robust.Shared.Input.Binding; using Robust.Shared.IoC; namespace Content.Client.GameObjects.EntitySystems @@ -21,9 +22,16 @@ namespace Content.Client.GameObjects.EntitySystems { base.Initialize(); - var inputSys = EntitySystemManager.GetEntitySystem(); - inputSys.BindMap.BindFunction(ContentKeyFunctions.OpenCharacterMenu, - InputCmdHandler.FromDelegate(s => HandleOpenCharacterMenu())); + CommandBinds.Builder + .Bind(ContentKeyFunctions.OpenCharacterMenu, + InputCmdHandler.FromDelegate(s => HandleOpenCharacterMenu())) + .Register(); + } + + public override void Shutdown() + { + CommandBinds.Unregister(); + base.Shutdown(); } private void HandleOpenCharacterMenu() diff --git a/Content.Client/GameObjects/EntitySystems/ClientInventorySystem.cs b/Content.Client/GameObjects/EntitySystems/ClientInventorySystem.cs index b1a2c8b67d..ccfb3ac7d0 100644 --- a/Content.Client/GameObjects/EntitySystems/ClientInventorySystem.cs +++ b/Content.Client/GameObjects/EntitySystems/ClientInventorySystem.cs @@ -5,6 +5,7 @@ using Robust.Client.Player; using Robust.Client.UserInterface.CustomControls; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Input; +using Robust.Shared.Input.Binding; using Robust.Shared.IoC; namespace Content.Client.GameObjects.EntitySystems @@ -20,9 +21,16 @@ namespace Content.Client.GameObjects.EntitySystems { base.Initialize(); - var inputSys = EntitySystemManager.GetEntitySystem(); - inputSys.BindMap.BindFunction(ContentKeyFunctions.OpenInventoryMenu, - InputCmdHandler.FromDelegate(s => HandleOpenInventoryMenu())); + CommandBinds.Builder + .Bind(ContentKeyFunctions.OpenInventoryMenu, + InputCmdHandler.FromDelegate(s => HandleOpenInventoryMenu())) + .Register(); + } + + public override void Shutdown() + { + CommandBinds.Unregister(); + base.Shutdown(); } private void HandleOpenInventoryMenu() diff --git a/Content.Client/GameObjects/EntitySystems/CombatModeSystem.cs b/Content.Client/GameObjects/EntitySystems/CombatModeSystem.cs index 3a80a2a959..1ea36b6ae0 100644 --- a/Content.Client/GameObjects/EntitySystems/CombatModeSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/CombatModeSystem.cs @@ -14,6 +14,7 @@ using Robust.Client.Interfaces.Graphics.Overlays; using Robust.Client.Interfaces.Input; using Robust.Client.Player; using Robust.Shared.Input; +using Robust.Shared.Input.Binding; using Robust.Shared.Interfaces.Timing; using Robust.Shared.IoC; using Robust.Shared.Maths; @@ -31,8 +32,6 @@ namespace Content.Client.GameObjects.EntitySystems [Dependency] private readonly IGameTiming _gameTiming; #pragma warning restore 649 - private InputSystem _inputSystem; - public override void Initialize() { base.Initialize(); @@ -40,9 +39,16 @@ namespace Content.Client.GameObjects.EntitySystems _gameHud.OnCombatModeChanged = OnCombatModeChanged; _gameHud.OnTargetingZoneChanged = OnTargetingZoneChanged; - _inputSystem = EntitySystemManager.GetEntitySystem(); - _inputSystem.BindMap.BindFunction(ContentKeyFunctions.ToggleCombatMode, - InputCmdHandler.FromDelegate(CombatModeToggled)); + CommandBinds.Builder + .Bind(ContentKeyFunctions.ToggleCombatMode, + InputCmdHandler.FromDelegate(CombatModeToggled)) + .Register(); + } + + public override void Shutdown() + { + CommandBinds.Unregister(); + base.Shutdown(); } private void CombatModeToggled(ICommonSession session) diff --git a/Content.Client/GameObjects/EntitySystems/ConstructorSystem.cs b/Content.Client/GameObjects/EntitySystems/ConstructorSystem.cs index 3a6f0a0167..95bec8cfd2 100644 --- a/Content.Client/GameObjects/EntitySystems/ConstructorSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/ConstructorSystem.cs @@ -6,6 +6,7 @@ using Robust.Client.GameObjects.EntitySystems; using Robust.Client.Player; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Input; +using Robust.Shared.Input.Binding; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; @@ -24,11 +25,19 @@ namespace Content.Client.GameObjects.EntitySystems base.Initialize(); var inputSys = EntitySystemManager.GetEntitySystem(); - inputSys.BindMap.BindFunction(ContentKeyFunctions.OpenCraftingMenu, - new PointerInputCmdHandler(HandleOpenCraftingMenu)); - inputSys.BindMap.BindFunction(EngineKeyFunctions.Use, - new PointerInputCmdHandler(HandleUse)); + CommandBinds.Builder + .Bind(ContentKeyFunctions.OpenCraftingMenu, + new PointerInputCmdHandler(HandleOpenCraftingMenu)) + .Bind(EngineKeyFunctions.Use, + new PointerInputCmdHandler(HandleUse)) + .Register(); + } + + public override void Shutdown() + { + CommandBinds.Unregister(); + base.Shutdown(); } private bool HandleOpenCraftingMenu(in PointerInputCmdHandler.PointerInputCmdArgs args) diff --git a/Content.Client/GameObjects/EntitySystems/ExamineSystem.cs b/Content.Client/GameObjects/EntitySystems/ExamineSystem.cs index ab07851402..f799ffa00a 100644 --- a/Content.Client/GameObjects/EntitySystems/ExamineSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/ExamineSystem.cs @@ -14,6 +14,7 @@ using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.GameObjects; using Robust.Shared.Input; +using Robust.Shared.Input.Binding; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; @@ -42,8 +43,15 @@ namespace Content.Client.GameObjects.EntitySystems { IoCManager.InjectDependencies(this); - var inputSys = EntitySystemManager.GetEntitySystem(); - inputSys.BindMap.BindFunction(ContentKeyFunctions.ExamineEntity, new PointerInputCmdHandler(HandleExamine)); + CommandBinds.Builder + .Bind(ContentKeyFunctions.ExamineEntity, new PointerInputCmdHandler(HandleExamine)) + .Register(); + } + + public override void Shutdown() + { + CommandBinds.Unregister(); + base.Shutdown(); } private bool HandleExamine(ICommonSession session, GridCoordinates coords, EntityUid uid) diff --git a/Content.Client/GameObjects/EntitySystems/VerbSystem.cs b/Content.Client/GameObjects/EntitySystems/VerbSystem.cs index a28a7c39e9..6e5a2a50f8 100644 --- a/Content.Client/GameObjects/EntitySystems/VerbSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/VerbSystem.cs @@ -24,6 +24,7 @@ using Robust.Client.Utility; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Input; +using Robust.Shared.Input.Binding; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Timing; using Robust.Shared.IoC; @@ -65,9 +66,16 @@ namespace Content.Client.GameObjects.EntitySystems IoCManager.InjectDependencies(this); - var input = EntitySystemManager.GetEntitySystem(); - input.BindMap.BindFunction(ContentKeyFunctions.OpenContextMenu, - new PointerInputCmdHandler(OnOpenContextMenu)); + CommandBinds.Builder + .Bind(ContentKeyFunctions.OpenContextMenu, + new PointerInputCmdHandler(OnOpenContextMenu)) + .Register(); + } + + public override void Shutdown() + { + CommandBinds.Unregister(); + base.Shutdown(); } public void OpenContextMenu(IEntity entity, ScreenCoordinates screenCoordinates) diff --git a/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs index 160f8d756b..1252e24b9d 100644 --- a/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs @@ -1,21 +1,18 @@ using System; using System.Linq; -using Content.Server.GameObjects.Components.Interactable; using Content.Server.GameObjects.Components.Mobs; using Content.Server.GameObjects.Components.Timing; using Content.Server.Interfaces.GameObjects; -using Content.Shared.GameObjects.Components.Interactable; using Content.Server.Utility; using Content.Shared.GameObjects.Components.Inventory; using Content.Shared.Input; -using Content.Shared.Physics; using JetBrains.Annotations; using Robust.Server.GameObjects.EntitySystems; using Robust.Server.Interfaces.Player; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Components; -using Robust.Shared.GameObjects.Systems; using Robust.Shared.Input; +using Robust.Shared.Input.Binding; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects.Components; using Robust.Shared.Interfaces.Map; @@ -319,16 +316,21 @@ namespace Content.Server.GameObjects.EntitySystems public override void Initialize() { - var inputSys = EntitySystemManager.GetEntitySystem(); - inputSys.BindMap.BindFunction(EngineKeyFunctions.Use, - new PointerInputCmdHandler(HandleUseItemInHand)); - inputSys.BindMap.BindFunction(ContentKeyFunctions.WideAttack, - new PointerInputCmdHandler(HandleWideAttack)); - inputSys.BindMap.BindFunction(ContentKeyFunctions.ActivateItemInWorld, - new PointerInputCmdHandler(HandleActivateItemInWorld)); + CommandBinds.Builder + .Bind(EngineKeyFunctions.Use, + new PointerInputCmdHandler(HandleUseItemInHand)) + .Bind(ContentKeyFunctions.WideAttack, + new PointerInputCmdHandler(HandleWideAttack)) + .Bind(ContentKeyFunctions.ActivateItemInWorld, + new PointerInputCmdHandler(HandleActivateItemInWorld)) + .Register(); } - + public override void Shutdown() + { + CommandBinds.Unregister(); + base.Shutdown(); + } private bool HandleActivateItemInWorld(ICommonSession session, GridCoordinates coords, EntityUid uid) { diff --git a/Content.Server/GameObjects/EntitySystems/HandsSystem.cs b/Content.Server/GameObjects/EntitySystems/HandsSystem.cs index 1a518b864d..578a94cb84 100644 --- a/Content.Server/GameObjects/EntitySystems/HandsSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/HandsSystem.cs @@ -12,6 +12,7 @@ using Robust.Server.Interfaces.Player; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Input; +using Robust.Shared.Input.Binding; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Map; using Robust.Shared.IoC; @@ -40,26 +41,20 @@ namespace Content.Server.GameObjects.EntitySystems SubscribeLocalEvent(HandleContainerModified); SubscribeLocalEvent(HandleContainerModified); - var input = EntitySystemManager.GetEntitySystem(); - input.BindMap.BindFunction(ContentKeyFunctions.SwapHands, InputCmdHandler.FromDelegate(HandleSwapHands)); - input.BindMap.BindFunction(ContentKeyFunctions.Drop, new PointerInputCmdHandler(HandleDrop)); - input.BindMap.BindFunction(ContentKeyFunctions.ActivateItemInHand, InputCmdHandler.FromDelegate(HandleActivateItem)); - input.BindMap.BindFunction(ContentKeyFunctions.ThrowItemInHand, new PointerInputCmdHandler(HandleThrowItem)); - input.BindMap.BindFunction(ContentKeyFunctions.SmartEquipBackpack, InputCmdHandler.FromDelegate(HandleSmartEquipBackpack)); - input.BindMap.BindFunction(ContentKeyFunctions.SmartEquipBelt, InputCmdHandler.FromDelegate(HandleSmartEquipBelt)); + CommandBinds.Builder + .Bind(ContentKeyFunctions.SwapHands, InputCmdHandler.FromDelegate(HandleSwapHands)) + .Bind(ContentKeyFunctions.Drop, new PointerInputCmdHandler(HandleDrop)) + .Bind(ContentKeyFunctions.ActivateItemInHand, InputCmdHandler.FromDelegate(HandleActivateItem)) + .Bind(ContentKeyFunctions.ThrowItemInHand, new PointerInputCmdHandler(HandleThrowItem)) + .Bind(ContentKeyFunctions.SmartEquipBackpack, InputCmdHandler.FromDelegate(HandleSmartEquipBackpack)) + .Bind(ContentKeyFunctions.SmartEquipBelt, InputCmdHandler.FromDelegate(HandleSmartEquipBelt)) + .Register(); } /// public override void Shutdown() { - if (EntitySystemManager.TryGetEntitySystem(out InputSystem input)) - { - input.BindMap.UnbindFunction(ContentKeyFunctions.SwapHands); - input.BindMap.UnbindFunction(ContentKeyFunctions.Drop); - input.BindMap.UnbindFunction(ContentKeyFunctions.ActivateItemInHand); - input.BindMap.UnbindFunction(ContentKeyFunctions.ThrowItemInHand); - } - + CommandBinds.Unregister(); base.Shutdown(); } diff --git a/Content.Server/GameObjects/EntitySystems/MoverSystem.cs b/Content.Server/GameObjects/EntitySystems/MoverSystem.cs index 8a2d72eef3..6e23b73861 100644 --- a/Content.Server/GameObjects/EntitySystems/MoverSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/MoverSystem.cs @@ -6,6 +6,7 @@ using Content.Server.Interfaces.GameObjects.Components.Movement; using Content.Shared.Audio; using Content.Shared.GameObjects.Components.Inventory; using Content.Shared.GameObjects.Components.Movement; +using Content.Shared.Input; using Content.Shared.Maps; using Content.Shared.Physics; using JetBrains.Annotations; @@ -19,6 +20,7 @@ using Robust.Shared.GameObjects.Components; using Robust.Shared.GameObjects.Components.Transform; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Input; +using Robust.Shared.Input.Binding; using Robust.Shared.Interfaces.Configuration; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects.Components; @@ -77,11 +79,13 @@ namespace Content.Server.GameObjects.EntitySystems var input = EntitySystemManager.GetEntitySystem(); - input.BindMap.BindFunction(EngineKeyFunctions.MoveUp, moveUpCmdHandler); - input.BindMap.BindFunction(EngineKeyFunctions.MoveLeft, moveLeftCmdHandler); - input.BindMap.BindFunction(EngineKeyFunctions.MoveRight, moveRightCmdHandler); - input.BindMap.BindFunction(EngineKeyFunctions.MoveDown, moveDownCmdHandler); - input.BindMap.BindFunction(EngineKeyFunctions.Run, runCmdHandler); + CommandBinds.Builder + .Bind(EngineKeyFunctions.MoveUp, moveUpCmdHandler) + .Bind(EngineKeyFunctions.MoveLeft, moveLeftCmdHandler) + .Bind(EngineKeyFunctions.MoveRight, moveRightCmdHandler) + .Bind(EngineKeyFunctions.MoveDown, moveDownCmdHandler) + .Bind(EngineKeyFunctions.Run, runCmdHandler) + .Register(); SubscribeLocalEvent(PlayerAttached); SubscribeLocalEvent(PlayerDetached); @@ -110,15 +114,7 @@ namespace Content.Server.GameObjects.EntitySystems /// public override void Shutdown() { - if (EntitySystemManager.TryGetEntitySystem(out InputSystem input)) - { - input.BindMap.UnbindFunction(EngineKeyFunctions.MoveUp); - input.BindMap.UnbindFunction(EngineKeyFunctions.MoveLeft); - input.BindMap.UnbindFunction(EngineKeyFunctions.MoveRight); - input.BindMap.UnbindFunction(EngineKeyFunctions.MoveDown); - input.BindMap.UnbindFunction(EngineKeyFunctions.Run); - } - + CommandBinds.Unregister(); base.Shutdown(); } diff --git a/RobustToolbox b/RobustToolbox index 29083fdb6f..31c5c9373f 160000 --- a/RobustToolbox +++ b/RobustToolbox @@ -1 +1 @@ -Subproject commit 29083fdb6f35fadb4c51f56b9eb0065e7f5c9e68 +Subproject commit 31c5c9373f661aac6f59168bfb7720bb923b78eb