mirror of
https://github.com/ppy/osu.git
synced 2025-02-19 09:52:53 +08:00
Refactor MonthDropdown to ensure all the posts are within a given month
This commit is contained in:
parent
b0297c6324
commit
f4801c08ff
@ -14,6 +14,7 @@ using System.Linq;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.News.Sidebar
|
namespace osu.Game.Overlays.News.Sidebar
|
||||||
{
|
{
|
||||||
@ -26,8 +27,10 @@ namespace osu.Game.Overlays.News.Sidebar
|
|||||||
|
|
||||||
private readonly FillFlowContainer postsFlow;
|
private readonly FillFlowContainer postsFlow;
|
||||||
|
|
||||||
public MonthDropdown(IEnumerable<APINewsPost> posts)
|
public MonthDropdown(int month, int year, IEnumerable<APINewsPost> posts)
|
||||||
{
|
{
|
||||||
|
Debug.Assert(posts.All(p => p.PublishedAt.Month == month && p.PublishedAt.Year == year));
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
Masking = true;
|
Masking = true;
|
||||||
InternalChild = new FillFlowContainer
|
InternalChild = new FillFlowContainer
|
||||||
@ -38,7 +41,7 @@ namespace osu.Game.Overlays.News.Sidebar
|
|||||||
Spacing = new Vector2(0, 5),
|
Spacing = new Vector2(0, 5),
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new DropdownHeader(posts.ElementAt(0).PublishedAt)
|
new DropdownHeader(month, year)
|
||||||
{
|
{
|
||||||
IsOpen = { BindTarget = IsOpen }
|
IsOpen = { BindTarget = IsOpen }
|
||||||
},
|
},
|
||||||
@ -102,8 +105,10 @@ namespace osu.Game.Overlays.News.Sidebar
|
|||||||
|
|
||||||
private readonly SpriteIcon icon;
|
private readonly SpriteIcon icon;
|
||||||
|
|
||||||
public DropdownHeader(DateTimeOffset date)
|
public DropdownHeader(int month, int year)
|
||||||
{
|
{
|
||||||
|
var date = new DateTime(year, month, 1);
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
Height = header_height;
|
Height = header_height;
|
||||||
Action = IsOpen.Toggle;
|
Action = IsOpen.Toggle;
|
||||||
|
@ -86,11 +86,14 @@ namespace osu.Game.Overlays.News.Sidebar
|
|||||||
var keys = lookup.Select(kvp => kvp.Key);
|
var keys = lookup.Select(kvp => kvp.Key);
|
||||||
var sortedKeys = keys.OrderByDescending(k => k).ToList();
|
var sortedKeys = keys.OrderByDescending(k => k).ToList();
|
||||||
|
|
||||||
|
var year = metadata.NewValue.CurrentYear;
|
||||||
|
|
||||||
for (int i = 0; i < sortedKeys.Count; i++)
|
for (int i = 0; i < sortedKeys.Count; i++)
|
||||||
{
|
{
|
||||||
var posts = lookup[sortedKeys[i]];
|
var month = sortedKeys[i];
|
||||||
|
var posts = lookup[month];
|
||||||
|
|
||||||
monthsFlow.Add(new MonthDropdown(posts)
|
monthsFlow.Add(new MonthDropdown(month, year, posts)
|
||||||
{
|
{
|
||||||
IsOpen = { Value = i == 0 }
|
IsOpen = { Value = i == 0 }
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user