]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
PlayerListControl fixes. (#25248)
authorPieter-Jan Briers <pieterjan.briers+git@gmail.com>
Tue, 20 Feb 2024 09:13:48 +0000 (10:13 +0100)
committerGitHub <noreply@github.com>
Tue, 20 Feb 2024 09:13:48 +0000 (10:13 +0100)
* 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.

Content.Client/Administration/UI/CustomControls/PlayerListControl.xaml.cs
Content.Shared/Administration/PlayerInfo.cs

index 41c3ac76f980484dcf8c69ebe9bb1726f545a435..2bef0d87019bcaba79c372feec43b170002bf13d 100644 (file)
@@ -29,6 +29,8 @@ namespace Content.Client.Administration.UI.CustomControls
         private IEntityManager _entManager;
         private IUserInterfaceManager _uiManager;
 
+        private PlayerInfo? _selectedPlayer;
+
         public PlayerListControl()
         {
             _entManager = IoCManager.Resolve<IEntityManager>();
@@ -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<PlayerInfo>? 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();
         }
 
index 74fd7e9dc06b3cfbe674c0699fb15741c53b0b3b..93f1aa0b39313766c43bfca97b3f23bd2f91efda 100644 (file)
@@ -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();
+        }
     }
 }