Input Handling (#90)
* Migrates the Examine system to the new Input system. * Update Engine.
This commit is contained in:
@@ -28,7 +28,7 @@ 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
|
||||||
|
|
||||||
private InputCommand OpenMenuCommand;
|
private InputCmdHandler _openMenuCmdHandler;
|
||||||
|
|
||||||
public override void OnRemove()
|
public override void OnRemove()
|
||||||
{
|
{
|
||||||
@@ -42,7 +42,7 @@ 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(); });
|
_openMenuCmdHandler = InputCmdHandler.FromDelegate(session => { Window.AddToScreen(); Window.Open(); });
|
||||||
serializer.DataField(ref TemplateName, "Template", "HumanInventory");
|
serializer.DataField(ref TemplateName, "Template", "HumanInventory");
|
||||||
Window.CreateInventory(TemplateName);
|
Window.CreateInventory(TemplateName);
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ namespace Content.Client.GameObjects
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PlayerAttachedMsg _:
|
case PlayerAttachedMsg _:
|
||||||
inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, OpenMenuCommand);
|
inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, _openMenuCmdHandler);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PlayerDetachedMsg _:
|
case PlayerDetachedMsg _:
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using SS14.Shared.Interfaces.GameObjects;
|
|||||||
using SS14.Shared.Interfaces.GameObjects.Components;
|
using SS14.Shared.Interfaces.GameObjects.Components;
|
||||||
using SS14.Shared.Interfaces.Network;
|
using SS14.Shared.Interfaces.Network;
|
||||||
using SS14.Shared.IoC;
|
using SS14.Shared.IoC;
|
||||||
|
using SS14.Shared.Players;
|
||||||
using SS14.Shared.Serialization;
|
using SS14.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects
|
namespace Content.Server.GameObjects
|
||||||
@@ -42,9 +43,9 @@ namespace Content.Server.GameObjects
|
|||||||
// Mostly arbitrary.
|
// Mostly arbitrary.
|
||||||
public const float PICKUP_RANGE = 2;
|
public const float PICKUP_RANGE = 2;
|
||||||
|
|
||||||
private InputCommand SwapHandsCommand;
|
private InputCmdHandler _swapHandsCmdHandler;
|
||||||
private InputCommand DropCommand;
|
private InputCmdHandler _dropCmdHandler;
|
||||||
private InputCommand ActivateItemInHandCommand;
|
private InputCmdHandler _activateItemInHandCmdHandler;
|
||||||
|
|
||||||
public override void ExposeData(ObjectSerializer serializer)
|
public override void ExposeData(ObjectSerializer serializer)
|
||||||
{
|
{
|
||||||
@@ -250,7 +251,7 @@ namespace Content.Server.GameObjects
|
|||||||
return new HandsComponentState(dict, ActiveIndex);
|
return new HandsComponentState(dict, ActiveIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SwapHands()
|
private void SwapHands(ICommonSession channel)
|
||||||
{
|
{
|
||||||
var index = orderedHands.FindIndex(x => x == ActiveIndex);
|
var index = orderedHands.FindIndex(x => x == ActiveIndex);
|
||||||
index++;
|
index++;
|
||||||
@@ -298,9 +299,9 @@ namespace Content.Server.GameObjects
|
|||||||
case PlayerAttachedMsg msg:
|
case PlayerAttachedMsg msg:
|
||||||
InitInputCommands();
|
InitInputCommands();
|
||||||
input = msg.NewPlayer.Input;
|
input = msg.NewPlayer.Input;
|
||||||
input.SetCommand(ContentKeyFunctions.SwapHands, SwapHandsCommand);
|
input.SetCommand(ContentKeyFunctions.SwapHands, _swapHandsCmdHandler);
|
||||||
input.SetCommand(ContentKeyFunctions.Drop, DropCommand);
|
input.SetCommand(ContentKeyFunctions.Drop, _dropCmdHandler);
|
||||||
input.SetCommand(ContentKeyFunctions.ActivateItemInHand, ActivateItemInHandCommand);
|
input.SetCommand(ContentKeyFunctions.ActivateItemInHand, _activateItemInHandCmdHandler);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PlayerDetachedMsg msg:
|
case PlayerDetachedMsg msg:
|
||||||
@@ -314,14 +315,14 @@ namespace Content.Server.GameObjects
|
|||||||
|
|
||||||
private void InitInputCommands()
|
private void InitInputCommands()
|
||||||
{
|
{
|
||||||
if (SwapHandsCommand != null)
|
if (_swapHandsCmdHandler != null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SwapHandsCommand = InputCommand.FromDelegate(SwapHands);
|
_swapHandsCmdHandler = InputCmdHandler.FromDelegate(SwapHands);
|
||||||
DropCommand = InputCommand.FromDelegate(() => Drop(ActiveIndex));
|
_dropCmdHandler = InputCmdHandler.FromDelegate(session => Drop(ActiveIndex));
|
||||||
ActivateItemInHandCommand = InputCommand.FromDelegate(() =>
|
_activateItemInHandCmdHandler = InputCmdHandler.FromDelegate(session =>
|
||||||
{
|
{
|
||||||
var used = GetActiveHand?.Owner;
|
var used = GetActiveHand?.Owner;
|
||||||
if (used != null)
|
if (used != null)
|
||||||
|
|||||||
@@ -58,9 +58,6 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
case ClickType.Left:
|
case ClickType.Left:
|
||||||
EntitySystemManager.GetEntitySystem<InteractionSystem>().UserInteraction(message, player);
|
EntitySystemManager.GetEntitySystem<InteractionSystem>().UserInteraction(message, player);
|
||||||
break;
|
break;
|
||||||
case (ClickType.Left | ClickType.Shift):
|
|
||||||
EntitySystemManager.GetEntitySystem<ExamineSystem>().Examine(message, player);
|
|
||||||
break;
|
|
||||||
case ClickType.Right:
|
case ClickType.Right:
|
||||||
//Verb System
|
//Verb System
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
using SS14.Server.Interfaces.Chat;
|
using System;
|
||||||
using SS14.Server.Interfaces.GameObjects;
|
using System.Text;
|
||||||
|
using Content.Shared.Input;
|
||||||
|
using SS14.Server.GameObjects.EntitySystems;
|
||||||
|
using SS14.Server.Interfaces.Chat;
|
||||||
|
using SS14.Server.Interfaces.Player;
|
||||||
using SS14.Shared.GameObjects;
|
using SS14.Shared.GameObjects;
|
||||||
using SS14.Shared.GameObjects.Systems;
|
using SS14.Shared.GameObjects.Systems;
|
||||||
using SS14.Shared.Interfaces.GameObjects;
|
using SS14.Shared.Input;
|
||||||
using SS14.Shared.Interfaces.GameObjects.Components;
|
using SS14.Shared.Interfaces.GameObjects.Components;
|
||||||
using SS14.Shared.IoC;
|
using SS14.Shared.IoC;
|
||||||
using SS14.Shared.Log;
|
using SS14.Shared.Log;
|
||||||
using System;
|
using SS14.Shared.Map;
|
||||||
using System.Text;
|
using SS14.Shared.Players;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.EntitySystems
|
namespace Content.Server.GameObjects.EntitySystems
|
||||||
{
|
{
|
||||||
@@ -22,51 +26,57 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
|
|
||||||
public class ExamineSystem : EntitySystem
|
public class ExamineSystem : EntitySystem
|
||||||
{
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
public void Examine(ClickEventMessage msg, IEntity player)
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
//Get entity clicked upon from UID if valid UID, if not assume no entity clicked upon and null
|
var inputSys = EntitySystemManager.GetEntitySystem<InputSystem>();
|
||||||
IEntity examined = null;
|
inputSys.BindMap.BindFunction(ContentKeyFunctions.ExamineEntity, new PointerInputCmdHandler(HandleExamine));
|
||||||
if (msg.Uid.IsValid())
|
}
|
||||||
examined = EntityManager.GetEntity(msg.Uid);
|
|
||||||
|
|
||||||
if (examined == null)
|
private void HandleExamine(ICommonSession session, GridLocalCoordinates coords, EntityUid uid)
|
||||||
|
{
|
||||||
|
if (!(session is IPlayerSession svSession))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var playerEnt = svSession.AttachedEntity;
|
||||||
|
if (!EntityManager.TryGetEntity(uid, out var examined))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//Verify player has a transform component
|
//Verify player has a transform component
|
||||||
if (!player.TryGetComponent<ITransformComponent>(out var playerTransform))
|
if (!playerEnt.TryGetComponent<ITransformComponent>(out var playerTransform))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//Verify player is on the same map as the entity he clicked on
|
|
||||||
else if (msg.Coordinates.MapID != playerTransform.MapID)
|
|
||||||
{
|
|
||||||
Logger.Warning(string.Format("Player named {0} clicked on a map he isn't located on", player.Name));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Start a stringbuilder since we have no idea how many times this could be appended to
|
//Verify player is on the same map as the entity he clicked on
|
||||||
StringBuilder fullexaminetext = new StringBuilder("This is " + examined.Name);
|
if (coords.MapID != playerTransform.MapID)
|
||||||
|
{
|
||||||
|
Logger.WarningS("sys.examine", $"Player named {session.Name} clicked on a map he isn't located on");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Start a StringBuilder since we have no idea how many times this could be appended to
|
||||||
|
var fullExamineText = new StringBuilder("This is " + examined.Name);
|
||||||
|
|
||||||
//Add an entity description if one is declared
|
//Add an entity description if one is declared
|
||||||
if (!string.IsNullOrEmpty(examined.Description))
|
if (!string.IsNullOrEmpty(examined.Description))
|
||||||
{
|
{
|
||||||
fullexaminetext.Append(Environment.NewLine + examined.Description);
|
fullExamineText.Append(Environment.NewLine + examined.Description);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add component statuses from components that report one
|
//Add component statuses from components that report one
|
||||||
foreach (var examinecomponents in examined.GetAllComponents<IExamine>())
|
foreach (var examineComponents in examined.GetAllComponents<IExamine>())
|
||||||
{
|
{
|
||||||
string componentdescription = examinecomponents.Examine();
|
var componentDescription = examineComponents.Examine();
|
||||||
if (!string.IsNullOrEmpty(componentdescription))
|
if (string.IsNullOrEmpty(componentDescription))
|
||||||
{
|
continue;
|
||||||
fullexaminetext.Append(Environment.NewLine + componentdescription);
|
|
||||||
}
|
fullExamineText.Append(Environment.NewLine);
|
||||||
|
fullExamineText.Append(componentDescription);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Send to client chat channel
|
//Send to client chat channel
|
||||||
//TODO: Fix fact you can only send to all clients because you cant resolve clients from player entities
|
IoCManager.Resolve<IChatManager>().DispatchMessage(SS14.Shared.Console.ChatChannel.Visual, fullExamineText.ToString(), session.Index);
|
||||||
IoCManager.Resolve<IChatManager>().DispatchMessage(SS14.Shared.Console.ChatChannel.Visual, fullexaminetext.ToString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using SS14.Shared.Input;
|
using SS14.Shared.Input;
|
||||||
|
|
||||||
namespace Content.Shared.Input
|
namespace Content.Shared.Input
|
||||||
{
|
{
|
||||||
@@ -9,5 +9,6 @@ namespace Content.Shared.Input
|
|||||||
public static readonly BoundKeyFunction Drop = "Drop";
|
public static readonly BoundKeyFunction Drop = "Drop";
|
||||||
public static readonly BoundKeyFunction ActivateItemInHand = "ActivateItemInHand";
|
public static readonly BoundKeyFunction ActivateItemInHand = "ActivateItemInHand";
|
||||||
public static readonly BoundKeyFunction OpenCharacterMenu = "OpenCharacterMenu";
|
public static readonly BoundKeyFunction OpenCharacterMenu = "OpenCharacterMenu";
|
||||||
|
public static readonly BoundKeyFunction ExamineEntity = "ExamineEntity";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,3 +12,7 @@ binds:
|
|||||||
- function: OpenCharacterMenu
|
- function: OpenCharacterMenu
|
||||||
key: C
|
key: C
|
||||||
type: State
|
type: State
|
||||||
|
- function: ExamineEntity
|
||||||
|
key: MouseLeft
|
||||||
|
mod1: Shift
|
||||||
|
type: State
|
||||||
|
|||||||
2
engine
2
engine
Submodule engine updated: 830ff0f5b1...21b00df2b1
Reference in New Issue
Block a user