]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix popup messages appearing when someone tries to open a door without a tool. (...
authornikthechampiongr <32041239+nikthechampiongr@users.noreply.github.com>
Fri, 27 Oct 2023 02:26:52 +0000 (02:26 +0000)
committerGitHub <noreply@github.com>
Fri, 27 Oct 2023 02:26:52 +0000 (22:26 -0400)
* The fixTM

* typo fix

* addressing review

Content.Server/Doors/Systems/AirlockSystem.cs
Content.Shared/Doors/Systems/SharedDoorBoltSystem.cs
Content.Shared/Prying/Components/PryingComponent.cs
Content.Shared/Prying/Systems/PryingSystem.cs

index ce517febf6dc0acee726df4a41e399c8bc048bcd..dd6f121353de22799bdaad5baa8951fb2b68372e 100644 (file)
@@ -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)
index a950fe6930aff39c954de43d949310985a77bd84..a9a52010fd6c9b6792e92dcc45675b0338a2bd23 100644 (file)
@@ -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)
index 4442481dce17e5b3ccc33132fa2753316d019950..7a7f304d8f83406ec677a3b896204358b02dcc62 100644 (file)
@@ -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;
 }
 
index 19e63de29e093c48790c6a79f7743766880482ec..5fd94c343855c4b77750a39bc7edfcc3ae739985 100644 (file)
@@ -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<PryUnpoweredComponent>(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)