1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 04:07:24 +08:00
osu-lazer/osu.Game/Overlays/Options/CheckBoxOption.cs

55 lines
1.6 KiB
C#
Raw Normal View History

2016-11-09 19:13:13 +08:00
using System;
using osu.Framework.Configuration;
using osu.Framework.Graphics.UserInterface;
2016-11-09 19:13:13 +08:00
namespace osu.Game.Overlays.Options
{
public class CheckBoxOption : BasicCheckBox
{
private Bindable<bool> bindable;
public Bindable<bool> Bindable
{
set
{
if (bindable != null)
bindable.ValueChanged -= bindableValueChanged;
bindable = value;
if (bindable != null)
{
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;
}
}
}
private void bindableValueChanged(object sender, EventArgs e)
{
State = bindable.Value ? CheckBoxState.Checked : CheckBoxState.Unchecked;
}
2016-11-09 19:13:13 +08:00
protected override void Dispose(bool isDisposing)
2016-11-09 19:13:13 +08:00
{
if (bindable != null)
bindable.ValueChanged -= bindableValueChanged;
base.Dispose(isDisposing);
2016-11-09 19:13:13 +08:00
}
protected override void OnChecked()
2016-11-09 19:13:13 +08:00
{
if (bindable != null)
bindable.Value = true;
base.OnChecked();
2016-11-09 19:13:13 +08:00
}
protected override void OnUnchecked()
{
if (bindable != null)
bindable.Value = false;
base.OnUnchecked();
}
}
}