Make clickable 1% nicer (#29706)
* Make vox roundstart I believe all the issues are fixed. * Click detection bandaid * Make clickable 1% nicer Still bad. Still doesn't handle multi-viewports well.
This commit is contained in:
@@ -2,6 +2,7 @@ using System.Linq;
|
||||
using System.Numerics;
|
||||
using Content.Client.Clickable;
|
||||
using Content.Client.UserInterface;
|
||||
using Content.Client.Viewport;
|
||||
using Content.Shared.Input;
|
||||
using Robust.Client.ComponentTrees;
|
||||
using Robust.Client.GameObjects;
|
||||
@@ -13,11 +14,13 @@ using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Graphics;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Timing;
|
||||
using YamlDotNet.Serialization.TypeInspectors;
|
||||
|
||||
namespace Content.Client.Gameplay
|
||||
{
|
||||
@@ -98,7 +101,15 @@ namespace Content.Client.Gameplay
|
||||
|
||||
public EntityUid? GetClickedEntity(MapCoordinates coordinates)
|
||||
{
|
||||
var first = GetClickableEntities(coordinates).FirstOrDefault();
|
||||
return GetClickedEntity(coordinates, _eyeManager.CurrentEye);
|
||||
}
|
||||
|
||||
public EntityUid? GetClickedEntity(MapCoordinates coordinates, IEye? eye)
|
||||
{
|
||||
if (eye == null)
|
||||
return null;
|
||||
|
||||
var first = GetClickableEntities(coordinates, eye).FirstOrDefault();
|
||||
return first.IsValid() ? first : null;
|
||||
}
|
||||
|
||||
@@ -110,6 +121,20 @@ namespace Content.Client.Gameplay
|
||||
|
||||
public IEnumerable<EntityUid> GetClickableEntities(MapCoordinates coordinates)
|
||||
{
|
||||
return GetClickableEntities(coordinates, _eyeManager.CurrentEye);
|
||||
}
|
||||
|
||||
public IEnumerable<EntityUid> GetClickableEntities(MapCoordinates coordinates, IEye? eye)
|
||||
{
|
||||
/*
|
||||
* TODO:
|
||||
* 1. Stuff like MeleeWeaponSystem need an easy way to hook into viewport specific entities / entities under mouse
|
||||
* 2. Cleanup the mess around InteractionOutlineSystem + below the keybind click detection.
|
||||
*/
|
||||
|
||||
if (eye == null)
|
||||
return Array.Empty<EntityUid>();
|
||||
|
||||
// Find all the entities intersecting our click
|
||||
var spriteTree = _entityManager.EntitySysManager.GetEntitySystem<SpriteTreeSystem>();
|
||||
var entities = spriteTree.QueryAabb(coordinates.MapId, Box2.CenteredAround(coordinates.Position, new Vector2(1, 1)));
|
||||
@@ -117,15 +142,12 @@ namespace Content.Client.Gameplay
|
||||
// Check the entities against whether or not we can click them
|
||||
var foundEntities = new List<(EntityUid, int, uint, float)>(entities.Count);
|
||||
var clickQuery = _entityManager.GetEntityQuery<ClickableComponent>();
|
||||
var xformQuery = _entityManager.GetEntityQuery<TransformComponent>();
|
||||
|
||||
// TODO: Smelly
|
||||
var eye = _eyeManager.CurrentEye;
|
||||
var clickables = _entityManager.System<ClickableSystem>();
|
||||
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
if (clickQuery.TryGetComponent(entity.Uid, out var component) &&
|
||||
component.CheckClick(entity.Component, entity.Transform, xformQuery, coordinates.Position, eye, out var drawDepthClicked, out var renderOrder, out var bottom))
|
||||
clickables.CheckClick((entity.Uid, component, entity.Component, entity.Transform), coordinates.Position, eye, out var drawDepthClicked, out var renderOrder, out var bottom))
|
||||
{
|
||||
foundEntities.Add((entity.Uid, drawDepthClicked, renderOrder, bottom));
|
||||
}
|
||||
@@ -188,7 +210,15 @@ namespace Content.Client.Gameplay
|
||||
if (args.Viewport is IViewportControl vp && kArgs.PointerLocation.IsValid)
|
||||
{
|
||||
var mousePosWorld = vp.PixelToMap(kArgs.PointerLocation.Position);
|
||||
entityToClick = GetClickedEntity(mousePosWorld);
|
||||
|
||||
if (vp is ScalingViewport svp)
|
||||
{
|
||||
entityToClick = GetClickedEntity(mousePosWorld, svp.Eye);
|
||||
}
|
||||
else
|
||||
{
|
||||
entityToClick = GetClickedEntity(mousePosWorld);
|
||||
}
|
||||
|
||||
coordinates = _mapManager.TryFindGridAt(mousePosWorld, out _, out var grid) ?
|
||||
grid.MapToGrid(mousePosWorld) :
|
||||
|
||||
Reference in New Issue
Block a user