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.
|
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
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-17 16:17:02 +08:00
|
|
|
|
using osuTK;
|
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 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;
|
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,
|
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();
|
|
|
|
|
|
2021-05-18 00:53:09 +08:00
|
|
|
|
metadata.BindValueChanged(_ => recreateDrawables(), true);
|
|
|
|
|
}
|
2021-05-17 16:17:02 +08:00
|
|
|
|
|
2021-05-18 00:53:09 +08:00
|
|
|
|
private void recreateDrawables()
|
|
|
|
|
{
|
|
|
|
|
yearsFlow.Clear();
|
|
|
|
|
|
|
|
|
|
if (metadata.Value == null)
|
|
|
|
|
{
|
|
|
|
|
Hide();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-05-11 20:33:27 +08:00
|
|
|
|
|
2021-10-27 12:04:41 +08:00
|
|
|
|
int currentYear = metadata.Value.CurrentYear;
|
2021-05-17 16:17:02 +08:00
|
|
|
|
|
2021-10-27 12:04:41 +08:00
|
|
|
|
foreach (int y in metadata.Value.Years)
|
2021-05-18 00:53:09 +08:00
|
|
|
|
yearsFlow.Add(new YearButton(y, y == currentYear));
|
2021-05-17 16:17:02 +08:00
|
|
|
|
|
2021-05-18 00:53:09 +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; }
|
|
|
|
|
|
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-17 16:36:53 +08:00
|
|
|
|
Year = year;
|
2021-05-13 21:16:19 +08:00
|
|
|
|
this.isCurrent = isCurrent;
|
|
|
|
|
|
2021-05-12 04:43:01 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2021-05-17 16:17:02 +08:00
|
|
|
|
Width = 0.25f;
|
2021-05-12 04:43:01 +08:00
|
|
|
|
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,
|
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-20 20:45:39 +08:00
|
|
|
|
Action = () =>
|
|
|
|
|
{
|
|
|
|
|
if (!isCurrent)
|
|
|
|
|
overlay?.ShowYear(Year);
|
|
|
|
|
};
|
2021-05-10 12:43:01 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|