1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 19:47:24 +08:00
osu-lazer/osu.Game/Overlays/News/NewsHeader.cs

71 lines
1.9 KiB
C#
Raw Normal View History

// 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.
2020-07-12 20:45:48 +08:00
using System;
2019-08-10 23:06:52 +08:00
using osu.Framework.Bindables;
2019-08-10 18:53:34 +08:00
using osu.Framework.Graphics;
namespace osu.Game.Overlays.News
{
public class NewsHeader : BreadcrumbControlOverlayHeader
2019-08-10 18:53:34 +08:00
{
2020-07-12 20:45:48 +08:00
private const string front_page_string = "frontpage";
2019-08-10 18:53:34 +08:00
2020-07-12 20:45:48 +08:00
public Action ShowFrontPage;
private readonly Bindable<string> article = new Bindable<string>(null);
2019-08-10 23:06:52 +08:00
2019-08-10 18:53:34 +08:00
public NewsHeader()
{
2020-07-12 20:45:48 +08:00
TabControl.AddItem(front_page_string);
2019-08-10 23:06:52 +08:00
article.BindValueChanged(onArticleChanged, true);
}
protected override void LoadComplete()
{
base.LoadComplete();
2020-07-12 20:45:48 +08:00
Current.BindValueChanged(e =>
{
if (e.NewValue == front_page_string)
ShowFrontPage?.Invoke();
});
2019-08-10 18:53:34 +08:00
}
2020-07-12 20:45:48 +08:00
public void SetFrontPage() => article.Value = null;
public void SetArticle(string slug) => article.Value = slug;
private void onArticleChanged(ValueChangedEvent<string> e)
2019-08-10 23:06:52 +08:00
{
2020-07-12 20:45:48 +08:00
if (e.OldValue != null)
TabControl.RemoveItem(e.OldValue);
2019-08-10 23:06:52 +08:00
2020-07-12 20:45:48 +08:00
if (e.NewValue != null)
2019-08-10 23:06:52 +08:00
{
2020-07-12 20:45:48 +08:00
TabControl.AddItem(e.NewValue);
Current.Value = e.NewValue;
2019-08-10 23:06:52 +08:00
}
else
{
2020-07-12 20:45:48 +08:00
Current.Value = front_page_string;
2019-08-10 23:06:52 +08:00
}
}
protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/news");
2019-08-10 18:53:34 +08:00
protected override OverlayTitle CreateTitle() => new NewsHeaderTitle();
2019-08-10 18:53:34 +08:00
private class NewsHeaderTitle : OverlayTitle
2019-08-10 18:53:34 +08:00
{
public NewsHeaderTitle()
{
2019-12-27 02:03:39 +08:00
Title = "news";
2020-09-07 01:13:06 +08:00
Description = "get up-to-date on community happenings";
IconTexture = "Icons/Hexacons/news";
2019-08-10 18:53:34 +08:00
}
}
}
}