diff --git a/osu.Game.Tests/Visual/Online/TestSceneNewsOverlay.cs b/osu.Game.Tests/Visual/Online/TestSceneNewsOverlay.cs index f0dc309d01..e35ef4916b 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneNewsOverlay.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneNewsOverlay.cs @@ -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")); } } } diff --git a/osu.Game/Overlays/News/NewsHeader.cs b/osu.Game/Overlays/News/NewsHeader.cs index 8214c71b3a..ee7991c0c6 100644 --- a/osu.Game/Overlays/News/NewsHeader.cs +++ b/osu.Game/Overlays/News/NewsHeader.cs @@ -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 Post = new Bindable(null); - - public Action ShowFrontPage; + public readonly Bindable Post = new Bindable(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 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 current) + { + if (current.NewValue == FRONT_PAGE_STRING) + Post.Value = FRONT_PAGE_STRING; + } + + private void onPostChanged(ValueChangedEvent 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; } } diff --git a/osu.Game/Overlays/NewsOverlay.cs b/osu.Game/Overlays/NewsOverlay.cs index 4cd83f83af..db989e71bf 100644 --- a/osu.Game/Overlays/NewsOverlay.cs +++ b/osu.Game/Overlays/NewsOverlay.cs @@ -15,10 +15,9 @@ namespace osu.Game.Overlays { public class NewsOverlay : FullscreenOverlay { - public readonly Bindable Current = new Bindable(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 current) + private void onPostChanged(ValueChangedEvent post) { cancellationToken?.Cancel(); loading.Show(); - if (current.NewValue == null) + if (post.NewValue == NewsHeader.FRONT_PAGE_STRING) { LoadDisplay(new FrontPageDisplay()); return;