Fix gas analyzer and anom scanner wrong state (#38285)

* Fix gas analyzer and anomaly scanner UI activation issue

* save

* fix comment

* milkalyzer
This commit is contained in:
themias
2025-06-12 17:16:07 -04:00
committed by GitHub
parent 570accb102
commit 19271e6bc9
5 changed files with 35 additions and 46 deletions

View File

@@ -20,6 +20,7 @@ public sealed class AnomalyScannerBoundUserInterface : BoundUserInterface
_menu = new AnomalyScannerMenu(); _menu = new AnomalyScannerMenu();
_menu.OpenCentered(); _menu.OpenCentered();
_menu.OnClose += Close;
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)

View File

@@ -1,4 +1,4 @@
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using static Content.Shared.Atmos.Components.GasAnalyzerComponent; using static Content.Shared.Atmos.Components.GasAnalyzerComponent;
@@ -18,6 +18,7 @@ namespace Content.Client.Atmos.UI
base.Open(); base.Open();
_window = this.CreateWindowCenteredLeft<GasAnalyzerWindow>(); _window = this.CreateWindowCenteredLeft<GasAnalyzerWindow>();
_window.OnClose += Close;
} }
protected override void ReceiveMessage(BoundUserInterfaceMessage message) protected override void ReceiveMessage(BoundUserInterfaceMessage message)
@@ -29,15 +30,6 @@ namespace Content.Client.Atmos.UI
_window.Populate(cast); _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) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); base.Dispose(disposing);

View File

@@ -33,9 +33,12 @@ public sealed class GasAnalyzerSystem : EntitySystem
base.Initialize(); base.Initialize();
SubscribeLocalEvent<GasAnalyzerComponent, AfterInteractEvent>(OnAfterInteract); SubscribeLocalEvent<GasAnalyzerComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<GasAnalyzerComponent, GasAnalyzerDisableMessage>(OnDisabledMessage);
SubscribeLocalEvent<GasAnalyzerComponent, DroppedEvent>(OnDropped); Subs.BuiEvents<GasAnalyzerComponent>(GasAnalyzerUiKey.Key, subs =>
SubscribeLocalEvent<GasAnalyzerComponent, UseInHandEvent>(OnUseInHand); {
subs.Event<BoundUIOpenedEvent>(OnBoundUIOpened);
subs.Event<BoundUIClosedEvent>(OnBoundUIClosed);
});
} }
public override void Update(float frameTime) public override void Update(float frameTime)
@@ -72,21 +75,6 @@ public sealed class GasAnalyzerSystem : EntitySystem
args.Handled = true; 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> /// <summary>
/// Handles analyzer activation logic /// Handles analyzer activation logic
/// </summary> /// </summary>
@@ -104,16 +92,6 @@ public sealed class GasAnalyzerSystem : EntitySystem
UpdateAnalyzer(entity.Owner, entity.Comp); 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> /// <summary>
/// Closes the UI, sets the icon to off, and removes it from the update list /// Closes the UI, sets the icon to off, and removes it from the update list
/// </summary> /// </summary>
@@ -121,6 +99,9 @@ public sealed class GasAnalyzerSystem : EntitySystem
{ {
_userInterface.CloseUi(entity.Owner, GasAnalyzerUiKey.Key, user); _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; entity.Comp.Enabled = false;
Dirty(entity); Dirty(entity);
_appearance.SetData(entity.Owner, GasAnalyzerVisuals.Enabled, entity.Comp.Enabled); _appearance.SetData(entity.Owner, GasAnalyzerVisuals.Enabled, entity.Comp.Enabled);
@@ -130,9 +111,25 @@ public sealed class GasAnalyzerSystem : EntitySystem
/// <summary> /// <summary>
/// Disables the analyzer when the user closes the UI /// Disables the analyzer when the user closes the UI
/// </summary> /// </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> /// <summary>

View File

@@ -94,12 +94,6 @@ public sealed partial class GasAnalyzerComponent : Component
("gasAmount", Amount)); ("gasAmount", Amount));
} }
} }
[Serializable, NetSerializable]
public sealed class GasAnalyzerDisableMessage : BoundUserInterfaceMessage
{
}
} }
[Serializable, NetSerializable] [Serializable, NetSerializable]

View File

@@ -139,6 +139,11 @@
layers: layers:
- state: milkalyzer - state: milkalyzer
- type: GasAnalyzer - type: GasAnalyzer
- type: ActivatableUI
inHandsOnly: true
singleUser: true
requireActiveHand: false
key: enum.GasAnalyzerUiKey.Key
- type: UserInterface - type: UserInterface
interfaces: interfaces:
enum.GasAnalyzerUiKey.Key: enum.GasAnalyzerUiKey.Key: