1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 22:22:54 +08:00
osu-lazer/osu.Game/Overlays/Wiki/WikiHeader.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

88 lines
2.5 KiB
C#
Raw Normal View History

2021-04-19 17:24:47 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2022-06-17 15:37:17 +08:00
#nullable disable
using System;
using System.Linq;
using osu.Framework.Bindables;
2021-04-19 17:24:47 +08:00
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Graphics;
2021-07-19 19:23:26 +08:00
using osu.Game.Localisation;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Resources.Localisation.Web;
2021-04-19 17:24:47 +08:00
namespace osu.Game.Overlays.Wiki
{
public partial class WikiHeader : BreadcrumbControlOverlayHeader
{
public static LocalisableString IndexPageString => LayoutStrings.HeaderHelpIndex;
public readonly Bindable<APIWikiPage> WikiPageData = new Bindable<APIWikiPage>();
public Action ShowIndexPage;
public Action ShowParentPage;
2021-04-19 17:24:47 +08:00
public WikiHeader()
{
TabControl.AddItem(IndexPageString);
Current.Value = IndexPageString;
WikiPageData.BindValueChanged(onWikiPageChange);
Current.BindValueChanged(onCurrentChange);
}
private void onWikiPageChange(ValueChangedEvent<APIWikiPage> e)
{
if (e.NewValue == null)
return;
TabControl.Clear();
Current.Value = null;
TabControl.AddItem(IndexPageString);
if (e.NewValue.Path == WikiOverlay.INDEX_PATH)
{
Current.Value = IndexPageString;
return;
}
if (e.NewValue.Subtitle != null)
TabControl.AddItem(e.NewValue.Subtitle);
TabControl.AddItem(e.NewValue.Title);
Current.Value = e.NewValue.Title;
2021-04-19 17:24:47 +08:00
}
2021-07-17 20:33:26 +08:00
private void onCurrentChange(ValueChangedEvent<LocalisableString?> e)
{
if (e.NewValue == TabControl.Items.LastOrDefault())
return;
if (e.NewValue == IndexPageString)
{
ShowIndexPage?.Invoke();
return;
}
ShowParentPage?.Invoke();
}
2021-04-19 17:24:47 +08:00
protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/wiki");
protected override OverlayTitle CreateTitle() => new WikiHeaderTitle();
private partial class WikiHeaderTitle : OverlayTitle
{
public WikiHeaderTitle()
{
2021-08-03 15:34:21 +08:00
Title = PageTitleStrings.MainWikiControllerDefault;
2021-07-19 19:23:26 +08:00
Description = NamedOverlayComponentStrings.WikiDescription;
Icon = OsuIcon.Wiki;
2021-04-19 17:24:47 +08:00
}
}
}
}