2019-08-12 18:16:41 +00: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.
|
|
|
|
|
|
2019-08-10 15:06:52 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-08-10 10:53:34 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.News
|
|
|
|
|
{
|
2019-12-28 01:57:41 +00:00
|
|
|
|
public class NewsHeader : BreadcrumbControlOverlayHeader
|
2019-08-10 10:53:34 +00:00
|
|
|
|
{
|
2020-07-09 00:40:14 +00:00
|
|
|
|
public const string FRONT_PAGE_STRING = "frontpage";
|
2019-08-10 10:53:34 +00:00
|
|
|
|
|
2020-07-09 00:40:14 +00:00
|
|
|
|
public readonly Bindable<string> Post = new Bindable<string>(FRONT_PAGE_STRING);
|
2019-08-10 15:06:52 +00:00
|
|
|
|
|
2019-08-10 10:53:34 +00:00
|
|
|
|
public NewsHeader()
|
|
|
|
|
{
|
2020-07-09 00:40:14 +00:00
|
|
|
|
TabControl.AddItem(FRONT_PAGE_STRING);
|
|
|
|
|
Current.Value = FRONT_PAGE_STRING;
|
|
|
|
|
Current.BindValueChanged(onCurrentChanged);
|
|
|
|
|
Post.BindValueChanged(onPostChanged, true);
|
|
|
|
|
}
|
2019-08-10 15:06:52 +00:00
|
|
|
|
|
2020-07-09 00:40:14 +00:00
|
|
|
|
public void SetFrontPage() => Post.Value = FRONT_PAGE_STRING;
|
2019-08-10 15:06:52 +00:00
|
|
|
|
|
2020-07-09 00:40:14 +00:00
|
|
|
|
public void SetArticle(string slug) => Post.Value = slug;
|
|
|
|
|
|
|
|
|
|
private void onCurrentChanged(ValueChangedEvent<string> current)
|
|
|
|
|
{
|
|
|
|
|
if (current.NewValue == FRONT_PAGE_STRING)
|
|
|
|
|
Post.Value = FRONT_PAGE_STRING;
|
2019-08-10 10:53:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 00:40:14 +00:00
|
|
|
|
private void onPostChanged(ValueChangedEvent<string> post)
|
2019-08-10 15:06:52 +00:00
|
|
|
|
{
|
2020-07-09 00:40:14 +00:00
|
|
|
|
if (post.OldValue != FRONT_PAGE_STRING)
|
|
|
|
|
TabControl.RemoveItem(post.OldValue);
|
2019-08-10 15:06:52 +00:00
|
|
|
|
|
2020-07-09 00:40:14 +00:00
|
|
|
|
if (post.NewValue != FRONT_PAGE_STRING)
|
2019-08-10 15:06:52 +00:00
|
|
|
|
{
|
2020-07-09 00:40:14 +00:00
|
|
|
|
TabControl.AddItem(post.NewValue);
|
|
|
|
|
Current.Value = post.NewValue;
|
2019-08-10 15:06:52 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-07-09 00:40:14 +00:00
|
|
|
|
Current.Value = FRONT_PAGE_STRING;
|
2019-08-10 15:06:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 12:36:19 +00:00
|
|
|
|
protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/news");
|
2019-08-10 10:53:34 +00:00
|
|
|
|
|
2020-03-24 21:08:20 +00:00
|
|
|
|
protected override OverlayTitle CreateTitle() => new NewsHeaderTitle();
|
2019-08-10 10:53:34 +00:00
|
|
|
|
|
2020-03-24 21:08:20 +00:00
|
|
|
|
private class NewsHeaderTitle : OverlayTitle
|
2019-08-10 10:53:34 +00:00
|
|
|
|
{
|
|
|
|
|
public NewsHeaderTitle()
|
|
|
|
|
{
|
2019-12-26 18:03:39 +00:00
|
|
|
|
Title = "news";
|
2020-03-24 21:08:20 +00:00
|
|
|
|
IconTexture = "Icons/news";
|
2019-08-10 10:53:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|