]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make guidebook start with some entries collapsed (#16181)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Sun, 7 May 2023 03:12:29 +0000 (15:12 +1200)
committerGitHub <noreply@github.com>
Sun, 7 May 2023 03:12:29 +0000 (13:12 +1000)
Content.Client/Guidebook/Controls/GuidebookWindow.xaml
Content.Client/UserInterface/Controls/FancyTree/FancyTree.xaml.cs
Content.Client/UserInterface/Systems/Guidebook/GuidebookUIController.cs

index b8c4f9e2518a4a74599d92767e3a851df0fab2ad..1d19a92231cfa6adf63ec68cc19b9edc1b0877b5 100644 (file)
@@ -9,7 +9,7 @@
     <SplitContainer Orientation="Horizontal" HorizontalExpand="True" Name="Split">
         <!-- Guide select -->
         <BoxContainer Orientation="Horizontal" Name="TreeBox">
-            <fancyTree:FancyTree Name="Tree" VerticalExpand="True" HorizontalExpand="True"/>
+            <fancyTree:FancyTree Name="Tree" VerticalExpand="True" HorizontalExpand="True" Access="Public"/>
             <cc:VSeparator StyleClasses="LowDivider" Margin="0 -2"/>
         </BoxContainer>
         <ScrollContainer Name="Scroll" HScrollEnabled="False" HorizontalExpand="True" VerticalExpand="True">
index ae50c74929667c7f9d50bbcd96ca02c6ce3238dd..1df5864926f16a81941101ba633b2336643a38c1 100644 (file)
@@ -176,20 +176,30 @@ public sealed partial class FancyTree : Control
         OnSelectedItemChanged?.Invoke(newSelection);
     }
 
-    public void SetAllExpanded(bool value)
+    /// <summary>
+    ///     Recursively expands or collapse all entries, optionally up to some depth.
+    /// </summary>
+    /// <param name="value">Whether to expand or collapse the entries</param>
+    /// <param name="depth">The recursion depth. If negative, implies no limit. Zero will expand only the top-level entries.</param>
+    public void SetAllExpanded(bool value, int depth = -1)
     {
         foreach (var item in Body.Children)
         {
-            RecursiveSetExpanded((TreeItem) item, value);
+            RecursiveSetExpanded((TreeItem) item, value, depth);
         }
     }
 
-    public void RecursiveSetExpanded(TreeItem item, bool value)
+    public void RecursiveSetExpanded(TreeItem item, bool value, int depth)
     {
         item.SetExpanded(value);
+
+        if (depth == 0)
+            return;
+        depth--;
+        
         foreach (var child in item.Body.Children)
         {
-            RecursiveSetExpanded((TreeItem) child, value);
+            RecursiveSetExpanded((TreeItem) child, value, depth);
         }
     }
 
index 66376df3171357b76ca3ddcebeea57f6d437e8aa..20e3158f748ea9fda86b0c16efdbe15e1f500f9f 100644 (file)
@@ -116,7 +116,7 @@ public sealed class GuidebookUIController : UIController, IOnStateEntered<LobbyS
     }
 
     /// <summary>
-    ///     Opens the guidebook.
+    ///     Opens or closes the guidebook.
     /// </summary>
     /// <param name="guides">What guides should be shown. If not specified, this will instead list all the entries</param>
     /// <param name="rootEntries">A list of guides that should form the base of the table of contents. If not specified,
@@ -162,6 +162,11 @@ public sealed class GuidebookUIController : UIController, IOnStateEntered<LobbyS
         }
 
         _guideWindow.UpdateGuides(guides, rootEntries, forceRoot, selected);
+
+        // Expand up to depth-2.
+        _guideWindow.Tree.SetAllExpanded(false);
+        _guideWindow.Tree.SetAllExpanded(true, 1);
+
         _guideWindow.OpenCenteredRight();
     }