2016-11-09 19:13:13 +08:00
|
|
|
|
using System;
|
2016-11-15 18:34:20 +08:00
|
|
|
|
using osu.Framework;
|
2016-11-08 08:04:31 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
2016-11-15 18:34:20 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Transformations;
|
2016-11-08 08:04:31 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2016-11-15 18:34:20 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
using osu.Framework.Input;
|
2016-11-08 08:04:31 +08:00
|
|
|
|
|
2016-11-09 19:13:13 +08:00
|
|
|
|
namespace osu.Game.Overlays.Options
|
|
|
|
|
{
|
2016-11-15 18:34:20 +08:00
|
|
|
|
public class CheckBoxOption : CheckBox
|
2016-11-09 19:13:13 +08:00
|
|
|
|
{
|
|
|
|
|
private Bindable<bool> bindable;
|
|
|
|
|
|
|
|
|
|
public Bindable<bool> Bindable
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (bindable != null)
|
|
|
|
|
bindable.ValueChanged -= bindableValueChanged;
|
|
|
|
|
bindable = value;
|
|
|
|
|
if (bindable != null)
|
2016-11-08 08:04:31 +08:00
|
|
|
|
{
|
|
|
|
|
bool state = State == CheckBoxState.Checked;
|
|
|
|
|
if (state != bindable.Value)
|
|
|
|
|
State = bindable.Value ? CheckBoxState.Checked : CheckBoxState.Unchecked;
|
2016-11-09 19:13:13 +08:00
|
|
|
|
bindable.ValueChanged += bindableValueChanged;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 18:34:20 +08: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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Light light;
|
|
|
|
|
private SpriteText labelSpriteText;
|
|
|
|
|
|
|
|
|
|
public CheckBoxOption()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
labelSpriteText = new SpriteText(),
|
|
|
|
|
light = new Light()
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Margin = new MarginPadding { Right = 5 },
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-09 19:13:13 +08:00
|
|
|
|
private void bindableValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
State = bindable.Value ? CheckBoxState.Checked : CheckBoxState.Unchecked;
|
2016-11-08 08:04:31 +08:00
|
|
|
|
}
|
2016-11-09 19:13:13 +08:00
|
|
|
|
|
2016-11-08 08:04:31 +08:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
2016-11-09 19:13:13 +08:00
|
|
|
|
{
|
|
|
|
|
if (bindable != null)
|
2016-11-08 08:04:31 +08:00
|
|
|
|
bindable.ValueChanged -= bindableValueChanged;
|
|
|
|
|
base.Dispose(isDisposing);
|
2016-11-09 19:13:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 18:34:20 +08:00
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
2016-11-16 01:46:48 +08:00
|
|
|
|
light.Glowing = true;
|
2016-11-15 18:34:20 +08:00
|
|
|
|
return base.OnHover(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
2016-11-16 01:46:48 +08:00
|
|
|
|
light.Glowing = false;
|
2016-11-15 18:34:20 +08:00
|
|
|
|
base.OnHoverLost(state);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 08:04:31 +08:00
|
|
|
|
protected override void OnChecked()
|
2016-11-09 19:13:13 +08:00
|
|
|
|
{
|
|
|
|
|
if (bindable != null)
|
2016-11-08 08:04:31 +08:00
|
|
|
|
bindable.Value = true;
|
2016-11-15 18:34:20 +08:00
|
|
|
|
|
|
|
|
|
light.State = CheckBoxState.Checked;
|
2016-11-09 19:13:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnUnchecked()
|
|
|
|
|
{
|
|
|
|
|
if (bindable != null)
|
|
|
|
|
bindable.Value = false;
|
2016-11-15 18:34:20 +08:00
|
|
|
|
|
|
|
|
|
light.State = CheckBoxState.Unchecked;
|
2016-11-09 19:13:13 +08:00
|
|
|
|
}
|
2016-11-15 18:34:20 +08:00
|
|
|
|
|
|
|
|
|
private class Light : Container, IStateful<CheckBoxState>
|
|
|
|
|
{
|
|
|
|
|
private Box fill;
|
|
|
|
|
|
|
|
|
|
const float border_width = 3;
|
|
|
|
|
|
|
|
|
|
Color4 hoverColour = new Color4(255, 221, 238, 255);
|
|
|
|
|
Color4 defaultColour = new Color4(255, 102, 170, 255);
|
|
|
|
|
Color4 glowColour = new Color4(187, 17, 119, 0);
|
|
|
|
|
|
|
|
|
|
public Light()
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(40, 12);
|
|
|
|
|
|
|
|
|
|
Masking = true;
|
|
|
|
|
|
|
|
|
|
Colour = defaultColour;
|
|
|
|
|
|
|
|
|
|
EdgeEffect = new EdgeEffect
|
|
|
|
|
{
|
|
|
|
|
Colour = glowColour,
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
|
Radius = 10,
|
|
|
|
|
Roundness = 8,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CornerRadius = Height / 2;
|
|
|
|
|
Masking = true;
|
|
|
|
|
BorderColour = Color4.White;
|
|
|
|
|
BorderThickness = border_width;
|
|
|
|
|
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
fill = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = 0.01f, //todo: remove once we figure why containers aren't drawing at all times
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-16 01:46:48 +08:00
|
|
|
|
public bool Glowing
|
2016-11-15 18:34:20 +08:00
|
|
|
|
{
|
2016-11-16 01:46:48 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value)
|
|
|
|
|
{
|
|
|
|
|
FadeColour(hoverColour, 500, EasingTypes.OutQuint);
|
|
|
|
|
FadeGlowTo(1, 500, EasingTypes.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FadeGlowTo(0, 500);
|
|
|
|
|
FadeColour(defaultColour, 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-15 18:34:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CheckBoxState state;
|
|
|
|
|
|
|
|
|
|
public CheckBoxState State
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
state = value;
|
|
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case CheckBoxState.Checked:
|
|
|
|
|
fill.FadeIn(200, EasingTypes.OutQuint);
|
|
|
|
|
break;
|
|
|
|
|
case CheckBoxState.Unchecked:
|
|
|
|
|
fill.FadeTo(0.01f, 200, EasingTypes.OutQuint); //todo: remove once we figure why containers aren't drawing at all times
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-09 19:13:13 +08:00
|
|
|
|
}
|
|
|
|
|
}
|