Refactored input system

This commit is contained in:
ShadowCommander
2019-08-04 16:03:51 -07:00
parent b996466b3d
commit 7422d9148a
8 changed files with 70 additions and 43 deletions

View File

@@ -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();
}

View File

@@ -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;

View File

@@ -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);

View File

@@ -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,9 +203,14 @@ 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);
if (!args.CanFocus)
{
return;
}
var leftHandContains = _handL.Contains((Vector2i)args.RelativePosition);
var rightHandContains = _handR.Contains((Vector2i)args.RelativePosition);
@@ -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<IEntitySystemManager>();
esm.GetEntitySystem<VerbSystem>().OpenContextMenu(entity, new ScreenCoordinates(args.GlobalPosition));
esm.GetEntitySystem<VerbSystem>().OpenContextMenu(entity, new ScreenCoordinates(args.PointerLocation.Position));
}
}
}

View File

@@ -200,7 +200,7 @@ namespace Content.Server.GameObjects.EntitySystems
public override void Initialize()
{
var inputSys = EntitySystemManager.GetEntitySystem<InputSystem>();
inputSys.BindMap.BindFunction(ContentKeyFunctions.UseItemInHand,
inputSys.BindMap.BindFunction(EngineKeyFunctions.Use,
new PointerInputCmdHandler(HandleUseItemInHand));
inputSys.BindMap.BindFunction(ContentKeyFunctions.ActivateItemInWorld,
new PointerInputCmdHandler(HandleActivateItemInWorld));

View File

@@ -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";
}
}

View File

@@ -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