1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-24 16:07:25 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/PageSelector/PageSelectorPageButton.cs

71 lines
2.1 KiB
C#
Raw Normal View History

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