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)
{
if (this.IsPowered(uid, EntityManager) && !args.PryPowered)
{
Popup.PopupEntity(Loc.GetString("airlock-component-cannot-pry-is-powered-message"), uid, args.User);
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)

View File

@@ -23,12 +23,16 @@ 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);
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)
{

View 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;
}

View 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)