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.
|
|
|
|
|
|
2021-05-19 12:28:12 +00:00
|
|
|
|
using System;
|
2019-12-08 17:49:58 +00:00
|
|
|
|
using System.Threading;
|
2019-08-10 15:06:52 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-08-10 10:22:45 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2021-05-19 12:28:12 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-08-10 10:53:34 +00:00
|
|
|
|
using osu.Game.Overlays.News;
|
2020-07-08 17:07:29 +00:00
|
|
|
|
using osu.Game.Overlays.News.Displays;
|
2021-05-19 12:28:12 +00:00
|
|
|
|
using osu.Game.Overlays.News.Sidebar;
|
2019-08-10 10:22:45 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
2021-01-18 08:13:38 +00:00
|
|
|
|
public class NewsOverlay : OnlineOverlay<NewsHeader>
|
2019-08-10 10:22:45 +00:00
|
|
|
|
{
|
2020-07-12 12:45:48 +00:00
|
|
|
|
private readonly Bindable<string> article = new Bindable<string>(null);
|
|
|
|
|
|
2021-05-19 12:28:12 +00:00
|
|
|
|
private readonly Container sidebarContainer;
|
2021-05-19 12:36:05 +00:00
|
|
|
|
private readonly NewsSidebar sidebar;
|
2021-05-19 12:28:12 +00:00
|
|
|
|
|
2021-05-20 05:30:40 +00:00
|
|
|
|
private readonly Container content;
|
|
|
|
|
|
2021-05-20 05:11:42 +00:00
|
|
|
|
private CancellationTokenSource cancellationToken;
|
|
|
|
|
|
2021-05-20 05:12:34 +00:00
|
|
|
|
private bool displayUpdateRequired = true;
|
|
|
|
|
|
2020-01-24 09:24:35 +00:00
|
|
|
|
public NewsOverlay()
|
2021-02-18 09:04:41 +00:00
|
|
|
|
: base(OverlayColourScheme.Purple, false)
|
2020-01-24 09:24:35 +00:00
|
|
|
|
{
|
2021-05-20 05:30:40 +00:00
|
|
|
|
Child = new GridContainer
|
2021-05-19 12:28:12 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RowDimensions = new[]
|
|
|
|
|
{
|
|
|
|
|
new Dimension(GridSizeMode.AutoSize)
|
|
|
|
|
},
|
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
|
{
|
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
|
new Dimension()
|
|
|
|
|
},
|
|
|
|
|
Content = new[]
|
|
|
|
|
{
|
|
|
|
|
new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
sidebarContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
2021-05-19 12:36:05 +00:00
|
|
|
|
Child = sidebar = new NewsSidebar()
|
2021-05-19 12:28:12 +00:00
|
|
|
|
},
|
|
|
|
|
content = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-20 05:30:40 +00:00
|
|
|
|
};
|
2020-01-24 09:24:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 15:24:13 +00:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2020-08-05 09:50:37 +00:00
|
|
|
|
|
|
|
|
|
// should not be run until first pop-in to avoid requesting data before user views.
|
2020-08-03 07:03:42 +00:00
|
|
|
|
article.BindValueChanged(onArticleChanged);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 07:48:12 +00:00
|
|
|
|
protected override NewsHeader CreateHeader() => new NewsHeader
|
|
|
|
|
{
|
|
|
|
|
ShowFrontPage = ShowFrontPage
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-03 07:03:42 +00:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
base.PopIn();
|
|
|
|
|
|
|
|
|
|
if (displayUpdateRequired)
|
|
|
|
|
{
|
|
|
|
|
article.TriggerChange();
|
|
|
|
|
displayUpdateRequired = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOutComplete()
|
|
|
|
|
{
|
|
|
|
|
base.PopOutComplete();
|
|
|
|
|
displayUpdateRequired = true;
|
2020-07-08 15:24:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowFrontPage()
|
|
|
|
|
{
|
2020-07-12 12:45:48 +00:00
|
|
|
|
article.Value = null;
|
2020-07-09 00:40:14 +00:00
|
|
|
|
Show();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 12:36:05 +00:00
|
|
|
|
public void ShowYear(int year)
|
|
|
|
|
{
|
2021-05-20 05:11:42 +00:00
|
|
|
|
loadFrontPage(year);
|
2021-05-19 12:36:05 +00:00
|
|
|
|
Show();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 00:40:14 +00:00
|
|
|
|
public void ShowArticle(string slug)
|
|
|
|
|
{
|
2020-07-12 12:45:48 +00:00
|
|
|
|
article.Value = slug;
|
2020-07-08 15:24:13 +00:00
|
|
|
|
Show();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-20 05:12:34 +00:00
|
|
|
|
protected void LoadDisplay(Drawable display)
|
|
|
|
|
{
|
|
|
|
|
ScrollFlow.ScrollToStart();
|
2021-05-20 05:30:40 +00:00
|
|
|
|
LoadComponentAsync(display, loaded => content.Child = loaded, (cancellationToken = new CancellationTokenSource()).Token);
|
2021-05-20 05:12:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
|
sidebarContainer.Height = DrawHeight;
|
|
|
|
|
sidebarContainer.Y = Math.Clamp(ScrollFlow.Current - Header.DrawHeight, 0, Math.Max(ScrollFlow.ScrollContent.DrawHeight - DrawHeight - Header.DrawHeight, 0));
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-12 12:45:48 +00:00
|
|
|
|
private void onArticleChanged(ValueChangedEvent<string> e)
|
2019-12-08 17:49:58 +00:00
|
|
|
|
{
|
2020-07-12 12:45:48 +00:00
|
|
|
|
if (e.NewValue == null)
|
2021-05-19 12:36:05 +00:00
|
|
|
|
loadFrontPage();
|
2021-05-20 05:11:42 +00:00
|
|
|
|
else
|
|
|
|
|
loadArticle(e.NewValue);
|
2021-05-19 12:36:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadFrontPage(int year = 0)
|
|
|
|
|
{
|
2021-05-20 05:11:42 +00:00
|
|
|
|
beginLoading();
|
|
|
|
|
|
2021-05-19 12:36:05 +00:00
|
|
|
|
Header.SetFrontPage();
|
|
|
|
|
|
|
|
|
|
var page = new FrontPageDisplay(year);
|
|
|
|
|
page.ResponseReceived += r =>
|
|
|
|
|
{
|
|
|
|
|
sidebar.Metadata.Value = r.SidebarMetadata;
|
|
|
|
|
Loading.Hide();
|
|
|
|
|
};
|
|
|
|
|
LoadDisplay(page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadArticle(string article)
|
|
|
|
|
{
|
2021-05-20 05:11:42 +00:00
|
|
|
|
beginLoading();
|
|
|
|
|
|
2021-05-19 12:36:05 +00:00
|
|
|
|
Header.SetArticle(article);
|
|
|
|
|
|
|
|
|
|
// Temporary, should be handled by ArticleDisplay later
|
2020-07-08 15:24:13 +00:00
|
|
|
|
LoadDisplay(Empty());
|
2021-05-19 12:36:05 +00:00
|
|
|
|
Loading.Hide();
|
2020-07-08 15:24:13 +00:00
|
|
|
|
}
|
2019-12-08 17:49:58 +00:00
|
|
|
|
|
2021-05-20 05:11:42 +00:00
|
|
|
|
private void beginLoading()
|
|
|
|
|
{
|
|
|
|
|
cancellationToken?.Cancel();
|
|
|
|
|
Loading.Show();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|