From ef849a0156e52d93c3a3c3b03f30858b33400292 Mon Sep 17 00:00:00 2001 From: Fildrance Date: Wed, 21 Feb 2024 17:47:23 +0300 Subject: [PATCH] fix: #25102 cryo pod now uses health-analyzer system to update body state in UI (#25109) * fix: cryo pod now uses health-analyzer system to update body state in UI * refactor: use EntityEventRefHandler instead ComponentEventRefHandler in CryoPodComponent subscribe on EntRemovedFromContainerMessage --------- Co-authored-by: pa.pecherskij --- .../Components/HealthAnalyzerComponent.cs | 2 +- Content.Server/Medical/CryoPodSystem.cs | 18 ++++++++++++++++++ .../Structures/Machines/Medical/cryo_pod.yml | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Content.Server/Medical/Components/HealthAnalyzerComponent.cs b/Content.Server/Medical/Components/HealthAnalyzerComponent.cs index 0002f275c5..a7fed0cae3 100644 --- a/Content.Server/Medical/Components/HealthAnalyzerComponent.cs +++ b/Content.Server/Medical/Components/HealthAnalyzerComponent.cs @@ -7,7 +7,7 @@ namespace Content.Server.Medical.Components; /// After scanning, retrieves the target Uid to use with its related UI. /// [RegisterComponent] -[Access(typeof(HealthAnalyzerSystem))] +[Access(typeof(HealthAnalyzerSystem), typeof(CryoPodSystem))] public sealed partial class HealthAnalyzerComponent : Component { /// diff --git a/Content.Server/Medical/CryoPodSystem.cs b/Content.Server/Medical/CryoPodSystem.cs index 25a47933a8..97ae72bd11 100644 --- a/Content.Server/Medical/CryoPodSystem.cs +++ b/Content.Server/Medical/CryoPodSystem.cs @@ -30,6 +30,7 @@ using Content.Shared.Medical.Cryogenics; using Content.Shared.MedicalScanner; using Content.Shared.Verbs; using Robust.Server.GameObjects; +using Robust.Shared.Containers; using Robust.Shared.Timing; using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem; @@ -71,6 +72,7 @@ public sealed partial class CryoPodSystem : SharedCryoPodSystem SubscribeLocalEvent(OnGasAnalyzed); SubscribeLocalEvent(OnActivateUIAttempt); SubscribeLocalEvent(OnActivateUI); + SubscribeLocalEvent(OnEjected); } public override void Update(float frameTime) @@ -187,6 +189,11 @@ public sealed partial class CryoPodSystem : SharedCryoPodSystem TryComp(entity.Comp.BodyContainer.ContainedEntity, out var temp); TryComp(entity.Comp.BodyContainer.ContainedEntity, out var bloodstream); + if (TryComp(entity, out var healthAnalyzer)) + { + healthAnalyzer.ScannedEntity = entity.Comp.BodyContainer.ContainedEntity; + } + _userInterfaceSystem.TrySendUiMessage( entity.Owner, HealthAnalyzerUiKey.Key, @@ -282,5 +289,16 @@ public sealed partial class CryoPodSystem : SharedCryoPodSystem args.GasMixtures = gasMixDict; } + private void OnEjected(Entity cryoPod, ref EntRemovedFromContainerMessage args) + { + if (TryComp(cryoPod.Owner, out var healthAnalyzer)) + { + healthAnalyzer.ScannedEntity = null; + } + + // if body is ejected - no need to display health-analyzer + _uiSystem.TryCloseAll(cryoPod.Owner, HealthAnalyzerUiKey.Key); + } + #endregion } diff --git a/Resources/Prototypes/Entities/Structures/Machines/Medical/cryo_pod.yml b/Resources/Prototypes/Entities/Structures/Machines/Medical/cryo_pod.yml index f150a3f63b..6ac969171e 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/Medical/cryo_pod.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/Medical/cryo_pod.yml @@ -85,6 +85,8 @@ whitelist: components: - FitsInDispenser + - type: HealthAnalyzer + scanDelay: 0 - type: UserInterface interfaces: - key: enum.HealthAnalyzerUiKey.Key -- 2.51.2