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:
@@ -20,6 +20,7 @@ public sealed class AnomalyScannerBoundUserInterface : BoundUserInterface
|
||||
|
||||
_menu = new AnomalyScannerMenu();
|
||||
_menu.OpenCentered();
|
||||
_menu.OnClose += Close;
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -94,12 +94,6 @@ public sealed partial class GasAnalyzerComponent : Component
|
||||
("gasAmount", Amount));
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class GasAnalyzerDisableMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user