From 8f181b45341b73cda7838b8e323b1d2dae52440a Mon Sep 17 00:00:00 2001 From: nikthechampiongr <32041239+nikthechampiongr@users.noreply.github.com> Date: Fri, 27 Oct 2023 02:26:52 +0000 Subject: [PATCH] Fix popup messages appearing when someone tries to open a door without a tool. (#21099) * The fixTM * typo fix * addressing review --- Content.Server/Doors/Systems/AirlockSystem.cs | 15 +++++++---- .../Doors/Systems/SharedDoorBoltSystem.cs | 14 +++++++---- .../Prying/Components/PryingComponent.cs | 2 ++ Content.Shared/Prying/Systems/PryingSystem.cs | 25 +++++++++++++------ 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/Content.Server/Doors/Systems/AirlockSystem.cs b/Content.Server/Doors/Systems/AirlockSystem.cs index ce517febf6..dd6f121353 100644 --- a/Content.Server/Doors/Systems/AirlockSystem.cs +++ b/Content.Server/Doors/Systems/AirlockSystem.cs @@ -178,11 +178,16 @@ public sealed class AirlockSystem : SharedAirlockSystem private void OnBeforePry(EntityUid uid, AirlockComponent component, ref BeforePryEvent args) { - if (this.IsPowered(uid, EntityManager) && !args.PryPowered) - { - Popup.PopupEntity(Loc.GetString("airlock-component-cannot-pry-is-powered-message"), uid, args.User); - args.Cancelled = true; - } + if (args.Cancelled) + return; + + if (!this.IsPowered(uid, EntityManager) || args.PryPowered) + return; + + args.Message = "airlock-component-cannot-pry-is-powered-message"; + + args.Cancelled = true; + } public bool CanChangeState(EntityUid uid, AirlockComponent component) diff --git a/Content.Shared/Doors/Systems/SharedDoorBoltSystem.cs b/Content.Shared/Doors/Systems/SharedDoorBoltSystem.cs index a950fe6930..a9a52010fd 100644 --- a/Content.Shared/Doors/Systems/SharedDoorBoltSystem.cs +++ b/Content.Shared/Doors/Systems/SharedDoorBoltSystem.cs @@ -23,11 +23,15 @@ public abstract class SharedDoorBoltSystem : EntitySystem private void OnDoorPry(EntityUid uid, DoorBoltComponent component, ref BeforePryEvent args) { - if (component.BoltsDown && !args.Force) - { - Popup.PopupEntity(Loc.GetString("airlock-component-cannot-pry-is-bolted-message"), uid, args.User); - args.Cancelled = true; - } + if (args.Cancelled) + return; + + if (!component.BoltsDown || args.Force) + return; + + args.Message = "airlock-component-cannot-pry-is-bolted-message"; + + args.Cancelled = true; } private void OnBeforeDoorOpened(EntityUid uid, DoorBoltComponent component, BeforeDoorOpenedEvent args) diff --git a/Content.Shared/Prying/Components/PryingComponent.cs b/Content.Shared/Prying/Components/PryingComponent.cs index 4442481dce..7a7f304d8f 100644 --- a/Content.Shared/Prying/Components/PryingComponent.cs +++ b/Content.Shared/Prying/Components/PryingComponent.cs @@ -51,6 +51,8 @@ public record struct BeforePryEvent(EntityUid User, bool PryPowered, bool Force) public readonly bool Force = Force; + public string? Message; + public bool Cancelled; } diff --git a/Content.Shared/Prying/Systems/PryingSystem.cs b/Content.Shared/Prying/Systems/PryingSystem.cs index 19e63de29e..5fd94c3438 100644 --- a/Content.Shared/Prying/Systems/PryingSystem.cs +++ b/Content.Shared/Prying/Systems/PryingSystem.cs @@ -7,6 +7,7 @@ using Content.Shared.Database; using Content.Shared.Doors.Components; using System.Diagnostics.CodeAnalysis; using Content.Shared.Interaction; +using Content.Shared.Popups; using PryUnpoweredComponent = Content.Shared.Prying.Components.PryUnpoweredComponent; namespace Content.Shared.Prying.Systems; @@ -19,6 +20,7 @@ public sealed class PryingSystem : EntitySystem [Dependency] private readonly ISharedAdminLogManager _adminLog = default!; [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!; [Dependency] private readonly SharedAudioSystem _audioSystem = default!; + [Dependency] private readonly SharedPopupSystem Popup = default!; public override void Initialize() { @@ -68,10 +70,12 @@ public sealed class PryingSystem : EntitySystem if (!comp.Enabled) return false; - if (!CanPry(target, user, comp)) + if (!CanPry(target, user, out var message, comp)) { + if (message != null) + Popup.PopupEntity(Loc.GetString(message), target, user); // If we have reached this point we want the event that caused this - // to be marked as handled as a popup would be generated on failure. + // to be marked as handled. return true; } @@ -87,15 +91,16 @@ public sealed class PryingSystem : EntitySystem { id = null; - if (!CanPry(target, user)) + // We don't care about displaying a message if no tool was used. + if (!CanPry(target, user, out _)) // If we have reached this point we want the event that caused this - // to be marked as handled as a popup would be generated on failure. + // to be marked as handled. return true; return StartPry(target, user, null, 0.1f, out id); // hand-prying is much slower } - private bool CanPry(EntityUid target, EntityUid user, PryingComponent? comp = null) + private bool CanPry(EntityUid target, EntityUid user, out string? message, PryingComponent? comp = null) { BeforePryEvent canev; @@ -106,15 +111,19 @@ public sealed class PryingSystem : EntitySystem else { if (!TryComp(target, out _)) + { + message = null; return false; + } + canev = new BeforePryEvent(user, false, false); } RaiseLocalEvent(target, ref canev); - if (canev.Cancelled) - return false; - return true; + message = canev.Message; + + return !canev.Cancelled; } private bool StartPry(EntityUid target, EntityUid user, EntityUid? tool, float toolModifier, [NotNullWhen(true)] out DoAfterId? id)