1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 16:42:53 +08:00
osu-lazer/osu.Game/Overlays/News/Sidebar/YearsPanel.cs

101 lines
3.1 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.Graphics.Containers;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osuTK;
using System.Linq;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using System.Collections.Generic;
using osu.Game.Graphics;
using osu.Framework.Bindables;
2021-05-11 20:33:27 +08:00
using osu.Game.Online.API.Requests.Responses;
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
private FillFlowContainer<YearButton> flow;
[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
Width = 160;
AutoSizeAxes = Axes.Y;
Masking = true;
CornerRadius = 6;
InternalChildren = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background3
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding(5),
Child = flow = new FillFlowContainer<YearButton>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Spacing = new Vector2(5)
}
}
};
}
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
flow.Children = m.NewValue.Years.Select(y => new YearButton(y)).ToArray();
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;
public YearButton(int year)
{
Size = new Vector2(33.75f, 15);
Child = text = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 12),
Text = year.ToString()
};
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
IdleColour = colourProvider.Light2;
HoverColour = colourProvider.Light1;
Action = () => { }; // Avoid button being disabled since there's no proper action assigned.
2021-05-10 12:43:01 +08:00
}
}
}
}