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.
|
|
|
|
|
2021-05-20 15:00:22 +08:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
2021-05-20 01:28:26 +08:00
|
|
|
using osu.Framework.Bindables;
|
2021-04-19 17:24:47 +08:00
|
|
|
using osu.Framework.Graphics;
|
2021-05-20 01:28:26 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-04-19 17:24:47 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Wiki
|
|
|
|
{
|
|
|
|
public class WikiHeader : BreadcrumbControlOverlayHeader
|
|
|
|
{
|
|
|
|
private const string index_page_string = "index";
|
2021-05-20 01:28:26 +08:00
|
|
|
private const string index_path = "Main_Page";
|
|
|
|
|
2021-05-20 15:00:22 +08:00
|
|
|
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(index_page_string);
|
2021-05-20 01:28:26 +08:00
|
|
|
Current.Value = index_page_string;
|
|
|
|
|
|
|
|
WikiPageData.BindValueChanged(onWikiPageChange);
|
2021-05-20 15:00:22 +08:00
|
|
|
Current.BindValueChanged(onCurrentChange);
|
2021-05-20 01:28:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void onWikiPageChange(ValueChangedEvent<APIWikiPage> e)
|
|
|
|
{
|
|
|
|
if (e.NewValue == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
TabControl.Clear();
|
|
|
|
Current.Value = null;
|
|
|
|
|
|
|
|
TabControl.AddItem(index_page_string);
|
|
|
|
|
|
|
|
if (e.NewValue.Path == index_path)
|
|
|
|
{
|
|
|
|
Current.Value = index_page_string;
|
|
|
|
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-05-20 15:00:22 +08:00
|
|
|
private void onCurrentChange(ValueChangedEvent<string> e)
|
|
|
|
{
|
|
|
|
if (e.NewValue == TabControl.Items.LastOrDefault())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (e.NewValue == index_page_string)
|
|
|
|
{
|
|
|
|
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 class WikiHeaderTitle : OverlayTitle
|
|
|
|
{
|
|
|
|
public WikiHeaderTitle()
|
|
|
|
{
|
|
|
|
Title = "wiki";
|
|
|
|
Description = "knowledge base";
|
|
|
|
IconTexture = "Icons/Hexacons/wiki";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|