]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make storage UI close upon being locked (#27810)
authorSphiral <145869023+SphiraI@users.noreply.github.com>
Thu, 9 May 2024 06:50:50 +0000 (01:50 -0500)
committerGitHub <noreply@github.com>
Thu, 9 May 2024 06:50:50 +0000 (23:50 -0700)
* make storage close on lock

* formatting and comments

* Update Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs

Co-authored-by: ShadowCommander <shadowjjt@gmail.com>
* Apply suggestions from code review

Co-authored-by: ShadowCommander <shadowjjt@gmail.com>
* Swap to foreach instead of for

Co-authored-by: Kara <lunarautomaton6@gmail.com>
---------

Co-authored-by: ShadowCommander <shadowjjt@gmail.com>
Co-authored-by: Kara <lunarautomaton6@gmail.com>
Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs

index 771513a0a8b1e7515d26fca9d4d9c6acaae96758..ba840cd67adb009b0bc5dbce1267c15ed46df731 100644 (file)
@@ -109,6 +109,7 @@ public abstract class SharedStorageSystem : EntitySystem
         SubscribeLocalEvent<StorageComponent, AfterInteractEvent>(AfterInteract);
         SubscribeLocalEvent<StorageComponent, DestructionEventArgs>(OnDestroy);
         SubscribeLocalEvent<StorageComponent, BoundUIOpenedEvent>(OnBoundUIOpen);
+        SubscribeLocalEvent<StorageComponent, LockToggledEvent>(OnLockToggled);
         SubscribeLocalEvent<MetaDataComponent, StackCountChangedEvent>(OnStackCountChanged);
 
         SubscribeLocalEvent<StorageComponent, EntInsertedIntoContainerMessage>(OnEntInserted);
@@ -1401,6 +1402,25 @@ public abstract class SharedStorageSystem : EntitySystem
         return _nextSmallest[item.Size];
     }
 
+    /// <summary>
+    /// Checks if a storage's UI is open by anyone when locked, and closes it unless they're an admin.
+    /// </summary>
+    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) &&