1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 14:29:36 +08:00
osu-lazer/osu.Game/Overlays/News/Sidebar/YearsPanel.cs

121 lines
3.6 KiB
C#
Raw Normal View History

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.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2021-05-10 12:43:01 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2021-05-10 12:43:01 +08:00
using osu.Framework.Graphics.Shapes;
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-17 16:17:02 +08:00
using osuTK;
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 16:17:02 +08:00
private FillFlowContainer yearsFlow;
2021-05-10 12:43:01 +08:00
[BackgroundDependencyLoader]
2021-05-19 14:45:24 +08:00
private void load(OverlayColourProvider overlayColours, 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;
RelativeSizeAxes = Axes.X;
2021-05-10 12:43:01 +08:00
Masking = true;
CornerRadius = 6;
InternalChildren = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
2021-05-19 14:45:24 +08:00
Colour = overlayColours.Background3
2021-05-10 12:43:01 +08:00
},
2021-05-17 16:17:02 +08:00
new Container
2021-05-10 12:43:01 +08:00
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
2021-05-17 16:17:02 +08:00
Padding = new MarginPadding(5),
Child = yearsFlow = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Spacing = new Vector2(0, 5)
}
2021-05-10 12:43:01 +08:00
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
metadata.BindValueChanged(_ => recreateDrawables(), true);
}
2021-05-17 16:17:02 +08:00
private void recreateDrawables()
{
yearsFlow.Clear();
if (metadata.Value == null)
{
Hide();
return;
}
2021-05-11 20:33:27 +08:00
int currentYear = metadata.Value.CurrentYear;
2021-05-17 16:17:02 +08:00
foreach (int y in metadata.Value.Years)
yearsFlow.Add(new YearButton(y, y == currentYear));
2021-05-17 16:17:02 +08:00
Show();
2021-05-10 12:43:01 +08:00
}
2021-05-17 16:36:53 +08:00
public class YearButton : OsuHoverContainer
2021-05-10 12:43:01 +08:00
{
2021-05-17 16:36:53 +08:00
public int Year { get; }
2021-05-19 20:38:53 +08:00
[Resolved(canBeNull: true)]
private NewsOverlay overlay { get; set; }
private readonly bool isCurrent;
2021-05-10 12:43:01 +08:00
public YearButton(int year, bool isCurrent)
2021-05-10 12:43:01 +08:00
{
2021-05-17 16:36:53 +08:00
Year = year;
this.isCurrent = isCurrent;
RelativeSizeAxes = Axes.X;
2021-05-17 16:17:02 +08:00
Width = 0.25f;
Height = 15;
2021-05-17 15:11:46 +08:00
2021-05-17 15:54:45 +08:00
Child = new OsuSpriteText
2021-05-10 12:43:01 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
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)
{
IdleColour = isCurrent ? Color4.White : colourProvider.Light2;
HoverColour = isCurrent ? Color4.White : colourProvider.Light1;
Action = () =>
{
if (!isCurrent)
overlay?.ShowYear(Year);
};
2021-05-10 12:43:01 +08:00
}
}
}
}