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.Input;
|
||||
using SS14.Client.GameObjects;
|
||||
using SS14.Client.Interfaces.Input;
|
||||
using SS14.Client.UserInterface;
|
||||
using SS14.Client.UserInterface.Controls;
|
||||
using SS14.Client.UserInterface.CustomControls;
|
||||
@@ -25,7 +27,8 @@ namespace Content.Client.GameObjects
|
||||
{
|
||||
private InventoryWindow Window;
|
||||
private string TemplateName = "HumanInventory"; //stored for serialization purposes
|
||||
public event EventHandler<BoundKeyChangedMessage> OnCharacterMenuKey;
|
||||
|
||||
private InputCommand OpenMenuCommand;
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
@@ -39,12 +42,14 @@ namespace Content.Client.GameObjects
|
||||
base.ExposeData(serializer);
|
||||
|
||||
Window = new InventoryWindow(this);
|
||||
OpenMenuCommand = InputCommand.FromDelegate(() => { Window.AddToScreen(); Window.Open(); });
|
||||
serializer.DataField(ref TemplateName, "Template", "HumanInventory");
|
||||
Window.CreateInventory(TemplateName);
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null)
|
||||
{
|
||||
var inputMgr = IoCManager.Resolve<IInputManager>();
|
||||
switch (message)
|
||||
{
|
||||
//Updates what we are storing in UI slots
|
||||
@@ -58,30 +63,14 @@ namespace Content.Client.GameObjects
|
||||
Window.RemoveFromSlot(msg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register a hotkey to open the character menu with
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
OnCharacterMenuKey += OpenMenu;
|
||||
IoCManager.Resolve<IEntityManager>().SubscribeEvent<BoundKeyChangedMessage>(OnCharacterMenuKey, this);
|
||||
}
|
||||
case PlayerAttachedMsg _:
|
||||
inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, OpenMenuCommand);
|
||||
break;
|
||||
|
||||
/// <summary>
|
||||
/// Hotkey opens the character menu window
|
||||
/// </summary>
|
||||
/// <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();
|
||||
case PlayerDetachedMsg _:
|
||||
inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.Input;
|
||||
using SS14.Server.GameObjects;
|
||||
using SS14.Server.GameObjects.Components.Container;
|
||||
using SS14.Server.Interfaces.Player;
|
||||
@@ -40,6 +41,10 @@ namespace Content.Server.GameObjects
|
||||
// Mostly arbitrary.
|
||||
public const float PICKUP_RANGE = 2;
|
||||
|
||||
private InputCommand SwapHandsCommand;
|
||||
private InputCommand DropCommand;
|
||||
private InputCommand ActivateItemInHandCommand;
|
||||
|
||||
public override void ExposeData(EntitySerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
@@ -256,6 +261,7 @@ namespace Content.Server.GameObjects
|
||||
{
|
||||
base.HandleMessage(message, netChannel, component);
|
||||
|
||||
IPlayerInput input;
|
||||
switch (message)
|
||||
{
|
||||
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
|
||||
case BoundKeyChangedMsg msg:
|
||||
if (msg.State != BoundKeyState.Down)
|
||||
return;
|
||||
switch (msg.Function)
|
||||
{
|
||||
case BoundKeyFunctions.SwitchHands:
|
||||
SwapHands();
|
||||
break;
|
||||
case BoundKeyFunctions.Drop:
|
||||
Drop(ActiveIndex);
|
||||
break;
|
||||
case BoundKeyFunctions.ActivateItemInHand:
|
||||
var used = GetActiveHand?.Owner;
|
||||
if (used != null)
|
||||
{
|
||||
InteractionSystem.TryUseInteraction(Owner, used);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerAttachedMsg msg:
|
||||
InitInputCommands();
|
||||
input = msg.NewPlayer.Input;
|
||||
input.SetCommand(ContentKeyFunctions.SwapHands, SwapHandsCommand);
|
||||
input.SetCommand(ContentKeyFunctions.Drop, DropCommand);
|
||||
input.SetCommand(ContentKeyFunctions.ActivateItemInHand, ActivateItemInHandCommand);
|
||||
break;
|
||||
|
||||
case PlayerDetachedMsg msg:
|
||||
input = msg.OldPlayer.Input;
|
||||
input.SetCommand(ContentKeyFunctions.SwapHands, null);
|
||||
input.SetCommand(ContentKeyFunctions.Drop, null);
|
||||
input.SetCommand(ContentKeyFunctions.ActivateItemInHand, null);
|
||||
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>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
<Compile Include="Input\ContentKeyFunctions.cs" />
|
||||
</ItemGroup>
|
||||
<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.
|
||||
[Serializable]
|
||||
[Serializable, NetSerializable]
|
||||
public class HandsComponentState : ComponentState
|
||||
{
|
||||
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