Skip to content

Commit

Permalink
add default page support for the guidebook (space-wizards#28772)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmoGarbage404 authored and AJCM committed Jun 9, 2024
1 parent 68ec47a commit 4469a77
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Content.Client/Guidebook/Controls/GuidebookWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
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;

Expand All @@ -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!;

Expand All @@ -34,6 +38,20 @@ public GuidebookWindow()
};
}

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)
Expand Down
6 changes: 6 additions & 0 deletions Content.Shared/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public sealed class CCVars : CVars
public static readonly CVarDef<string> RulesFile =
CVarDef.Create("server.rules_file", "DefaultRuleset", CVar.REPLICATED | CVar.SERVER);

/// <summary>
/// Guide entry that is displayed by default when a guide is opened.
/// </summary>
public static readonly CVarDef<string> DefaultGuide =
CVarDef.Create("server.default_guide", "NewPlayer", CVar.REPLICATED | CVar.SERVER);

/*
* Ambience
*/
Expand Down

0 comments on commit 4469a77

Please sign in to comment.