]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make APC UI work correctly with multiple users (#32465)
authoreoineoineoin <github@eoinrul.es>
Sat, 12 Oct 2024 08:21:43 +0000 (09:21 +0100)
committerGitHub <noreply@github.com>
Sat, 12 Oct 2024 08:21:43 +0000 (19:21 +1100)
* Make APC UI work correctly with multiple users

* Check access only on client, when constructing UI

* Do TODO (Thanks, Robust 236.1)

---------

Co-authored-by: Eoin Mcloughlin <helloworld@eoinrul.es>
Content.Client/Power/APC/ApcBoundUserInterface.cs
Content.Client/Power/APC/UI/ApcMenu.xaml.cs
Content.Server/Power/Components/ApcComponent.cs
Content.Server/Power/EntitySystems/ApcSystem.cs
Content.Shared/APC/SharedApc.cs
Resources/Prototypes/Entities/Structures/Power/apc.yml

index a790c5d984ad137d306d8530207d8b3e2666f9e2..5c4036a9159e6fe9cfd3827fa46a0e1bf3f946b1 100644 (file)
@@ -1,8 +1,9 @@
-using Content.Client.Power.APC.UI;
+using Content.Client.Power.APC.UI;
+using Content.Shared.Access.Systems;
 using Content.Shared.APC;
 using JetBrains.Annotations;
-using Robust.Client.GameObjects;
 using Robust.Client.UserInterface;
+using Robust.Shared.Player;
 
 namespace Content.Client.Power.APC
 {
@@ -22,6 +23,14 @@ namespace Content.Client.Power.APC
             _menu = this.CreateWindow<ApcMenu>();
             _menu.SetEntity(Owner);
             _menu.OnBreaker += BreakerPressed;
+
+            var hasAccess = false;
+            if (PlayerManager.LocalEntity != null)
+            {
+                var accessReader = EntMan.System<AccessReaderSystem>();
+                hasAccess = accessReader.IsAllowed((EntityUid)PlayerManager.LocalEntity, Owner);
+            }
+            _menu?.SetAccessEnabled(hasAccess);
         }
 
         protected override void UpdateState(BoundUserInterfaceState state)
index 2f61ea63a864032fd93c474f7dcae96ff2b15433..25e885b3c7a1855a603d71f33d84d9000595980d 100644 (file)
@@ -1,4 +1,4 @@
-using Robust.Client.AutoGenerated;
+using Robust.Client.AutoGenerated;
 using Robust.Client.UserInterface.XAML;
 using Robust.Client.GameObjects;
 using Robust.Shared.IoC;
@@ -36,19 +36,9 @@ namespace Content.Client.Power.APC.UI
         {
             var castState = (ApcBoundInterfaceState) state;
 
-            if (BreakerButton != null)
+            if (!BreakerButton.Disabled)
             {
-                if(castState.HasAccess == false)
-                {
-                    BreakerButton.Disabled = true;
-                    BreakerButton.ToolTip = Loc.GetString("apc-component-insufficient-access");
-                }
-                else
-                {
-                    BreakerButton.Disabled = false;
-                    BreakerButton.ToolTip = null;
-                    BreakerButton.Pressed = castState.MainBreaker;
-                }
+                BreakerButton.Pressed = castState.MainBreaker;
             }
 
             if (PowerLabel != null)
@@ -86,6 +76,20 @@ namespace Content.Client.Power.APC.UI
             }
         }
 
+        public void SetAccessEnabled(bool hasAccess)
+        {
+            if(hasAccess)
+            {
+                BreakerButton.Disabled = false;
+                BreakerButton.ToolTip = null;
+            }
+            else
+            {
+                BreakerButton.Disabled = true;
+                BreakerButton.ToolTip = Loc.GetString("apc-component-insufficient-access");
+            }
+        }
+
         private void UpdateChargeBarColor(float charge)
         {
             if (ChargeBar == null)
index bee8defc43e46cacd66343e9533f9e3f48860f53..0bf9bc1872163ecb870adec9b149372b56910b5c 100644 (file)
@@ -25,9 +25,6 @@ public sealed partial class ApcComponent : BaseApcNetComponent
 
     [DataField("enabled")]
     public bool MainBreakerEnabled = true;
-    // TODO: remove this since it probably breaks when 2 people use it
-    [DataField("hasAccess")]
-    public bool HasAccess = false;
 
     /// <summary>
     /// APC state needs to always be updated after first processing tick.
index 52c19c302cee907aa45d7b25e567b1de0b430a52..14dddbb43e329ac9a7725d791bdfeb867c4494ed 100644 (file)
@@ -2,7 +2,6 @@ using Content.Server.Emp;
 using Content.Server.Popups;
 using Content.Server.Power.Components;
 using Content.Server.Power.Pow3r;
-using Content.Shared.Access.Components;
 using Content.Shared.Access.Systems;
 using Content.Shared.APC;
 using Content.Shared.Emag.Components;
@@ -71,11 +70,8 @@ public sealed class ApcSystem : EntitySystem
         component.NeedStateUpdate = true;
     }
 
-    //Update the HasAccess var for UI to read
     private void OnBoundUiOpen(EntityUid uid, ApcComponent component, BoundUIOpenedEvent args)
     {
-        // TODO: this should be per-player not stored on the apc
-        component.HasAccess = _accessReader.IsAllowed(args.Actor, uid);
         UpdateApcState(uid, component);
     }
 
@@ -165,7 +161,7 @@ public sealed class ApcSystem : EntitySystem
         // TODO: Fix ContentHelpers or make a new one coz this is cooked.
         var charge = ContentHelpers.RoundToNearestLevels(battery.CurrentStorage / battery.Capacity, 1.0, 100 / ChargeAccuracy) / 100f * ChargeAccuracy;
 
-        var state = new ApcBoundInterfaceState(apc.MainBreakerEnabled, apc.HasAccess,
+        var state = new ApcBoundInterfaceState(apc.MainBreakerEnabled,
             (int) MathF.Ceiling(battery.CurrentSupply), apc.LastExternalState,
             charge);
 
index bf9fdc9444ba50ae5bb4afef0401b45b06375be9..802c06a6ab6f83664d300220c0edae043be6e264 100644 (file)
@@ -178,15 +178,13 @@ namespace Content.Shared.APC
     public sealed class ApcBoundInterfaceState : BoundUserInterfaceState, IEquatable<ApcBoundInterfaceState>
     {
         public readonly bool MainBreaker;
-        public readonly bool HasAccess;
         public readonly int Power;
         public readonly ApcExternalPowerState ApcExternalPower;
         public readonly float Charge;
 
-        public ApcBoundInterfaceState(bool mainBreaker, bool hasAccess, int power, ApcExternalPowerState apcExternalPower, float charge)
+        public ApcBoundInterfaceState(bool mainBreaker, int power, ApcExternalPowerState apcExternalPower, float charge)
         {
             MainBreaker = mainBreaker;
-            HasAccess = hasAccess;
             Power = power;
             ApcExternalPower = apcExternalPower;
             Charge = charge;
@@ -197,7 +195,6 @@ namespace Content.Shared.APC
             if (ReferenceEquals(null, other)) return false;
             if (ReferenceEquals(this, other)) return true;
             return MainBreaker == other.MainBreaker &&
-                   HasAccess == other.HasAccess &&
                    Power == other.Power &&
                    ApcExternalPower == other.ApcExternalPower &&
                    MathHelper.CloseTo(Charge, other.Charge);
@@ -210,7 +207,7 @@ namespace Content.Shared.APC
 
         public override int GetHashCode()
         {
-            return HashCode.Combine(MainBreaker, HasAccess, Power, (int) ApcExternalPower, Charge);
+            return HashCode.Combine(MainBreaker, Power, (int) ApcExternalPower, Charge);
         }
     }
 
index 7c0537dec6e763662fb4907458f344c9e314c2f8..abf6931c5ee13f38a0c1fcc6ee22e46563d72488 100644 (file)
@@ -91,7 +91,6 @@
         type: ApcBoundUserInterface
   - type: ActivatableUI
     inHandsOnly: false
-    singleUser: true
     key: enum.ApcUiKey.Key
   - type: Construction
     graph: APC