Files
tbd-station-14/Content.Client/Graphics/Overlays/FlashOverlay.cs
GraniteSidewalk 549d84174c Singularity Shaders and a lot of Shader Stuff (#2517)
* Beginnings of singulo shader

* LOTS of changes!!

* Minor changes

* Singulo stuff

* Aesthetic changes to singulo

* Combining singulo change

* ShaderAura uses IEntities now, not IPlayerSession

* Fixes?

* Fixes draw order for atmos

* using fix

* Address reviews

* nuget.config whaaa

* nuget haha

* nuget why are you so dum

* happy now

* Preparing for omegachange

* Merge from seventh level of hell

* woork

* Ignorecomponents add

* mmf

* RobustToolbox?

* Fixes

* Fixes Robust?

* adds sprite

* Nullables

* Crit overlay stuff

* Commits Robust
2021-03-09 02:33:41 -08:00

65 lines
2.2 KiB
C#

using Robust.Client.Graphics;
using Robust.Shared.Enums;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
namespace Content.Client.Graphics.Overlays
{
public class FlashOverlay : Overlay
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IClyde _displayManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
public override OverlaySpace Space => OverlaySpace.ScreenSpace;
private readonly ShaderInstance _shader;
private double _startTime = -1;
private double _lastsFor = 1;
private Texture _screenshotTexture;
public FlashOverlay()
{
IoCManager.InjectDependencies(this);
_shader = _prototypeManager.Index<ShaderPrototype>("FlashedEffect").Instance().Duplicate();
}
public void ReceiveFlash(double duration)
{
_displayManager.Screenshot(ScreenshotType.BeforeUI, image =>
{
var rgba32Image = image.CloneAs<Rgba32>(Configuration.Default);
_screenshotTexture = _displayManager.LoadTextureFromImage(rgba32Image);
});
_startTime = _gameTiming.CurTime.TotalSeconds;
_lastsFor = duration;
}
protected override void Draw(DrawingHandleBase handle, OverlaySpace currentSpace)
{
var percentComplete = (float) ((_gameTiming.CurTime.TotalSeconds - _startTime) / _lastsFor);
if (percentComplete >= 1.0f)
return;
handle.UseShader(_shader);
_shader?.SetParameter("percentComplete", percentComplete);
var screenSpaceHandle = handle as DrawingHandleScreen;
var screenSize = UIBox2.FromDimensions((0, 0), _displayManager.ScreenSize);
if (_screenshotTexture != null)
{
screenSpaceHandle?.DrawTextureRect(_screenshotTexture, screenSize);
}
}
protected override void DisposeBehavior()
{
base.Dispose();
_screenshotTexture = null;
}
}
}