Click Migration (#94)

* Migrated Interaction system to the new Input system.

* Contexts are now set up in content.
This commit is contained in:
Acruid
2018-08-16 15:57:11 -07:00
committed by GitHub
parent 189a52c6d7
commit ce5760d46c
11 changed files with 67 additions and 81 deletions

View File

@@ -71,6 +71,7 @@
<Compile Include="EntryPoint.cs" /> <Compile Include="EntryPoint.cs" />
<Compile Include="GameObjects\Components\Inventory\ClientInventoryComponent.cs" /> <Compile Include="GameObjects\Components\Inventory\ClientInventoryComponent.cs" />
<Compile Include="GameObjects\Components\Storage\ClientStorageComponent.cs" /> <Compile Include="GameObjects\Components\Storage\ClientStorageComponent.cs" />
<Compile Include="Input\ContentContexts.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="GameObjects\Components\Items\ClientHandsComponent.cs" /> <Compile Include="GameObjects\Components\Items\ClientHandsComponent.cs" />
<Compile Include="Interfaces\GameObjects\Components\Items\IHandsComponent.cs" /> <Compile Include="Interfaces\GameObjects\Components\Items\IHandsComponent.cs" />

View File

@@ -3,7 +3,9 @@ using Content.Client.GameObjects.Components.Construction;
using Content.Client.GameObjects.Components.Power; using Content.Client.GameObjects.Components.Power;
using Content.Client.GameObjects.Components.SmoothWalling; using Content.Client.GameObjects.Components.SmoothWalling;
using Content.Client.GameObjects.Components.Storage; using Content.Client.GameObjects.Components.Storage;
using Content.Client.Input;
using Content.Client.Interfaces.GameObjects; using Content.Client.Interfaces.GameObjects;
using SS14.Client.Interfaces.Input;
using SS14.Shared.ContentPack; using SS14.Shared.ContentPack;
using SS14.Shared.Interfaces.GameObjects; using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.IoC; using SS14.Shared.IoC;
@@ -63,6 +65,16 @@ namespace Content.Client
factory.RegisterIgnore("Smes"); factory.RegisterIgnore("Smes");
prototypes.RegisterIgnore("material"); prototypes.RegisterIgnore("material");
}
public override void PostInit()
{
base.PostInit();
// Setup key contexts
var inputMan = IoCManager.Resolve<IInputManager>();
ContentContexts.SetupContexts(inputMan.Contexts);
} }
} }
} }

View File

@@ -0,0 +1,23 @@
using Content.Shared.Input;
using SS14.Shared.Input;
namespace Content.Client.Input
{
/// <summary>
/// Contains a helper function for setting up all content
/// contexts, and modifying existing engine ones.
/// </summary>
public static class ContentContexts
{
public static void SetupContexts(IInputContextContainer contexts)
{
var human = contexts.GetContext("human");
human.AddFunction(ContentKeyFunctions.SwapHands);
human.AddFunction(ContentKeyFunctions.Drop);
human.AddFunction(ContentKeyFunctions.ActivateItemInHand);
human.AddFunction(ContentKeyFunctions.OpenCharacterMenu);
human.AddFunction(ContentKeyFunctions.ExamineEntity);
human.AddFunction(ContentKeyFunctions.UseItemInHand);
}
}
}

View File

@@ -91,7 +91,6 @@
<Compile Include="GameObjects\Components\Weapon\Ranged\Projectile\ProjectileWeapon.cs" /> <Compile Include="GameObjects\Components\Weapon\Ranged\Projectile\ProjectileWeapon.cs" />
<Compile Include="GameObjects\Components\Weapon\Ranged\RangedWeapon.cs" /> <Compile Include="GameObjects\Components\Weapon\Ranged\RangedWeapon.cs" />
<Compile Include="GameObjects\ContainerSlot.cs" /> <Compile Include="GameObjects\ContainerSlot.cs" />
<Compile Include="GameObjects\EntitySystems\Click\ClickParser.cs" />
<Compile Include="GameObjects\EntitySystems\Click\ExamineSystem.cs" /> <Compile Include="GameObjects\EntitySystems\Click\ExamineSystem.cs" />
<Compile Include="GameObjects\EntitySystems\Click\InteractionSystem.cs" /> <Compile Include="GameObjects\EntitySystems\Click\InteractionSystem.cs" />
<Compile Include="GameObjects\EntitySystems\DoorSystem.cs" /> <Compile Include="GameObjects\EntitySystems\DoorSystem.cs" />

View File

@@ -1,67 +0,0 @@
using System;
using SS14.Server.Interfaces.Player;
using SS14.Shared.GameObjects;
using SS14.Shared.GameObjects.Systems;
using SS14.Shared.Input;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Interfaces.Network;
using SS14.Shared.IoC;
namespace Content.Server.GameObjects.EntitySystems
{
/// <summary>
/// Catches clicks from the client and parses them to relevant entity systems
/// </summary>
public class ClickParserSystem : EntitySystem
{
/// <inheritdoc />
public override void RegisterMessageTypes()
{
base.RegisterMessageTypes();
RegisterMessageType<ClickEventMessage>();
}
/// <summary>
/// Grab click events sent from the client input system
/// </summary>
/// <param name="channel"></param>
/// <param name="message"></param>
public override void HandleNetMessage(INetChannel channel, EntitySystemMessage message)
{
base.HandleNetMessage(channel, message);
var playerMan = IoCManager.Resolve<IPlayerManager>();
var session = playerMan.GetSessionByChannel(channel);
var playerentity = session.AttachedEntity;
if (playerentity == null)
return;
switch (message)
{
case ClickEventMessage msg:
ParseClickMessage(msg, playerentity);
break;
}
}
/// <summary>
/// Parse click to the relevant entity system
/// </summary>
/// <param name="message"></param>
/// <param name="player"></param>
private void ParseClickMessage(ClickEventMessage message, IEntity player)
{
switch (message.Click)
{
case ClickType.Left:
EntitySystemManager.GetEntitySystem<InteractionSystem>().UserInteraction(message, player);
break;
case ClickType.Right:
//Verb System
break;
}
}
}
}

View File

@@ -1,16 +1,21 @@
using Content.Server.Interfaces.GameObjects; using System;
using Content.Server.Interfaces.GameObjects;
using SS14.Server.Interfaces.GameObjects; using SS14.Server.Interfaces.GameObjects;
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.Interfaces.GameObjects;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Content.Shared.Input;
using SS14.Shared.Input; using SS14.Shared.Input;
using SS14.Shared.Log; using SS14.Shared.Log;
using SS14.Shared.Map; using SS14.Shared.Map;
using SS14.Server.GameObjects; using SS14.Server.GameObjects;
using SS14.Server.GameObjects.EntitySystems;
using SS14.Server.Interfaces.Player;
using SS14.Shared.Interfaces.GameObjects.Components; using SS14.Shared.Interfaces.GameObjects.Components;
using SS14.Shared.GameObjects.Components.BoundingBox; using SS14.Shared.GameObjects.Components.BoundingBox;
using SS14.Shared.Players;
namespace Content.Server.GameObjects.EntitySystems namespace Content.Server.GameObjects.EntitySystems
{ {
@@ -92,12 +97,22 @@ namespace Content.Server.GameObjects.EntitySystems
public const float INTERACTION_RANGE = 2; public const float INTERACTION_RANGE = 2;
public const float INTERACTION_RANGE_SQUARED = INTERACTION_RANGE * INTERACTION_RANGE; public const float INTERACTION_RANGE_SQUARED = INTERACTION_RANGE * INTERACTION_RANGE;
public void UserInteraction(ClickEventMessage msg, IEntity player) public override void Initialize()
{
var inputSys = EntitySystemManager.GetEntitySystem<InputSystem>();
inputSys.BindMap.BindFunction(ContentKeyFunctions.UseItemInHand, new PointerInputCmdHandler(HandleUseItemInHand));
}
private void HandleUseItemInHand(ICommonSession session, GridLocalCoordinates coords, EntityUid uid)
{
UserInteraction(((IPlayerSession)session).AttachedEntity, coords, uid);
}
private void UserInteraction(IEntity player, GridLocalCoordinates coordinates, EntityUid clickedUid)
{ {
//Get entity clicked upon from UID if valid UID, if not assume no entity clicked upon and null //Get entity clicked upon from UID if valid UID, if not assume no entity clicked upon and null
IEntity attacked = null; if (!EntityManager.TryGetEntity(clickedUid, out var attacked))
if (msg.Uid.IsValid()) return;
attacked = EntityManager.GetEntity(msg.Uid);
//Verify player has a transform component //Verify player has a transform component
if (!player.TryGetComponent<ITransformComponent>(out var playerTransform)) if (!player.TryGetComponent<ITransformComponent>(out var playerTransform))
@@ -105,7 +120,7 @@ namespace Content.Server.GameObjects.EntitySystems
return; return;
} }
//Verify player is on the same map as the entity he clicked on //Verify player is on the same map as the entity he clicked on
else if (msg.Coordinates.MapID != playerTransform.MapID) else if (coordinates.MapID != playerTransform.MapID)
{ {
Logger.Warning(string.Format("Player named {0} clicked on a map he isn't located on", player.Name)); Logger.Warning(string.Format("Player named {0} clicked on a map he isn't located on", player.Name));
return; return;
@@ -129,7 +144,7 @@ namespace Content.Server.GameObjects.EntitySystems
if (attacked == null && item != null) if (attacked == null && item != null)
{ {
//AFTERATTACK: Check if we clicked on an empty location, if so the only interaction we can do is afterattack //AFTERATTACK: Check if we clicked on an empty location, if so the only interaction we can do is afterattack
InteractAfterattack(player, item, msg.Coordinates); InteractAfterattack(player, item, coordinates);
return; return;
} }
else if (attacked == null) else if (attacked == null)
@@ -147,7 +162,7 @@ namespace Content.Server.GameObjects.EntitySystems
//Check if ClickLocation is in object bounds here, if not lets log as warning and see why //Check if ClickLocation is in object bounds here, if not lets log as warning and see why
if (attacked.TryGetComponent(out BoundingBoxComponent boundingbox)) if (attacked.TryGetComponent(out BoundingBoxComponent boundingbox))
{ {
if (!boundingbox.WorldAABB.Contains(msg.Coordinates.Position)) if (!boundingbox.WorldAABB.Contains(coordinates.Position))
{ {
Logger.Warning(string.Format("Player {0} clicked {1} outside of its bounding box component somehow", player.Name, attacked.Name)); Logger.Warning(string.Format("Player {0} clicked {1} outside of its bounding box component somehow", player.Name, attacked.Name));
return; return;
@@ -161,7 +176,7 @@ namespace Content.Server.GameObjects.EntitySystems
{ {
if (item != null) if (item != null)
{ {
RangedInteraction(player, item, attacked, msg.Coordinates); RangedInteraction(player, item, attacked, coordinates);
return; return;
} }
return; //Add some form of ranged attackhand here if you need it someday, or perhaps just ways to modify the range of attackhand return; //Add some form of ranged attackhand here if you need it someday, or perhaps just ways to modify the range of attackhand
@@ -171,7 +186,7 @@ namespace Content.Server.GameObjects.EntitySystems
//ATTACKBY/AFTERATTACK: We will either use the item on the nearby object //ATTACKBY/AFTERATTACK: We will either use the item on the nearby object
if (item != null) if (item != null)
{ {
Interaction(player, item, attacked, msg.Coordinates); Interaction(player, item, attacked, coordinates);
} }
//ATTACKHAND: Since our hand is empty we will use attackhand //ATTACKHAND: Since our hand is empty we will use attackhand
else else

View File

@@ -10,5 +10,6 @@ namespace Content.Shared.Input
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"; public static readonly BoundKeyFunction ExamineEntity = "ExamineEntity";
public static readonly BoundKeyFunction UseItemInHand = "UseItemInHand";
} }
} }

View File

@@ -16,3 +16,6 @@ binds:
key: MouseLeft key: MouseLeft
mod1: Shift mod1: Shift
type: State type: State
- function: UseItemInHand
key: MouseLeft
type: state

View File

@@ -184,7 +184,6 @@ Global
{C899FCA4-7037-4E49-ABC2-44DE72487110}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C899FCA4-7037-4E49-ABC2-44DE72487110}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C899FCA4-7037-4E49-ABC2-44DE72487110}.Debug|Any CPU.Build.0 = Debug|Any CPU {C899FCA4-7037-4E49-ABC2-44DE72487110}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C899FCA4-7037-4E49-ABC2-44DE72487110}.Debug|x64.ActiveCfg = Debug|Any CPU {C899FCA4-7037-4E49-ABC2-44DE72487110}.Debug|x64.ActiveCfg = Debug|Any CPU
{C899FCA4-7037-4E49-ABC2-44DE72487110}.Debug|x64.Build.0 = Debug|Any CPU
{C899FCA4-7037-4E49-ABC2-44DE72487110}.Debug|x86.ActiveCfg = Debug|Any CPU {C899FCA4-7037-4E49-ABC2-44DE72487110}.Debug|x86.ActiveCfg = Debug|Any CPU
{C899FCA4-7037-4E49-ABC2-44DE72487110}.Debug|x86.Build.0 = Debug|Any CPU {C899FCA4-7037-4E49-ABC2-44DE72487110}.Debug|x86.Build.0 = Debug|Any CPU
{C899FCA4-7037-4E49-ABC2-44DE72487110}.Release|Any CPU.ActiveCfg = Debug|Any CPU {C899FCA4-7037-4E49-ABC2-44DE72487110}.Release|Any CPU.ActiveCfg = Debug|Any CPU

2
engine

Submodule engine updated: 900e2c94e8...bddd355f17