Eye damage (#10262)
This commit is contained in:
68
Content.Client/Eye/Blinding/BlurryVisionOverlay.cs
Normal file
68
Content.Client/Eye/Blinding/BlurryVisionOverlay.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
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 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 _blurryVisionXShader;
|
||||
private readonly ShaderInstance _blurryVisionYShader;
|
||||
private BlurryVisionComponent _blurryVisionComponent = default!;
|
||||
|
||||
public BlurryVisionOverlay()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
_blurryVisionXShader = _prototypeManager.Index<ShaderPrototype>("BlurryVisionX").InstanceUnique();
|
||||
_blurryVisionYShader = _prototypeManager.Index<ShaderPrototype>("BlurryVisionY").InstanceUnique();
|
||||
}
|
||||
|
||||
protected override bool BeforeDraw(in OverlayDrawArgs args)
|
||||
{
|
||||
var playerEntity = _playerManager.LocalPlayer?.ControlledEntity;
|
||||
|
||||
if (playerEntity == null)
|
||||
return false;
|
||||
|
||||
if (!_entityManager.TryGetComponent<BlurryVisionComponent>(playerEntity, out var blurComp))
|
||||
return false;
|
||||
|
||||
if (!blurComp.Active)
|
||||
return false;
|
||||
|
||||
if (_entityManager.TryGetComponent<BlindableComponent>(playerEntity, out var blindComp)
|
||||
&& blindComp.Sources > 0)
|
||||
return false;
|
||||
|
||||
_blurryVisionComponent = blurComp;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void Draw(in OverlayDrawArgs args)
|
||||
{
|
||||
if (ScreenTexture == null)
|
||||
return;
|
||||
|
||||
_blurryVisionXShader?.SetParameter("SCREEN_TEXTURE", ScreenTexture);
|
||||
_blurryVisionXShader?.SetParameter("BLUR_AMOUNT", (_blurryVisionComponent.Magnitude / 10));
|
||||
_blurryVisionYShader?.SetParameter("SCREEN_TEXTURE", ScreenTexture);
|
||||
_blurryVisionYShader?.SetParameter("BLUR_AMOUNT", (_blurryVisionComponent.Magnitude / 10));
|
||||
|
||||
var worldHandle = args.WorldHandle;
|
||||
var viewport = args.WorldBounds;
|
||||
worldHandle.SetTransform(Matrix3.Identity);
|
||||
worldHandle.UseShader(_blurryVisionXShader);
|
||||
worldHandle.DrawRect(viewport, Color.White);
|
||||
worldHandle.UseShader(_blurryVisionYShader);
|
||||
worldHandle.DrawRect(viewport, Color.White);
|
||||
}
|
||||
}
|
||||
}
|
||||
61
Content.Client/Eye/Blinding/BlurryVisionSystem.cs
Normal file
61
Content.Client/Eye/Blinding/BlurryVisionSystem.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Content.Shared.Eye.Blinding;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Client.Eye.Blinding;
|
||||
|
||||
public sealed class BlurryVisionSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _player = default!;
|
||||
[Dependency] private readonly IOverlayManager _overlayMan = default!;
|
||||
private BlurryVisionOverlay _overlay = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<BlurryVisionComponent, ComponentInit>(OnBlurryInit);
|
||||
SubscribeLocalEvent<BlurryVisionComponent, ComponentShutdown>(OnBlurryShutdown);
|
||||
|
||||
SubscribeLocalEvent<BlurryVisionComponent, PlayerAttachedEvent>(OnPlayerAttached);
|
||||
SubscribeLocalEvent<BlurryVisionComponent, PlayerDetachedEvent>(OnPlayerDetached);
|
||||
|
||||
SubscribeLocalEvent<BlurryVisionComponent, ComponentHandleState>(OnHandleState);
|
||||
|
||||
_overlay = new();
|
||||
}
|
||||
|
||||
private void OnPlayerAttached(EntityUid uid, BlurryVisionComponent component, PlayerAttachedEvent args)
|
||||
{
|
||||
_overlayMan.AddOverlay(_overlay);
|
||||
}
|
||||
|
||||
private void OnPlayerDetached(EntityUid uid, BlurryVisionComponent component, PlayerDetachedEvent args)
|
||||
{
|
||||
_overlayMan.RemoveOverlay(_overlay);
|
||||
}
|
||||
|
||||
private void OnBlurryInit(EntityUid uid, BlurryVisionComponent component, ComponentInit args)
|
||||
{
|
||||
if (_player.LocalPlayer?.ControlledEntity == uid)
|
||||
_overlayMan.AddOverlay(_overlay);
|
||||
}
|
||||
|
||||
private void OnBlurryShutdown(EntityUid uid, BlurryVisionComponent component, ComponentShutdown args)
|
||||
{
|
||||
if (_player.LocalPlayer?.ControlledEntity == uid)
|
||||
{
|
||||
_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