A lot of BUIs aren't going to handle the state coming in cleanly but we can fix em as we find em.
40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using Content.Server.Power.Components;
|
|
using Content.Shared.Power.Components;
|
|
using Content.Shared.Power.EntitySystems;
|
|
using Content.Shared.UserInterface;
|
|
using Content.Shared.Wires;
|
|
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;
|
|
}
|
|
|
|
if (TryComp<WiresPanelComponent>(ent.Owner, out var panel) && panel.Open)
|
|
return;
|
|
|
|
args.Cancel();
|
|
}
|
|
|
|
private void OnPowerChanged(EntityUid uid, ActivatableUIRequiresPowerComponent component, ref PowerChangedEvent args)
|
|
{
|
|
if (!args.Powered)
|
|
_activatableUI.CloseAll(uid);
|
|
}
|
|
}
|