Make "no access" popups appear again. (#19034)

This commit is contained in:
Nemanja
2023-08-12 21:21:06 -04:00
committed by GitHub
parent d55fae0732
commit 175660c800
2 changed files with 14 additions and 37 deletions

View File

@@ -9,18 +9,21 @@ namespace Content.Shared.Lock;
/// </summary> /// </summary>
[RegisterComponent, NetworkedComponent] [RegisterComponent, NetworkedComponent]
[Access(typeof(LockSystem))] [Access(typeof(LockSystem))]
public sealed class LockComponent : Component [AutoGenerateComponentState]
public sealed partial class LockComponent : Component
{ {
/// <summary> /// <summary>
/// Whether or not the lock is locked. /// Whether or not the lock is locked.
/// </summary> /// </summary>
[DataField("locked"), ViewVariables(VVAccess.ReadWrite)] [DataField("locked"), ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public bool Locked = true; public bool Locked = true;
/// <summary> /// <summary>
/// Whether or not the lock is toggled by simply clicking. /// Whether or not the lock is toggled by simply clicking.
/// </summary> /// </summary>
[DataField("lockOnClick"), ViewVariables(VVAccess.ReadWrite)] [DataField("lockOnClick"), ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public bool LockOnClick; public bool LockOnClick;
/// <summary> /// <summary>
@@ -39,25 +42,19 @@ public sealed class LockComponent : Component
/// Whether or not an emag disables it. /// Whether or not an emag disables it.
/// </summary> /// </summary>
[DataField("breakOnEmag")] [DataField("breakOnEmag")]
[AutoNetworkedField]
public bool BreakOnEmag = true; public bool BreakOnEmag = true;
} }
[Serializable, NetSerializable] /// <summary>
public sealed class LockComponentState : ComponentState /// Event raised on the lock when a toggle is attempted.
{ /// Can be cancelled to prevent it.
public bool Locked; /// </summary>
public bool LockOnClick;
public LockComponentState(bool locked, bool lockOnClick)
{
Locked = locked;
LockOnClick = lockOnClick;
}
}
[ByRefEvent] [ByRefEvent]
public record struct LockToggleAttemptEvent(EntityUid User, bool Silent = false, bool Cancelled = false); public record struct LockToggleAttemptEvent(EntityUid User, bool Silent = false, bool Cancelled = false);
/// <summary>
/// Event raised on a lock after it has been toggled.
/// </summary>
[ByRefEvent] [ByRefEvent]
public readonly record struct LockToggledEvent(bool Locked); public readonly record struct LockToggledEvent(bool Locked);

View File

@@ -11,10 +11,6 @@ using Content.Shared.Storage.Components;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Network;
using Robust.Shared.Player;
using Robust.Shared.Timing;
using Robust.Shared.Utility; using Robust.Shared.Utility;
namespace Content.Shared.Lock; namespace Content.Shared.Lock;
@@ -25,7 +21,6 @@ namespace Content.Shared.Lock;
[UsedImplicitly] [UsedImplicitly]
public sealed class LockSystem : EntitySystem public sealed class LockSystem : EntitySystem
{ {
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly AccessReaderSystem _accessReader = default!; [Dependency] private readonly AccessReaderSystem _accessReader = default!;
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!; [Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly SharedAudioSystem _audio = default!;
@@ -36,8 +31,6 @@ public sealed class LockSystem : EntitySystem
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<LockComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<LockComponent, ComponentHandleState>(OnHandleState);
SubscribeLocalEvent<LockComponent, ComponentStartup>(OnStartup); SubscribeLocalEvent<LockComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<LockComponent, ActivateInWorldEvent>(OnActivated); SubscribeLocalEvent<LockComponent, ActivateInWorldEvent>(OnActivated);
SubscribeLocalEvent<LockComponent, StorageOpenAttemptEvent>(OnStorageOpenAttempt); SubscribeLocalEvent<LockComponent, StorageOpenAttemptEvent>(OnStorageOpenAttempt);
@@ -46,19 +39,6 @@ public sealed class LockSystem : EntitySystem
SubscribeLocalEvent<LockComponent, GotEmaggedEvent>(OnEmagged); SubscribeLocalEvent<LockComponent, GotEmaggedEvent>(OnEmagged);
} }
private void OnGetState(EntityUid uid, LockComponent component, ref ComponentGetState args)
{
args.State = new LockComponentState(component.Locked, component.LockOnClick);
}
private void OnHandleState(EntityUid uid, LockComponent component, ref ComponentHandleState args)
{
if (args.Current is not LockComponentState state)
return;
component.Locked = state.Locked;
component.LockOnClick = state.LockOnClick;
}
private void OnStartup(EntityUid uid, LockComponent lockComp, ComponentStartup args) private void OnStartup(EntityUid uid, LockComponent lockComp, ComponentStartup args)
{ {
_appearanceSystem.SetData(uid, StorageVisuals.CanLock, true); _appearanceSystem.SetData(uid, StorageVisuals.CanLock, true);
@@ -206,8 +186,8 @@ public sealed class LockSystem : EntitySystem
if (_accessReader.IsAllowed(user, reader)) if (_accessReader.IsAllowed(user, reader))
return true; return true;
if (!quiet && _timing.IsFirstTimePredicted) if (!quiet)
_sharedPopupSystem.PopupEntity(Loc.GetString("lock-comp-has-user-access-fail"), uid, Filter.Local(), true); _sharedPopupSystem.PopupClient(Loc.GetString("lock-comp-has-user-access-fail"), uid, user);
return false; return false;
} }