diff --git a/Content.Client/Anomaly/Ui/AnomalyScannerBoundUserInterface.cs b/Content.Client/Anomaly/Ui/AnomalyScannerBoundUserInterface.cs index 97bc0276e9..124057a701 100644 --- a/Content.Client/Anomaly/Ui/AnomalyScannerBoundUserInterface.cs +++ b/Content.Client/Anomaly/Ui/AnomalyScannerBoundUserInterface.cs @@ -20,6 +20,7 @@ public sealed class AnomalyScannerBoundUserInterface : BoundUserInterface _menu = new AnomalyScannerMenu(); _menu.OpenCentered(); + _menu.OnClose += Close; } protected override void UpdateState(BoundUserInterfaceState state) diff --git a/Content.Client/Atmos/UI/GasAnalyzerBoundUserInterface.cs b/Content.Client/Atmos/UI/GasAnalyzerBoundUserInterface.cs index f838a69fdf..3a5df3f9a8 100644 --- a/Content.Client/Atmos/UI/GasAnalyzerBoundUserInterface.cs +++ b/Content.Client/Atmos/UI/GasAnalyzerBoundUserInterface.cs @@ -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(); + _window.OnClose += Close; } protected override void ReceiveMessage(BoundUserInterfaceMessage message) @@ -29,15 +30,6 @@ namespace Content.Client.Atmos.UI _window.Populate(cast); } - /// - /// Closes UI and tells the server to disable the analyzer - /// - private void OnClose() - { - SendMessage(new GasAnalyzerDisableMessage()); - Close(); - } - protected override void Dispose(bool disposing) { base.Dispose(disposing); diff --git a/Content.Server/Atmos/EntitySystems/GasAnalyzerSystem.cs b/Content.Server/Atmos/EntitySystems/GasAnalyzerSystem.cs index c3f934549b..3cbe6575bf 100644 --- a/Content.Server/Atmos/EntitySystems/GasAnalyzerSystem.cs +++ b/Content.Server/Atmos/EntitySystems/GasAnalyzerSystem.cs @@ -33,9 +33,12 @@ public sealed class GasAnalyzerSystem : EntitySystem base.Initialize(); SubscribeLocalEvent(OnAfterInteract); - SubscribeLocalEvent(OnDisabledMessage); - SubscribeLocalEvent(OnDropped); - SubscribeLocalEvent(OnUseInHand); + + Subs.BuiEvents(GasAnalyzerUiKey.Key, subs => + { + subs.Event(OnBoundUIOpened); + subs.Event(OnBoundUIClosed); + }); } public override void Update(float frameTime) @@ -72,21 +75,6 @@ public sealed class GasAnalyzerSystem : EntitySystem args.Handled = true; } - /// - /// Activates the analyzer with no target, so it only scans the tile the user was on when activated - /// - private void OnUseInHand(Entity 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; - } - /// /// Handles analyzer activation logic /// @@ -104,16 +92,6 @@ public sealed class GasAnalyzerSystem : EntitySystem UpdateAnalyzer(entity.Owner, entity.Comp); } - /// - /// Close the UI, turn the analyzer off, and don't update when it's dropped - /// - private void OnDropped(Entity 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); - } - /// /// Closes the UI, sets the icon to off, and removes it from the update list /// @@ -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 /// /// Disables the analyzer when the user closes the UI /// - private void OnDisabledMessage(Entity entity, ref GasAnalyzerDisableMessage message) + private void OnBoundUIClosed(Entity entity, ref BoundUIClosedEvent args) { - DisableAnalyzer(entity); + if (HasComp(entity.Owner) + && !_userInterface.IsUiOpen(entity.Owner, args.UiKey)) + { + DisableAnalyzer(entity, args.Actor); + } + } + + /// + /// Enables the analyzer when the user opens the UI + /// + private void OnBoundUIOpened(Entity entity, ref BoundUIOpenedEvent args) + { + if (!HasComp(entity.Owner) + && _userInterface.IsUiOpen(entity.Owner, args.UiKey)) + { + ActivateAnalyzer(entity, args.Actor); + } } /// diff --git a/Content.Shared/Atmos/Components/GasAnalyzerComponent.cs b/Content.Shared/Atmos/Components/GasAnalyzerComponent.cs index c143e8cf85..115cb54892 100644 --- a/Content.Shared/Atmos/Components/GasAnalyzerComponent.cs +++ b/Content.Shared/Atmos/Components/GasAnalyzerComponent.cs @@ -94,12 +94,6 @@ public sealed partial class GasAnalyzerComponent : Component ("gasAmount", Amount)); } } - - [Serializable, NetSerializable] - public sealed class GasAnalyzerDisableMessage : BoundUserInterfaceMessage - { - - } } [Serializable, NetSerializable] diff --git a/Resources/Prototypes/Entities/Objects/Tools/cowtools.yml b/Resources/Prototypes/Entities/Objects/Tools/cowtools.yml index 2d584bd233..05816e817a 100644 --- a/Resources/Prototypes/Entities/Objects/Tools/cowtools.yml +++ b/Resources/Prototypes/Entities/Objects/Tools/cowtools.yml @@ -139,6 +139,11 @@ layers: - state: milkalyzer - type: GasAnalyzer + - type: ActivatableUI + inHandsOnly: true + singleUser: true + requireActiveHand: false + key: enum.GasAnalyzerUiKey.Key - type: UserInterface interfaces: enum.GasAnalyzerUiKey.Key: