2021-05-17 16:55:55 +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.
|
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2021-05-17 16:55:55 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
|
using osuTK;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.News.Sidebar
|
|
|
|
|
{
|
2021-06-04 01:12:29 +08:00
|
|
|
|
public class NewsSidebar : OverlaySidebar
|
2021-05-17 16:55:55 +08:00
|
|
|
|
{
|
|
|
|
|
[Cached]
|
|
|
|
|
public readonly Bindable<APINewsSidebar> Metadata = new Bindable<APINewsSidebar>();
|
|
|
|
|
|
|
|
|
|
private FillFlowContainer<MonthSection> monthsFlow;
|
|
|
|
|
|
2021-06-04 01:12:29 +08:00
|
|
|
|
protected override Drawable CreateContent() => new FillFlowContainer
|
2021-05-17 16:55:55 +08:00
|
|
|
|
{
|
2021-06-04 01:12:29 +08:00
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Spacing = new Vector2(0, 20),
|
|
|
|
|
Children = new Drawable[]
|
2021-05-17 16:55:55 +08:00
|
|
|
|
{
|
2021-06-04 01:12:29 +08:00
|
|
|
|
new YearsPanel(),
|
|
|
|
|
monthsFlow = new FillFlowContainer<MonthSection>
|
2021-05-17 16:55:55 +08:00
|
|
|
|
{
|
2021-06-04 01:12:29 +08:00
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Spacing = new Vector2(0, 10)
|
2021-05-17 16:55:55 +08:00
|
|
|
|
}
|
2021-06-04 01:12:29 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
2021-05-17 16:55:55 +08:00
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
Metadata.BindValueChanged(onMetadataChanged, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onMetadataChanged(ValueChangedEvent<APINewsSidebar> metadata)
|
|
|
|
|
{
|
|
|
|
|
monthsFlow.Clear();
|
|
|
|
|
|
|
|
|
|
if (metadata.NewValue == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var allPosts = metadata.NewValue.NewsPosts;
|
|
|
|
|
|
|
|
|
|
if (allPosts?.Any() != true)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-01-20 06:13:30 +08:00
|
|
|
|
var lookup = metadata.NewValue.NewsPosts.ToLookup(post => (post.PublishedAt.Month, post.PublishedAt.Year));
|
2021-05-17 16:55:55 +08:00
|
|
|
|
|
|
|
|
|
var keys = lookup.Select(kvp => kvp.Key);
|
2022-01-20 06:13:30 +08:00
|
|
|
|
var sortedKeys = keys.OrderByDescending(k => k.Year).ThenByDescending(k => k.Month).ToList();
|
2021-05-17 16:55:55 +08:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < sortedKeys.Count; i++)
|
|
|
|
|
{
|
2022-01-20 06:13:30 +08:00
|
|
|
|
var key = sortedKeys[i];
|
|
|
|
|
var posts = lookup[key];
|
2021-05-17 16:55:55 +08:00
|
|
|
|
|
2022-01-20 06:13:30 +08:00
|
|
|
|
monthsFlow.Add(new MonthSection(key.Month, key.Year, posts)
|
2021-05-17 16:55:55 +08:00
|
|
|
|
{
|
2021-05-19 14:48:31 +08:00
|
|
|
|
Expanded = { Value = i == 0 }
|
2021-05-17 16:55:55 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|