2024-01-28 18:37:24 +07:00
|
|
|
using Content.Shared._White.Overlays;
|
2024-01-26 17:36:10 +07:00
|
|
|
using Robust.Client.Graphics;
|
|
|
|
|
using Robust.Client.Player;
|
|
|
|
|
using Robust.Shared.Enums;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
2024-01-28 17:32:55 +07:00
|
|
|
namespace Content.Client._White.Overlays
|
2024-01-26 17:36:10 +07:00
|
|
|
{
|
|
|
|
|
public sealed class NightVisionOverlay : Overlay
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
|
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
|
|
|
|
|
|
|
|
public override bool RequestScreenTexture => true;
|
|
|
|
|
|
|
|
|
|
public override OverlaySpace Space => OverlaySpace.WorldSpace;
|
|
|
|
|
|
|
|
|
|
private readonly ShaderInstance _shader;
|
|
|
|
|
|
|
|
|
|
public NightVisionOverlay()
|
|
|
|
|
{
|
|
|
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
|
_shader = _prototypeManager.Index<ShaderPrototype>("NightVision").InstanceUnique();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Draw(in OverlayDrawArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (ScreenTexture == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var handle = args.WorldHandle;
|
|
|
|
|
|
2024-07-19 16:27:01 +00:00
|
|
|
if (_playerManager.LocalEntity == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var uid = _playerManager.LocalEntity.Value;
|
|
|
|
|
|
2024-03-14 01:19:30 +09:00
|
|
|
Color? color = null;
|
|
|
|
|
|
2024-07-19 16:27:01 +00:00
|
|
|
if (_entityManager.TryGetComponent<NightVisionComponent>(uid, out var component) && component.IsActive)
|
|
|
|
|
{
|
|
|
|
|
color = SetParameters(component);
|
|
|
|
|
}
|
|
|
|
|
else if (_entityManager.TryGetComponent<ThermalVisionComponent>(uid, out var thermal) && thermal.IsActive)
|
2024-01-26 17:36:10 +07:00
|
|
|
{
|
2024-07-19 16:27:01 +00:00
|
|
|
color = SetParameters(thermal);
|
2024-03-14 01:19:30 +09:00
|
|
|
}
|
2024-07-19 16:27:01 +00:00
|
|
|
else if (_entityManager.TryGetComponent<TemporaryNightVisionComponent>(uid, out var tempNvComp))
|
2024-03-14 01:19:30 +09:00
|
|
|
{
|
2024-07-19 16:27:01 +00:00
|
|
|
color = SetParameters(tempNvComp);
|
|
|
|
|
}
|
|
|
|
|
else if (_entityManager.TryGetComponent<TemporaryThermalVisionComponent>(uid, out var tempThermal))
|
|
|
|
|
{
|
|
|
|
|
color = SetParameters(tempThermal);
|
2024-01-26 17:36:10 +07:00
|
|
|
}
|
|
|
|
|
|
2024-03-14 01:19:30 +09:00
|
|
|
if (color == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-01-26 17:36:10 +07:00
|
|
|
_shader.SetParameter("SCREEN_TEXTURE", ScreenTexture);
|
|
|
|
|
|
|
|
|
|
handle.UseShader(_shader);
|
2024-03-14 01:19:30 +09:00
|
|
|
handle.DrawRect(args.WorldBounds, color.Value);
|
2024-01-26 17:36:10 +07:00
|
|
|
handle.UseShader(null);
|
|
|
|
|
}
|
2024-07-19 16:27:01 +00:00
|
|
|
|
|
|
|
|
private Color SetParameters(BaseNvOverlayComponent component)
|
|
|
|
|
{
|
|
|
|
|
_shader.SetParameter("tint", component.Tint);
|
|
|
|
|
_shader.SetParameter("luminance_threshold", component.Strength);
|
|
|
|
|
_shader.SetParameter("noise_amount", component.Noise);
|
|
|
|
|
return component.Color;
|
|
|
|
|
}
|
2024-01-26 17:36:10 +07:00
|
|
|
}
|
|
|
|
|
}
|