2019-01-24 08:43:03 +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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2019-06-09 07:47:48 +00:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
|
|
|
|
public class OsuCheckbox : Checkbox
|
|
|
|
|
{
|
|
|
|
|
public Color4 CheckedColor { get; set; } = Color4.Cyan;
|
|
|
|
|
public Color4 UncheckedColor { get; set; } = Color4.White;
|
|
|
|
|
public int FadeDuration { get; set; }
|
|
|
|
|
|
|
|
|
|
public string LabelText
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
2019-06-09 08:07:23 +00:00
|
|
|
|
if (labelText != null)
|
|
|
|
|
labelText.Text = value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MarginPadding LabelPadding
|
|
|
|
|
{
|
2019-06-09 08:07:23 +00:00
|
|
|
|
get => labelText?.Padding ?? new MarginPadding();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2019-06-09 08:07:23 +00:00
|
|
|
|
if (labelText != null)
|
|
|
|
|
labelText.Padding = value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected readonly Nub Nub;
|
|
|
|
|
|
2019-06-09 08:07:23 +00:00
|
|
|
|
private readonly OsuTextFlowContainer labelText;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private SampleChannel sampleChecked;
|
|
|
|
|
private SampleChannel sampleUnchecked;
|
|
|
|
|
|
|
|
|
|
public OsuCheckbox()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
|
2019-06-09 07:47:48 +00:00
|
|
|
|
const float nub_padding = 5;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2019-06-09 08:07:23 +00:00
|
|
|
|
labelText = new OsuTextFlowContainer
|
2019-06-09 07:47:48 +00:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Padding = new MarginPadding { Right = Nub.EXPANDED_SIZE + nub_padding }
|
|
|
|
|
},
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Nub = new Nub
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
2019-06-09 07:47:48 +00:00
|
|
|
|
Margin = new MarginPadding { Right = nub_padding },
|
2018-04-13 09:19:50 +00:00
|
|
|
|
},
|
|
|
|
|
new HoverClickSounds()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Nub.Current.BindTo(Current);
|
|
|
|
|
|
2019-06-11 09:24:50 +00:00
|
|
|
|
Current.DisabledChanged += disabled => labelText.Alpha = Nub.Alpha = disabled ? 0.3f : 1;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-15 05:09:30 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-08-15 05:09:30 +00:00
|
|
|
|
sampleChecked = audio.Samples.Get(@"UI/check-on");
|
|
|
|
|
sampleUnchecked = audio.Samples.Get(@"UI/check-off");
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
Nub.Glowing = true;
|
|
|
|
|
Nub.Expanded = true;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
return base.OnHover(e);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
Nub.Glowing = false;
|
|
|
|
|
Nub.Expanded = false;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
base.OnHoverLost(e);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-15 05:09:30 +00:00
|
|
|
|
protected override void OnUserChange(bool value)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-08-15 05:09:30 +00:00
|
|
|
|
base.OnUserChange(value);
|
|
|
|
|
if (value)
|
|
|
|
|
sampleChecked?.Play();
|
|
|
|
|
else
|
|
|
|
|
sampleUnchecked?.Play();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|