Files
tbd-station-14/Content.Client/GameObjects/Components/InteractionOutlineComponent.cs
Acruid ca4fd649fe Massive Namespace Cleanup (#3120)
* Engine namespace changes.

* Automated remove redundant using statements.

* Simplified Graphics namespace.

* Apparently the container system stores full type names in the map file.😞 This updates those names.

* API Changes to LocalizationManager.LoadCulture.

* Update submodule to v0.3.2
2021-02-11 01:13:03 -08:00

58 lines
1.9 KiB
C#

using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.Client.GameObjects.Components
{
[RegisterComponent]
public class InteractionOutlineComponent : Component
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private const string ShaderInRange = "SelectionOutlineInrange";
private const string ShaderOutOfRange = "SelectionOutline";
public override string Name => "InteractionOutline";
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;
}
}
}
}