36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using Content.Shared.Power;
|
|
using Content.Shared.Power.Components;
|
|
using Content.Shared.Power.EntitySystems;
|
|
using Content.Shared.UserInterface;
|
|
using ActivatableUISystem = Content.Shared.UserInterface.ActivatableUISystem;
|
|
|
|
namespace Content.Server.Power.EntitySystems;
|
|
|
|
public sealed class ActivatableUIRequiresPowerSystem : SharedActivatableUIRequiresPowerSystem
|
|
{
|
|
[Dependency] private readonly ActivatableUISystem _activatableUI = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<ActivatableUIRequiresPowerComponent, PowerChangedEvent>(OnPowerChanged);
|
|
}
|
|
|
|
protected override void OnActivate(Entity<ActivatableUIRequiresPowerComponent> ent, ref ActivatableUIOpenAttemptEvent args)
|
|
{
|
|
if (args.Cancelled || this.IsPowered(ent.Owner, EntityManager))
|
|
{
|
|
return;
|
|
}
|
|
|
|
args.Cancel();
|
|
}
|
|
|
|
private void OnPowerChanged(EntityUid uid, ActivatableUIRequiresPowerComponent component, ref PowerChangedEvent args)
|
|
{
|
|
if (!args.Powered)
|
|
_activatableUI.CloseAll(uid);
|
|
}
|
|
}
|