]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Predict ActivatableUIRequiresPower (#28405)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Thu, 30 May 2024 07:32:16 +0000 (17:32 +1000)
committerGitHub <noreply@github.com>
Thu, 30 May 2024 07:32:16 +0000 (00:32 -0700)
A lot of BUIs aren't going to handle the state coming in cleanly but we can fix em as we find em.

Content.Client/Power/ActivatableUIRequiresPowerSystem.cs
Content.Client/Power/EntitySystems/StaticPowerSystem.cs [new file with mode: 0644]
Content.Server/Power/EntitySystems/ActivatableUIRequiresPowerSystem.cs
Content.Shared/Power/EntitySystems/SharedActivatableUIRequiresPowerSystem.cs [new file with mode: 0644]

index 60ed8d87b9e6fc19895a984d0d91879b23d10b04..5a082485a5ac5a645639da1a9aed8e6037ba4ea8 100644 (file)
@@ -1,21 +1,27 @@
+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();
     }
 }
diff --git a/Content.Client/Power/EntitySystems/StaticPowerSystem.cs b/Content.Client/Power/EntitySystems/StaticPowerSystem.cs
new file mode 100644 (file)
index 0000000..2ca945c
--- /dev/null
@@ -0,0 +1,16 @@
+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;
+    }
+}
index 72843a65b84eb4bcee7dcd046f9c1583ca8c6c35..11f35634b20beefc74ed4cc6ec61224693ad5b79 100644 (file)
@@ -1,34 +1,33 @@
-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();
     }
 
diff --git a/Content.Shared/Power/EntitySystems/SharedActivatableUIRequiresPowerSystem.cs b/Content.Shared/Power/EntitySystems/SharedActivatableUIRequiresPowerSystem.cs
new file mode 100644 (file)
index 0000000..b3ac5bf
--- /dev/null
@@ -0,0 +1,15 @@
+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);
+}