* Cleanup warnings in MagazineVisualsSpriteTest * Cleanup warnings in WiresVisualizerSystem * Cleanup warnings in GunSystem.SpentAmmo * Cleanup warnings in GunSystem * Cleanup warnings in GunSystem.ChamberMagazine * Cleanup warnings in MeleeWeaponSystem.Effects * Cleanup warnings in ToggleableLightVisualsSystem * Cleanup warnings in StatusIconOverlay * Cleanup warnings in SpriteFadeSystem * Cleanup warnings in PdaVisualizerSystem * Cleanup warnings in EnvelopeSystem * Cleanup warnings in MechSystem * Cleanup warnings in MappingOverlay * Cleanup warnings in LockVisualizerSystem * Cleanup warnings in DragDropSystem * Cleanup warnings in GhostSystem * Cleanup warnings in TriggerSystem.Proximity * Cleanup warnings in DragonSystem * Cleanup warnings in PortableScrubberVisualsSystem * File-scoped namespace for PortableScrubberVisualsSystem
89 lines
2.7 KiB
C#
89 lines
2.7 KiB
C#
using Robust.Client.GameObjects;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.Input;
|
|
using Robust.Client.Player;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Shared.Enums;
|
|
using Robust.Shared.Prototypes;
|
|
using static Content.Client.Mapping.MappingState;
|
|
|
|
namespace Content.Client.Mapping;
|
|
|
|
public sealed class MappingOverlay : Overlay
|
|
{
|
|
[Dependency] private readonly IEntityManager _entities = default!;
|
|
[Dependency] private readonly IPlayerManager _player = default!;
|
|
[Dependency] private readonly IPrototypeManager _prototypes = default!;
|
|
|
|
private readonly SpriteSystem _sprite;
|
|
|
|
// 1 off in case something else uses these colors since we use them to compare
|
|
private static readonly Color PickColor = new(1, 255, 0);
|
|
private static readonly Color DeleteColor = new(255, 1, 0);
|
|
|
|
private readonly Dictionary<EntityUid, Color> _oldColors = new();
|
|
|
|
private readonly MappingState _state;
|
|
private readonly ShaderInstance _shader;
|
|
|
|
public override OverlaySpace Space => OverlaySpace.WorldSpace;
|
|
|
|
public MappingOverlay(MappingState state)
|
|
{
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
_sprite = _entities.System<SpriteSystem>();
|
|
|
|
_state = state;
|
|
_shader = _prototypes.Index<ShaderPrototype>("unshaded").Instance();
|
|
}
|
|
|
|
protected override void Draw(in OverlayDrawArgs args)
|
|
{
|
|
foreach (var (id, color) in _oldColors)
|
|
{
|
|
if (!_entities.TryGetComponent(id, out SpriteComponent? sprite))
|
|
continue;
|
|
|
|
if (sprite.Color == DeleteColor || sprite.Color == PickColor)
|
|
_sprite.SetColor((id, sprite), color);
|
|
}
|
|
|
|
_oldColors.Clear();
|
|
|
|
if (_player.LocalEntity == null)
|
|
return;
|
|
|
|
var handle = args.WorldHandle;
|
|
handle.UseShader(_shader);
|
|
|
|
switch (_state.State)
|
|
{
|
|
case CursorState.Pick:
|
|
{
|
|
if (_state.GetHoveredEntity() is { } entity &&
|
|
_entities.TryGetComponent(entity, out SpriteComponent? sprite))
|
|
{
|
|
_oldColors[entity] = sprite.Color;
|
|
_sprite.SetColor((entity, sprite), PickColor);
|
|
}
|
|
|
|
break;
|
|
}
|
|
case CursorState.Delete:
|
|
{
|
|
if (_state.GetHoveredEntity() is { } entity &&
|
|
_entities.TryGetComponent(entity, out SpriteComponent? sprite))
|
|
{
|
|
_oldColors[entity] = sprite.Color;
|
|
_sprite.SetColor((entity, sprite), DeleteColor);
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
handle.UseShader(null);
|
|
}
|
|
}
|