feat: night vision
This commit is contained in:
50
Content.Client/White/Overlays/NightVisionOverlay.cs
Normal file
50
Content.Client/White/Overlays/NightVisionOverlay.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Content.Shared.White.Overlays;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.White.Overlays
|
||||
{
|
||||
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;
|
||||
|
||||
if (!_entityManager.TryGetComponent<NightVisionComponent>(_playerManager.LocalSession?.AttachedEntity,
|
||||
out var component))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_shader.SetParameter("SCREEN_TEXTURE", ScreenTexture);
|
||||
_shader.SetParameter("tint", component.Tint);
|
||||
_shader.SetParameter("luminance_threshold", component.Strength);
|
||||
_shader.SetParameter("noise_amount", component.Noise);
|
||||
|
||||
handle.UseShader(_shader);
|
||||
handle.DrawRect(args.WorldBounds, component.Color);
|
||||
handle.UseShader(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
66
Content.Client/White/Overlays/NightVisionSystem.cs
Normal file
66
Content.Client/White/Overlays/NightVisionSystem.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.White.Overlays;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Client.White.Overlays;
|
||||
|
||||
public sealed class NightVisionSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _player = default!;
|
||||
[Dependency] private readonly IOverlayManager _overlayMan = default!;
|
||||
[Dependency] private readonly ILightManager _lightManager = default!;
|
||||
|
||||
private NightVisionOverlay _overlay = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<NightVisionComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<NightVisionComponent, ComponentRemove>(OnRemove);
|
||||
|
||||
SubscribeLocalEvent<NightVisionComponent, PlayerAttachedEvent>(OnPlayerAttached);
|
||||
SubscribeLocalEvent<NightVisionComponent, PlayerDetachedEvent>(OnPlayerDetached);
|
||||
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRestart);
|
||||
|
||||
_overlay = new NightVisionOverlay();
|
||||
}
|
||||
|
||||
private void OnPlayerAttached(EntityUid uid, NightVisionComponent component, PlayerAttachedEvent args)
|
||||
{
|
||||
_overlayMan.AddOverlay(_overlay);
|
||||
_lightManager.DrawLighting = false;
|
||||
}
|
||||
|
||||
private void OnPlayerDetached(EntityUid uid, NightVisionComponent component, PlayerDetachedEvent args)
|
||||
{
|
||||
_overlayMan.RemoveOverlay(_overlay);
|
||||
_lightManager.DrawLighting = true;
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, NightVisionComponent component, ComponentInit args)
|
||||
{
|
||||
if (_player.LocalSession?.AttachedEntity != uid)
|
||||
return;
|
||||
|
||||
_overlayMan.AddOverlay(_overlay);
|
||||
_lightManager.DrawLighting = false;
|
||||
}
|
||||
|
||||
private void OnRemove(EntityUid uid, NightVisionComponent component, ComponentRemove args)
|
||||
{
|
||||
if (_player.LocalSession?.AttachedEntity != uid)
|
||||
return;
|
||||
|
||||
_overlayMan.RemoveOverlay(_overlay);
|
||||
_lightManager.DrawLighting = true;
|
||||
}
|
||||
|
||||
private void OnRestart(RoundRestartCleanupEvent ev)
|
||||
{
|
||||
_overlayMan.RemoveOverlay(_overlay);
|
||||
_lightManager.DrawLighting = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user