2021-05-10 12:43:01 +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.
|
|
|
|
|
|
2021-05-17 15:24:43 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-05-10 12:43:01 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2021-05-17 15:24:43 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2021-05-10 12:43:01 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2021-05-17 15:24:43 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-05-10 12:43:01 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2021-05-17 15:24:43 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2021-05-10 12:43:01 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2021-05-11 20:33:27 +08:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-05-13 21:16:19 +08:00
|
|
|
|
using osuTK.Graphics;
|
2021-05-10 12:43:01 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.News.Sidebar
|
|
|
|
|
{
|
|
|
|
|
public class YearsPanel : CompositeDrawable
|
|
|
|
|
{
|
2021-05-11 20:33:27 +08:00
|
|
|
|
private readonly Bindable<APINewsSidebar> metadata = new Bindable<APINewsSidebar>();
|
2021-05-10 12:43:01 +08:00
|
|
|
|
|
2021-05-17 15:11:46 +08:00
|
|
|
|
private Container gridContent;
|
2021-05-10 12:43:01 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-05-11 20:33:27 +08:00
|
|
|
|
private void load(OverlayColourProvider colourProvider, Bindable<APINewsSidebar> metadata)
|
2021-05-10 12:43:01 +08:00
|
|
|
|
{
|
2021-05-11 20:33:27 +08:00
|
|
|
|
this.metadata.BindTo(metadata);
|
|
|
|
|
|
2021-05-10 12:43:01 +08:00
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2021-05-12 04:43:01 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2021-05-10 12:43:01 +08:00
|
|
|
|
Masking = true;
|
|
|
|
|
CornerRadius = 6;
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = colourProvider.Background3
|
|
|
|
|
},
|
2021-05-17 15:11:46 +08:00
|
|
|
|
gridContent = new Container
|
2021-05-10 12:43:01 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2021-05-12 04:43:01 +08:00
|
|
|
|
Padding = new MarginPadding(5)
|
2021-05-10 12:43:01 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2021-05-11 20:33:27 +08:00
|
|
|
|
metadata.BindValueChanged(m =>
|
2021-05-10 12:43:01 +08:00
|
|
|
|
{
|
2021-05-11 20:33:27 +08:00
|
|
|
|
if (m.NewValue == null)
|
2021-05-10 12:43:01 +08:00
|
|
|
|
{
|
2021-05-11 20:33:27 +08:00
|
|
|
|
Hide();
|
|
|
|
|
return;
|
2021-05-10 12:43:01 +08:00
|
|
|
|
}
|
2021-05-11 20:33:27 +08:00
|
|
|
|
|
2021-05-17 15:11:46 +08:00
|
|
|
|
gridContent.Child = new YearsGridContainer(m.NewValue.Years, m.NewValue.CurrentYear);
|
2021-05-11 20:33:27 +08:00
|
|
|
|
Show();
|
2021-05-10 12:43:01 +08:00
|
|
|
|
}, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class YearButton : OsuHoverContainer
|
|
|
|
|
{
|
|
|
|
|
protected override IEnumerable<Drawable> EffectTargets => new[] { text };
|
|
|
|
|
|
|
|
|
|
private readonly OsuSpriteText text;
|
2021-05-13 21:16:19 +08:00
|
|
|
|
private readonly bool isCurrent;
|
2021-05-10 12:43:01 +08:00
|
|
|
|
|
2021-05-13 21:16:19 +08:00
|
|
|
|
public YearButton(int year, bool isCurrent)
|
2021-05-10 12:43:01 +08:00
|
|
|
|
{
|
2021-05-13 21:16:19 +08:00
|
|
|
|
this.isCurrent = isCurrent;
|
|
|
|
|
|
2021-05-12 04:43:01 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
Height = 15;
|
2021-05-17 15:24:43 +08:00
|
|
|
|
Padding = new MarginPadding { Vertical = 2.5f };
|
2021-05-17 15:11:46 +08:00
|
|
|
|
|
2021-05-10 12:43:01 +08:00
|
|
|
|
Child = text = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2021-05-13 21:16:19 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: 12, weight: isCurrent ? FontWeight.SemiBold : FontWeight.Medium),
|
2021-05-10 12:43:01 +08:00
|
|
|
|
Text = year.ToString()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
|
{
|
2021-05-13 21:16:19 +08:00
|
|
|
|
IdleColour = isCurrent ? Color4.White : colourProvider.Light2;
|
|
|
|
|
HoverColour = isCurrent ? Color4.White : colourProvider.Light1;
|
2021-05-11 20:56:50 +08:00
|
|
|
|
Action = () => { }; // Avoid button being disabled since there's no proper action assigned.
|
2021-05-10 12:43:01 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-12 04:43:01 +08:00
|
|
|
|
|
|
|
|
|
private class YearsGridContainer : GridContainer
|
|
|
|
|
{
|
|
|
|
|
private const int column_count = 4;
|
|
|
|
|
|
|
|
|
|
private readonly int rowCount;
|
|
|
|
|
|
2021-05-13 21:16:19 +08:00
|
|
|
|
public YearsGridContainer(int[] years, int currentYear)
|
2021-05-12 04:43:01 +08:00
|
|
|
|
{
|
2021-05-17 15:24:43 +08:00
|
|
|
|
rowCount = (years.Length + column_count - 1) / column_count;
|
2021-05-12 04:43:01 +08:00
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2021-05-17 15:24:43 +08:00
|
|
|
|
RowDimensions = Enumerable.Range(0, rowCount).Select(_ => new Dimension(GridSizeMode.AutoSize)).ToArray();
|
2021-05-13 21:16:19 +08:00
|
|
|
|
Content = createContent(years, currentYear);
|
2021-05-12 04:43:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-13 21:16:19 +08:00
|
|
|
|
private Drawable[][] createContent(int[] years, int currentYear)
|
2021-05-12 04:43:01 +08:00
|
|
|
|
{
|
|
|
|
|
var buttons = new Drawable[rowCount][];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < rowCount; i++)
|
|
|
|
|
{
|
|
|
|
|
buttons[i] = new Drawable[column_count];
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < column_count; j++)
|
|
|
|
|
{
|
|
|
|
|
var index = i * column_count + j;
|
2021-05-13 21:16:19 +08:00
|
|
|
|
|
|
|
|
|
if (index >= years.Length)
|
|
|
|
|
{
|
|
|
|
|
buttons[i][j] = Empty();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var year = years[index];
|
|
|
|
|
var isCurrent = year == currentYear;
|
|
|
|
|
|
2021-05-17 15:24:43 +08:00
|
|
|
|
buttons[i][j] = new YearButton(year, isCurrent);
|
2021-05-13 21:16:19 +08:00
|
|
|
|
}
|
2021-05-12 04:43:01 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buttons;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-10 12:43:01 +08:00
|
|
|
|
}
|
|
|
|
|
}
|