From 4b10cab617f9c72bf26d6d0f50644ff8377a8308 Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Tue, 24 Oct 2023 19:07:47 -0700 Subject: [PATCH] Change ListContainer to send null when selected is removed from the data (#20595) --- .../UI/CustomControls/PlayerListControl.xaml.cs | 6 +++--- Content.Client/Storage/StorageBoundUserInterface.cs | 4 ++-- Content.Client/UserInterface/Controls/ListContainer.cs | 8 +++++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Content.Client/Administration/UI/CustomControls/PlayerListControl.xaml.cs b/Content.Client/Administration/UI/CustomControls/PlayerListControl.xaml.cs index 6142e3a831..5fa28bf1ac 100644 --- a/Content.Client/Administration/UI/CustomControls/PlayerListControl.xaml.cs +++ b/Content.Client/Administration/UI/CustomControls/PlayerListControl.xaml.cs @@ -22,7 +22,7 @@ namespace Content.Client.Administration.UI.CustomControls private List _playerList = new(); private readonly List _sortedPlayerList = new(); - public event Action? OnSelectionChanged; + public event Action? OnSelectionChanged; public IReadOnlyList PlayerInfo => _playerList; public Func? 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) { diff --git a/Content.Client/Storage/StorageBoundUserInterface.cs b/Content.Client/Storage/StorageBoundUserInterface.cs index 1842417a6e..9a3340e5b0 100644 --- a/Content.Client/Storage/StorageBoundUserInterface.cs +++ b/Content.Client/Storage/StorageBoundUserInterface.cs @@ -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) diff --git a/Content.Client/UserInterface/Controls/ListContainer.cs b/Content.Client/UserInterface/Controls/ListContainer.cs index d1bb103926..c66ef33d3f 100644 --- a/Content.Client/UserInterface/Controls/ListContainer.cs +++ b/Content.Client/UserInterface/Controls/ListContainer.cs @@ -22,7 +22,7 @@ public sealed class ListContainer : Control } public bool Toggle { get; set; } public Action? GenerateItem; - public Action? ItemPressed; + public Action? ItemPressed; public IReadOnlyList 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()