From de729f9037280791262cac9135d94524fec4814f Mon Sep 17 00:00:00 2001 From: Sphiral <145869023+SphiraI@users.noreply.github.com> Date: Thu, 9 May 2024 01:50:50 -0500 Subject: [PATCH] Make storage UI close upon being locked (#27810) * make storage close on lock * formatting and comments * Update Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs Co-authored-by: ShadowCommander * Apply suggestions from code review Co-authored-by: ShadowCommander * Swap to foreach instead of for Co-authored-by: Kara --------- Co-authored-by: ShadowCommander Co-authored-by: Kara --- .../EntitySystems/SharedStorageSystem.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs index 771513a0a8..ba840cd67a 100644 --- a/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs +++ b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs @@ -109,6 +109,7 @@ public abstract class SharedStorageSystem : EntitySystem SubscribeLocalEvent(AfterInteract); SubscribeLocalEvent(OnDestroy); SubscribeLocalEvent(OnBoundUIOpen); + SubscribeLocalEvent(OnLockToggled); SubscribeLocalEvent(OnStackCountChanged); SubscribeLocalEvent(OnEntInserted); @@ -1401,6 +1402,25 @@ public abstract class SharedStorageSystem : EntitySystem return _nextSmallest[item.Size]; } + /// + /// Checks if a storage's UI is open by anyone when locked, and closes it unless they're an admin. + /// + private void OnLockToggled(EntityUid uid, StorageComponent component, ref LockToggledEvent args) + { + if (!args.Locked) + return; + + // Gets everyone looking at the UI + foreach (var actor in _ui.GetActors(uid, StorageComponent.StorageUiKey.Key)) + { + if (_admin.HasAdminFlag(actor, AdminFlags.Admin)) + continue; + + // And closes it unless they're an admin + _ui.CloseUi(uid, StorageComponent.StorageUiKey.Key, actor); + } + } + private void OnStackCountChanged(EntityUid uid, MetaDataComponent component, StackCountChangedEvent args) { if (_containerSystem.TryGetContainingContainer(uid, out var container, component) && -- 2.51.2