From: Pieter-Jan Briers Date: Tue, 20 Feb 2024 09:13:48 +0000 (+0100) Subject: PlayerListControl fixes. (#25248) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=74a31ac5f3316cc865ab9f39f39efff4e0b9e748;p=space-station-14.git PlayerListControl fixes. (#25248) * PlayerListControl fixes. Fix a button being selected by default always, which then can't be selected properly for real. This affected multiple admin UIs. This broke due to upstream RT changes but ButtonGroup was always kinda busted so whatever. Uses the new IsNoneSetAllowed to implement everything properly. Also make sure the selected player STAYS selected when filtering the list and stuff. Also this PlayerInfo record has been changed to only do equality on the User ID because otherwise it'd need to compare each field individually which would be weird. * Revert changes to ListContainer This change was made default in the engine, no longer necessary here. --- diff --git a/Content.Client/Administration/UI/CustomControls/PlayerListControl.xaml.cs b/Content.Client/Administration/UI/CustomControls/PlayerListControl.xaml.cs index 41c3ac76f9..2bef0d8701 100644 --- a/Content.Client/Administration/UI/CustomControls/PlayerListControl.xaml.cs +++ b/Content.Client/Administration/UI/CustomControls/PlayerListControl.xaml.cs @@ -29,6 +29,8 @@ namespace Content.Client.Administration.UI.CustomControls private IEntityManager _entManager; private IUserInterfaceManager _uiManager; + private PlayerInfo? _selectedPlayer; + public PlayerListControl() { _entManager = IoCManager.Resolve(); @@ -54,6 +56,7 @@ namespace Content.Client.Administration.UI.CustomControls return; OnSelectionChanged?.Invoke(selectedPlayer); + _selectedPlayer = selectedPlayer; // update label text. Only required if there is some override (e.g. unread bwoink count). if (OverrideText != null && args.Button.Children.FirstOrDefault()?.Children?.FirstOrDefault() is Label label) @@ -95,6 +98,8 @@ namespace Content.Client.Administration.UI.CustomControls _sortedPlayerList.Sort((a, b) => Comparison(a, b)); PlayerListContainer.PopulateList(_sortedPlayerList.Select(info => new PlayerListData(info)).ToList()); + if (_selectedPlayer != null) + PlayerListContainer.Select(new PlayerListData(_selectedPlayer)); } public void PopulateList(IReadOnlyList? players = null) @@ -102,6 +107,9 @@ namespace Content.Client.Administration.UI.CustomControls players ??= _adminSystem.PlayerList; _playerList = players.ToList(); + if (_selectedPlayer != null && !_playerList.Contains(_selectedPlayer)) + _selectedPlayer = null; + FilterList(); } diff --git a/Content.Shared/Administration/PlayerInfo.cs b/Content.Shared/Administration/PlayerInfo.cs index 74fd7e9dc0..93f1aa0b39 100644 --- a/Content.Shared/Administration/PlayerInfo.cs +++ b/Content.Shared/Administration/PlayerInfo.cs @@ -4,7 +4,7 @@ using Robust.Shared.Serialization; namespace Content.Shared.Administration { [Serializable, NetSerializable] - public record PlayerInfo( + public sealed record PlayerInfo( string Username, string CharacterName, string IdentityName, @@ -20,5 +20,15 @@ namespace Content.Shared.Administration public string PlaytimeString => _playtimeString ??= OverallPlaytime?.ToString("%d':'hh':'mm") ?? Loc.GetString("generic-unknown-title"); + + public bool Equals(PlayerInfo? other) + { + return other?.SessionId == SessionId; + } + + public override int GetHashCode() + { + return SessionId.GetHashCode(); + } } }