mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-06-09 10:06:34 +02:00
83c2a1be11
* [Dependency] source generator No more reflection, no more codegen at runtime Also various changes to Roslyn helpers to make this easier to write. Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback. No fallback is available for [field: Dependency] properties, due to a Roslyn bug. Code Fixes exist. We love Roslyn * Apply dependencies generator changes to all code * Release notes * Preprocessor got hands * Handle nullable dependencies These are bad but gotta deal with it. * Apply suggestions from code review Co-authored-by: Moony <moony@hellomouse.net> * Fine, let's not use collection expressions --------- Co-authored-by: Moony <moony@hellomouse.net>
89 lines
3.0 KiB
C#
89 lines
3.0 KiB
C#
using System.Numerics;
|
|
using Robust.Client.ComponentTrees;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Shared.Console;
|
|
using Robust.Shared.Enums;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Robust.Client.GameObjects
|
|
{
|
|
public sealed partial class ShowSpriteBBCommand : LocalizedEntityCommands
|
|
{
|
|
[Dependency] private SpriteBoundsSystem _system = default!;
|
|
|
|
public override string Command => "showspritebb";
|
|
|
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
_system.Enabled ^= true;
|
|
}
|
|
}
|
|
|
|
public sealed partial class SpriteBoundsSystem : EntitySystem
|
|
{
|
|
[Dependency] private IOverlayManager _overlayManager = default!;
|
|
|
|
private SpriteBoundsOverlay? _overlay;
|
|
|
|
public bool Enabled
|
|
{
|
|
get => _enabled;
|
|
set
|
|
{
|
|
if (_enabled == value) return;
|
|
|
|
_enabled = value;
|
|
|
|
if (_enabled)
|
|
{
|
|
DebugTools.AssertNull(_overlay);
|
|
_overlay = new SpriteBoundsOverlay(EntityManager);
|
|
_overlayManager.AddOverlay(_overlay);
|
|
}
|
|
else
|
|
{
|
|
if (_overlay == null) return;
|
|
_overlayManager.RemoveOverlay(_overlay);
|
|
_overlay = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool _enabled;
|
|
}
|
|
|
|
public sealed class SpriteBoundsOverlay(IEntityManager entMan) : Overlay
|
|
{
|
|
public override OverlaySpace Space => OverlaySpace.WorldSpace;
|
|
|
|
private readonly SharedTransformSystem _xformSystem = entMan.System<SharedTransformSystem>();
|
|
private readonly SpriteSystem _spriteSystem = entMan.System<SpriteSystem>();
|
|
private readonly SpriteTreeSystem _renderTree = entMan.System<SpriteTreeSystem>();
|
|
|
|
protected internal override void Draw(in OverlayDrawArgs args)
|
|
{
|
|
var handle = args.WorldHandle;
|
|
var currentMap = args.MapId;
|
|
var viewport = args.WorldBounds;
|
|
|
|
foreach (var entry in _renderTree.QueryAabb(currentMap, viewport))
|
|
{
|
|
var (sprite, xform) = entry;
|
|
var (worldPos, worldRot) = _xformSystem.GetWorldPositionRotation(xform);
|
|
var bounds = _spriteSystem.CalculateBounds((entry.Uid, sprite), worldPos, worldRot, args.Viewport.Eye?.Rotation ?? default);
|
|
|
|
// Get scaled down bounds used to indicate the "south" of a sprite.
|
|
var localBound = bounds.Box;
|
|
var smallLocal = localBound.Scale(0.2f).Translated(-new Vector2(0f, localBound.Extents.Y));
|
|
var southIndicator = new Box2Rotated(smallLocal, bounds.Rotation, bounds.Origin);
|
|
|
|
handle.DrawRect(bounds, Color.Red.WithAlpha(0.2f));
|
|
handle.DrawRect(southIndicator, Color.Blue.WithAlpha(0.5f));
|
|
}
|
|
}
|
|
}
|
|
}
|