mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* 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>
72 lines
2.5 KiB
C#
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);
|
|
}
|
|
}
|