[2 lines] fix blinding (#9690)
* Adds blinding + blindfolds (#8688) * Adds blinding + blindfolds * Don't break examining lol * moment * fix toggle lights behavior * move checks around * Sloth review * Added a salvage funny * review * woops * Switch circle shader Co-authored-by: wrexbe <wrexbe@protonmail.com> * resolve merge conflict Co-authored-by: wrexbe <wrexbe@protonmail.com>
This commit is contained in:
80
Content.Client/Eye/Blinding/BlindOverlay.cs
Normal file
80
Content.Client/Eye/Blinding/BlindOverlay.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Content.Shared.Eye.Blinding;
|
||||
|
||||
namespace Content.Client.Eye.Blinding
|
||||
{
|
||||
public sealed class BlindOverlay : Overlay
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] IEntityManager _entityManager = default!;
|
||||
[Dependency] ILightManager _lightManager = default!;
|
||||
|
||||
|
||||
public override bool RequestScreenTexture => true;
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpace;
|
||||
private readonly ShaderInstance _greyscaleShader;
|
||||
private readonly ShaderInstance _circleMaskShader;
|
||||
|
||||
private BlindableComponent _blindableComponent = default!;
|
||||
|
||||
public BlindOverlay()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
_greyscaleShader = _prototypeManager.Index<ShaderPrototype>("GreyscaleFullscreen").InstanceUnique();
|
||||
_circleMaskShader = _prototypeManager.Index<ShaderPrototype>("CircleMask").InstanceUnique();
|
||||
}
|
||||
protected override bool BeforeDraw(in OverlayDrawArgs args)
|
||||
{
|
||||
var playerEntity = _playerManager.LocalPlayer?.ControlledEntity;
|
||||
|
||||
if (playerEntity == null)
|
||||
return false;
|
||||
|
||||
if (!_entityManager.TryGetComponent<BlindableComponent>(playerEntity, out var blindComp))
|
||||
return false;
|
||||
|
||||
_blindableComponent = blindComp;
|
||||
|
||||
var blind = _blindableComponent.Sources > 0;
|
||||
|
||||
if (!blind && _blindableComponent.LightSetup) // Turn FOV back on if we can see again
|
||||
{
|
||||
_lightManager.Enabled = true;
|
||||
_blindableComponent.LightSetup = false;
|
||||
_blindableComponent.GraceFrame = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return blind;
|
||||
}
|
||||
|
||||
protected override void Draw(in OverlayDrawArgs args)
|
||||
{
|
||||
if (ScreenTexture == null)
|
||||
return;
|
||||
|
||||
if (!_blindableComponent.GraceFrame)
|
||||
{
|
||||
_blindableComponent.LightSetup = true; // Ok we touched the lights
|
||||
_lightManager.Enabled = false;
|
||||
} else
|
||||
{
|
||||
_blindableComponent.GraceFrame = false;
|
||||
}
|
||||
|
||||
_greyscaleShader?.SetParameter("SCREEN_TEXTURE", ScreenTexture);
|
||||
|
||||
var worldHandle = args.WorldHandle;
|
||||
var viewport = args.WorldBounds;
|
||||
worldHandle.SetTransform(Matrix3.Identity);
|
||||
worldHandle.UseShader(_greyscaleShader);
|
||||
worldHandle.DrawRect(viewport, Color.White);
|
||||
worldHandle.UseShader(_circleMaskShader);
|
||||
worldHandle.DrawRect(viewport, Color.White);
|
||||
}
|
||||
}
|
||||
}
|
||||
55
Content.Client/Eye/Blinding/BlindingSystem.cs
Normal file
55
Content.Client/Eye/Blinding/BlindingSystem.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
|
||||
using Content.Shared.Eye.Blinding;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
|
||||
namespace Content.Client.Eye.Blinding;
|
||||
|
||||
public sealed class BlindingSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _player = default!;
|
||||
[Dependency] private readonly IOverlayManager _overlayMan = default!;
|
||||
[Dependency] ILightManager _lightManager = default!;
|
||||
|
||||
|
||||
private BlindOverlay _overlay = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<BlindableComponent, ComponentInit>(OnBlindInit);
|
||||
SubscribeLocalEvent<BlindableComponent, ComponentShutdown>(OnBlindShutdown);
|
||||
|
||||
SubscribeLocalEvent<BlindableComponent, PlayerAttachedEvent>(OnPlayerAttached);
|
||||
SubscribeLocalEvent<BlindableComponent, PlayerDetachedEvent>(OnPlayerDetached);
|
||||
|
||||
_overlay = new();
|
||||
}
|
||||
|
||||
private void OnPlayerAttached(EntityUid uid, BlindableComponent component, PlayerAttachedEvent args)
|
||||
{
|
||||
_overlayMan.AddOverlay(_overlay);
|
||||
}
|
||||
|
||||
private void OnPlayerDetached(EntityUid uid, BlindableComponent component, PlayerDetachedEvent args)
|
||||
{
|
||||
_overlayMan.RemoveOverlay(_overlay);
|
||||
_lightManager.Enabled = true;
|
||||
}
|
||||
|
||||
private void OnBlindInit(EntityUid uid, BlindableComponent component, ComponentInit args)
|
||||
{
|
||||
if (_player.LocalPlayer?.ControlledEntity == uid)
|
||||
_overlayMan.AddOverlay(_overlay);
|
||||
}
|
||||
|
||||
private void OnBlindShutdown(EntityUid uid, BlindableComponent component, ComponentShutdown args)
|
||||
{
|
||||
if (_player.LocalPlayer?.ControlledEntity == uid)
|
||||
{
|
||||
_overlayMan.RemoveOverlay(_overlay);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user