1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 20:03:21 +08:00

Fix checkbox not updating correctly.

This commit is contained in:
Dean Herbert 2016-11-09 20:13:13 +09:00 committed by GitHub
parent d6dafd6b70
commit 904d258dc3

View File

@ -1,53 +1,54 @@
using System; using System;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
namespace osu.Game.Overlays.Options namespace osu.Game.Overlays.Options
{ {
public class CheckBoxOption : BasicCheckBox public class CheckBoxOption : BasicCheckBox
{ {
private Bindable<bool> bindable; private Bindable<bool> bindable;
public Bindable<bool> Bindable public Bindable<bool> Bindable
{ {
set set
{ {
if (bindable != null) if (bindable != null)
bindable.ValueChanged -= bindableValueChanged; bindable.ValueChanged -= bindableValueChanged;
bindable = value; bindable = value;
if (bindable != null) if (bindable != null)
{ {
bool state = State == CheckBoxState.Checked; bool state = State == CheckBoxState.Checked;
if (state != bindable.Value) if (state != bindable.Value)
State = bindable.Value ? CheckBoxState.Checked : CheckBoxState.Unchecked; State = bindable.Value ? CheckBoxState.Checked : CheckBoxState.Unchecked;
bindable.ValueChanged += bindableValueChanged; bindable.ValueChanged += bindableValueChanged;
} }
} }
} }
private void bindableValueChanged(object sender, EventArgs e)
{ private void bindableValueChanged(object sender, EventArgs e)
State = bindable.Value ? CheckBoxState.Checked : CheckBoxState.Unchecked; {
} State = bindable.Value ? CheckBoxState.Checked : CheckBoxState.Unchecked;
}
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
if (bindable != null) if (bindable != null)
bindable.ValueChanged -= bindableValueChanged; bindable.ValueChanged -= bindableValueChanged;
base.Dispose(isDisposing); base.Dispose(isDisposing);
} }
protected override void OnChecked() protected override void OnChecked()
{ {
if (bindable != null) if (bindable != null)
bindable.Value = true; bindable.Value = true;
base.OnChecked(); base.OnChecked();
} }
protected override void OnUnchecked() protected override void OnUnchecked()
{ {
if (bindable != null) if (bindable != null)
bindable.Value = false; bindable.Value = false;
base.OnChecked(); base.OnUnchecked();
} }
} }
} }