2017-02-07 13:59:30 +09:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-12-06 18:56:20 +09:00
|
|
|
|
|
2016-12-05 19:45:54 +09:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2016-11-07 19:04:31 -05:00
|
|
|
|
using osu.Framework.Configuration;
|
2016-11-15 19:34:20 +09:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2016-11-07 19:04:31 -05:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2017-01-31 18:37:11 +09:00
|
|
|
|
using osu.Framework.Input;
|
2017-01-31 18:53:52 +09:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2016-11-15 19:34:20 +09:00
|
|
|
|
using OpenTK.Graphics;
|
2016-11-07 19:04:31 -05:00
|
|
|
|
|
2017-01-31 18:37:11 +09:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
2016-11-09 20:13:13 +09:00
|
|
|
|
{
|
2017-03-31 17:38:33 +09:00
|
|
|
|
public class OsuCheckbox : Checkbox
|
2016-11-09 20:13:13 +09:00
|
|
|
|
{
|
|
|
|
|
private Bindable<bool> bindable;
|
|
|
|
|
|
|
|
|
|
public Bindable<bool> Bindable
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
bindable = value;
|
2017-04-10 17:10:15 +09:00
|
|
|
|
Current.BindTo(bindable);
|
2016-11-09 20:13:13 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 19:34:20 +09:00
|
|
|
|
public Color4 CheckedColor { get; set; } = Color4.Cyan;
|
|
|
|
|
public Color4 UncheckedColor { get; set; } = Color4.White;
|
|
|
|
|
public int FadeDuration { get; set; }
|
|
|
|
|
|
|
|
|
|
public string LabelText
|
|
|
|
|
{
|
|
|
|
|
get { return labelSpriteText?.Text; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (labelSpriteText != null)
|
|
|
|
|
labelSpriteText.Text = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MarginPadding LabelPadding
|
|
|
|
|
{
|
|
|
|
|
get { return labelSpriteText?.Padding ?? new MarginPadding(); }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (labelSpriteText != null)
|
|
|
|
|
labelSpriteText.Padding = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 16:40:35 +09:00
|
|
|
|
protected readonly Nub Nub;
|
|
|
|
|
|
2017-03-23 13:41:50 +09:00
|
|
|
|
private readonly SpriteText labelSpriteText;
|
2017-02-18 17:35:04 +09:00
|
|
|
|
private SampleChannel sampleChecked;
|
|
|
|
|
private SampleChannel sampleUnchecked;
|
2016-11-15 19:34:20 +09:00
|
|
|
|
|
2017-01-31 18:37:11 +09:00
|
|
|
|
public OsuCheckbox()
|
2016-11-15 19:34:20 +09:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-01-31 18:53:52 +09:00
|
|
|
|
labelSpriteText = new OsuSpriteText(),
|
2017-05-30 16:40:35 +09:00
|
|
|
|
Nub = new Nub
|
2016-11-15 19:34:20 +09:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Margin = new MarginPadding { Right = 5 },
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-30 16:40:35 +09:00
|
|
|
|
Nub.Current.BindTo(Current);
|
2017-04-10 17:10:15 +09:00
|
|
|
|
|
2017-04-10 14:31:08 +09:00
|
|
|
|
Current.ValueChanged += newValue =>
|
|
|
|
|
{
|
|
|
|
|
if (newValue)
|
|
|
|
|
sampleChecked?.Play();
|
|
|
|
|
else
|
|
|
|
|
sampleUnchecked?.Play();
|
|
|
|
|
};
|
2017-04-21 13:53:11 +09:00
|
|
|
|
|
|
|
|
|
Current.DisabledChanged += disabled =>
|
|
|
|
|
{
|
|
|
|
|
Alpha = disabled ? 0.3f : 1;
|
|
|
|
|
};
|
2016-11-09 20:13:13 +09:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 19:34:20 +09:00
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
2017-05-30 16:40:35 +09:00
|
|
|
|
Nub.Glowing = true;
|
|
|
|
|
Nub.Expanded = true;
|
2016-11-15 19:34:20 +09:00
|
|
|
|
return base.OnHover(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
2017-05-30 16:40:35 +09:00
|
|
|
|
Nub.Glowing = false;
|
|
|
|
|
Nub.Expanded = false;
|
2016-11-15 19:34:20 +09:00
|
|
|
|
base.OnHoverLost(state);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-05 19:45:54 +09:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
|
{
|
|
|
|
|
sampleChecked = audio.Sample.Get(@"Checkbox/check-on");
|
|
|
|
|
sampleUnchecked = audio.Sample.Get(@"Checkbox/check-off");
|
|
|
|
|
}
|
2016-11-09 20:13:13 +09:00
|
|
|
|
}
|
|
|
|
|
}
|