Input Refactor (#72)
This commit is contained in:
committed by
GitHub
parent
b13d100107
commit
f1ec10e3e1
@@ -1,5 +1,7 @@
|
|||||||
using Content.Shared.GameObjects;
|
using Content.Shared.GameObjects;
|
||||||
|
using Content.Shared.Input;
|
||||||
using SS14.Client.GameObjects;
|
using SS14.Client.GameObjects;
|
||||||
|
using SS14.Client.Interfaces.Input;
|
||||||
using SS14.Client.UserInterface;
|
using SS14.Client.UserInterface;
|
||||||
using SS14.Client.UserInterface.Controls;
|
using SS14.Client.UserInterface.Controls;
|
||||||
using SS14.Client.UserInterface.CustomControls;
|
using SS14.Client.UserInterface.CustomControls;
|
||||||
@@ -25,7 +27,8 @@ namespace Content.Client.GameObjects
|
|||||||
{
|
{
|
||||||
private InventoryWindow Window;
|
private InventoryWindow Window;
|
||||||
private string TemplateName = "HumanInventory"; //stored for serialization purposes
|
private string TemplateName = "HumanInventory"; //stored for serialization purposes
|
||||||
public event EventHandler<BoundKeyChangedMessage> OnCharacterMenuKey;
|
|
||||||
|
private InputCommand OpenMenuCommand;
|
||||||
|
|
||||||
public override void OnRemove()
|
public override void OnRemove()
|
||||||
{
|
{
|
||||||
@@ -39,12 +42,14 @@ namespace Content.Client.GameObjects
|
|||||||
base.ExposeData(serializer);
|
base.ExposeData(serializer);
|
||||||
|
|
||||||
Window = new InventoryWindow(this);
|
Window = new InventoryWindow(this);
|
||||||
|
OpenMenuCommand = InputCommand.FromDelegate(() => { Window.AddToScreen(); Window.Open(); });
|
||||||
serializer.DataField(ref TemplateName, "Template", "HumanInventory");
|
serializer.DataField(ref TemplateName, "Template", "HumanInventory");
|
||||||
Window.CreateInventory(TemplateName);
|
Window.CreateInventory(TemplateName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null)
|
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null)
|
||||||
{
|
{
|
||||||
|
var inputMgr = IoCManager.Resolve<IInputManager>();
|
||||||
switch (message)
|
switch (message)
|
||||||
{
|
{
|
||||||
//Updates what we are storing in UI slots
|
//Updates what we are storing in UI slots
|
||||||
@@ -58,30 +63,14 @@ namespace Content.Client.GameObjects
|
|||||||
Window.RemoveFromSlot(msg);
|
Window.RemoveFromSlot(msg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
case PlayerAttachedMsg _:
|
||||||
/// Register a hotkey to open the character menu with
|
inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, OpenMenuCommand);
|
||||||
/// </summary>
|
break;
|
||||||
public override void Initialize()
|
|
||||||
{
|
|
||||||
base.Initialize();
|
|
||||||
OnCharacterMenuKey += OpenMenu;
|
|
||||||
IoCManager.Resolve<IEntityManager>().SubscribeEvent<BoundKeyChangedMessage>(OnCharacterMenuKey, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
case PlayerDetachedMsg _:
|
||||||
/// Hotkey opens the character menu window
|
inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, null);
|
||||||
/// </summary>
|
break;
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="message"></param>
|
|
||||||
private void OpenMenu(object sender, BoundKeyChangedMessage message)
|
|
||||||
{
|
|
||||||
if (message.Function == BoundKeyFunctions.OpenCharacterMenu && message.State == BoundKeyState.Down)
|
|
||||||
{
|
|
||||||
Window.AddToScreen();
|
|
||||||
Window.Open();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using Content.Server.GameObjects.EntitySystems;
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
using Content.Server.Interfaces.GameObjects;
|
using Content.Server.Interfaces.GameObjects;
|
||||||
using Content.Shared.GameObjects;
|
using Content.Shared.GameObjects;
|
||||||
|
using Content.Shared.Input;
|
||||||
using SS14.Server.GameObjects;
|
using SS14.Server.GameObjects;
|
||||||
using SS14.Server.GameObjects.Components.Container;
|
using SS14.Server.GameObjects.Components.Container;
|
||||||
using SS14.Server.Interfaces.Player;
|
using SS14.Server.Interfaces.Player;
|
||||||
@@ -40,6 +41,10 @@ namespace Content.Server.GameObjects
|
|||||||
// Mostly arbitrary.
|
// Mostly arbitrary.
|
||||||
public const float PICKUP_RANGE = 2;
|
public const float PICKUP_RANGE = 2;
|
||||||
|
|
||||||
|
private InputCommand SwapHandsCommand;
|
||||||
|
private InputCommand DropCommand;
|
||||||
|
private InputCommand ActivateItemInHandCommand;
|
||||||
|
|
||||||
public override void ExposeData(EntitySerializer serializer)
|
public override void ExposeData(EntitySerializer serializer)
|
||||||
{
|
{
|
||||||
base.ExposeData(serializer);
|
base.ExposeData(serializer);
|
||||||
@@ -256,6 +261,7 @@ namespace Content.Server.GameObjects
|
|||||||
{
|
{
|
||||||
base.HandleMessage(message, netChannel, component);
|
base.HandleMessage(message, netChannel, component);
|
||||||
|
|
||||||
|
IPlayerInput input;
|
||||||
switch (message)
|
switch (message)
|
||||||
{
|
{
|
||||||
case ClientChangedHandMsg msg:
|
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
|
//Boundkeychangedmsg only works for the player entity and doesn't need any extra verification
|
||||||
case BoundKeyChangedMsg msg:
|
case PlayerAttachedMsg msg:
|
||||||
if (msg.State != BoundKeyState.Down)
|
InitInputCommands();
|
||||||
return;
|
input = msg.NewPlayer.Input;
|
||||||
switch (msg.Function)
|
input.SetCommand(ContentKeyFunctions.SwapHands, SwapHandsCommand);
|
||||||
{
|
input.SetCommand(ContentKeyFunctions.Drop, DropCommand);
|
||||||
case BoundKeyFunctions.SwitchHands:
|
input.SetCommand(ContentKeyFunctions.ActivateItemInHand, ActivateItemInHandCommand);
|
||||||
SwapHands();
|
break;
|
||||||
break;
|
|
||||||
case BoundKeyFunctions.Drop:
|
case PlayerDetachedMsg msg:
|
||||||
Drop(ActiveIndex);
|
input = msg.OldPlayer.Input;
|
||||||
break;
|
input.SetCommand(ContentKeyFunctions.SwapHands, null);
|
||||||
case BoundKeyFunctions.ActivateItemInHand:
|
input.SetCommand(ContentKeyFunctions.Drop, null);
|
||||||
var used = GetActiveHand?.Owner;
|
input.SetCommand(ContentKeyFunctions.ActivateItemInHand, null);
|
||||||
if (used != null)
|
|
||||||
{
|
|
||||||
InteractionSystem.TryUseInteraction(Owner, used);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,6 +98,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="app.config" />
|
<None Include="app.config" />
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
<Compile Include="Input\ContentKeyFunctions.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
||||||
@@ -13,7 +13,7 @@ namespace Content.Shared.GameObjects
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The IDs of the items get synced over the network.
|
// The IDs of the items get synced over the network.
|
||||||
[Serializable]
|
[Serializable, NetSerializable]
|
||||||
public class HandsComponentState : ComponentState
|
public class HandsComponentState : ComponentState
|
||||||
{
|
{
|
||||||
public readonly Dictionary<string, EntityUid> Hands;
|
public readonly Dictionary<string, EntityUid> Hands;
|
||||||
|
|||||||
13
Content.Shared/Input/ContentKeyFunctions.cs
Normal file
13
Content.Shared/Input/ContentKeyFunctions.cs
Normal file
@@ -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";
|
||||||
|
}
|
||||||
|
}
|
||||||
14
Resources/keybinds_content.yml
Normal file
14
Resources/keybinds_content.yml
Normal file
@@ -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
|
||||||
2
engine
2
engine
Submodule engine updated: 909bb5936f...dc80060757
Reference in New Issue
Block a user