From 7422d9148ad110b73b748edcf0b5bf9e8d327c76 Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Sun, 4 Aug 2019 16:03:51 -0700 Subject: [PATCH] Refactored input system --- Content.Client/Chat/ChatBox.cs | 9 ++- .../EntitySystems/RangedWeaponSystem.cs | 4 +- Content.Client/Input/ContentContexts.cs | 2 +- Content.Client/UserInterface/HandsGui.cs | 23 ++++--- .../EntitySystems/Click/InteractionSystem.cs | 2 +- Content.Shared/Input/ContentKeyFunctions.cs | 2 +- Resources/keybinds.yml | 69 +++++++++++-------- RobustToolbox | 2 +- 8 files changed, 70 insertions(+), 43 deletions(-) diff --git a/Content.Client/Chat/ChatBox.cs b/Content.Client/Chat/ChatBox.cs index fc86a3c3fb..74717204fe 100644 --- a/Content.Client/Chat/ChatBox.cs +++ b/Content.Client/Chat/ChatBox.cs @@ -121,9 +121,14 @@ namespace Content.Client.Chat AddChild(outerVBox); } - protected override void MouseDown(GUIMouseButtonEventArgs e) + protected override void KeyBindDown(GUIBoundKeyEventArgs args) { - base.MouseDown(e); + base.KeyBindDown(args); + + if (!args.CanFocus) + { + return; + } Input.GrabKeyboardFocus(); } diff --git a/Content.Client/GameObjects/EntitySystems/RangedWeaponSystem.cs b/Content.Client/GameObjects/EntitySystems/RangedWeaponSystem.cs index 9071ee8e31..11216aa891 100644 --- a/Content.Client/GameObjects/EntitySystems/RangedWeaponSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/RangedWeaponSystem.cs @@ -1,4 +1,4 @@ -using Content.Client.GameObjects.Components.Weapons.Ranged; +using Content.Client.GameObjects.Components.Weapons.Ranged; using Content.Client.Interfaces.GameObjects; using Content.Shared.Input; using Robust.Client.GameObjects.EntitySystems; @@ -37,7 +37,7 @@ namespace Content.Client.GameObjects.EntitySystems base.Update(frameTime); var canFireSemi = _isFirstShot; - var state = _inputSystem.CmdStates.GetState(ContentKeyFunctions.UseItemInHand); + var state = _inputSystem.CmdStates.GetState(EngineKeyFunctions.Use); if (state != BoundKeyState.Down) { _isFirstShot = true; diff --git a/Content.Client/Input/ContentContexts.cs b/Content.Client/Input/ContentContexts.cs index d768e88611..13c5a43518 100644 --- a/Content.Client/Input/ContentContexts.cs +++ b/Content.Client/Input/ContentContexts.cs @@ -21,12 +21,12 @@ namespace Content.Client.Input human.AddFunction(ContentKeyFunctions.Drop); human.AddFunction(ContentKeyFunctions.ActivateItemInHand); human.AddFunction(ContentKeyFunctions.OpenCharacterMenu); - human.AddFunction(ContentKeyFunctions.UseItemInHand); human.AddFunction(ContentKeyFunctions.ActivateItemInWorld); human.AddFunction(ContentKeyFunctions.ThrowItemInHand); human.AddFunction(ContentKeyFunctions.OpenContextMenu); human.AddFunction(ContentKeyFunctions.OpenCraftingMenu); human.AddFunction(ContentKeyFunctions.OpenInventoryMenu); + human.AddFunction(ContentKeyFunctions.MouseMiddle); // Disabled until there is feedback, so hitting tab doesn't suddenly break interaction. // human.AddFunction(ContentKeyFunctions.ToggleCombatMode); diff --git a/Content.Client/UserInterface/HandsGui.cs b/Content.Client/UserInterface/HandsGui.cs index 7a3dfbbf56..292da6f617 100644 --- a/Content.Client/UserInterface/HandsGui.cs +++ b/Content.Client/UserInterface/HandsGui.cs @@ -2,6 +2,7 @@ using Content.Client.GameObjects.EntitySystems; using Content.Client.Interfaces.GameObjects; using Content.Client.Utility; +using Content.Shared.Input; using Robust.Client.Graphics; using Robust.Client.Input; using Robust.Client.Interfaces.GameObjects.Components; @@ -9,6 +10,7 @@ using Robust.Client.Interfaces.ResourceManagement; using Robust.Client.Player; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; +using Robust.Shared.Input; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; @@ -201,12 +203,17 @@ namespace Content.Client.UserInterface return _handL.Contains((Vector2i) point) || _handR.Contains((Vector2i) point); } - protected override void MouseDown(GUIMouseButtonEventArgs args) + protected override void KeyBindDown(GUIBoundKeyEventArgs args) { - base.MouseDown(args); + base.KeyBindDown(args); - var leftHandContains = _handL.Contains((Vector2i) args.RelativePosition); - var rightHandContains = _handR.Contains((Vector2i) args.RelativePosition); + if (!args.CanFocus) + { + return; + } + + var leftHandContains = _handL.Contains((Vector2i)args.RelativePosition); + var rightHandContains = _handR.Contains((Vector2i)args.RelativePosition); string handIndex; if (leftHandContains) @@ -222,7 +229,7 @@ namespace Content.Client.UserInterface return; } - if (args.Button == Mouse.Button.Left) + if (args.Function == EngineKeyFunctions.Use) { if (!TryGetHands(out var hands)) return; @@ -238,12 +245,12 @@ namespace Content.Client.UserInterface } } - else if (args.Button == Mouse.Button.Middle) + else if (args.Function == ContentKeyFunctions.MouseMiddle) { SendSwitchHandTo(handIndex); } - else if (args.Button == Mouse.Button.Right) + else if (args.Function == ContentKeyFunctions.OpenContextMenu) { if (!TryGetHands(out var hands)) { @@ -257,7 +264,7 @@ namespace Content.Client.UserInterface } var esm = IoCManager.Resolve(); - esm.GetEntitySystem().OpenContextMenu(entity, new ScreenCoordinates(args.GlobalPosition)); + esm.GetEntitySystem().OpenContextMenu(entity, new ScreenCoordinates(args.PointerLocation.Position)); } } } diff --git a/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs index 3f851589dc..0c98ead8f5 100644 --- a/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs @@ -200,7 +200,7 @@ namespace Content.Server.GameObjects.EntitySystems public override void Initialize() { var inputSys = EntitySystemManager.GetEntitySystem(); - inputSys.BindMap.BindFunction(ContentKeyFunctions.UseItemInHand, + inputSys.BindMap.BindFunction(EngineKeyFunctions.Use, new PointerInputCmdHandler(HandleUseItemInHand)); inputSys.BindMap.BindFunction(ContentKeyFunctions.ActivateItemInWorld, new PointerInputCmdHandler(HandleActivateItemInWorld)); diff --git a/Content.Shared/Input/ContentKeyFunctions.cs b/Content.Shared/Input/ContentKeyFunctions.cs index 2b63091d36..501e433c97 100644 --- a/Content.Shared/Input/ContentKeyFunctions.cs +++ b/Content.Shared/Input/ContentKeyFunctions.cs @@ -18,6 +18,6 @@ namespace Content.Shared.Input public static readonly BoundKeyFunction SwapHands = "SwapHands"; public static readonly BoundKeyFunction ThrowItemInHand = "ThrowItemInHand"; public static readonly BoundKeyFunction ToggleCombatMode = "ToggleCombatMode"; - public static readonly BoundKeyFunction UseItemInHand = "UseItemInHand"; // use hand item on world entity + public static readonly BoundKeyFunction MouseMiddle = "MouseMiddle"; } } diff --git a/Resources/keybinds.yml b/Resources/keybinds.yml index d21fbb314c..b72e6baf7c 100644 --- a/Resources/keybinds.yml +++ b/Resources/keybinds.yml @@ -1,78 +1,86 @@ version: 1 # Not used right now, whatever. binds: +- function: Use + type: state + key: MouseLeft + canFocus: true - function: ShowDebugMonitors + type: Toggle key: F3 - type: Toggle - function: HideUI - key: F4 type: Toggle + key: F4 - function: MoveUp + type: State key: W - type: State - function: MoveLeft + type: State key: A - type: State - function: MoveRight + type: State key: D - type: State - function: MoveDown + type: State key: S - type: State - function: Run + type: State key: Shift - type: State - function: ShowEscapeMenu + type: State key: Escape - type: State - function: FocusChatWindow + type: State key: T - type: State - function: EditorLinePlace - key: MouseLeft - mod1: Shift type: State + key: MouseLeft + canFocus: true + mod1: Shift - function: EditorGridPlace - key: MouseLeft - mod1: Control type: State + key: MouseLeft + canFocus: true + mod1: Control - function: EditorPlaceObject - key: MouseLeft type: State + key: MouseLeft + canFocus: true - function: EditorCancelPlace - key: MouseRight type: State + key: MouseRight + canFocus: true - function: EditorRotateObject + type: State key: MouseMiddle - type: State - function: SwapHands + type: State key: X - type: State - function: Drop + type: State key: Q - type: State - function: ActivateItemInHand + type: State key: Z - type: State - function: OpenCharacterMenu + type: State key: C - type: State - function: ExamineEntity - key: MouseLeft - mod1: Shift type: State -- function: UseItemInHand key: MouseLeft - type: state + canFocus: true + mod1: Shift - function: ActivateItemInWorld + type: state key: E - type: state - function: ThrowItemInHand + type: state key: MouseLeft + canFocus: true mod1: Control - type: state - function: OpenContextMenu - key: MouseRight type: state + key: MouseRight + canFocus: true - function: ToggleCombatMode type: Toggle key: Tab @@ -85,3 +93,10 @@ binds: - function: OpenInventoryMenu type: state key: I +- function: ShowDebugConsole + type: state + key: Tilde +- function: MouseMiddle + type: state + key: MouseMiddle + canFocus: true \ No newline at end of file diff --git a/RobustToolbox b/RobustToolbox index 3f7cd1f1b2..a9d8044105 160000 --- a/RobustToolbox +++ b/RobustToolbox @@ -1 +1 @@ -Subproject commit 3f7cd1f1b2da2b2e4b0e046632030c8011f85912 +Subproject commit a9d8044105d40b8e85267ed4fb9e98889bc60c92