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

View File

@@ -159,7 +159,7 @@ public record struct InsertIntoEntityStorageAttemptEvent(bool Cancelled = false)
public record struct StoreMobInItemContainerAttemptEvent(bool Handled, bool Cancelled = false);
[ByRefEvent]
public record struct StorageOpenAttemptEvent(bool Silent, bool Cancelled = false);
public record struct StorageOpenAttemptEvent(EntityUid User, bool Silent, bool Cancelled = false);
[ByRefEvent]
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);
return !ev.Cancelled;