FlashSystem.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Content.Shared.Flash;
  2. using Content.Shared.Flash.Components;
  3. using Content.Shared.StatusEffect;
  4. using Robust.Client.Graphics;
  5. using Robust.Client.Player;
  6. using Robust.Shared.Player;
  7. namespace Content.Client.Flash;
  8. public sealed class FlashSystem : SharedFlashSystem
  9. {
  10. [Dependency] private readonly IPlayerManager _player = default!;
  11. [Dependency] private readonly IOverlayManager _overlayMan = default!;
  12. private FlashOverlay _overlay = default!;
  13. public override void Initialize()
  14. {
  15. base.Initialize();
  16. SubscribeLocalEvent<FlashedComponent, ComponentInit>(OnInit);
  17. SubscribeLocalEvent<FlashedComponent, ComponentShutdown>(OnShutdown);
  18. SubscribeLocalEvent<FlashedComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
  19. SubscribeLocalEvent<FlashedComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);
  20. _overlay = new();
  21. }
  22. private void OnPlayerAttached(EntityUid uid, FlashedComponent component, LocalPlayerAttachedEvent args)
  23. {
  24. _overlayMan.AddOverlay(_overlay);
  25. }
  26. private void OnPlayerDetached(EntityUid uid, FlashedComponent component, LocalPlayerDetachedEvent args)
  27. {
  28. _overlay.ScreenshotTexture = null;
  29. _overlay.RequestScreenTexture = false;
  30. _overlayMan.RemoveOverlay(_overlay);
  31. }
  32. private void OnInit(EntityUid uid, FlashedComponent component, ComponentInit args)
  33. {
  34. if (_player.LocalEntity == uid)
  35. {
  36. _overlay.RequestScreenTexture = true;
  37. _overlayMan.AddOverlay(_overlay);
  38. }
  39. }
  40. private void OnShutdown(EntityUid uid, FlashedComponent component, ComponentShutdown args)
  41. {
  42. if (_player.LocalEntity == uid)
  43. {
  44. _overlay.ScreenshotTexture = null;
  45. _overlay.RequestScreenTexture = false;
  46. _overlayMan.RemoveOverlay(_overlay);
  47. }
  48. }
  49. }