Fix popup messages appearing when someone tries to open a door without a tool. (#21099)

* The fixTM

* typo fix

* addressing review
This commit is contained in:
nikthechampiongr
2023-10-27 02:26:52 +00:00
committed by GitHub
parent 7a0759f2c0
commit 8f181b4534
4 changed files with 38 additions and 18 deletions

View File

@@ -178,11 +178,16 @@ public sealed class AirlockSystem : SharedAirlockSystem
private void OnBeforePry(EntityUid uid, AirlockComponent component, ref BeforePryEvent args) private void OnBeforePry(EntityUid uid, AirlockComponent component, ref BeforePryEvent args)
{ {
if (this.IsPowered(uid, EntityManager) && !args.PryPowered) if (args.Cancelled)
{ return;
Popup.PopupEntity(Loc.GetString("airlock-component-cannot-pry-is-powered-message"), uid, args.User);
if (!this.IsPowered(uid, EntityManager) || args.PryPowered)
return;
args.Message = "airlock-component-cannot-pry-is-powered-message";
args.Cancelled = true; args.Cancelled = true;
}
} }
public bool CanChangeState(EntityUid uid, AirlockComponent component) public bool CanChangeState(EntityUid uid, AirlockComponent component)

View File

@@ -23,12 +23,16 @@ public abstract class SharedDoorBoltSystem : EntitySystem
private void OnDoorPry(EntityUid uid, DoorBoltComponent component, ref BeforePryEvent args) private void OnDoorPry(EntityUid uid, DoorBoltComponent component, ref BeforePryEvent args)
{ {
if (component.BoltsDown && !args.Force) if (args.Cancelled)
{ return;
Popup.PopupEntity(Loc.GetString("airlock-component-cannot-pry-is-bolted-message"), uid, args.User);
if (!component.BoltsDown || args.Force)
return;
args.Message = "airlock-component-cannot-pry-is-bolted-message";
args.Cancelled = true; args.Cancelled = true;
} }
}
private void OnBeforeDoorOpened(EntityUid uid, DoorBoltComponent component, BeforeDoorOpenedEvent args) private void OnBeforeDoorOpened(EntityUid uid, DoorBoltComponent component, BeforeDoorOpenedEvent args)
{ {

View File

@@ -51,6 +51,8 @@ public record struct BeforePryEvent(EntityUid User, bool PryPowered, bool Force)
public readonly bool Force = Force; public readonly bool Force = Force;
public string? Message;
public bool Cancelled; public bool Cancelled;
} }

View File

@@ -7,6 +7,7 @@ using Content.Shared.Database;
using Content.Shared.Doors.Components; using Content.Shared.Doors.Components;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Popups;
using PryUnpoweredComponent = Content.Shared.Prying.Components.PryUnpoweredComponent; using PryUnpoweredComponent = Content.Shared.Prying.Components.PryUnpoweredComponent;
namespace Content.Shared.Prying.Systems; namespace Content.Shared.Prying.Systems;
@@ -19,6 +20,7 @@ public sealed class PryingSystem : EntitySystem
[Dependency] private readonly ISharedAdminLogManager _adminLog = default!; [Dependency] private readonly ISharedAdminLogManager _adminLog = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!; [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly SharedAudioSystem _audioSystem = default!; [Dependency] private readonly SharedAudioSystem _audioSystem = default!;
[Dependency] private readonly SharedPopupSystem Popup = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -68,10 +70,12 @@ public sealed class PryingSystem : EntitySystem
if (!comp.Enabled) if (!comp.Enabled)
return false; 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 // 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 true;
} }
@@ -87,15 +91,16 @@ public sealed class PryingSystem : EntitySystem
{ {
id = null; 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 // 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 true;
return StartPry(target, user, null, 0.1f, out id); // hand-prying is much slower 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; BeforePryEvent canev;
@@ -106,15 +111,19 @@ public sealed class PryingSystem : EntitySystem
else else
{ {
if (!TryComp<PryUnpoweredComponent>(target, out _)) if (!TryComp<PryUnpoweredComponent>(target, out _))
{
message = null;
return false; return false;
}
canev = new BeforePryEvent(user, false, false); canev = new BeforePryEvent(user, false, false);
} }
RaiseLocalEvent(target, ref canev); RaiseLocalEvent(target, ref canev);
if (canev.Cancelled) message = canev.Message;
return false;
return true; return !canev.Cancelled;
} }
private bool StartPry(EntityUid target, EntityUid user, EntityUid? tool, float toolModifier, [NotNullWhen(true)] out DoAfterId? id) private bool StartPry(EntityUid target, EntityUid user, EntityUid? tool, float toolModifier, [NotNullWhen(true)] out DoAfterId? id)