2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2017-03-23 11:22:31 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2021-06-18 20:00:08 +08:00
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2017-03-23 11:22:31 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-03-23 11:22:31 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2021-02-22 16:14:00 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-23 11:22:31 +08:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-03-31 16:38:33 +08:00
|
|
|
|
/// A Checkbox styled to be placed in line with an <see cref="OsuTabControl{T}"/>
|
2017-03-23 11:22:31 +08:00
|
|
|
|
/// </summary>
|
2017-03-31 16:38:33 +08:00
|
|
|
|
public partial class OsuTabControlCheckbox : Checkbox
|
2017-03-23 11:22:31 +08:00
|
|
|
|
{
|
2017-03-23 13:47:27 +08:00
|
|
|
|
private readonly Box box;
|
|
|
|
|
private readonly SpriteText text;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-23 11:29:28 +08:00
|
|
|
|
private Color4? accentColour;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2017-03-23 11:22:31 +08:00
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => accentColour.GetValueOrDefault();
|
2017-03-23 11:22:31 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
accentColour = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-07-05 04:24:13 +08:00
|
|
|
|
updateFade();
|
2017-03-23 11:22:31 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-02-22 16:14:00 +08:00
|
|
|
|
public LocalisableString Text
|
2017-03-23 11:22:31 +08:00
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => text.Text;
|
|
|
|
|
set => text.Text = value;
|
2017-03-23 11:22:31 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-23 11:29:28 +08:00
|
|
|
|
private const float transition_length = 500;
|
2021-06-18 20:00:08 +08:00
|
|
|
|
private Sample sampleChecked;
|
|
|
|
|
private Sample sampleUnchecked;
|
2023-05-03 13:33:30 +08:00
|
|
|
|
private readonly SpriteIcon icon;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-31 16:38:33 +08:00
|
|
|
|
public OsuTabControlCheckbox()
|
2017-03-23 11:22:31 +08:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-23 11:22:31 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Margin = new MarginPadding { Top = 5, Bottom = 5, },
|
|
|
|
|
Spacing = new Vector2(5f, 0f),
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2019-07-26 14:10:00 +08:00
|
|
|
|
text = new OsuSpriteText { Font = OsuFont.GetFont(size: 14) },
|
2017-08-03 13:36:21 +08:00
|
|
|
|
icon = new SpriteIcon
|
2017-03-23 11:22:31 +08:00
|
|
|
|
{
|
2017-08-03 13:36:21 +08:00
|
|
|
|
Size = new Vector2(14),
|
2019-04-02 18:55:24 +08:00
|
|
|
|
Icon = FontAwesome.Regular.Circle,
|
2017-03-23 11:22:31 +08:00
|
|
|
|
Shadow = true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
box = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 1,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2021-06-18 20:00:08 +08:00
|
|
|
|
}
|
2017-03-23 11:22:31 +08:00
|
|
|
|
};
|
2019-07-05 09:07:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-06-18 20:00:08 +08:00
|
|
|
|
private void load(OsuColour colours, AudioManager audio)
|
2019-07-05 09:07:45 +08:00
|
|
|
|
{
|
|
|
|
|
if (accentColour == null)
|
|
|
|
|
AccentColour = colours.Blue;
|
2021-06-18 20:00:08 +08:00
|
|
|
|
|
|
|
|
|
sampleChecked = audio.Samples.Get(@"UI/check-on");
|
|
|
|
|
sampleUnchecked = audio.Samples.Get(@"UI/check-off");
|
2023-05-03 15:26:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2023-05-03 13:33:30 +08:00
|
|
|
|
|
2023-05-03 15:26:54 +08:00
|
|
|
|
Current.BindValueChanged(selected =>
|
2023-05-03 13:33:30 +08:00
|
|
|
|
{
|
|
|
|
|
icon.Icon = selected.NewValue ? FontAwesome.Regular.CheckCircle : FontAwesome.Regular.Circle;
|
|
|
|
|
text.Font = text.Font.With(weight: selected.NewValue ? FontWeight.Bold : FontWeight.Medium);
|
|
|
|
|
|
|
|
|
|
updateFade();
|
2023-05-03 15:26:54 +08:00
|
|
|
|
});
|
2019-07-05 09:07:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
|
{
|
|
|
|
|
updateFade();
|
|
|
|
|
return base.OnHover(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
|
{
|
|
|
|
|
if (!Current.Value)
|
|
|
|
|
updateFade();
|
|
|
|
|
|
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-18 20:00:08 +08:00
|
|
|
|
protected override void OnUserChange(bool value)
|
|
|
|
|
{
|
|
|
|
|
base.OnUserChange(value);
|
|
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
|
sampleChecked?.Play();
|
|
|
|
|
else
|
|
|
|
|
sampleUnchecked?.Play();
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-05 09:07:45 +08:00
|
|
|
|
private void updateFade()
|
|
|
|
|
{
|
2020-07-12 09:27:47 +08:00
|
|
|
|
box.FadeTo(Current.Value || IsHovered ? 1 : 0, transition_length, Easing.OutQuint);
|
|
|
|
|
text.FadeColour(Current.Value || IsHovered ? Color4.White : AccentColour, transition_length, Easing.OutQuint);
|
2017-03-23 11:22:31 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|