add default page support for the guidebook (#28772)

This commit is contained in:
Nemanja
2024-06-09 11:55:21 -04:00
committed by GitHub
parent ad9d18771e
commit c549573f7a
2 changed files with 24 additions and 0 deletions

View File

@@ -4,10 +4,12 @@ using Content.Client.UserInterface.ControlExtensions;
using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Controls.FancyTree;
using Content.Client.UserInterface.Systems.Info;
using Content.Shared.CCVar;
using Content.Shared.Guidebook;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;
using Robust.Shared.ContentPack;
using Robust.Shared.Prototypes;
@@ -16,6 +18,8 @@ namespace Content.Client.Guidebook.Controls;
[GenerateTypedNameReferences]
public sealed partial class GuidebookWindow : FancyWindow, ILinkClickHandler
{
[Dependency] private readonly IConfigurationManager _configuration = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IResourceManager _resourceManager = default!;
[Dependency] private readonly DocumentParsingManager _parsingMan = default!;
@@ -34,6 +38,20 @@ public sealed partial class GuidebookWindow : FancyWindow, ILinkClickHandler
};
}
protected override void Opened()
{
base.Opened();
var guideProto = _configuration.GetCVar(CCVars.DefaultGuide);
if (_prototypeManager.TryIndex<GuideEntryPrototype>(guideProto, out var guideEntry))
{
if (Tree.Items.FirstOrDefault(x => x.Metadata is GuideEntry entry && entry.Id == guideProto) is { } item)
Tree.SetSelectedIndex(item.Index);
else
ShowGuide(guideEntry);
}
}
private void OnSelectionChanged(TreeItem? item)
{
if (item != null && item.Metadata is GuideEntry entry)