mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 10:22:56 +08:00
Implement sidebar metadata handling in NewsOverlay
This commit is contained in:
parent
6cc4ffadab
commit
e3ed9b8135
@ -1,6 +1,7 @@
|
||||
// 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 System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using osu.Framework.Allocation;
|
||||
@ -15,6 +16,8 @@ namespace osu.Game.Overlays.News.Displays
|
||||
{
|
||||
public class FrontPageDisplay : CompositeDrawable
|
||||
{
|
||||
public Action<GetNewsResponse> ResponseReceived;
|
||||
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
|
||||
@ -24,6 +27,13 @@ namespace osu.Game.Overlays.News.Displays
|
||||
private GetNewsRequest request;
|
||||
private Cursor lastCursor;
|
||||
|
||||
private readonly int year;
|
||||
|
||||
public FrontPageDisplay(int year = 0)
|
||||
{
|
||||
this.year = year;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
@ -74,13 +84,15 @@ namespace osu.Game.Overlays.News.Displays
|
||||
{
|
||||
request?.Cancel();
|
||||
|
||||
request = new GetNewsRequest(cursor: lastCursor);
|
||||
request = new GetNewsRequest(year, lastCursor);
|
||||
request.Success += response => Schedule(() => onSuccess(response));
|
||||
api.PerformAsync(request);
|
||||
}
|
||||
|
||||
private CancellationTokenSource cancellationToken;
|
||||
|
||||
private bool initialLoad = true;
|
||||
|
||||
private void onSuccess(GetNewsResponse response)
|
||||
{
|
||||
cancellationToken?.Cancel();
|
||||
@ -101,6 +113,12 @@ namespace osu.Game.Overlays.News.Displays
|
||||
content.Add(loaded);
|
||||
showMore.IsLoading = false;
|
||||
showMore.Alpha = lastCursor == null ? 0 : 1;
|
||||
|
||||
if (initialLoad)
|
||||
{
|
||||
ResponseReceived?.Invoke(response);
|
||||
initialLoad = false;
|
||||
}
|
||||
}, (cancellationToken = new CancellationTokenSource()).Token);
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ namespace osu.Game.Overlays
|
||||
|
||||
private readonly Container content;
|
||||
private readonly Container sidebarContainer;
|
||||
private readonly NewsSidebar sidebar;
|
||||
|
||||
public NewsOverlay()
|
||||
: base(OverlayColourScheme.Purple, false)
|
||||
@ -44,7 +45,7 @@ namespace osu.Game.Overlays
|
||||
sidebarContainer = new Container
|
||||
{
|
||||
AutoSizeAxes = Axes.X,
|
||||
Child = new NewsSidebar()
|
||||
Child = sidebar = new NewsSidebar()
|
||||
},
|
||||
content = new Container
|
||||
{
|
||||
@ -94,6 +95,12 @@ namespace osu.Game.Overlays
|
||||
Show();
|
||||
}
|
||||
|
||||
public void ShowYear(int year)
|
||||
{
|
||||
showYear(year);
|
||||
Show();
|
||||
}
|
||||
|
||||
public void ShowArticle(string slug)
|
||||
{
|
||||
article.Value = slug;
|
||||
@ -102,6 +109,14 @@ namespace osu.Game.Overlays
|
||||
|
||||
private CancellationTokenSource cancellationToken;
|
||||
|
||||
private void showYear(int year)
|
||||
{
|
||||
cancellationToken?.Cancel();
|
||||
Loading.Show();
|
||||
|
||||
loadFrontPage(year);
|
||||
}
|
||||
|
||||
private void onArticleChanged(ValueChangedEvent<string> e)
|
||||
{
|
||||
cancellationToken?.Cancel();
|
||||
@ -109,13 +124,33 @@ namespace osu.Game.Overlays
|
||||
|
||||
if (e.NewValue == null)
|
||||
{
|
||||
Header.SetFrontPage();
|
||||
LoadDisplay(new FrontPageDisplay());
|
||||
loadFrontPage();
|
||||
return;
|
||||
}
|
||||
|
||||
Header.SetArticle(e.NewValue);
|
||||
loadArticle(e.NewValue);
|
||||
}
|
||||
|
||||
private void loadFrontPage(int year = 0)
|
||||
{
|
||||
Header.SetFrontPage();
|
||||
|
||||
var page = new FrontPageDisplay(year);
|
||||
page.ResponseReceived += r =>
|
||||
{
|
||||
sidebar.Metadata.Value = r.SidebarMetadata;
|
||||
Loading.Hide();
|
||||
};
|
||||
LoadDisplay(page);
|
||||
}
|
||||
|
||||
private void loadArticle(string article)
|
||||
{
|
||||
Header.SetArticle(article);
|
||||
|
||||
// Temporary, should be handled by ArticleDisplay later
|
||||
LoadDisplay(Empty());
|
||||
Loading.Hide();
|
||||
}
|
||||
|
||||
protected void LoadDisplay(Drawable display)
|
||||
@ -124,7 +159,6 @@ namespace osu.Game.Overlays
|
||||
LoadComponentAsync(display, loaded =>
|
||||
{
|
||||
Child = loaded;
|
||||
Loading.Hide();
|
||||
}, (cancellationToken = new CancellationTokenSource()).Token);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user