Click Migration (#94)
* Migrated Interaction system to the new Input system. * Contexts are now set up in content.
This commit is contained in:
@@ -71,6 +71,7 @@
|
||||
<Compile Include="EntryPoint.cs" />
|
||||
<Compile Include="GameObjects\Components\Inventory\ClientInventoryComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Storage\ClientStorageComponent.cs" />
|
||||
<Compile Include="Input\ContentContexts.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="GameObjects\Components\Items\ClientHandsComponent.cs" />
|
||||
<Compile Include="Interfaces\GameObjects\Components\Items\IHandsComponent.cs" />
|
||||
|
||||
@@ -3,7 +3,9 @@ using Content.Client.GameObjects.Components.Construction;
|
||||
using Content.Client.GameObjects.Components.Power;
|
||||
using Content.Client.GameObjects.Components.SmoothWalling;
|
||||
using Content.Client.GameObjects.Components.Storage;
|
||||
using Content.Client.Input;
|
||||
using Content.Client.Interfaces.GameObjects;
|
||||
using SS14.Client.Interfaces.Input;
|
||||
using SS14.Shared.ContentPack;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
@@ -63,6 +65,16 @@ namespace Content.Client
|
||||
factory.RegisterIgnore("Smes");
|
||||
|
||||
prototypes.RegisterIgnore("material");
|
||||
|
||||
}
|
||||
|
||||
public override void PostInit()
|
||||
{
|
||||
base.PostInit();
|
||||
|
||||
// Setup key contexts
|
||||
var inputMan = IoCManager.Resolve<IInputManager>();
|
||||
ContentContexts.SetupContexts(inputMan.Contexts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
23
Content.Client/Input/ContentContexts.cs
Normal file
23
Content.Client/Input/ContentContexts.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,6 @@
|
||||
<Compile Include="GameObjects\Components\Weapon\Ranged\Projectile\ProjectileWeapon.cs" />
|
||||
<Compile Include="GameObjects\Components\Weapon\Ranged\RangedWeapon.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\InteractionSystem.cs" />
|
||||
<Compile Include="GameObjects\EntitySystems\DoorSystem.cs" />
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,21 @@
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using System;
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using SS14.Server.Interfaces.GameObjects;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.GameObjects.Systems;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Shared.Input;
|
||||
using SS14.Shared.Input;
|
||||
using SS14.Shared.Log;
|
||||
using SS14.Shared.Map;
|
||||
using SS14.Server.GameObjects;
|
||||
using SS14.Server.GameObjects.EntitySystems;
|
||||
using SS14.Server.Interfaces.Player;
|
||||
using SS14.Shared.Interfaces.GameObjects.Components;
|
||||
using SS14.Shared.GameObjects.Components.BoundingBox;
|
||||
using SS14.Shared.Players;
|
||||
|
||||
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_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
|
||||
IEntity attacked = null;
|
||||
if (msg.Uid.IsValid())
|
||||
attacked = EntityManager.GetEntity(msg.Uid);
|
||||
if (!EntityManager.TryGetEntity(clickedUid, out var attacked))
|
||||
return;
|
||||
|
||||
//Verify player has a transform component
|
||||
if (!player.TryGetComponent<ITransformComponent>(out var playerTransform))
|
||||
@@ -105,7 +120,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
return;
|
||||
}
|
||||
//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));
|
||||
return;
|
||||
@@ -129,7 +144,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
if (attacked == null && item != null)
|
||||
{
|
||||
//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;
|
||||
}
|
||||
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
|
||||
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));
|
||||
return;
|
||||
@@ -161,7 +176,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
RangedInteraction(player, item, attacked, msg.Coordinates);
|
||||
RangedInteraction(player, item, attacked, coordinates);
|
||||
return;
|
||||
}
|
||||
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
|
||||
if (item != null)
|
||||
{
|
||||
Interaction(player, item, attacked, msg.Coordinates);
|
||||
Interaction(player, item, attacked, coordinates);
|
||||
}
|
||||
//ATTACKHAND: Since our hand is empty we will use attackhand
|
||||
else
|
||||
|
||||
@@ -108,4 +108,4 @@
|
||||
<Compile Include="Construction\ConstructionPrototype.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -10,5 +10,6 @@ namespace Content.Shared.Input
|
||||
public static readonly BoundKeyFunction ActivateItemInHand = "ActivateItemInHand";
|
||||
public static readonly BoundKeyFunction OpenCharacterMenu = "OpenCharacterMenu";
|
||||
public static readonly BoundKeyFunction ExamineEntity = "ExamineEntity";
|
||||
public static readonly BoundKeyFunction UseItemInHand = "UseItemInHand";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,3 +16,6 @@ binds:
|
||||
key: MouseLeft
|
||||
mod1: Shift
|
||||
type: State
|
||||
- function: UseItemInHand
|
||||
key: MouseLeft
|
||||
type: state
|
||||
|
||||
@@ -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.Build.0 = 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.Build.0 = Debug|Any CPU
|
||||
{C899FCA4-7037-4E49-ABC2-44DE72487110}.Release|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
|
||||
2
engine
2
engine
Submodule engine updated: 900e2c94e8...bddd355f17
Reference in New Issue
Block a user