1
0

ActivatableUIRequiresPowerSystem.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using Content.Shared.Power;
  2. using Content.Shared.Power.Components;
  3. using Content.Shared.Power.EntitySystems;
  4. using Content.Shared.UserInterface;
  5. using ActivatableUISystem = Content.Shared.UserInterface.ActivatableUISystem;
  6. namespace Content.Server.Power.EntitySystems;
  7. public sealed class ActivatableUIRequiresPowerSystem : SharedActivatableUIRequiresPowerSystem
  8. {
  9. [Dependency] private readonly ActivatableUISystem _activatableUI = default!;
  10. public override void Initialize()
  11. {
  12. base.Initialize();
  13. SubscribeLocalEvent<ActivatableUIRequiresPowerComponent, PowerChangedEvent>(OnPowerChanged);
  14. }
  15. protected override void OnActivate(Entity<ActivatableUIRequiresPowerComponent> ent, ref ActivatableUIOpenAttemptEvent args)
  16. {
  17. if (args.Cancelled || this.IsPowered(ent.Owner, EntityManager))
  18. {
  19. return;
  20. }
  21. args.Cancel();
  22. }
  23. private void OnPowerChanged(EntityUid uid, ActivatableUIRequiresPowerComponent component, ref PowerChangedEvent args)
  24. {
  25. if (!args.Powered)
  26. _activatableUI.CloseAll(uid);
  27. }
  28. }