Use new command binding system supporting multiple bindings (#1043)

Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
chairbender
2020-05-31 14:32:05 -07:00
committed by GitHub
parent f14701033b
commit 12f3b6bb7b
10 changed files with 102 additions and 62 deletions

View File

@@ -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<InputSystem>();
inputSys.BindMap.BindFunction(ContentKeyFunctions.OpenCharacterMenu,
InputCmdHandler.FromDelegate(s => HandleOpenCharacterMenu()));
CommandBinds.Builder
.Bind(ContentKeyFunctions.OpenCharacterMenu,
InputCmdHandler.FromDelegate(s => HandleOpenCharacterMenu()))
.Register<CharacterInterfaceSystem>();
}
public override void Shutdown()
{
CommandBinds.Unregister<CharacterInterfaceSystem>();
base.Shutdown();
}
private void HandleOpenCharacterMenu()

View File

@@ -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<InputSystem>();
inputSys.BindMap.BindFunction(ContentKeyFunctions.OpenInventoryMenu,
InputCmdHandler.FromDelegate(s => HandleOpenInventoryMenu()));
CommandBinds.Builder
.Bind(ContentKeyFunctions.OpenInventoryMenu,
InputCmdHandler.FromDelegate(s => HandleOpenInventoryMenu()))
.Register<ClientInventorySystem>();
}
public override void Shutdown()
{
CommandBinds.Unregister<ClientInventorySystem>();
base.Shutdown();
}
private void HandleOpenInventoryMenu()

View File

@@ -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>();
_inputSystem.BindMap.BindFunction(ContentKeyFunctions.ToggleCombatMode,
InputCmdHandler.FromDelegate(CombatModeToggled));
CommandBinds.Builder
.Bind(ContentKeyFunctions.ToggleCombatMode,
InputCmdHandler.FromDelegate(CombatModeToggled))
.Register<CombatModeSystem>();
}
public override void Shutdown()
{
CommandBinds.Unregister<CombatModeSystem>();
base.Shutdown();
}
private void CombatModeToggled(ICommonSession session)

View File

@@ -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<InputSystem>();
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<ConstructorSystem>();
}
public override void Shutdown()
{
CommandBinds.Unregister<ConstructorSystem>();
base.Shutdown();
}
private bool HandleOpenCraftingMenu(in PointerInputCmdHandler.PointerInputCmdArgs args)

View File

@@ -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<InputSystem>();
inputSys.BindMap.BindFunction(ContentKeyFunctions.ExamineEntity, new PointerInputCmdHandler(HandleExamine));
CommandBinds.Builder
.Bind(ContentKeyFunctions.ExamineEntity, new PointerInputCmdHandler(HandleExamine))
.Register<ExamineSystem>();
}
public override void Shutdown()
{
CommandBinds.Unregister<ExamineSystem>();
base.Shutdown();
}
private bool HandleExamine(ICommonSession session, GridCoordinates coords, EntityUid uid)

View File

@@ -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<InputSystem>();
input.BindMap.BindFunction(ContentKeyFunctions.OpenContextMenu,
new PointerInputCmdHandler(OnOpenContextMenu));
CommandBinds.Builder
.Bind(ContentKeyFunctions.OpenContextMenu,
new PointerInputCmdHandler(OnOpenContextMenu))
.Register<VerbSystem>();
}
public override void Shutdown()
{
CommandBinds.Unregister<VerbSystem>();
base.Shutdown();
}
public void OpenContextMenu(IEntity entity, ScreenCoordinates screenCoordinates)

View File

@@ -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<InputSystem>();
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<InteractionSystem>();
}
public override void Shutdown()
{
CommandBinds.Unregister<InteractionSystem>();
base.Shutdown();
}
private bool HandleActivateItemInWorld(ICommonSession session, GridCoordinates coords, EntityUid uid)
{

View File

@@ -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<EntRemovedFromContainerMessage>(HandleContainerModified);
SubscribeLocalEvent<EntInsertedIntoContainerMessage>(HandleContainerModified);
var input = EntitySystemManager.GetEntitySystem<InputSystem>();
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<HandsSystem>();
}
/// <inheritdoc />
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<HandsSystem>();
base.Shutdown();
}

View File

@@ -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<InputSystem>();
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<MoverSystem>();
SubscribeLocalEvent<PlayerAttachSystemMessage>(PlayerAttached);
SubscribeLocalEvent<PlayerDetachedSystemMessage>(PlayerDetached);
@@ -110,15 +114,7 @@ namespace Content.Server.GameObjects.EntitySystems
/// <inheritdoc />
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<MoverSystem>();
base.Shutdown();
}