Change ListContainer to send null when selected is removed from the data (#20595)
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user