Files
OldThink/Content.Server/Power/EntitySystems/ActivatableUIRequiresPowerSystem.cs

39 lines
1.4 KiB
C#
Raw Normal View History

using Content.Shared.Popups;
using Content.Server.Power.Components;
using Content.Server.UserInterface;
using JetBrains.Annotations;
2023-03-24 03:09:45 +03:00
using Content.Shared.Wires;
2023-03-24 03:09:45 +03:00
namespace Content.Server.Power.EntitySystems;
[UsedImplicitly]
internal sealed class ActivatableUIRequiresPowerSystem : EntitySystem
{
2023-03-24 03:09:45 +03:00
[Dependency] private readonly ActivatableUISystem _activatableUI = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
public override void Initialize()
{
2023-03-24 03:09:45 +03:00
base.Initialize();
2023-03-24 03:09:45 +03:00
SubscribeLocalEvent<ActivatableUIRequiresPowerComponent, ActivatableUIOpenAttemptEvent>(OnActivate);
SubscribeLocalEvent<ActivatableUIRequiresPowerComponent, PowerChangedEvent>(OnPowerChanged);
}
2023-03-24 03:09:45 +03:00
private void OnActivate(EntityUid uid, ActivatableUIRequiresPowerComponent component, ActivatableUIOpenAttemptEvent args)
{
if (args.Cancelled) return;
if (this.IsPowered(uid, EntityManager)) return;
if (TryComp<WiresPanelComponent>(uid, out var panel) && panel.Open)
return;
_popup.PopupCursor(Loc.GetString("base-computer-ui-component-not-powered", ("machine", uid)), args.User);
args.Cancel();
}
2023-03-24 03:09:45 +03:00
private void OnPowerChanged(EntityUid uid, ActivatableUIRequiresPowerComponent component, ref PowerChangedEvent args)
{
if (!args.Powered)
_activatableUI.CloseAll(uid);
}
}