mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 08:43:20 +08:00
Rewrite YearsPanel
to not be insanely long
This commit is contained in:
parent
ae1e62288d
commit
abeeda5d04
@ -1,17 +1,17 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using System;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.News.Sidebar
|
||||
@ -77,6 +77,7 @@ namespace osu.Game.Overlays.News.Sidebar
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = 15;
|
||||
Padding = new MarginPadding { Vertical = 2.5f };
|
||||
|
||||
Child = text = new OsuSpriteText
|
||||
{
|
||||
@ -99,39 +100,19 @@ namespace osu.Game.Overlays.News.Sidebar
|
||||
private class YearsGridContainer : GridContainer
|
||||
{
|
||||
private const int column_count = 4;
|
||||
private const float spacing = 5f;
|
||||
|
||||
private readonly int rowCount;
|
||||
|
||||
public YearsGridContainer(int[] years, int currentYear)
|
||||
{
|
||||
rowCount = (int)Math.Ceiling((float)years.Length / column_count);
|
||||
rowCount = (years.Length + column_count - 1) / column_count;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
RowDimensions = getRowDimensions();
|
||||
ColumnDimensions = getColumnDimensions();
|
||||
RowDimensions = Enumerable.Range(0, rowCount).Select(_ => new Dimension(GridSizeMode.AutoSize)).ToArray();
|
||||
Content = createContent(years, currentYear);
|
||||
}
|
||||
|
||||
private Dimension[] getRowDimensions()
|
||||
{
|
||||
var rowDimensions = new Dimension[rowCount];
|
||||
for (int i = 0; i < rowCount; i++)
|
||||
rowDimensions[i] = new Dimension(GridSizeMode.AutoSize);
|
||||
|
||||
return rowDimensions;
|
||||
}
|
||||
|
||||
private Dimension[] getColumnDimensions()
|
||||
{
|
||||
var columnDimensions = new Dimension[column_count];
|
||||
for (int i = 0; i < column_count; i++)
|
||||
columnDimensions[i] = new Dimension(GridSizeMode.Relative, size: 1f / column_count);
|
||||
|
||||
return columnDimensions;
|
||||
}
|
||||
|
||||
private Drawable[][] createContent(int[] years, int currentYear)
|
||||
{
|
||||
var buttons = new Drawable[rowCount][];
|
||||
@ -153,19 +134,7 @@ namespace osu.Game.Overlays.News.Sidebar
|
||||
var year = years[index];
|
||||
var isCurrent = year == currentYear;
|
||||
|
||||
buttons[i][j] = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Padding = new MarginPadding
|
||||
{
|
||||
Top = i == 0 ? 0 : spacing / 2,
|
||||
Bottom = i == rowCount - 1 ? 0 : spacing / 2,
|
||||
Left = j == 0 ? 0 : spacing / 2,
|
||||
Right = j == column_count - 1 ? 0 : spacing / 2
|
||||
},
|
||||
Child = new YearButton(year, isCurrent)
|
||||
};
|
||||
buttons[i][j] = new YearButton(year, isCurrent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user