Files
tbd-station-14/Content.Client/Atmos/Overlays/FireTileOverlay.cs
2022-06-12 11:54:41 +10:00

58 lines
2.0 KiB
C#

using Content.Client.Atmos.EntitySystems;
using Robust.Client.Graphics;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using Robust.Shared.Map;
namespace Content.Client.Atmos.Overlays
{
public sealed class FireTileOverlay : Overlay
{
private readonly GasTileOverlaySystem _gasTileOverlaySystem;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowFOV;
private readonly ShaderInstance _shader;
public FireTileOverlay()
{
IoCManager.InjectDependencies(this);
_gasTileOverlaySystem = EntitySystem.Get<GasTileOverlaySystem>();
_shader = _prototypeManager.Index<ShaderPrototype>("unshaded").Instance().Duplicate();
ZIndex = GasTileOverlaySystem.GasOverlayZIndex + 1;
}
protected override void Draw(in OverlayDrawArgs args)
{
var drawHandle = args.WorldHandle;
var mapId = args.Viewport.Eye!.Position.MapId;
var worldBounds = args.WorldBounds;
drawHandle.UseShader(_shader);
foreach (var mapGrid in _mapManager.FindGridsIntersecting(mapId, worldBounds))
{
if (!_gasTileOverlaySystem.HasData(mapGrid.GridEntityId))
continue;
drawHandle.SetTransform(mapGrid.WorldMatrix);
foreach (var tile in mapGrid.GetTilesIntersecting(worldBounds))
{
var enumerator = _gasTileOverlaySystem.GetFireOverlays(mapGrid.GridEntityId, tile.GridIndices);
while (enumerator.MoveNext(out var tuple))
{
drawHandle.DrawTexture(tuple.Texture, new Vector2(tile.X, tile.Y), tuple.Color);
}
}
}
drawHandle.SetTransform(Matrix3.Identity);
}
}
}