using Content.Shared.Flash;
using Content.Shared.Flash.Components;
using Content.Shared.StatusEffect;
-using Content.Client.Viewport;
using Robust.Client.Graphics;
-using Robust.Client.State;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
-using SixLabors.ImageSharp.PixelFormats;
namespace Content.Client.Flash
{
public sealed class FlashOverlay : Overlay
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
- [Dependency] private readonly IClyde _displayManager = default!;
- [Dependency] private readonly IStateManager _stateManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IGameTiming _timing = default!;
- private readonly StatusEffectsSystem _statusSys;
+ private readonly StatusEffectsSystem _statusSys;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
private readonly ShaderInstance _shader;
PercentComplete = timeDone / lastsFor;
}
- public void ReceiveFlash()
- {
- if (_stateManager.CurrentState is IMainViewportState state)
- {
- // take a screenshot
- // note that the callback takes a while and ScreenshotTexture will be null the first few Draws
- state.Viewport.Viewport.Screenshot(image =>
- {
- var rgba32Image = image.CloneAs<Rgba32>(SixLabors.ImageSharp.Configuration.Default);
- ScreenshotTexture = _displayManager.LoadTextureFromImage(rgba32Image);
- });
- }
- }
-
protected override bool BeforeDraw(in OverlayDrawArgs args)
{
if (!_entityManager.TryGetComponent(_playerManager.LocalEntity, out EyeComponent? eyeComp))
protected override void Draw(in OverlayDrawArgs args)
{
+ if (RequestScreenTexture && ScreenTexture != null)
+ {
+ ScreenshotTexture = ScreenTexture;
+ RequestScreenTexture = false; // we only need the first frame, so we can stop the request now for performance reasons
+ }
if (ScreenshotTexture == null)
return;
{
base.DisposeBehavior();
ScreenshotTexture = null;
- PercentComplete = 1.0f;
}
}
}
SubscribeLocalEvent<FlashedComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<FlashedComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<FlashedComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);
- SubscribeLocalEvent<FlashedComponent, StatusEffectAddedEvent>(OnStatusAdded);
_overlay = new();
}
private void OnPlayerDetached(EntityUid uid, FlashedComponent component, LocalPlayerDetachedEvent args)
{
- _overlay.PercentComplete = 1.0f;
_overlay.ScreenshotTexture = null;
+ _overlay.RequestScreenTexture = false;
_overlayMan.RemoveOverlay(_overlay);
}
{
if (_player.LocalEntity == uid)
{
+ _overlay.RequestScreenTexture = true;
_overlayMan.AddOverlay(_overlay);
}
}
{
if (_player.LocalEntity == uid)
{
- _overlay.PercentComplete = 1.0f;
_overlay.ScreenshotTexture = null;
+ _overlay.RequestScreenTexture = false;
_overlayMan.RemoveOverlay(_overlay);
}
}
-
- private void OnStatusAdded(EntityUid uid, FlashedComponent component, StatusEffectAddedEvent args)
- {
- if (_player.LocalEntity == uid && args.Key == FlashedKey)
- {
- _overlay.ReceiveFlash();
- }
- }
}