]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Alphabetically sorted guidebook entries (#24963)
authorSk1tch <ben.peter.smith@gmail.com>
Thu, 8 Feb 2024 23:23:34 +0000 (15:23 -0800)
committerGitHub <noreply@github.com>
Thu, 8 Feb 2024 23:23:34 +0000 (18:23 -0500)
* - Renamed GetSortedRootEntries to GetSortedEntries and added child sorting logic
- Removed unessesary Tree.SetAllExpanded(true) call in RepopulateTree

* Adding back deleted setallexpanded call to check if test passes

---------

Co-authored-by: Your Name <you@example.com>
Content.Client/Guidebook/Controls/GuidebookWindow.xaml.cs

index 113c192beb9a35b460b1e38b2aba1bbed1aa2ac1..4776386c1dd75e0afcbe13449bec1edf0bda54ea 100644 (file)
@@ -98,22 +98,33 @@ public sealed partial class GuidebookWindow : FancyWindow, ILinkClickHandler
         }
     }
 
-    private IEnumerable<GuideEntry> GetSortedRootEntries(List<string>? rootEntries)
+    private IEnumerable<GuideEntry> GetSortedEntries(List<string>? rootEntries)
     {
         if (rootEntries == null)
         {
             HashSet<string> entries = new(_entries.Keys);
             foreach (var entry in _entries.Values)
             {
+                if (entry.Children.Count > 0)
+                {
+                    var sortedChildren = entry.Children
+                        .Select(childId => _entries[childId])
+                        .OrderBy(childEntry => childEntry.Priority)
+                        .ThenBy(childEntry => Loc.GetString(childEntry.Name))
+                        .Select(childEntry => childEntry.Id)
+                        .ToList();
+
+                    entry.Children = sortedChildren;
+                }
                 entries.ExceptWith(entry.Children);
             }
             rootEntries = entries.ToList();
         }
 
         return rootEntries
-            .Select(x => _entries[x])
-            .OrderBy(x => x.Priority)
-            .ThenBy(x => Loc.GetString(x.Name));
+            .Select(rootEntryId => _entries[rootEntryId])
+            .OrderBy(rootEntry => rootEntry.Priority)
+            .ThenBy(rootEntry => Loc.GetString(rootEntry.Name));
     }
 
     private void RepopulateTree(List<string>? roots = null, string? forcedRoot = null)
@@ -123,7 +134,7 @@ public sealed partial class GuidebookWindow : FancyWindow, ILinkClickHandler
         HashSet<string> addedEntries = new();
 
         TreeItem? parent = forcedRoot == null ? null : AddEntry(forcedRoot, null, addedEntries);
-        foreach (var entry in GetSortedRootEntries(roots))
+        foreach (var entry in GetSortedEntries(roots))
         {
             AddEntry(entry.Id, parent, addedEntries);
         }