* Convert all shader prototype string literals to protoids in overlays * Convert more shader prototype literal strings to protoids * Convert ValidatePrototypeId to ProtoId * Later
85 lines
3.1 KiB
C#
85 lines
3.1 KiB
C#
using System.Numerics;
|
|
using Content.Client.Parallax;
|
|
using Content.Client.Weather;
|
|
using Content.Shared.Salvage;
|
|
using Content.Shared.Weather;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Shared.Enums;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Client.Overlays;
|
|
|
|
/// <summary>
|
|
/// Simple re-useable overlay with stencilled texture.
|
|
/// </summary>
|
|
public sealed partial class StencilOverlay : Overlay
|
|
{
|
|
private static readonly ProtoId<ShaderPrototype> CircleShader = "WorldGradientCircle";
|
|
private static readonly ProtoId<ShaderPrototype> StencilMask = "StencilMask";
|
|
private static readonly ProtoId<ShaderPrototype> StencilDraw = "StencilDraw";
|
|
|
|
[Dependency] private readonly IClyde _clyde = default!;
|
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
|
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
|
private readonly ParallaxSystem _parallax;
|
|
private readonly SharedTransformSystem _transform;
|
|
private readonly SharedMapSystem _map;
|
|
private readonly SpriteSystem _sprite;
|
|
private readonly WeatherSystem _weather;
|
|
|
|
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowFOV;
|
|
|
|
private IRenderTexture? _blep;
|
|
|
|
private readonly ShaderInstance _shader;
|
|
|
|
public StencilOverlay(ParallaxSystem parallax, SharedTransformSystem transform, SharedMapSystem map, SpriteSystem sprite, WeatherSystem weather)
|
|
{
|
|
ZIndex = ParallaxSystem.ParallaxZIndex + 1;
|
|
_parallax = parallax;
|
|
_transform = transform;
|
|
_map = map;
|
|
_sprite = sprite;
|
|
_weather = weather;
|
|
IoCManager.InjectDependencies(this);
|
|
_shader = _protoManager.Index(CircleShader).InstanceUnique();
|
|
}
|
|
|
|
protected override void Draw(in OverlayDrawArgs args)
|
|
{
|
|
var mapUid = _map.GetMapOrInvalid(args.MapId);
|
|
var invMatrix = args.Viewport.GetWorldToLocalMatrix();
|
|
|
|
if (_blep?.Texture.Size != args.Viewport.Size)
|
|
{
|
|
_blep?.Dispose();
|
|
_blep = _clyde.CreateRenderTarget(args.Viewport.Size, new RenderTargetFormatParameters(RenderTargetColorFormat.Rgba8Srgb), name: "weather-stencil");
|
|
}
|
|
|
|
if (_entManager.TryGetComponent<WeatherComponent>(mapUid, out var comp))
|
|
{
|
|
foreach (var (proto, weather) in comp.Weather)
|
|
{
|
|
if (!_protoManager.TryIndex<WeatherPrototype>(proto, out var weatherProto))
|
|
continue;
|
|
|
|
var alpha = _weather.GetPercent(weather, mapUid);
|
|
DrawWeather(args, weatherProto, alpha, invMatrix);
|
|
}
|
|
}
|
|
|
|
if (_entManager.TryGetComponent<RestrictedRangeComponent>(mapUid, out var restrictedRangeComponent))
|
|
{
|
|
DrawRestrictedRange(args, restrictedRangeComponent, invMatrix);
|
|
}
|
|
|
|
args.WorldHandle.UseShader(null);
|
|
args.WorldHandle.SetTransform(Matrix3x2.Identity);
|
|
}
|
|
}
|