]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make guidebook remember where you left off (#31375)
author12rabbits <53499656+12rabbits@users.noreply.github.com>
Mon, 26 Aug 2024 23:06:54 +0000 (16:06 -0700)
committerGitHub <noreply@github.com>
Mon, 26 Aug 2024 23:06:54 +0000 (01:06 +0200)
* Guidebook tracks last read entry

* Persistent guidebook fixes

* Persistent guidebook requested changes

* Update Content.Client/UserInterface/Systems/Guidebook/GuidebookUIController.cs

---------

Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
Content.Client/Guidebook/Controls/GuidebookWindow.xaml.cs
Content.Client/UserInterface/Systems/Guidebook/GuidebookUIController.cs

index 469b0ed22245eaed329fd48d1e1613f312621ecf..de06d85bb04cabd40b8d246e189501369f82b5cb 100644 (file)
@@ -23,6 +23,8 @@ public sealed partial class GuidebookWindow : FancyWindow, ILinkClickHandler
 
     private readonly ISawmill _sawmill;
 
+    public ProtoId<GuideEntryPrototype> LastEntry;
+
     public GuidebookWindow()
     {
         RobustXamlLoader.Load(this);
@@ -90,6 +92,8 @@ public sealed partial class GuidebookWindow : FancyWindow, ILinkClickHandler
 
             _sawmill.Error($"Failed to parse contents of guide document {entry.Id}.");
         }
+
+        LastEntry = entry.Id;
     }
 
     public void UpdateGuides(
index 03ea47827f6319e0aae4bbc479355b8a83c3e190..702b0a52ac46f403ec136cb12bde368350684359 100644 (file)
@@ -30,6 +30,7 @@ public sealed class GuidebookUIController : UIController, IOnStateEntered<LobbyS
 
     private GuidebookWindow? _guideWindow;
     private MenuButton? GuidebookButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.GuidebookButton;
+    private ProtoId<GuideEntryPrototype>? _lastEntry;
 
     public void OnStateEntered(LobbyState state)
     {
@@ -142,7 +143,10 @@ public sealed class GuidebookUIController : UIController, IOnStateEntered<LobbyS
             GuidebookButton.Pressed = false;
 
         if (_guideWindow != null)
+        {
             _guideWindow.ReturnContainer.Visible = false;
+            _lastEntry = _guideWindow.LastEntry;
+        }
     }
 
     private void OnWindowOpen()
@@ -176,8 +180,6 @@ public sealed class GuidebookUIController : UIController, IOnStateEntered<LobbyS
         if (GuidebookButton != null)
             GuidebookButton.SetClickPressed(!_guideWindow.IsOpen);
 
-        selected ??= _configuration.GetCVar(CCVars.DefaultGuide);
-
         if (guides == null)
         {
             guides = _prototypeManager.EnumeratePrototypes<GuideEntryPrototype>()
@@ -193,6 +195,17 @@ public sealed class GuidebookUIController : UIController, IOnStateEntered<LobbyS
             }
         }
 
+        if (selected == null)
+        {
+            if (_lastEntry is { } lastEntry && guides.ContainsKey(lastEntry))
+            {
+                selected = _lastEntry;
+            }
+            else
+            {
+                selected = _configuration.GetCVar(CCVars.DefaultGuide);
+            }
+        }
         _guideWindow.UpdateGuides(guides, rootEntries, forceRoot, selected);
 
         // Expand up to depth-2.