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.
|
|
|
|
|
|
2019-12-09 01:49:58 +08:00
|
|
|
|
using System.Threading;
|
2019-08-10 23:06:52 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-08-10 18:22:45 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-08-10 18:53:34 +08:00
|
|
|
|
using osu.Game.Overlays.News;
|
2020-07-09 01:07:29 +08:00
|
|
|
|
using osu.Game.Overlays.News.Displays;
|
2019-08-10 18:22:45 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
2021-01-18 15:48:12 +08:00
|
|
|
|
public class NewsOverlay : WebOverlay<NewsHeader>
|
2019-08-10 18:22:45 +08:00
|
|
|
|
{
|
2020-07-12 20:45:48 +08:00
|
|
|
|
private readonly Bindable<string> article = new Bindable<string>(null);
|
|
|
|
|
|
2020-01-24 17:24:35 +08:00
|
|
|
|
public NewsOverlay()
|
2021-01-18 15:48:12 +08:00
|
|
|
|
: base(OverlayColourScheme.Purple)
|
2020-01-24 17:24:35 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 23:24:13 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2020-08-05 17:50:37 +08:00
|
|
|
|
|
|
|
|
|
// should not be run until first pop-in to avoid requesting data before user views.
|
2020-08-03 15:03:42 +08:00
|
|
|
|
article.BindValueChanged(onArticleChanged);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 15:48:12 +08:00
|
|
|
|
protected override NewsHeader CreateHeader() => new NewsHeader
|
|
|
|
|
{
|
|
|
|
|
ShowFrontPage = ShowFrontPage
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-03 15:03:42 +08:00
|
|
|
|
private bool displayUpdateRequired = true;
|
|
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
base.PopIn();
|
|
|
|
|
|
|
|
|
|
if (displayUpdateRequired)
|
|
|
|
|
{
|
|
|
|
|
article.TriggerChange();
|
|
|
|
|
displayUpdateRequired = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOutComplete()
|
|
|
|
|
{
|
|
|
|
|
base.PopOutComplete();
|
|
|
|
|
displayUpdateRequired = true;
|
2020-07-08 23:24:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowFrontPage()
|
|
|
|
|
{
|
2020-07-12 20:45:48 +08:00
|
|
|
|
article.Value = null;
|
2020-07-09 08:40:14 +08:00
|
|
|
|
Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowArticle(string slug)
|
|
|
|
|
{
|
2020-07-12 20:45:48 +08:00
|
|
|
|
article.Value = slug;
|
2020-07-08 23:24:13 +08:00
|
|
|
|
Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CancellationTokenSource cancellationToken;
|
2019-12-09 01:49:58 +08:00
|
|
|
|
|
2020-07-12 20:45:48 +08:00
|
|
|
|
private void onArticleChanged(ValueChangedEvent<string> e)
|
2019-12-09 01:49:58 +08:00
|
|
|
|
{
|
2020-07-08 23:24:13 +08:00
|
|
|
|
cancellationToken?.Cancel();
|
2021-01-18 15:48:12 +08:00
|
|
|
|
Loading.Show();
|
2020-07-08 23:24:13 +08:00
|
|
|
|
|
2020-07-12 20:45:48 +08:00
|
|
|
|
if (e.NewValue == null)
|
2020-07-08 23:24:13 +08:00
|
|
|
|
{
|
2020-09-03 15:27:31 +08:00
|
|
|
|
Header.SetFrontPage();
|
2020-07-09 06:26:56 +08:00
|
|
|
|
LoadDisplay(new FrontPageDisplay());
|
2020-07-08 23:24:13 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2019-12-09 01:49:58 +08:00
|
|
|
|
|
2020-09-03 15:27:31 +08:00
|
|
|
|
Header.SetArticle(e.NewValue);
|
2020-07-08 23:24:13 +08:00
|
|
|
|
LoadDisplay(Empty());
|
|
|
|
|
}
|
2019-12-09 01:49:58 +08:00
|
|
|
|
|
2020-07-08 23:24:13 +08:00
|
|
|
|
protected void LoadDisplay(Drawable display)
|
|
|
|
|
{
|
2021-01-18 15:48:12 +08:00
|
|
|
|
ScrollFlow.ScrollToStart();
|
2020-07-08 23:24:13 +08:00
|
|
|
|
LoadComponentAsync(display, loaded =>
|
2019-12-09 01:49:58 +08:00
|
|
|
|
{
|
2021-01-18 15:48:12 +08:00
|
|
|
|
Child = loaded;
|
|
|
|
|
Loading.Hide();
|
2020-07-08 23:24:13 +08:00
|
|
|
|
}, (cancellationToken = new CancellationTokenSource()).Token);
|
2019-12-09 01:49:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 23:24:13 +08:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
2019-08-10 23:06:52 +08:00
|
|
|
|
{
|
2020-07-08 23:24:13 +08:00
|
|
|
|
cancellationToken?.Cancel();
|
|
|
|
|
base.Dispose(isDisposing);
|
2019-08-10 18:22:45 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|