]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Change ListContainer to send null when selected is removed from the data (#20595)
authorShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
Wed, 25 Oct 2023 02:07:47 +0000 (19:07 -0700)
committerGitHub <noreply@github.com>
Wed, 25 Oct 2023 02:07:47 +0000 (22:07 -0400)
Content.Client/Administration/UI/CustomControls/PlayerListControl.xaml.cs
Content.Client/Storage/StorageBoundUserInterface.cs
Content.Client/UserInterface/Controls/ListContainer.cs

index 6142e3a83181a34d8d5d1898aaafb327cacf5b96..5fa28bf1ac751b6890780ef5ac133411126c0870 100644 (file)
@@ -22,7 +22,7 @@ namespace Content.Client.Administration.UI.CustomControls
         private List<PlayerInfo> _playerList = new();
         private readonly List<PlayerInfo> _sortedPlayerList = new();
 
-        public event Action<PlayerInfo?>? OnSelectionChanged;
+        public event Action<PlayerInfo>? OnSelectionChanged;
         public IReadOnlyList<PlayerInfo> PlayerInfo => _playerList;
 
         public Func<PlayerInfo, string, string>? OverrideText;
@@ -46,9 +46,9 @@ namespace Content.Client.Administration.UI.CustomControls
             BackgroundPanel.PanelOverride = new StyleBoxFlat {BackgroundColor = new Color(32, 32, 40)};
         }
 
-        private void PlayerListItemPressed(BaseButton.ButtonEventArgs args, ListData data)
+        private void PlayerListItemPressed(BaseButton.ButtonEventArgs? args, ListData? data)
         {
-            if (data is not PlayerListData {Info: var selectedPlayer})
+            if (args == null || data is not PlayerListData {Info: var selectedPlayer})
                 return;
             if (args.Event.Function == EngineKeyFunctions.UIClick)
             {
index 1842417a6e212a1b3ed20175652a72f36d9ffd42..9a3340e5b0ed5242fbc0604b7b541a759cabf038 100644 (file)
@@ -61,9 +61,9 @@ namespace Content.Client.Storage
             _window?.BuildEntityList(uid, component);
         }
 
-        public void InteractWithItem(BaseButton.ButtonEventArgs args, ListData cData)
+        public void InteractWithItem(BaseButton.ButtonEventArgs? args, ListData? cData)
         {
-            if (cData is not EntityListData { Uid: var entity })
+            if (args == null || cData is not EntityListData { Uid: var entity })
                 return;
 
             if (args.Event.Function == EngineKeyFunctions.UIClick)
index d1bb103926f9ebcd5abb38bc5394f5d9c4a05a29..c66ef33d3f879e59e2261d0fe6284418def7fda0 100644 (file)
@@ -22,7 +22,7 @@ public sealed class ListContainer : Control
     }
     public bool Toggle { get; set; }
     public Action<ListData, ListContainerButton>? GenerateItem;
-    public Action<BaseButton.ButtonEventArgs, ListData>? ItemPressed;
+    public Action<BaseButton.ButtonEventArgs?, ListData?>? ItemPressed;
     public IReadOnlyList<ListData> Data => _data;
 
     private const int DefaultSeparation = 3;
@@ -92,6 +92,12 @@ public sealed class ListContainer : Control
         _data = data.ToList();
         _updateChildren = true;
         InvalidateArrange();
+
+        if (_selected != null && !data.Contains(_selected))
+        {
+            _selected = null;
+            ItemPressed?.Invoke(null, null);
+        }
     }
 
     public void DirtyList()