Outlines moved to InteractionOutlineComponent, now change color when in interaction range.

This commit is contained in:
Pieter-Jan Briers
2019-12-06 02:08:17 +01:00
parent a912c999a9
commit 689d16ee65
34 changed files with 153 additions and 15 deletions

View File

@@ -0,0 +1,59 @@
using Robust.Client.Graphics.Shaders;
using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.Client.GameObjects.Components
{
[RegisterComponent]
public class InteractionOutlineComponent : Component
{
private const string ShaderInRange = "selection_outline_inrange";
private const string ShaderOutOfRange = "selection_outline";
public override string Name => "InteractionOutline";
#pragma warning disable 649
[Dependency] private readonly IPrototypeManager _prototypeManager;
#pragma warning restore 649
private ShaderInstance _selectionShaderInstance;
private ShaderInstance _selectionShaderInRangeInstance;
/// <inheritdoc />
public override void Initialize()
{
base.Initialize();
_selectionShaderInRangeInstance = _prototypeManager.Index<ShaderPrototype>(ShaderInRange).Instance();
_selectionShaderInstance = _prototypeManager.Index<ShaderPrototype>(ShaderOutOfRange).Instance();
}
public void OnMouseEnter(bool inInteractionRange)
{
if (Owner.TryGetComponent(out ISpriteComponent sprite))
{
sprite.PostShader = inInteractionRange ? _selectionShaderInRangeInstance : _selectionShaderInstance;
sprite.RenderOrder = Owner.EntityManager.CurrentTick.Value;
}
}
public void OnMouseLeave()
{
if (Owner.TryGetComponent(out ISpriteComponent sprite))
{
sprite.PostShader = null;
sprite.RenderOrder = 0;
}
}
public void UpdateInRange(bool inInteractionRange)
{
if (Owner.TryGetComponent(out ISpriteComponent sprite))
{
sprite.PostShader = inInteractionRange ? _selectionShaderInRangeInstance : _selectionShaderInstance;
}
}
}
}

View File

@@ -1,5 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using Content.Client.GameObjects.Components;
using Content.Client.GameObjects.EntitySystems;
using Content.Shared.GameObjects;
using Robust.Client.GameObjects.EntitySystems;
using Robust.Client.Interfaces.GameObjects;
using Robust.Client.Interfaces.GameObjects.Components;
@@ -63,21 +66,37 @@ namespace Content.Client.State
var mousePosWorld = eyeManager.ScreenToWorld(new ScreenCoordinates(inputManager.MouseScreenPosition));
var entityToClick = GetEntityUnderPosition(mousePosWorld);
var inRange = false;
if (playerManager.LocalPlayer.ControlledEntity != null && entityToClick != null)
{
var playerPos = playerManager.LocalPlayer.ControlledEntity.Transform.GridPosition;
var entityPos = entityToClick.Transform.GridPosition;
var distance = playerPos.Distance(_mapManager, entityPos);
inRange = distance <= VerbUtility.InteractionRange;
}
InteractionOutlineComponent outline;
if (entityToClick == lastHoveredEntity)
{
if (entityToClick != null && entityToClick.TryGetComponent(out outline))
{
outline.UpdateInRange(inRange);
}
return;
}
if (lastHoveredEntity != null && !lastHoveredEntity.Deleted)
if (lastHoveredEntity != null && !lastHoveredEntity.Deleted &&
lastHoveredEntity.TryGetComponent(out outline))
{
lastHoveredEntity.GetComponent<IClientClickableComponent>().OnMouseLeave();
outline.OnMouseLeave();
}
lastHoveredEntity = entityToClick;
if (lastHoveredEntity != null)
if (lastHoveredEntity != null && lastHoveredEntity.TryGetComponent(out outline))
{
lastHoveredEntity.GetComponent<IClientClickableComponent>().OnMouseEnter();
outline.OnMouseEnter(inRange);
}
}
@@ -91,7 +110,8 @@ namespace Content.Client.State
{
// Find all the entities intersecting our click
var worldCoords = coordinates.ToWorld(_mapManager);
var entities = _entityManager.GetEntitiesIntersecting(_mapManager.GetGrid(coordinates.GridID).ParentMapId, worldCoords.Position);
var entities = _entityManager.GetEntitiesIntersecting(_mapManager.GetGrid(coordinates.GridID).ParentMapId,
worldCoords.Position);
// Check the entities against whether or not we can click them
var foundEntities = new List<(IEntity clicked, int drawDepth)>();
@@ -123,6 +143,7 @@ namespace Content.Client.State
{
return val;
}
var transx = x.clicked.Transform;
var transy = y.clicked.Transform;
return transx.GridPosition.Y.CompareTo(transy.GridPosition.Y);
@@ -142,7 +163,8 @@ namespace Content.Client.State
var mousePosWorld = eyeManager.ScreenToWorld(args.PointerLocation);
var entityToClick = GetEntityUnderPosition(mousePosWorld);
var message = new FullInputCmdMessage(timing.CurTick, funcId, args.State, mousePosWorld, args.PointerLocation, entityToClick?.Uid ?? EntityUid.Invalid);
var message = new FullInputCmdMessage(timing.CurTick, funcId, args.State, mousePosWorld,
args.PointerLocation, entityToClick?.Uid ?? EntityUid.Invalid);
// client side command handlers will always be sent the local player session.
var session = playerManager.LocalPlayer.Session;