2019-08-12 18:16:41 +00: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 17:49:58 +00:00
|
|
|
|
using System.Threading;
|
2019-08-12 18:16:41 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-08-10 15:06:52 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-08-10 10:22:45 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-08-10 10:53:34 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-08-10 10:22:45 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2020-07-08 15:24:13 +00:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-08-10 10:53:34 +00:00
|
|
|
|
using osu.Game.Overlays.News;
|
2019-08-10 10:22:45 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
|
|
|
|
public class NewsOverlay : FullscreenOverlay
|
|
|
|
|
{
|
2019-08-10 15:06:52 +00:00
|
|
|
|
public readonly Bindable<string> Current = new Bindable<string>(null);
|
|
|
|
|
|
2020-07-08 15:24:13 +00:00
|
|
|
|
private Container content;
|
|
|
|
|
private LoadingLayer loading;
|
|
|
|
|
private OverlayScrollContainer scrollFlow;
|
|
|
|
|
|
2020-01-24 09:24:35 +00:00
|
|
|
|
public NewsOverlay()
|
|
|
|
|
: base(OverlayColourScheme.Purple)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-10 10:22:45 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
2020-07-08 15:24:13 +00:00
|
|
|
|
private void load()
|
2019-08-10 10:22:45 +00:00
|
|
|
|
{
|
2020-07-08 15:24:13 +00:00
|
|
|
|
NewsHeader header;
|
|
|
|
|
|
2019-08-10 10:22:45 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-07-08 15:24:13 +00:00
|
|
|
|
Colour = ColourProvider.Background5,
|
2019-08-10 10:53:34 +00:00
|
|
|
|
},
|
2020-07-08 15:24:13 +00:00
|
|
|
|
scrollFlow = new OverlayScrollContainer
|
2019-08-10 10:53:34 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-07-08 15:24:13 +00:00
|
|
|
|
ScrollbarVisible = false,
|
2019-08-10 10:53:34 +00:00
|
|
|
|
Child = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2019-08-14 19:52:36 +00:00
|
|
|
|
header = new NewsHeader
|
2019-08-14 18:24:36 +00:00
|
|
|
|
{
|
|
|
|
|
ShowFrontPage = ShowFrontPage
|
|
|
|
|
},
|
2020-07-08 15:24:13 +00:00
|
|
|
|
content = new Container
|
2019-08-14 18:24:36 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
}
|
2019-08-10 10:53:34 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2020-07-08 15:24:13 +00:00
|
|
|
|
loading = new LoadingLayer(content),
|
2019-08-10 10:22:45 +00:00
|
|
|
|
};
|
2019-08-10 15:06:52 +00:00
|
|
|
|
|
2020-02-03 21:43:04 +00:00
|
|
|
|
header.Post.BindTo(Current);
|
2019-08-10 15:06:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 15:24:13 +00:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
Current.BindValueChanged(onCurrentChanged, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowFrontPage()
|
|
|
|
|
{
|
|
|
|
|
Current.Value = null;
|
|
|
|
|
Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CancellationTokenSource cancellationToken;
|
2019-12-08 17:49:58 +00:00
|
|
|
|
|
2020-07-08 15:24:13 +00:00
|
|
|
|
private void onCurrentChanged(ValueChangedEvent<string> current)
|
2019-12-08 17:49:58 +00:00
|
|
|
|
{
|
2020-07-08 15:24:13 +00:00
|
|
|
|
cancellationToken?.Cancel();
|
|
|
|
|
loading.Show();
|
|
|
|
|
|
|
|
|
|
if (current.NewValue == null)
|
|
|
|
|
{
|
|
|
|
|
LoadDisplay(Empty());
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-12-08 17:49:58 +00:00
|
|
|
|
|
2020-07-08 15:24:13 +00:00
|
|
|
|
LoadDisplay(Empty());
|
|
|
|
|
}
|
2019-12-08 17:49:58 +00:00
|
|
|
|
|
2020-07-08 15:24:13 +00:00
|
|
|
|
protected void LoadDisplay(Drawable display)
|
|
|
|
|
{
|
|
|
|
|
scrollFlow.ScrollToStart();
|
|
|
|
|
LoadComponentAsync(display, loaded =>
|
2019-12-08 17:49:58 +00:00
|
|
|
|
{
|
2020-07-08 15:24:13 +00:00
|
|
|
|
content.Child = loaded;
|
|
|
|
|
loading.Hide();
|
|
|
|
|
}, (cancellationToken = new CancellationTokenSource()).Token);
|
2019-12-08 17:49:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 15:24:13 +00:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
2019-08-10 15:06:52 +00:00
|
|
|
|
{
|
2020-07-08 15:24:13 +00:00
|
|
|
|
cancellationToken?.Cancel();
|
|
|
|
|
base.Dispose(isDisposing);
|
2019-08-10 10:22:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|