1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 09:32:55 +08:00

Fix SettingsItem bindable logic (#7080)

Fix SettingsItem bindable logic
This commit is contained in:
Dean Herbert 2019-12-10 18:49:16 +09:00 committed by GitHub
commit 33f946da3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -53,27 +53,10 @@ namespace osu.Game.Overlays.Settings
}
}
// hold a reference to the provided bindable so we don't have to in every settings section.
private Bindable<T> bindable;
public virtual Bindable<T> Bindable
{
get => bindable;
set
{
if (bindable != null)
controlWithCurrent?.Current.UnbindFrom(bindable);
bindable = value;
controlWithCurrent?.Current.BindTo(bindable);
if (ShowsDefaultIndicator)
{
restoreDefaultButton.Bindable = bindable.GetBoundCopy();
restoreDefaultButton.Bindable.TriggerChange();
}
}
get => controlWithCurrent.Current;
set => controlWithCurrent.Current = value;
}
public virtual IEnumerable<string> FilterTerms => Keywords == null ? new[] { LabelText } : new List<string>(Keywords) { LabelText }.ToArray();
@ -110,7 +93,12 @@ namespace osu.Game.Overlays.Settings
private void load()
{
if (controlWithCurrent != null)
{
controlWithCurrent.Current.DisabledChanged += disabled => { Colour = disabled ? Color4.Gray : Color4.White; };
if (ShowsDefaultIndicator)
restoreDefaultButton.Bindable = controlWithCurrent.Current;
}
}
private class RestoreDefaultValueButton : Container, IHasTooltip
@ -125,6 +113,7 @@ namespace osu.Game.Overlays.Settings
bindable = value;
bindable.ValueChanged += _ => UpdateState();
bindable.DisabledChanged += _ => UpdateState();
UpdateState();
}
}