2019-08-13 02:16:41 +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.
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-08-10 23:06:52 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-08-10 18:53:34 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-08-10 23:06:52 +08:00
|
|
|
|
using System;
|
2019-08-10 18:53:34 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.News
|
|
|
|
|
{
|
2019-12-28 09:57:41 +08:00
|
|
|
|
public class NewsHeader : BreadcrumbControlOverlayHeader
|
2019-08-10 18:53:34 +08:00
|
|
|
|
{
|
2019-12-27 02:03:39 +08:00
|
|
|
|
private const string front_page_string = "frontpage";
|
2019-08-10 18:53:34 +08:00
|
|
|
|
|
|
|
|
|
private NewsHeaderTitle title;
|
|
|
|
|
|
2019-08-10 23:06:52 +08:00
|
|
|
|
public readonly Bindable<string> Current = new Bindable<string>(null);
|
|
|
|
|
|
|
|
|
|
public Action ShowFrontPage;
|
|
|
|
|
|
2019-08-10 18:53:34 +08:00
|
|
|
|
public NewsHeader()
|
|
|
|
|
{
|
2020-01-21 11:00:12 +08:00
|
|
|
|
TabControl.AddItem(front_page_string);
|
2019-08-10 23:06:52 +08:00
|
|
|
|
|
2020-01-21 11:00:12 +08:00
|
|
|
|
TabControl.Current.ValueChanged += e =>
|
2019-08-10 23:06:52 +08:00
|
|
|
|
{
|
|
|
|
|
if (e.NewValue == front_page_string)
|
|
|
|
|
ShowFrontPage?.Invoke();
|
|
|
|
|
};
|
|
|
|
|
|
2019-12-27 02:03:39 +08:00
|
|
|
|
Current.ValueChanged += showPost;
|
2019-08-10 18:53:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-27 02:03:39 +08:00
|
|
|
|
private void showPost(ValueChangedEvent<string> e)
|
2019-08-10 23:06:52 +08:00
|
|
|
|
{
|
|
|
|
|
if (e.OldValue != null)
|
2020-01-21 11:00:12 +08:00
|
|
|
|
TabControl.RemoveItem(e.OldValue);
|
2019-08-10 23:06:52 +08:00
|
|
|
|
|
|
|
|
|
if (e.NewValue != null)
|
|
|
|
|
{
|
2020-01-21 11:00:12 +08:00
|
|
|
|
TabControl.AddItem(e.NewValue);
|
|
|
|
|
TabControl.Current.Value = e.NewValue;
|
2019-08-10 23:06:52 +08:00
|
|
|
|
|
2019-12-27 02:03:39 +08:00
|
|
|
|
title.IsReadingPost = true;
|
2019-08-10 23:06:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-01-21 11:00:12 +08:00
|
|
|
|
TabControl.Current.Value = front_page_string;
|
2019-12-27 02:03:39 +08:00
|
|
|
|
title.IsReadingPost = false;
|
2019-08-10 23:06:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-10 18:53:34 +08:00
|
|
|
|
protected override Drawable CreateBackground() => new NewsHeaderBackground();
|
|
|
|
|
|
|
|
|
|
protected override ScreenTitle CreateTitle() => title = new NewsHeaderTitle();
|
|
|
|
|
|
|
|
|
|
private class NewsHeaderBackground : Sprite
|
|
|
|
|
{
|
|
|
|
|
public NewsHeaderBackground()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
FillMode = FillMode.Fill;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(TextureStore textures)
|
|
|
|
|
{
|
2019-08-10 22:12:42 +08:00
|
|
|
|
Texture = textures.Get(@"Headers/news");
|
2019-08-10 18:53:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class NewsHeaderTitle : ScreenTitle
|
|
|
|
|
{
|
2019-12-27 02:03:39 +08:00
|
|
|
|
private const string post_string = "post";
|
2019-08-10 18:53:34 +08:00
|
|
|
|
|
2019-12-27 02:03:39 +08:00
|
|
|
|
public bool IsReadingPost
|
2019-08-10 18:53:34 +08:00
|
|
|
|
{
|
2019-12-27 02:03:39 +08:00
|
|
|
|
set => Section = value ? post_string : front_page_string;
|
2019-08-10 18:53:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NewsHeaderTitle()
|
|
|
|
|
{
|
2019-12-27 02:03:39 +08:00
|
|
|
|
Title = "news";
|
|
|
|
|
IsReadingPost = false;
|
2019-08-10 18:53:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-15 02:24:36 +08:00
|
|
|
|
protected override Drawable CreateIcon() => new ScreenTitleTextureIcon(@"Icons/news");
|
2019-08-10 18:53:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|