Predicted lock popups (#16692)

This commit is contained in:
metalgearsloth
2023-05-22 23:18:51 +10:00
committed by GitHub
parent 20faa3169e
commit 3ed2650e8b
3 changed files with 13 additions and 17 deletions

View File

@@ -13,6 +13,7 @@ using JetBrains.Annotations;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.Network; using Robust.Shared.Network;
using Robust.Shared.Player;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using Robust.Shared.Utility; using Robust.Shared.Utility;
@@ -25,7 +26,6 @@ namespace Content.Shared.Lock;
public sealed class LockSystem : EntitySystem public sealed class LockSystem : EntitySystem
{ {
[Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly INetManager _net = 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!;
@@ -87,8 +87,9 @@ public sealed class LockSystem : EntitySystem
{ {
if (!component.Locked) if (!component.Locked)
return; return;
if (!args.Silent && _net.IsServer)
_sharedPopupSystem.PopupEntity(Loc.GetString("entity-storage-component-locked-message"), uid); if (!args.Silent)
_sharedPopupSystem.PopupClient(Loc.GetString("entity-storage-component-locked-message"), uid, args.User);
args.Cancelled = true; args.Cancelled = true;
} }
@@ -119,11 +120,8 @@ public sealed class LockSystem : EntitySystem
if (!HasUserAccess(uid, user, quiet: false)) if (!HasUserAccess(uid, user, quiet: false))
return false; return false;
if (_net.IsServer) _sharedPopupSystem.PopupClient(Loc.GetString("lock-comp-do-lock-success",
{
_sharedPopupSystem.PopupEntity(Loc.GetString("lock-comp-do-lock-success",
("entityName", Identity.Name(uid, EntityManager))), uid, user); ("entityName", Identity.Name(uid, EntityManager))), uid, user);
}
_audio.PlayPredicted(lockComp.LockSound, uid, user, AudioParams.Default.WithVolume(-5)); _audio.PlayPredicted(lockComp.LockSound, uid, user, AudioParams.Default.WithVolume(-5));
lockComp.Locked = true; lockComp.Locked = true;
@@ -146,14 +144,12 @@ public sealed class LockSystem : EntitySystem
if (!Resolve(uid, ref lockComp)) if (!Resolve(uid, ref lockComp))
return; return;
if (_net.IsServer)
{
if (user is { Valid: true }) if (user is { Valid: true })
{ {
_sharedPopupSystem.PopupEntity(Loc.GetString("lock-comp-do-unlock-success", _sharedPopupSystem.PopupClient(Loc.GetString("lock-comp-do-unlock-success",
("entityName", Identity.Name(uid, EntityManager))), uid, user.Value); ("entityName", Identity.Name(uid, EntityManager))), uid, user.Value);
} }
}
_audio.PlayPredicted(lockComp.UnlockSound, uid, user, AudioParams.Default.WithVolume(-5)); _audio.PlayPredicted(lockComp.UnlockSound, uid, user, AudioParams.Default.WithVolume(-5));
lockComp.Locked = false; lockComp.Locked = false;
@@ -210,8 +206,8 @@ public sealed class LockSystem : EntitySystem
if (_accessReader.IsAllowed(user, reader)) if (_accessReader.IsAllowed(user, reader))
return true; return true;
if (!quiet && _net.IsClient && _timing.IsFirstTimePredicted) if (!quiet && _timing.IsFirstTimePredicted)
_sharedPopupSystem.PopupEntity(Loc.GetString("lock-comp-has-user-access-fail"), uid, user); _sharedPopupSystem.PopupEntity(Loc.GetString("lock-comp-has-user-access-fail"), uid, Filter.Local(), true);
return false; return false;
} }

View File

@@ -159,7 +159,7 @@ public record struct InsertIntoEntityStorageAttemptEvent(bool Cancelled = false)
public record struct StoreMobInItemContainerAttemptEvent(bool Handled, bool Cancelled = false); public record struct StoreMobInItemContainerAttemptEvent(bool Handled, bool Cancelled = false);
[ByRefEvent] [ByRefEvent]
public record struct StorageOpenAttemptEvent(bool Silent, bool Cancelled = false); public record struct StorageOpenAttemptEvent(EntityUid User, bool Silent, bool Cancelled = false);
[ByRefEvent] [ByRefEvent]
public readonly record struct StorageBeforeOpenEvent; public readonly record struct StorageBeforeOpenEvent;

View File

@@ -340,7 +340,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
} }
} }
var ev = new StorageOpenAttemptEvent(silent); var ev = new StorageOpenAttemptEvent(user, silent);
RaiseLocalEvent(target, ref ev, true); RaiseLocalEvent(target, ref ev, true);
return !ev.Cancelled; return !ev.Cancelled;