Fix decal draw-order (#22953)

* Fix decal draw-order

Using the new overlayspace ensures they don't draw above grids above them.

* a
This commit is contained in:
metalgearsloth
2023-12-31 03:12:39 +11:00
committed by GitHub
parent ad67a23aa1
commit 9ce847a840

View File

@@ -2,18 +2,17 @@ using Content.Shared.Decals;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Enums;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
namespace Content.Client.Decals.Overlays
{
public sealed class DecalOverlay : Overlay
public sealed class DecalOverlay : GridOverlay
{
private readonly SpriteSystem _sprites;
private readonly IEntityManager _entManager;
private readonly IPrototypeManager _prototypeManager;
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowEntities;
private readonly Dictionary<string, (Texture Texture, bool SnapCardinals)> _cachedTextures = new(64);
public DecalOverlay(
@@ -28,22 +27,29 @@ namespace Content.Client.Decals.Overlays
protected override void Draw(in OverlayDrawArgs args)
{
if (args.MapId == MapId.Nullspace)
return;
var grid = Grid;
if (!_entManager.TryGetComponent(grid, out DecalGridComponent? decalGrid) ||
!_entManager.TryGetComponent(grid, out TransformComponent? xform))
{
return;
}
if (xform.MapID != args.MapId)
return;
// Shouldn't need to clear cached textures unless the prototypes get reloaded.
var handle = args.WorldHandle;
var xformSystem = _entManager.System<TransformSystem>();
var eyeAngle = args.Viewport.Eye?.Rotation ?? Angle.Zero;
var gridQuery = _entManager.AllEntityQueryEnumerator<DecalGridComponent, TransformComponent>();
while (gridQuery.MoveNext(out var decalGrid, out var xform))
{
if (xform.MapID != args.MapId)
continue;
var zIndexDictionary = decalGrid.DecalRenderIndex;
if (zIndexDictionary.Count == 0)
continue;
return;
var (_, worldRot, worldMatrix) = xformSystem.GetWorldPositionRotationMatrix(xform);
@@ -75,7 +81,6 @@ namespace Content.Client.Decals.Overlays
handle.DrawTexture(cache.Texture, decal.Coordinates, angle, decal.Color);
}
}
}
handle.SetTransform(Matrix3.Identity);
}