1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-07 16:12:55 +08:00

Fix some pieces of SettingsItem getting dimmed twice when disabled

This commit is contained in:
Dean Herbert 2020-03-23 13:11:40 +09:00
parent aefd2fd847
commit 3a3df06e0b
2 changed files with 16 additions and 10 deletions

View File

@ -8,16 +8,14 @@ namespace osu.Game.Overlays.Settings
{ {
public class SettingsCheckbox : SettingsItem<bool> public class SettingsCheckbox : SettingsItem<bool>
{ {
private OsuCheckbox checkbox;
private string labelText; private string labelText;
protected override Drawable CreateControl() => checkbox = new OsuCheckbox(); protected override Drawable CreateControl() => new OsuCheckbox();
public override string LabelText public override string LabelText
{ {
get => labelText; get => labelText;
set => checkbox.LabelText = labelText = value; set => ((OsuCheckbox)Control).LabelText = labelText = value;
} }
} }
} }

View File

@ -33,22 +33,24 @@ namespace osu.Game.Overlays.Settings
protected readonly FillFlowContainer FlowContent; protected readonly FillFlowContainer FlowContent;
private SpriteText text; private SpriteText labelText;
public bool ShowsDefaultIndicator = true; public bool ShowsDefaultIndicator = true;
public virtual string LabelText public virtual string LabelText
{ {
get => text?.Text ?? string.Empty; get => labelText?.Text ?? string.Empty;
set set
{ {
if (text == null) if (labelText == null)
{ {
// construct lazily for cases where the label is not needed (may be provided by the Control). // construct lazily for cases where the label is not needed (may be provided by the Control).
FlowContent.Insert(-1, text = new OsuSpriteText()); FlowContent.Insert(-1, labelText = new OsuSpriteText());
updateDisabled();
} }
text.Text = value; labelText.Text = value;
} }
} }
@ -96,13 +98,19 @@ namespace osu.Game.Overlays.Settings
if (controlWithCurrent != null) if (controlWithCurrent != null)
{ {
controlWithCurrent.Current.ValueChanged += _ => SettingChanged?.Invoke(); controlWithCurrent.Current.ValueChanged += _ => SettingChanged?.Invoke();
controlWithCurrent.Current.DisabledChanged += disabled => { Colour = disabled ? Color4.Gray : Color4.White; }; controlWithCurrent.Current.DisabledChanged += _ => updateDisabled();
if (ShowsDefaultIndicator) if (ShowsDefaultIndicator)
restoreDefaultButton.Bindable = controlWithCurrent.Current; restoreDefaultButton.Bindable = controlWithCurrent.Current;
} }
} }
private void updateDisabled()
{
if (labelText != null)
labelText.Alpha = controlWithCurrent.Current.Disabled ? 0.3f : 1;
}
private class RestoreDefaultValueButton : Container, IHasTooltip private class RestoreDefaultValueButton : Container, IHasTooltip
{ {
private Bindable<T> bindable; private Bindable<T> bindable;