Sprite-based click detection.
This commit is contained in:
@@ -17,6 +17,7 @@ using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Client.State
|
||||
@@ -54,7 +55,9 @@ namespace Content.Client.State
|
||||
base.FrameUpdate(e);
|
||||
|
||||
var mousePosWorld = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition);
|
||||
var entityToClick = _userInterfaceManager.CurrentlyHovered != null ? null : GetEntityUnderPosition(mousePosWorld);
|
||||
var entityToClick = _userInterfaceManager.CurrentlyHovered != null
|
||||
? null
|
||||
: GetEntityUnderPosition(mousePosWorld);
|
||||
|
||||
var inRange = false;
|
||||
if (_playerManager.LocalPlayer.ControlledEntity != null && entityToClick != null)
|
||||
@@ -62,7 +65,10 @@ namespace Content.Client.State
|
||||
var playerPos = _playerManager.LocalPlayer.ControlledEntity.Transform.MapPosition;
|
||||
var entityPos = entityToClick.Transform.MapPosition;
|
||||
inRange = _entitySystemManager.GetEntitySystem<SharedInteractionSystem>()
|
||||
.InRangeUnobstructed(playerPos, entityPos, predicate:entity => entity == _playerManager.LocalPlayer.ControlledEntity || entity == entityToClick, insideBlockerValid:true);
|
||||
.InRangeUnobstructed(playerPos, entityPos,
|
||||
predicate: entity =>
|
||||
entity == _playerManager.LocalPlayer.ControlledEntity || entity == entityToClick,
|
||||
insideBlockerValid: true);
|
||||
}
|
||||
|
||||
InteractionOutlineComponent outline;
|
||||
@@ -72,6 +78,7 @@ namespace Content.Client.State
|
||||
{
|
||||
outline.UpdateInRange(inRange);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -103,17 +110,18 @@ namespace Content.Client.State
|
||||
public IList<IEntity> GetEntitiesUnderPosition(MapCoordinates coordinates)
|
||||
{
|
||||
// Find all the entities intersecting our click
|
||||
var entities = _entityManager.GetEntitiesIntersecting(coordinates.MapId, coordinates.Position);
|
||||
var entities = _entityManager.GetEntitiesIntersecting(coordinates.MapId,
|
||||
Box2.CenteredAround(coordinates.Position, (1, 1)));
|
||||
|
||||
// Check the entities against whether or not we can click them
|
||||
var foundEntities = new List<(IEntity clicked, int drawDepth)>();
|
||||
var foundEntities = new List<(IEntity clicked, int drawDepth, uint renderOrder)>();
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
if (entity.TryGetComponent<IClientClickableComponent>(out var component)
|
||||
if (entity.TryGetComponent<ClickableComponent>(out var component)
|
||||
&& entity.Transform.IsMapTransform
|
||||
&& component.CheckClick(coordinates.Position, out var drawDepthClicked))
|
||||
&& component.CheckClick(coordinates.Position, out var drawDepthClicked, out var renderOrder))
|
||||
{
|
||||
foundEntities.Add((entity, drawDepthClicked));
|
||||
foundEntities.Add((entity, drawDepthClicked, renderOrder));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,9 +134,10 @@ namespace Content.Client.State
|
||||
return foundEntities.Select(a => a.clicked).ToList();
|
||||
}
|
||||
|
||||
internal class ClickableEntityComparer : IComparer<(IEntity clicked, int depth)>
|
||||
internal class ClickableEntityComparer : IComparer<(IEntity clicked, int depth, uint renderOrder)>
|
||||
{
|
||||
public int Compare((IEntity clicked, int depth) x, (IEntity clicked, int depth) y)
|
||||
public int Compare((IEntity clicked, int depth, uint renderOrder) x,
|
||||
(IEntity clicked, int depth, uint renderOrder) y)
|
||||
{
|
||||
var val = x.depth.CompareTo(y.depth);
|
||||
if (val != 0)
|
||||
@@ -136,9 +145,24 @@ namespace Content.Client.State
|
||||
return val;
|
||||
}
|
||||
|
||||
// Turning this off it can make picking stuff out of lockers and such up a bit annoying.
|
||||
/*
|
||||
val = x.renderOrder.CompareTo(y.renderOrder);
|
||||
if (val != 0)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
*/
|
||||
|
||||
var transx = x.clicked.Transform;
|
||||
var transy = y.clicked.Transform;
|
||||
return transx.GridPosition.Y.CompareTo(transy.GridPosition.Y);
|
||||
val = transx.GridPosition.Y.CompareTo(transy.GridPosition.Y);
|
||||
if (val != 0)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
return x.clicked.Uid.CompareTo(y.clicked.Uid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user