2020-01-04 16:36:05 +00: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 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2020-01-04 16:36:05 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface.PageSelector
|
|
|
|
|
{
|
2022-01-04 08:52:40 +00:00
|
|
|
|
public partial class PageSelectorPageButton : PageSelectorButton
|
2020-01-04 16:36:05 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly BindableBool selected = new BindableBool();
|
|
|
|
|
|
|
|
|
|
public bool Selected
|
|
|
|
|
{
|
|
|
|
|
set => selected.Value = value;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-04 09:46:44 +00:00
|
|
|
|
public int PageNumber { get; }
|
2020-01-04 16:36:05 +00:00
|
|
|
|
|
2020-01-04 18:14:56 +00:00
|
|
|
|
private OsuSpriteText text;
|
2020-01-04 16:36:05 +00:00
|
|
|
|
|
2022-01-04 09:46:44 +00:00
|
|
|
|
public PageSelectorPageButton(int pageNumber)
|
2020-01-04 16:36:05 +00:00
|
|
|
|
{
|
2022-01-04 09:46:44 +00:00
|
|
|
|
PageNumber = pageNumber;
|
2020-01-04 18:14:56 +00:00
|
|
|
|
|
|
|
|
|
Action = () =>
|
2020-01-04 16:36:05 +00:00
|
|
|
|
{
|
2020-01-04 18:14:56 +00:00
|
|
|
|
if (!selected.Value)
|
|
|
|
|
selected.Value = true;
|
2020-01-04 16:36:05 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-04 18:14:56 +00:00
|
|
|
|
protected override Drawable CreateContent() => text = new OsuSpriteText
|
|
|
|
|
{
|
2022-01-04 09:14:42 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold),
|
2022-01-04 09:46:44 +00:00
|
|
|
|
Text = PageNumber.ToString(),
|
2020-01-04 18:14:56 +00:00
|
|
|
|
};
|
|
|
|
|
|
2020-01-04 16:36:05 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
2022-01-04 09:14:42 +00:00
|
|
|
|
Background.Colour = ColourProvider.Highlight1;
|
2022-01-04 07:58:32 +00:00
|
|
|
|
Background.Alpha = 0;
|
2020-01-04 16:36:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
selected.BindValueChanged(onSelectedChanged, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onSelectedChanged(ValueChangedEvent<bool> selected)
|
|
|
|
|
{
|
2020-01-04 18:14:56 +00:00
|
|
|
|
Background.FadeTo(selected.NewValue ? 1 : 0, DURATION, Easing.OutQuint);
|
2022-01-04 09:19:23 +00:00
|
|
|
|
|
2022-01-04 09:14:42 +00:00
|
|
|
|
text.FadeColour(selected.NewValue ? ColourProvider.Dark4 : ColourProvider.Light3, DURATION, Easing.OutQuint);
|
2022-01-04 09:19:23 +00:00
|
|
|
|
text.Font = text.Font.With(weight: IsHovered ? FontWeight.SemiBold : FontWeight.Regular);
|
2020-01-04 16:36:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-04 18:14:56 +00:00
|
|
|
|
protected override void UpdateHoverState()
|
2020-01-04 16:36:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (selected.Value)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-01-04 09:14:42 +00:00
|
|
|
|
text.FadeColour(IsHovered ? ColourProvider.Light2 : ColourProvider.Light1, DURATION, Easing.OutQuint);
|
2020-01-04 16:36:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|