2021-11-23 18:19:08 +00:00
|
|
|
using Content.Shared.Popups;
|
|
|
|
|
using Content.Server.Power.Components;
|
|
|
|
|
using Content.Server.UserInterface;
|
2022-03-12 13:26:06 -05:00
|
|
|
using Content.Server.WireHacking;
|
2021-11-23 18:19:08 +00:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Power.EntitySystems
|
|
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
internal sealed class ActivatableUIRequiresPowerSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly ActivatableUISystem _activatableUISystem = default!;
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<ActivatableUIRequiresPowerComponent, ActivatableUIOpenAttemptEvent>(OnActivate);
|
|
|
|
|
SubscribeLocalEvent<ActivatableUIRequiresPowerComponent, PowerChangedEvent>(OnPowerChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnActivate(EntityUid uid, ActivatableUIRequiresPowerComponent component, ActivatableUIOpenAttemptEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Cancelled) return;
|
|
|
|
|
if (EntityManager.TryGetComponent<ApcPowerReceiverComponent>(uid, out var power) && !power.Powered)
|
|
|
|
|
{
|
2022-03-12 13:26:06 -05:00
|
|
|
if (TryComp<WiresComponent>(uid, out var wires) && wires.IsPanelOpen)
|
|
|
|
|
return;
|
|
|
|
|
args.User.PopupMessageCursor(Loc.GetString("base-computer-ui-component-not-powered", ("machine", uid)));
|
2021-11-23 18:19:08 +00:00
|
|
|
args.Cancel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnPowerChanged(EntityUid uid, ActivatableUIRequiresPowerComponent component, PowerChangedEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (!args.Powered)
|
|
|
|
|
_activatableUISystem.CloseAll(uid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|