2019-08-12 20:16:41 +02: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-08 18:49:58 +01:00
|
|
|
|
using System.Threading;
|
2019-08-12 20:16:41 +02:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-08-10 17:06:52 +02:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-08-10 12:22:45 +02:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-08-10 12:53:34 +02:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-08-10 12:22:45 +02:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2020-07-08 18:24:13 +03:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-08-10 12:53:34 +02:00
|
|
|
|
using osu.Game.Overlays.News;
|
2020-07-08 20:07:29 +03:00
|
|
|
|
using osu.Game.Overlays.News.Displays;
|
2019-08-10 12:22:45 +02:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
2020-09-03 16:27:31 +09:00
|
|
|
|
public class NewsOverlay : FullscreenOverlay<NewsHeader>
|
2019-08-10 12:22:45 +02:00
|
|
|
|
{
|
2020-07-12 15:45:48 +03:00
|
|
|
|
private readonly Bindable<string> article = new Bindable<string>(null);
|
|
|
|
|
|
2020-07-08 18:24:13 +03:00
|
|
|
|
private Container content;
|
|
|
|
|
private LoadingLayer loading;
|
|
|
|
|
private OverlayScrollContainer scrollFlow;
|
|
|
|
|
|
2020-01-24 12:24:35 +03:00
|
|
|
|
public NewsOverlay()
|
2020-09-03 16:27:31 +09:00
|
|
|
|
: base(OverlayColourScheme.Purple, new NewsHeader())
|
2020-01-24 12:24:35 +03:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-10 12:22:45 +02:00
|
|
|
|
[BackgroundDependencyLoader]
|
2020-07-08 18:24:13 +03:00
|
|
|
|
private void load()
|
2019-08-10 12:22:45 +02:00
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-07-08 18:24:13 +03:00
|
|
|
|
Colour = ColourProvider.Background5,
|
2019-08-10 12:53:34 +02:00
|
|
|
|
},
|
2020-07-08 18:24:13 +03:00
|
|
|
|
scrollFlow = new OverlayScrollContainer
|
2019-08-10 12:53:34 +02:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-07-08 18:24:13 +03:00
|
|
|
|
ScrollbarVisible = false,
|
2019-08-10 12:53:34 +02:00
|
|
|
|
Child = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2020-09-03 16:27:31 +09:00
|
|
|
|
Header.With(h =>
|
2020-07-12 15:45:48 +03:00
|
|
|
|
{
|
2020-09-03 16:27:31 +09:00
|
|
|
|
h.ShowFrontPage = ShowFrontPage;
|
|
|
|
|
}),
|
2020-07-08 18:24:13 +03:00
|
|
|
|
content = new Container
|
2019-08-14 20:24:36 +02:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
}
|
2019-08-10 12:53:34 +02:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-01-04 22:42:39 +09:00
|
|
|
|
loading = new LoadingLayer(true),
|
2019-08-10 12:22:45 +02:00
|
|
|
|
};
|
2019-08-10 17:06:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 18:24:13 +03:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2020-08-05 18:50:37 +09:00
|
|
|
|
|
|
|
|
|
// should not be run until first pop-in to avoid requesting data before user views.
|
2020-08-03 10:03:42 +03:00
|
|
|
|
article.BindValueChanged(onArticleChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 18:24:13 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowFrontPage()
|
|
|
|
|
{
|
2020-07-12 15:45:48 +03:00
|
|
|
|
article.Value = null;
|
2020-07-09 03:40:14 +03:00
|
|
|
|
Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowArticle(string slug)
|
|
|
|
|
{
|
2020-07-12 15:45:48 +03:00
|
|
|
|
article.Value = slug;
|
2020-07-08 18:24:13 +03:00
|
|
|
|
Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CancellationTokenSource cancellationToken;
|
2019-12-08 18:49:58 +01:00
|
|
|
|
|
2020-07-12 15:45:48 +03:00
|
|
|
|
private void onArticleChanged(ValueChangedEvent<string> e)
|
2019-12-08 18:49:58 +01:00
|
|
|
|
{
|
2020-07-08 18:24:13 +03:00
|
|
|
|
cancellationToken?.Cancel();
|
|
|
|
|
loading.Show();
|
|
|
|
|
|
2020-07-12 15:45:48 +03:00
|
|
|
|
if (e.NewValue == null)
|
2020-07-08 18:24:13 +03:00
|
|
|
|
{
|
2020-09-03 16:27:31 +09:00
|
|
|
|
Header.SetFrontPage();
|
2020-07-09 01:26:56 +03:00
|
|
|
|
LoadDisplay(new FrontPageDisplay());
|
2020-07-08 18:24:13 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
2019-12-08 18:49:58 +01:00
|
|
|
|
|
2020-09-03 16:27:31 +09:00
|
|
|
|
Header.SetArticle(e.NewValue);
|
2020-07-08 18:24:13 +03:00
|
|
|
|
LoadDisplay(Empty());
|
|
|
|
|
}
|
2019-12-08 18:49:58 +01:00
|
|
|
|
|
2020-07-08 18:24:13 +03:00
|
|
|
|
protected void LoadDisplay(Drawable display)
|
|
|
|
|
{
|
|
|
|
|
scrollFlow.ScrollToStart();
|
|
|
|
|
LoadComponentAsync(display, loaded =>
|
2019-12-08 18:49:58 +01:00
|
|
|
|
{
|
2020-07-08 18:24:13 +03:00
|
|
|
|
content.Child = loaded;
|
|
|
|
|
loading.Hide();
|
|
|
|
|
}, (cancellationToken = new CancellationTokenSource()).Token);
|
2019-12-08 18:49:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 18:24:13 +03:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
2019-08-10 17:06:52 +02:00
|
|
|
|
{
|
2020-07-08 18:24:13 +03:00
|
|
|
|
cancellationToken?.Cancel();
|
|
|
|
|
base.Dispose(isDisposing);
|
2019-08-10 12:22:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|