Make guidebook remember where you left off (#31375)

* 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>
This commit is contained in:
12rabbits
2024-08-26 16:06:54 -07:00
committed by GitHub
parent e85c25a746
commit 367cdfd439
2 changed files with 19 additions and 2 deletions

View 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(

View 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.