CatStation/Content.Client/Overlays/NightVisionOverlay.cs
Samuka 710a6bf61a
Add accessibility option to remove noise from the night vision overlay (#44526)
* disable noise button

* make noise static instead of disabling it

* Revert "make noise static instead of disabling it"

This reverts commit 3392776ad85fe6fa7c704785e2e685d9d32b0e7f.

* rename to _configManager

* Minor formatting

---------

Co-authored-by: SlamBamActionman <slambamactionman@gmail.com>
2026-07-06 12:41:21 +00:00

72 lines
2.5 KiB
C#

using Content.Shared.CCVar;
using Robust.Client.Graphics;
using Robust.Shared.Configuration;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
namespace Content.Client.Overlays;
/// <summary>
/// Fullscreen overlay that applies the night-vision shader to the rendered screen.
/// </summary>
public sealed partial class NightVisionOverlay : Overlay
{
[Dependency] private IPrototypeManager _prototypeManager = default!;
[Dependency] private IConfigurationManager _configManager = default!;
private static readonly ProtoId<ShaderPrototype> Shader = "NightVision";
private readonly ShaderInstance _nightVisionShader;
public Color OverlayColor { get; private set; } = Color.White;
public Color LightingColor { get; private set; } = Color.White;
public float NoiseAmount { get; private set; }
public float NoiseMultiplier { get; private set; }
public bool DisableNoise = false;
public override OverlaySpace Space => OverlaySpace.BeforeLighting | OverlaySpace.WorldSpace;
public override bool RequestScreenTexture => true;
public NightVisionOverlay()
{
IoCManager.InjectDependencies(this);
_nightVisionShader = _prototypeManager.Index(Shader).InstanceUnique();
_configManager.OnValueChanged(CCVars.DisableNightVisionNoise, OnNightVisionNoiseChanged, invokeImmediately: true);
}
private void OnNightVisionNoiseChanged(bool toggle)
{
DisableNoise = toggle;
}
public void SetParameters(Color overlayColor, Color lightingColor, float noiseAmount, float noiseMultiplier)
{
OverlayColor = overlayColor;
LightingColor = lightingColor;
NoiseAmount = noiseAmount;
NoiseMultiplier = noiseMultiplier;
}
protected override void Draw(in OverlayDrawArgs args)
{
if (ScreenTexture == null)
return;
var handle = args.WorldHandle;
var isSpace = args.Space == OverlaySpace.WorldSpace;
if (isSpace)
{
_nightVisionShader.SetParameter("SCREEN_TEXTURE", ScreenTexture);
_nightVisionShader.SetParameter("noise_amount", !DisableNoise ? NoiseAmount : 0);
_nightVisionShader.SetParameter("noise_multiplier", !DisableNoise ? NoiseMultiplier : 0);
handle.UseShader(_nightVisionShader);
}
var drawingColor = isSpace ? OverlayColor : LightingColor;
handle.DrawRect(args.WorldBounds, drawingColor);
if (isSpace)
handle.UseShader(null);
}
}