using Robust.Shared.Map;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Physics;
+using Robust.Shared.Physics.Components;
namespace Content.Client.Sprite;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IStateManager _stateManager = default!;
+ [Dependency] private readonly FixtureSystem _fixtures = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
[Dependency] private readonly IInputManager _inputManager = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
+ private List<(MapCoordinates Point, bool ExcludeBoundingBox)> _points = new();
+
private readonly HashSet<FadingSpriteComponent> _comps = new();
private EntityQuery<SpriteComponent> _spriteQuery;
private EntityQuery<SpriteFadeComponent> _fadeQuery;
private EntityQuery<FadingSpriteComponent> _fadingQuery;
-
- /// <summary>
- /// Radius of the mouse point for the intersection test
- /// </summary>
- private static Vector2 MouseRadius = new Vector2(10f * float.Epsilon, 10f * float.Epsilon);
+ private EntityQuery<FixturesComponent> _fixturesQuery;
private const float TargetAlpha = 0.4f;
private const float ChangeRate = 1f;
_spriteQuery = GetEntityQuery<SpriteComponent>();
_fadeQuery = GetEntityQuery<SpriteFadeComponent>();
_fadingQuery = GetEntityQuery<FadingSpriteComponent>();
+ _fixturesQuery = GetEntityQuery<FixturesComponent>();
SubscribeLocalEvent<FadingSpriteComponent, ComponentShutdown>(OnFadingShutdown);
}
{
var player = _playerManager.LocalEntity;
// ExcludeBoundingBox is set if we don't want to fade this sprite within the collision bounding boxes for the given POI
- var pointsOfInterest = new List<(MapCoordinates Point, bool ExcludeBoundingBox)>();
+ _points.Clear();
if (_uiManager.CurrentlyHovered is IViewportControl vp
&& _inputManager.MouseScreenPosition.IsValid)
{
- pointsOfInterest.Add((vp.PixelToMap(_inputManager.MouseScreenPosition.Position), true));
+ _points.Add((vp.PixelToMap(_inputManager.MouseScreenPosition.Position), true));
}
if (TryComp(player, out TransformComponent? playerXform))
{
- pointsOfInterest.Add((_transform.GetMapCoordinates(_playerManager.LocalEntity!.Value, xform: playerXform), false));
+ _points.Add((_transform.GetMapCoordinates(_playerManager.LocalEntity!.Value, xform: playerXform), false));
}
if (_stateManager.CurrentState is GameplayState state && _spriteQuery.TryGetComponent(player, out var playerSprite))
{
- foreach (var (mapPos, excludeBB) in pointsOfInterest)
+ foreach (var (mapPos, excludeBB) in _points)
{
// Also want to handle large entities even if they may not be clickable.
foreach (var ent in state.GetClickableEntities(mapPos, excludeFaded: false))
continue;
}
- if (excludeBB)
+ // If it intersects a fixture ignore it.
+ if (excludeBB && _fixturesQuery.TryComp(ent, out var body))
{
- var test = new Box2Rotated(mapPos.Position - MouseRadius, mapPos.Position + MouseRadius);
+ var transform = _physics.GetPhysicsTransform(ent);
var collided = false;
- foreach (var fixture in _physics.GetCollidingEntities(mapPos.MapId, test))
+
+ foreach (var fixture in body.Fixtures.Values)
{
- if (fixture.Owner == ent)
+ if (!fixture.Hard)
+ continue;
+
+ if (_fixtures.TestPoint(fixture.Shape, transform, mapPos.Position))
{
collided = true;
break;
}
}
+
+ // Check next entity
if (collided)
{
- break;
+ continue;
}
}