mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 12:57:36 +08:00
Don't set null value to show front page
This commit is contained in:
parent
dfa22b1e4c
commit
3ba8ec0fd7
@ -7,19 +7,21 @@ namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
public class TestSceneNewsOverlay : OsuTestScene
|
||||
{
|
||||
private NewsOverlay news;
|
||||
|
||||
protected override bool UseOnlineAPI => true;
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
Add(news = new NewsOverlay());
|
||||
AddStep(@"Show", news.Show);
|
||||
AddStep(@"Hide", news.Hide);
|
||||
|
||||
AddStep(@"Show front page", () => news.ShowFrontPage());
|
||||
AddStep(@"Custom article", () => news.Current.Value = "Test Article 101");
|
||||
NewsOverlay news;
|
||||
Add(news = new NewsOverlay());
|
||||
|
||||
AddStep("Show", news.Show);
|
||||
AddStep("Hide", news.Hide);
|
||||
|
||||
AddStep("Show front page", () => news.ShowFrontPage());
|
||||
AddStep("Custom article", () => news.ShowArticle("Test Article 101"));
|
||||
AddStep("Custom article", () => news.ShowArticle("Test Article 102"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,44 +3,46 @@
|
||||
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace osu.Game.Overlays.News
|
||||
{
|
||||
public class NewsHeader : BreadcrumbControlOverlayHeader
|
||||
{
|
||||
private const string front_page_string = "frontpage";
|
||||
public const string FRONT_PAGE_STRING = "frontpage";
|
||||
|
||||
public readonly Bindable<string> Post = new Bindable<string>(null);
|
||||
|
||||
public Action ShowFrontPage;
|
||||
public readonly Bindable<string> Post = new Bindable<string>(FRONT_PAGE_STRING);
|
||||
|
||||
public NewsHeader()
|
||||
{
|
||||
TabControl.AddItem(front_page_string);
|
||||
|
||||
Current.ValueChanged += e =>
|
||||
{
|
||||
if (e.NewValue == front_page_string)
|
||||
ShowFrontPage?.Invoke();
|
||||
};
|
||||
|
||||
Post.ValueChanged += showPost;
|
||||
TabControl.AddItem(FRONT_PAGE_STRING);
|
||||
Current.Value = FRONT_PAGE_STRING;
|
||||
Current.BindValueChanged(onCurrentChanged);
|
||||
Post.BindValueChanged(onPostChanged, true);
|
||||
}
|
||||
|
||||
private void showPost(ValueChangedEvent<string> e)
|
||||
{
|
||||
if (e.OldValue != null)
|
||||
TabControl.RemoveItem(e.OldValue);
|
||||
public void SetFrontPage() => Post.Value = FRONT_PAGE_STRING;
|
||||
|
||||
if (e.NewValue != null)
|
||||
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;
|
||||
}
|
||||
|
||||
private void onPostChanged(ValueChangedEvent<string> post)
|
||||
{
|
||||
if (post.OldValue != FRONT_PAGE_STRING)
|
||||
TabControl.RemoveItem(post.OldValue);
|
||||
|
||||
if (post.NewValue != FRONT_PAGE_STRING)
|
||||
{
|
||||
TabControl.AddItem(e.NewValue);
|
||||
Current.Value = e.NewValue;
|
||||
TabControl.AddItem(post.NewValue);
|
||||
Current.Value = post.NewValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
Current.Value = front_page_string;
|
||||
Current.Value = FRONT_PAGE_STRING;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,9 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
public class NewsOverlay : FullscreenOverlay
|
||||
{
|
||||
public readonly Bindable<string> Current = new Bindable<string>(null);
|
||||
|
||||
private Container content;
|
||||
private LoadingLayer loading;
|
||||
private NewsHeader header;
|
||||
private OverlayScrollContainer scrollFlow;
|
||||
|
||||
public NewsOverlay()
|
||||
@ -29,8 +28,6 @@ namespace osu.Game.Overlays
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
NewsHeader header;
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
@ -49,10 +46,7 @@ namespace osu.Game.Overlays
|
||||
Direction = FillDirection.Vertical,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
header = new NewsHeader
|
||||
{
|
||||
ShowFrontPage = ShowFrontPage
|
||||
},
|
||||
header = new NewsHeader(),
|
||||
content = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
@ -63,30 +57,34 @@ namespace osu.Game.Overlays
|
||||
},
|
||||
loading = new LoadingLayer(content),
|
||||
};
|
||||
|
||||
header.Post.BindTo(Current);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
Current.BindValueChanged(onCurrentChanged, true);
|
||||
header.Post.BindValueChanged(onPostChanged, true);
|
||||
}
|
||||
|
||||
public void ShowFrontPage()
|
||||
{
|
||||
Current.Value = null;
|
||||
header.SetFrontPage();
|
||||
Show();
|
||||
}
|
||||
|
||||
public void ShowArticle(string slug)
|
||||
{
|
||||
header.SetArticle(slug);
|
||||
Show();
|
||||
}
|
||||
|
||||
private CancellationTokenSource cancellationToken;
|
||||
|
||||
private void onCurrentChanged(ValueChangedEvent<string> current)
|
||||
private void onPostChanged(ValueChangedEvent<string> post)
|
||||
{
|
||||
cancellationToken?.Cancel();
|
||||
loading.Show();
|
||||
|
||||
if (current.NewValue == null)
|
||||
if (post.NewValue == NewsHeader.FRONT_PAGE_STRING)
|
||||
{
|
||||
LoadDisplay(new FrontPageDisplay());
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user