* Add mapping editor (#757) * Remove mapping actions, never again * Cleanup actions system * Jarvis, remove all references to CM14 * Fix InventoryUIController crashing when an InventoryGui is not found * Rename mapping1 to mapping * Clean up context calls * Add doc comments * Add delegate for hiding decals in the mapping screen * Jarvis mission failed * a * Add test * Fix not flushing save stream in mapping manager * change * Fix verbs * fixes * localise --------- Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
71 lines
2.2 KiB
C#
71 lines
2.2 KiB
C#
using System.Numerics;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.Input;
|
|
using Robust.Shared.Enums;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Client.Decals.Overlays;
|
|
|
|
public sealed class DecalPlacementOverlay : Overlay
|
|
{
|
|
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
|
[Dependency] private readonly IInputManager _inputManager = default!;
|
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
|
private readonly DecalPlacementSystem _placement;
|
|
private readonly SharedTransformSystem _transform;
|
|
private readonly SpriteSystem _sprite;
|
|
|
|
public override OverlaySpace Space => OverlaySpace.WorldSpaceEntities;
|
|
|
|
public DecalPlacementOverlay(DecalPlacementSystem placement, SharedTransformSystem transform, SpriteSystem sprite)
|
|
{
|
|
IoCManager.InjectDependencies(this);
|
|
_placement = placement;
|
|
_transform = transform;
|
|
_sprite = sprite;
|
|
ZIndex = 1000;
|
|
}
|
|
|
|
protected override void Draw(in OverlayDrawArgs args)
|
|
{
|
|
var (decal, snap, rotation, color) = _placement.GetActiveDecal();
|
|
|
|
if (decal == null)
|
|
return;
|
|
|
|
var mouseScreenPos = _inputManager.MouseScreenPosition;
|
|
var mousePos = _eyeManager.PixelToMap(mouseScreenPos);
|
|
|
|
if (mousePos.MapId != args.MapId)
|
|
return;
|
|
|
|
// No map support for decals
|
|
if (!_mapManager.TryFindGridAt(mousePos, out var gridUid, out var grid))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var worldMatrix = _transform.GetWorldMatrix(gridUid);
|
|
var invMatrix = _transform.GetInvWorldMatrix(gridUid);
|
|
|
|
var handle = args.WorldHandle;
|
|
handle.SetTransform(worldMatrix);
|
|
|
|
var localPos = Vector2.Transform(mousePos.Position, invMatrix);
|
|
|
|
if (snap)
|
|
{
|
|
localPos = localPos.Floored() + grid.TileSizeHalfVector;
|
|
}
|
|
|
|
// Nothing uses snap cardinals so probably don't need preview?
|
|
var aabb = Box2.UnitCentered.Translated(localPos);
|
|
var box = new Box2Rotated(aabb, rotation, localPos);
|
|
|
|
handle.DrawTextureRect(_sprite.Frame0(decal.Sprite), box, color);
|
|
handle.SetTransform(Matrix3x2.Identity);
|
|
}
|
|
}
|