]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix gas analyzer and anom scanner wrong state (#38285)
authorthemias <89101928+themias@users.noreply.github.com>
Thu, 12 Jun 2025 21:16:07 +0000 (17:16 -0400)
committerGitHub <noreply@github.com>
Thu, 12 Jun 2025 21:16:07 +0000 (14:16 -0700)
* Fix gas analyzer and anomaly scanner UI activation issue

* save

* fix comment

* milkalyzer

Content.Client/Anomaly/Ui/AnomalyScannerBoundUserInterface.cs
Content.Client/Atmos/UI/GasAnalyzerBoundUserInterface.cs
Content.Server/Atmos/EntitySystems/GasAnalyzerSystem.cs
Content.Shared/Atmos/Components/GasAnalyzerComponent.cs
Resources/Prototypes/Entities/Objects/Tools/cowtools.yml

index 97bc0276e94ccc5e161dc1c193485c990b010145..124057a701e7f48115774450bf715337f7963a52 100644 (file)
@@ -20,6 +20,7 @@ public sealed class AnomalyScannerBoundUserInterface : BoundUserInterface
 
         _menu = new AnomalyScannerMenu();
         _menu.OpenCentered();
+        _menu.OnClose += Close;
     }
 
     protected override void UpdateState(BoundUserInterfaceState state)
index f838a69fdf11cca73a00edd99721021afef2c4cc..3a5df3f9a88e3c50619b12e0eac2de3c0e5e380c 100644 (file)
@@ -1,4 +1,4 @@
-using Robust.Client.GameObjects;
+using Robust.Client.GameObjects;
 using Robust.Client.UserInterface;
 using static Content.Shared.Atmos.Components.GasAnalyzerComponent;
 
@@ -18,6 +18,7 @@ namespace Content.Client.Atmos.UI
             base.Open();
 
             _window = this.CreateWindowCenteredLeft<GasAnalyzerWindow>();
+            _window.OnClose += Close;
         }
 
         protected override void ReceiveMessage(BoundUserInterfaceMessage message)
@@ -29,15 +30,6 @@ namespace Content.Client.Atmos.UI
             _window.Populate(cast);
         }
 
-        /// <summary>
-        /// Closes UI and tells the server to disable the analyzer
-        /// </summary>
-        private void OnClose()
-        {
-            SendMessage(new GasAnalyzerDisableMessage());
-            Close();
-        }
-
         protected override void Dispose(bool disposing)
         {
             base.Dispose(disposing);
index c3f934549b0ebd4c0efd639d17ae0a4e07806afd..3cbe6575bf2c2e39428d52768bd55a99c2863a37 100644 (file)
@@ -33,9 +33,12 @@ public sealed class GasAnalyzerSystem : EntitySystem
         base.Initialize();
 
         SubscribeLocalEvent<GasAnalyzerComponent, AfterInteractEvent>(OnAfterInteract);
-        SubscribeLocalEvent<GasAnalyzerComponent, GasAnalyzerDisableMessage>(OnDisabledMessage);
-        SubscribeLocalEvent<GasAnalyzerComponent, DroppedEvent>(OnDropped);
-        SubscribeLocalEvent<GasAnalyzerComponent, UseInHandEvent>(OnUseInHand);
+
+        Subs.BuiEvents<GasAnalyzerComponent>(GasAnalyzerUiKey.Key, subs =>
+        {
+            subs.Event<BoundUIOpenedEvent>(OnBoundUIOpened);
+            subs.Event<BoundUIClosedEvent>(OnBoundUIClosed);
+        });
     }
 
     public override void Update(float frameTime)
@@ -72,21 +75,6 @@ public sealed class GasAnalyzerSystem : EntitySystem
         args.Handled = true;
     }
 
-    /// <summary>
-    /// Activates the analyzer with no target, so it only scans the tile the user was on when activated
-    /// </summary>
-    private void OnUseInHand(Entity<GasAnalyzerComponent> entity, ref UseInHandEvent args)
-    {
-        // Not checking for Handled because ActivatableUISystem already marks it as such.
-
-        if (!entity.Comp.Enabled)
-            ActivateAnalyzer(entity, args.User);
-        else
-            DisableAnalyzer(entity, args.User);
-
-        args.Handled = true;
-    }
-
     /// <summary>
     /// Handles analyzer activation logic
     /// </summary>
@@ -104,16 +92,6 @@ public sealed class GasAnalyzerSystem : EntitySystem
         UpdateAnalyzer(entity.Owner, entity.Comp);
     }
 
-    /// <summary>
-    /// Close the UI, turn the analyzer off, and don't update when it's dropped
-    /// </summary>
-    private void OnDropped(Entity<GasAnalyzerComponent> entity, ref DroppedEvent args)
-    {
-        if (args.User is var userId && entity.Comp.Enabled)
-            _popup.PopupEntity(Loc.GetString("gas-analyzer-shutoff"), userId, userId);
-        DisableAnalyzer(entity, args.User);
-    }
-
     /// <summary>
     /// Closes the UI, sets the icon to off, and removes it from the update list
     /// </summary>
@@ -121,6 +99,9 @@ public sealed class GasAnalyzerSystem : EntitySystem
     {
         _userInterface.CloseUi(entity.Owner, GasAnalyzerUiKey.Key, user);
 
+        if (user.HasValue && entity.Comp.Enabled)
+            _popup.PopupEntity(Loc.GetString("gas-analyzer-shutoff"), user.Value, user.Value);
+
         entity.Comp.Enabled = false;
         Dirty(entity);
         _appearance.SetData(entity.Owner, GasAnalyzerVisuals.Enabled, entity.Comp.Enabled);
@@ -130,9 +111,25 @@ public sealed class GasAnalyzerSystem : EntitySystem
     /// <summary>
     /// Disables the analyzer when the user closes the UI
     /// </summary>
-    private void OnDisabledMessage(Entity<GasAnalyzerComponent> entity, ref GasAnalyzerDisableMessage message)
+    private void OnBoundUIClosed(Entity<GasAnalyzerComponent> entity, ref BoundUIClosedEvent args)
     {
-        DisableAnalyzer(entity);
+        if (HasComp<ActiveGasAnalyzerComponent>(entity.Owner)
+            && !_userInterface.IsUiOpen(entity.Owner, args.UiKey))
+        {
+            DisableAnalyzer(entity, args.Actor);
+        }
+    }
+
+    /// <summary>
+    /// Enables the analyzer when the user opens the UI
+    /// </summary>
+    private void OnBoundUIOpened(Entity<GasAnalyzerComponent> entity, ref BoundUIOpenedEvent args)
+    {
+        if (!HasComp<ActiveGasAnalyzerComponent>(entity.Owner)
+            && _userInterface.IsUiOpen(entity.Owner, args.UiKey))
+        {
+            ActivateAnalyzer(entity, args.Actor);
+        }
     }
 
     /// <summary>
index c143e8cf85130557f7b6429cdefb1193b0d778f3..115cb548929bd5c6aed373e91c1152c71bf06262 100644 (file)
@@ -94,12 +94,6 @@ public sealed partial class GasAnalyzerComponent : Component
                  ("gasAmount", Amount));
         }
     }
-
-    [Serializable, NetSerializable]
-    public sealed class GasAnalyzerDisableMessage : BoundUserInterfaceMessage
-    {
-
-    }
 }
 
 [Serializable, NetSerializable]
index 2d584bd233c9e821b67fb41beca9a76217ba31c9..05816e817a3aaf7b8046f7e678111ce494faca32 100644 (file)
     layers:
     - state: milkalyzer
   - type: GasAnalyzer
+  - type: ActivatableUI
+    inHandsOnly: true
+    singleUser: true
+    requireActiveHand: false
+    key: enum.GasAnalyzerUiKey.Key
   - type: UserInterface
     interfaces:
       enum.GasAnalyzerUiKey.Key: