From 3b2921a3ccc5adfdd6d7c4020e814e4d56b5b3e3 Mon Sep 17 00:00:00 2001 From: Sk1tch Date: Thu, 8 Feb 2024 15:23:34 -0800 Subject: [PATCH] Alphabetically sorted guidebook entries (#24963) * - 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 --- .../Controls/GuidebookWindow.xaml.cs | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Content.Client/Guidebook/Controls/GuidebookWindow.xaml.cs b/Content.Client/Guidebook/Controls/GuidebookWindow.xaml.cs index 113c192beb..4776386c1d 100644 --- a/Content.Client/Guidebook/Controls/GuidebookWindow.xaml.cs +++ b/Content.Client/Guidebook/Controls/GuidebookWindow.xaml.cs @@ -98,22 +98,33 @@ public sealed partial class GuidebookWindow : FancyWindow, ILinkClickHandler } } - private IEnumerable GetSortedRootEntries(List? rootEntries) + private IEnumerable GetSortedEntries(List? rootEntries) { if (rootEntries == null) { HashSet 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? roots = null, string? forcedRoot = null) @@ -123,7 +134,7 @@ public sealed partial class GuidebookWindow : FancyWindow, ILinkClickHandler HashSet 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); } -- 2.52.0