Blindness refactor (#15705)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@ using Robust.Client.Player;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Content.Shared.Eye.Blinding;
|
||||
using Content.Shared.Eye.Blinding.Components;
|
||||
|
||||
namespace Content.Client.Eye.Blinding
|
||||
{
|
||||
@@ -46,7 +47,7 @@ namespace Content.Client.Eye.Blinding
|
||||
|
||||
_blindableComponent = blindComp;
|
||||
|
||||
var blind = _blindableComponent.Sources > 0;
|
||||
var blind = _blindableComponent.IsBlind;
|
||||
|
||||
if (!blind && _blindableComponent.LightSetup) // Turn FOV back on if we can see again
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Administration.Events;
|
||||
using Content.Shared.Eye.Blinding.Components;
|
||||
using Content.Shared.GameTicking;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Network;
|
||||
|
||||
@@ -4,24 +4,21 @@ using Robust.Client.Player;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Content.Shared.Eye.Blinding;
|
||||
using Content.Shared.Eye.Blinding.Components;
|
||||
|
||||
namespace Content.Client.Eye.Blinding
|
||||
{
|
||||
public sealed class BlurryVisionOverlay : Overlay
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
|
||||
public override bool RequestScreenTexture => true;
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpace;
|
||||
private readonly ShaderInstance _dim;
|
||||
private BlurryVisionComponent _blurryVisionComponent = default!;
|
||||
private float _magnitude;
|
||||
|
||||
public BlurryVisionOverlay()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
_dim = _prototypeManager.Index<ShaderPrototype>("Dim").InstanceUnique();
|
||||
}
|
||||
|
||||
protected override bool BeforeDraw(in OverlayDrawArgs args)
|
||||
@@ -40,33 +37,29 @@ namespace Content.Client.Eye.Blinding
|
||||
if (!_entityManager.TryGetComponent<BlurryVisionComponent>(playerEntity, out var blurComp))
|
||||
return false;
|
||||
|
||||
if (!blurComp.Active)
|
||||
if (blurComp.Magnitude <= 0)
|
||||
return false;
|
||||
|
||||
if (_entityManager.TryGetComponent<BlindableComponent>(playerEntity, out var blindComp)
|
||||
&& blindComp.Sources > 0)
|
||||
&& blindComp.IsBlind)
|
||||
return false;
|
||||
|
||||
_blurryVisionComponent = blurComp;
|
||||
_magnitude = blurComp.Magnitude;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void Draw(in OverlayDrawArgs args)
|
||||
{
|
||||
if (ScreenTexture == null)
|
||||
return;
|
||||
|
||||
var opacity = -(_blurryVisionComponent.Magnitude / 15) + 0.9f;
|
||||
|
||||
_dim.SetParameter("DAMAGE_AMOUNT", opacity);
|
||||
|
||||
// TODO make this better.
|
||||
// This is a really shitty effect.
|
||||
// Maybe gradually shrink the view-size?
|
||||
// Make the effect only apply to the edge of the viewport?
|
||||
// Actually make it blurry??
|
||||
var opacity = 0.5f * _magnitude / BlurryVisionComponent.MaxMagnitude;
|
||||
var worldHandle = args.WorldHandle;
|
||||
var viewport = args.WorldBounds;
|
||||
|
||||
worldHandle.UseShader(_dim);
|
||||
worldHandle.SetTransform(Matrix3.Identity);
|
||||
worldHandle.DrawRect(viewport, Color.Black);
|
||||
worldHandle.UseShader(null);
|
||||
worldHandle.DrawRect(viewport, Color.White.WithAlpha(opacity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Eye.Blinding;
|
||||
using Content.Shared.Eye.Blinding.Components;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
@@ -22,8 +23,6 @@ public sealed class BlurryVisionSystem : EntitySystem
|
||||
SubscribeLocalEvent<BlurryVisionComponent, PlayerAttachedEvent>(OnPlayerAttached);
|
||||
SubscribeLocalEvent<BlurryVisionComponent, PlayerDetachedEvent>(OnPlayerDetached);
|
||||
|
||||
SubscribeLocalEvent<BlurryVisionComponent, ComponentHandleState>(OnHandleState);
|
||||
|
||||
_overlay = new();
|
||||
}
|
||||
|
||||
@@ -50,12 +49,4 @@ public sealed class BlurryVisionSystem : EntitySystem
|
||||
_overlayMan.RemoveOverlay(_overlay);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnHandleState(EntityUid uid, BlurryVisionComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not BlurryVisionComponentState state)
|
||||
return;
|
||||
|
||||
component.Magnitude = state.Magnitude;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user