mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 20:43:21 +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.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -15,6 +16,8 @@ namespace osu.Game.Overlays.News.Displays
|
|||||||
{
|
{
|
||||||
public class FrontPageDisplay : CompositeDrawable
|
public class FrontPageDisplay : CompositeDrawable
|
||||||
{
|
{
|
||||||
|
public Action<GetNewsResponse> ResponseReceived;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IAPIProvider api { get; set; }
|
private IAPIProvider api { get; set; }
|
||||||
|
|
||||||
@ -24,6 +27,13 @@ namespace osu.Game.Overlays.News.Displays
|
|||||||
private GetNewsRequest request;
|
private GetNewsRequest request;
|
||||||
private Cursor lastCursor;
|
private Cursor lastCursor;
|
||||||
|
|
||||||
|
private readonly int year;
|
||||||
|
|
||||||
|
public FrontPageDisplay(int year = 0)
|
||||||
|
{
|
||||||
|
this.year = year;
|
||||||
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
@ -74,13 +84,15 @@ namespace osu.Game.Overlays.News.Displays
|
|||||||
{
|
{
|
||||||
request?.Cancel();
|
request?.Cancel();
|
||||||
|
|
||||||
request = new GetNewsRequest(cursor: lastCursor);
|
request = new GetNewsRequest(year, lastCursor);
|
||||||
request.Success += response => Schedule(() => onSuccess(response));
|
request.Success += response => Schedule(() => onSuccess(response));
|
||||||
api.PerformAsync(request);
|
api.PerformAsync(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CancellationTokenSource cancellationToken;
|
private CancellationTokenSource cancellationToken;
|
||||||
|
|
||||||
|
private bool initialLoad = true;
|
||||||
|
|
||||||
private void onSuccess(GetNewsResponse response)
|
private void onSuccess(GetNewsResponse response)
|
||||||
{
|
{
|
||||||
cancellationToken?.Cancel();
|
cancellationToken?.Cancel();
|
||||||
@ -101,6 +113,12 @@ namespace osu.Game.Overlays.News.Displays
|
|||||||
content.Add(loaded);
|
content.Add(loaded);
|
||||||
showMore.IsLoading = false;
|
showMore.IsLoading = false;
|
||||||
showMore.Alpha = lastCursor == null ? 0 : 1;
|
showMore.Alpha = lastCursor == null ? 0 : 1;
|
||||||
|
|
||||||
|
if (initialLoad)
|
||||||
|
{
|
||||||
|
ResponseReceived?.Invoke(response);
|
||||||
|
initialLoad = false;
|
||||||
|
}
|
||||||
}, (cancellationToken = new CancellationTokenSource()).Token);
|
}, (cancellationToken = new CancellationTokenSource()).Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
private readonly Container content;
|
private readonly Container content;
|
||||||
private readonly Container sidebarContainer;
|
private readonly Container sidebarContainer;
|
||||||
|
private readonly NewsSidebar sidebar;
|
||||||
|
|
||||||
public NewsOverlay()
|
public NewsOverlay()
|
||||||
: base(OverlayColourScheme.Purple, false)
|
: base(OverlayColourScheme.Purple, false)
|
||||||
@ -44,7 +45,7 @@ namespace osu.Game.Overlays
|
|||||||
sidebarContainer = new Container
|
sidebarContainer = new Container
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.X,
|
AutoSizeAxes = Axes.X,
|
||||||
Child = new NewsSidebar()
|
Child = sidebar = new NewsSidebar()
|
||||||
},
|
},
|
||||||
content = new Container
|
content = new Container
|
||||||
{
|
{
|
||||||
@ -94,6 +95,12 @@ namespace osu.Game.Overlays
|
|||||||
Show();
|
Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ShowYear(int year)
|
||||||
|
{
|
||||||
|
showYear(year);
|
||||||
|
Show();
|
||||||
|
}
|
||||||
|
|
||||||
public void ShowArticle(string slug)
|
public void ShowArticle(string slug)
|
||||||
{
|
{
|
||||||
article.Value = slug;
|
article.Value = slug;
|
||||||
@ -102,6 +109,14 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
private CancellationTokenSource cancellationToken;
|
private CancellationTokenSource cancellationToken;
|
||||||
|
|
||||||
|
private void showYear(int year)
|
||||||
|
{
|
||||||
|
cancellationToken?.Cancel();
|
||||||
|
Loading.Show();
|
||||||
|
|
||||||
|
loadFrontPage(year);
|
||||||
|
}
|
||||||
|
|
||||||
private void onArticleChanged(ValueChangedEvent<string> e)
|
private void onArticleChanged(ValueChangedEvent<string> e)
|
||||||
{
|
{
|
||||||
cancellationToken?.Cancel();
|
cancellationToken?.Cancel();
|
||||||
@ -109,13 +124,33 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
if (e.NewValue == null)
|
if (e.NewValue == null)
|
||||||
{
|
{
|
||||||
Header.SetFrontPage();
|
loadFrontPage();
|
||||||
LoadDisplay(new FrontPageDisplay());
|
|
||||||
return;
|
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());
|
LoadDisplay(Empty());
|
||||||
|
Loading.Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void LoadDisplay(Drawable display)
|
protected void LoadDisplay(Drawable display)
|
||||||
@ -124,7 +159,6 @@ namespace osu.Game.Overlays
|
|||||||
LoadComponentAsync(display, loaded =>
|
LoadComponentAsync(display, loaded =>
|
||||||
{
|
{
|
||||||
Child = loaded;
|
Child = loaded;
|
||||||
Loading.Hide();
|
|
||||||
}, (cancellationToken = new CancellationTokenSource()).Token);
|
}, (cancellationToken = new CancellationTokenSource()).Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user