-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
433 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 15 additions & 14 deletions
29
Content.Client/Overlays/Switchable/BaseSwitchableOverlay.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,48 @@ | ||
using System.Numerics; | ||
using Content.Shared.Overlays.Switchable; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Enums; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Client.Overlays.Switchable; | ||
|
||
public class BaseSwitchableOverlay<TComp> : Overlay | ||
where TComp : SwitchableOverlayComponent | ||
public sealed class BaseSwitchableOverlay<TComp> : Overlay where TComp : SwitchableOverlayComponent | ||
{ | ||
[Dependency] private readonly IPrototypeManager _prototype = default!; | ||
[Dependency] private readonly IPlayerManager _player = default!; | ||
[Dependency] private readonly IEntityManager _entity = default!; | ||
|
||
public override bool RequestScreenTexture => true; | ||
public override OverlaySpace Space => OverlaySpace.WorldSpace; | ||
|
||
private readonly ShaderInstance _shader; | ||
|
||
public TComp? Comp = null; | ||
|
||
public bool IsActive = true; | ||
|
||
public BaseSwitchableOverlay() | ||
{ | ||
IoCManager.InjectDependencies(this); | ||
_shader = _prototype.Index<ShaderPrototype>("NightVision").Instance().Duplicate(); | ||
_shader = _prototype.Index<ShaderPrototype>("NightVision").InstanceUnique(); | ||
} | ||
|
||
protected override void Draw(in OverlayDrawArgs args) | ||
{ | ||
if (ScreenTexture is null | ||
|| _player.LocalEntity == null | ||
|| !_entity.TryGetComponent<TComp>(_player.LocalEntity.Value, out var component) | ||
|| !component.IsActive) | ||
if (ScreenTexture is null || Comp is null || !IsActive) | ||
return; | ||
|
||
_shader.SetParameter("SCREEN_TEXTURE", ScreenTexture); | ||
_shader.SetParameter("tint", component.Tint); | ||
_shader.SetParameter("luminance_threshold", component.Strength); | ||
_shader.SetParameter("noise_amount", component.Noise); | ||
_shader.SetParameter("tint", Comp.Tint); | ||
_shader.SetParameter("luminance_threshold", Comp.Strength); | ||
_shader.SetParameter("noise_amount", Comp.Noise); | ||
|
||
var worldHandle = args.WorldHandle; | ||
|
||
var accumulator = Math.Clamp(Comp.PulseAccumulator, 0f, Comp.PulseTime); | ||
var alpha = Comp.PulseTime <= 0f ? 1f : float.Lerp(1f, 0f, accumulator / Comp.PulseTime); | ||
|
||
worldHandle.SetTransform(Matrix3x2.Identity); | ||
worldHandle.UseShader(_shader); | ||
worldHandle.DrawRect(args.WorldBounds, component.Color); | ||
worldHandle.DrawRect(args.WorldBounds, Comp.Color.WithAlpha(alpha)); | ||
worldHandle.UseShader(null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.