1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 23:27:25 +08:00
osu-lazer/osu.Game/Overlays/NewsOverlay.cs

114 lines
3.3 KiB
C#
Raw Normal View History

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