A lot of BUIs aren't going to handle the state coming in cleanly but we can fix em as we find em.
+using Content.Client.Power.EntitySystems;
+using Content.Shared.Popups;
using Content.Shared.Power.Components;
+using Content.Shared.Power.EntitySystems;
using Content.Shared.UserInterface;
using Content.Shared.Wires;
namespace Content.Client.Power;
-public sealed class ActivatableUIRequiresPowerSystem : EntitySystem
+public sealed class ActivatableUIRequiresPowerSystem : SharedActivatableUIRequiresPowerSystem
{
- public override void Initialize()
+ [Dependency] private readonly SharedPopupSystem _popup = default!;
+
+ protected override void OnActivate(Entity<ActivatableUIRequiresPowerComponent> ent, ref ActivatableUIOpenAttemptEvent args)
{
- base.Initialize();
+ if (args.Cancelled || this.IsPowered(ent.Owner, EntityManager))
+ {
+ return;
+ }
- SubscribeLocalEvent<ActivatableUIRequiresPowerComponent, ActivatableUIOpenAttemptEvent>(OnActivate);
- }
+ if (TryComp<WiresPanelComponent>(ent.Owner, out var panel) && panel.Open)
+ return;
- private void OnActivate(EntityUid uid, ActivatableUIRequiresPowerComponent component, ActivatableUIOpenAttemptEvent args)
- {
- // Client can't predict the power properly at the moment so rely upon the server to do it.
+ _popup.PopupClient(Loc.GetString("base-computer-ui-component-not-powered", ("machine", ent.Owner)), args.User, args.User);
args.Cancel();
}
}
--- /dev/null
+using Content.Client.Power.Components;
+
+namespace Content.Client.Power.EntitySystems;
+
+public static class StaticPowerSystem
+{
+ // Using this makes the call shorter.
+ // ReSharper disable once UnusedParameter.Global
+ public static bool IsPowered(this EntitySystem system, EntityUid uid, IEntityManager entManager, ApcPowerReceiverComponent? receiver = null)
+ {
+ if (receiver == null && !entManager.TryGetComponent(uid, out receiver))
+ return false;
+
+ return receiver.Powered;
+ }
+}
-using Content.Shared.Popups;
using Content.Server.Power.Components;
+using Content.Shared.Power.Components;
+using Content.Shared.Power.EntitySystems;
using Content.Shared.UserInterface;
-using JetBrains.Annotations;
using Content.Shared.Wires;
-using Content.Server.UserInterface;
-using Content.Shared.Power.Components;
using ActivatableUISystem = Content.Shared.UserInterface.ActivatableUISystem;
namespace Content.Server.Power.EntitySystems;
-public sealed class ActivatableUIRequiresPowerSystem : EntitySystem
+public sealed class ActivatableUIRequiresPowerSystem : SharedActivatableUIRequiresPowerSystem
{
[Dependency] private readonly ActivatableUISystem _activatableUI = default!;
- [Dependency] private readonly SharedPopupSystem _popup = default!;
public override void Initialize()
{
base.Initialize();
- SubscribeLocalEvent<ActivatableUIRequiresPowerComponent, ActivatableUIOpenAttemptEvent>(OnActivate);
SubscribeLocalEvent<ActivatableUIRequiresPowerComponent, PowerChangedEvent>(OnPowerChanged);
}
- private void OnActivate(EntityUid uid, ActivatableUIRequiresPowerComponent component, ActivatableUIOpenAttemptEvent args)
+ protected override void OnActivate(Entity<ActivatableUIRequiresPowerComponent> ent, ref ActivatableUIOpenAttemptEvent args)
{
- if (args.Cancelled) return;
- if (this.IsPowered(uid, EntityManager)) return;
- if (TryComp<WiresPanelComponent>(uid, out var panel) && panel.Open)
+ if (args.Cancelled || this.IsPowered(ent.Owner, EntityManager))
+ {
return;
- _popup.PopupCursor(Loc.GetString("base-computer-ui-component-not-powered", ("machine", uid)), args.User);
+ }
+
+ if (TryComp<WiresPanelComponent>(ent.Owner, out var panel) && panel.Open)
+ return;
+
args.Cancel();
}
--- /dev/null
+using Content.Shared.Power.Components;
+using Content.Shared.UserInterface;
+
+namespace Content.Shared.Power.EntitySystems;
+
+public abstract class SharedActivatableUIRequiresPowerSystem : EntitySystem
+{
+ public override void Initialize()
+ {
+ base.Initialize();
+ SubscribeLocalEvent<ActivatableUIRequiresPowerComponent, ActivatableUIOpenAttemptEvent>(OnActivate);
+ }
+
+ protected abstract void OnActivate(Entity<ActivatableUIRequiresPowerComponent> ent, ref ActivatableUIOpenAttemptEvent args);
+}