Updates various systems to the new InputCommandHandler delegate signature, implementing the new handled return value.

Modifies the construction system to use the newer InputHandler system, instead of the older ClickComponent system.
Updates the engine submodule.
This commit is contained in:
Acruid
2019-09-17 16:08:45 -07:00
parent b55d6cbf75
commit fc5d7835c0
9 changed files with 75 additions and 45 deletions

View File

@@ -1,7 +1,5 @@
using Content.Shared.Construction; using Content.Shared.Construction;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
namespace Content.Client.GameObjects.Components.Construction namespace Content.Client.GameObjects.Components.Construction
@@ -14,18 +12,5 @@ namespace Content.Client.GameObjects.Components.Construction
[ViewVariables] public ConstructionPrototype Prototype { get; set; } [ViewVariables] public ConstructionPrototype Prototype { get; set; }
[ViewVariables] public ConstructorComponent Master { get; set; } [ViewVariables] public ConstructorComponent Master { get; set; }
[ViewVariables] public int GhostID { get; set; } [ViewVariables] public int GhostID { get; set; }
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null,
IComponent component = null)
{
base.HandleMessage(message, netChannel, component);
switch (message)
{
case ClientEntityClickMsg clickMsg:
Master.TryStartConstruction(GhostID);
break;
}
}
} }
} }

View File

@@ -1,4 +1,4 @@
using Content.Client.Construction; using Content.Client.Construction;
using Content.Client.GameObjects.Components.Construction; using Content.Client.GameObjects.Components.Construction;
using Content.Client.UserInterface; using Content.Client.UserInterface;
using Content.Shared.Input; using Content.Shared.Input;
@@ -6,6 +6,7 @@ using Robust.Client.GameObjects.EntitySystems;
using Robust.Client.Player; using Robust.Client.Player;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Input; using Robust.Shared.Input;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
namespace Content.Client.GameObjects.EntitySystems namespace Content.Client.GameObjects.EntitySystems
@@ -15,6 +16,7 @@ namespace Content.Client.GameObjects.EntitySystems
#pragma warning disable 649 #pragma warning disable 649
[Dependency] private readonly IGameHud _gameHud; [Dependency] private readonly IGameHud _gameHud;
[Dependency] private readonly IPlayerManager _playerManager; [Dependency] private readonly IPlayerManager _playerManager;
[Dependency] private readonly IEntityManager _entityManager;
#pragma warning restore 649 #pragma warning restore 649
public override void Initialize() public override void Initialize()
@@ -24,14 +26,17 @@ namespace Content.Client.GameObjects.EntitySystems
var inputSys = EntitySystemManager.GetEntitySystem<InputSystem>(); var inputSys = EntitySystemManager.GetEntitySystem<InputSystem>();
inputSys.BindMap.BindFunction(ContentKeyFunctions.OpenCraftingMenu, inputSys.BindMap.BindFunction(ContentKeyFunctions.OpenCraftingMenu,
new PointerInputCmdHandler(HandleOpenCraftingMenu)); new PointerInputCmdHandler(HandleOpenCraftingMenu));
inputSys.BindMap.BindFunction(EngineKeyFunctions.Use,
new PointerInputCmdHandler(HandleUse));
} }
private void HandleOpenCraftingMenu(in PointerInputCmdHandler.PointerInputCmdArgs args) private bool HandleOpenCraftingMenu(in PointerInputCmdHandler.PointerInputCmdArgs args)
{ {
if (_playerManager.LocalPlayer.ControlledEntity == null if (_playerManager.LocalPlayer.ControlledEntity == null
|| !_playerManager.LocalPlayer.ControlledEntity.TryGetComponent(out ConstructorComponent constructor)) || !_playerManager.LocalPlayer.ControlledEntity.TryGetComponent(out ConstructorComponent constructor))
{ {
return; return false;
} }
var menu = constructor.ConstructionMenu; var menu = constructor.ConstructionMenu;
@@ -51,6 +56,23 @@ namespace Content.Client.GameObjects.EntitySystems
{ {
_setOpenValue(menu, true); _setOpenValue(menu, true);
} }
return true;
}
private bool HandleUse(in PointerInputCmdHandler.PointerInputCmdArgs args)
{
if (!args.EntityUid.IsValid() || !args.EntityUid.IsClientSide())
return false;
var entity = _entityManager.GetEntity(args.EntityUid);
if (!entity.TryGetComponent(out ConstructionGhostComponent ghostComp))
return false;
ghostComp.Master.TryStartConstruction(ghostComp.GhostID);
return true;
} }
private void _setOpenValue(ConstructionMenu menu, bool value) private void _setOpenValue(ConstructionMenu menu, bool value)

View File

@@ -51,21 +51,22 @@ namespace Content.Client.GameObjects.EntitySystems
RegisterMessageType<ExamineSystemMessages.ExamineInfoResponseMessage>(); RegisterMessageType<ExamineSystemMessages.ExamineInfoResponseMessage>();
} }
private void HandleExamine(ICommonSession session, GridCoordinates coords, EntityUid uid) private bool HandleExamine(ICommonSession session, GridCoordinates coords, EntityUid uid)
{ {
if (!uid.IsValid() || !_entityManager.TryGetEntity(uid, out var examined)) if (!uid.IsValid() || !_entityManager.TryGetEntity(uid, out var examined))
{ {
return; return false;
} }
var playerEntity = _playerManager.LocalPlayer.ControlledEntity; var playerEntity = _playerManager.LocalPlayer.ControlledEntity;
if (playerEntity == null || !CanExamine(playerEntity, examined)) if (playerEntity == null || !CanExamine(playerEntity, examined))
{ {
return; return false;
} }
DoExamine(examined); DoExamine(examined);
return true;
} }
public async void DoExamine(IEntity entity) public async void DoExamine(IEntity entity)

View File

@@ -76,24 +76,24 @@ namespace Content.Client.GameObjects.EntitySystems
_currentPopup.Open(box); _currentPopup.Open(box);
} }
private void OnOpenContextMenu(in PointerInputCmdHandler.PointerInputCmdArgs args) private bool OnOpenContextMenu(in PointerInputCmdHandler.PointerInputCmdArgs args)
{ {
if (_currentPopup != null) if (_currentPopup != null)
{ {
_closeContextMenu(); _closeContextMenu();
return; return true;
} }
if (!(_stateManager.CurrentState is GameScreen gameScreen)) if (!(_stateManager.CurrentState is GameScreen gameScreen))
{ {
return; return false;
} }
var entities = gameScreen.GetEntitiesUnderPosition(args.Coordinates); var entities = gameScreen.GetEntitiesUnderPosition(args.Coordinates);
if (entities.Count == 0) if (entities.Count == 0)
{ {
return; return false;
} }
_currentPopup = new VerbPopup(); _currentPopup = new VerbPopup();
@@ -110,6 +110,8 @@ namespace Content.Client.GameObjects.EntitySystems
var size = _currentPopup.List.CombinedMinimumSize; var size = _currentPopup.List.CombinedMinimumSize;
var box = UIBox2.FromDimensions(args.ScreenCoordinates.Position, size); var box = UIBox2.FromDimensions(args.ScreenCoordinates.Position, size);
_currentPopup.Open(box); _currentPopup.Open(box);
return true;
} }
private void OnContextButtonPressed(IEntity entity) private void OnContextButtonPressed(IEntity entity)

View File

@@ -371,9 +371,19 @@ namespace Content.Server.GameObjects.Components.Power
} }
} }
/// <summary>
/// The different methods that a <see cref="PowerDeviceComponent"/> can use to connect to a power network.
/// </summary>
public enum DrawTypes public enum DrawTypes
{ {
/// <summary>
/// This device cannot be connected to a power network.
/// </summary>
None = 0, None = 0,
/// <summary>
/// This device can connect to a <see cref=""/>
/// </summary>
Node = 1, Node = 1,
Provider = 2, Provider = 2,
Both = 3, Both = 3,

View File

@@ -6,6 +6,7 @@ using Robust.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Log; using Robust.Shared.Log;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Power namespace Content.Server.GameObjects.Components.Power
@@ -275,6 +276,10 @@ namespace Content.Server.GameObjects.Components.Power
/// </summary> /// </summary>
public bool CanServiceDevice(PowerDeviceComponent device) public bool CanServiceDevice(PowerDeviceComponent device)
{ {
// Stops an APC from trying to connect to itself
if (this == device)
return false;
return (device.Owner.Transform.WorldPosition - Owner.Transform.WorldPosition).LengthSquared <= _range; return (device.Owner.Transform.WorldPosition - Owner.Transform.WorldPosition).LengthSquared <= _range;
} }
} }

View File

@@ -206,24 +206,25 @@ namespace Content.Server.GameObjects.EntitySystems
new PointerInputCmdHandler(HandleActivateItemInWorld)); new PointerInputCmdHandler(HandleActivateItemInWorld));
} }
public void HandleActivateItemInWorld(ICommonSession session, GridCoordinates coords, EntityUid uid) private bool HandleActivateItemInWorld(ICommonSession session, GridCoordinates coords, EntityUid uid)
{ {
if (!EntityManager.TryGetEntity(uid, out var used)) if (!EntityManager.TryGetEntity(uid, out var used))
return; return false;
var playerEnt = ((IPlayerSession) session).AttachedEntity; var playerEnt = ((IPlayerSession) session).AttachedEntity;
if (playerEnt == null || !playerEnt.IsValid()) if (playerEnt == null || !playerEnt.IsValid())
{ {
return; return false;
} }
if (!playerEnt.Transform.GridPosition.InRange(_mapManager, used.Transform.GridPosition, InteractionRange)) if (!playerEnt.Transform.GridPosition.InRange(_mapManager, used.Transform.GridPosition, InteractionRange))
{ {
return; return false;
} }
InteractionActivate(playerEnt, used); InteractionActivate(playerEnt, used);
return true;
} }
private void InteractionActivate(IEntity user, IEntity used) private void InteractionActivate(IEntity user, IEntity used)
@@ -243,27 +244,27 @@ namespace Content.Server.GameObjects.EntitySystems
activateComp.Activate(new ActivateEventArgs {User = user}); activateComp.Activate(new ActivateEventArgs {User = user});
} }
private void HandleUseItemInHand(ICommonSession session, GridCoordinates coords, EntityUid uid) private bool HandleUseItemInHand(ICommonSession session, GridCoordinates coords, EntityUid uid)
{ {
// client sanitization // client sanitization
if (!_mapManager.GridExists(coords.GridID)) if (!_mapManager.GridExists(coords.GridID))
{ {
Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}"); Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}");
return; return true;
} }
if (uid.IsClientSide()) if (uid.IsClientSide())
{ {
Logger.WarningS("system.interaction", Logger.WarningS("system.interaction",
$"Client sent interaction with client-side entity. Session={session}, Uid={uid}"); $"Client sent interaction with client-side entity. Session={session}, Uid={uid}");
return; return true;
} }
var userEntity = ((IPlayerSession) session).AttachedEntity; var userEntity = ((IPlayerSession) session).AttachedEntity;
if (userEntity == null || !userEntity.IsValid()) if (userEntity == null || !userEntity.IsValid())
{ {
return; return true;
} }
if (userEntity.TryGetComponent(out CombatModeComponent combatMode) && combatMode.IsInCombatMode) if (userEntity.TryGetComponent(out CombatModeComponent combatMode) && combatMode.IsInCombatMode)
@@ -274,6 +275,8 @@ namespace Content.Server.GameObjects.EntitySystems
{ {
UserInteraction(userEntity, coords, uid); UserInteraction(userEntity, coords, uid);
} }
return true;
} }
private void UserInteraction(IEntity player, GridCoordinates coordinates, EntityUid clickedUid) private void UserInteraction(IEntity player, GridCoordinates coordinates, EntityUid clickedUid)

View File

@@ -97,18 +97,18 @@ namespace Content.Server.GameObjects.EntitySystems
handsComp.SwapHands(); handsComp.SwapHands();
} }
private void HandleDrop(ICommonSession session, GridCoordinates coords, EntityUid uid) private bool HandleDrop(ICommonSession session, GridCoordinates coords, EntityUid uid)
{ {
var ent = ((IPlayerSession) session).AttachedEntity; var ent = ((IPlayerSession) session).AttachedEntity;
if (ent == null || !ent.IsValid()) if (ent == null || !ent.IsValid())
{ {
return; return false;
} }
if (!ent.TryGetComponent(out HandsComponent handsComp)) if (!ent.TryGetComponent(out HandsComponent handsComp))
{ {
return; return false;
} }
if (coords.InRange(_mapManager, ent.Transform.GridPosition, InteractionSystem.InteractionRange)) if (coords.InRange(_mapManager, ent.Transform.GridPosition, InteractionSystem.InteractionRange))
@@ -119,6 +119,8 @@ namespace Content.Server.GameObjects.EntitySystems
{ {
handsComp.Drop(handsComp.ActiveIndex); handsComp.Drop(handsComp.ActiveIndex);
} }
return true;
} }
private static void HandleActivateItem(ICommonSession session) private static void HandleActivateItem(ICommonSession session)
@@ -129,23 +131,23 @@ namespace Content.Server.GameObjects.EntitySystems
handsComp.ActivateItem(); handsComp.ActivateItem();
} }
private void HandleThrowItem(ICommonSession session, GridCoordinates coords, EntityUid uid) private bool HandleThrowItem(ICommonSession session, GridCoordinates coords, EntityUid uid)
{ {
var plyEnt = ((IPlayerSession)session).AttachedEntity; var plyEnt = ((IPlayerSession)session).AttachedEntity;
if (plyEnt == null || !plyEnt.IsValid()) if (plyEnt == null || !plyEnt.IsValid())
return; return false;
if (!plyEnt.TryGetComponent(out HandsComponent handsComp)) if (!plyEnt.TryGetComponent(out HandsComponent handsComp))
return; return false;
if (!handsComp.CanDrop(handsComp.ActiveIndex)) if (!handsComp.CanDrop(handsComp.ActiveIndex))
return; return false;
var throwEnt = handsComp.GetHand(handsComp.ActiveIndex).Owner; var throwEnt = handsComp.GetHand(handsComp.ActiveIndex).Owner;
if (!handsComp.ThrowItem()) if (!handsComp.ThrowItem())
return; return false;
// pop off an item, or throw the single item in hand. // pop off an item, or throw the single item in hand.
if (!throwEnt.TryGetComponent(out StackComponent stackComp) || stackComp.Count < 2) if (!throwEnt.TryGetComponent(out StackComponent stackComp) || stackComp.Count < 2)
@@ -163,7 +165,7 @@ namespace Content.Server.GameObjects.EntitySystems
} }
if (!throwEnt.TryGetComponent(out CollidableComponent colComp)) if (!throwEnt.TryGetComponent(out CollidableComponent colComp))
return; return true;
colComp.CollisionEnabled = true; colComp.CollisionEnabled = true;
// I can now collide with player, so that i can do damage. // I can now collide with player, so that i can do damage.
@@ -203,7 +205,7 @@ namespace Content.Server.GameObjects.EntitySystems
lHomoDir.Normalize(); lHomoDir.Normalize();
transform.LocalRotation = new Angle(lHomoDir.Xy); transform.LocalRotation = new Angle(lHomoDir.Xy);
return true;
} }
} }
} }