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>
[RegisterComponent, NetworkedComponent]
[Access(typeof(LockSystem))]
public sealed class LockComponent : Component
[AutoGenerateComponentState]
public sealed partial class LockComponent : Component
{
/// <summary>
/// Whether or not the lock is locked.
/// </summary>
[DataField("locked"), ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public bool Locked = true;
/// <summary>
/// Whether or not the lock is toggled by simply clicking.
/// </summary>
[DataField("lockOnClick"), ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public bool LockOnClick;
/// <summary>
@@ -39,25 +42,19 @@ public sealed class LockComponent : Component
/// Whether or not an emag disables it.
/// </summary>
[DataField("breakOnEmag")]
[AutoNetworkedField]
public bool BreakOnEmag = true;
}
[Serializable, NetSerializable]
public sealed class LockComponentState : ComponentState
{
public bool Locked;
public bool LockOnClick;
public LockComponentState(bool locked, bool lockOnClick)
{
Locked = locked;
LockOnClick = lockOnClick;
}
}
/// <summary>
/// Event raised on the lock when a toggle is attempted.
/// Can be cancelled to prevent it.
/// </summary>
[ByRefEvent]
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]
public readonly record struct LockToggledEvent(bool Locked);

View File

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