From 840ba9f48efa82f31018e2042a72f2608561cf8a Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Sat, 21 Oct 2017 16:05:37 +1030 Subject: [PATCH] Allow the default indicator colour to be specified, and fix bug where disabled bindables could be reset --- osu.Game/Overlays/Settings/SettingsItem.cs | 43 ++++++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/osu.Game/Overlays/Settings/SettingsItem.cs b/osu.Game/Overlays/Settings/SettingsItem.cs index c98b2f1ee9..01b76605e0 100644 --- a/osu.Game/Overlays/Settings/SettingsItem.cs +++ b/osu.Game/Overlays/Settings/SettingsItem.cs @@ -36,6 +36,18 @@ namespace osu.Game.Overlays.Settings public bool ShowsDefaultIndicator = true; + private Color4? defaultIndicatorColour; + + public Color4 DefaultIndicatorColour + { + get { return defaultIndicatorColour ?? Color4.White; } + set + { + defaultIndicatorColour = value; + defaultIndicator?.SetIndicatorColour(DefaultIndicatorColour); + } + } + public virtual string LabelText { get { return text?.Text ?? string.Empty; } @@ -112,8 +124,9 @@ namespace osu.Game.Overlays.Settings if (defaultIndicator != null) { - defaultIndicator.Colour = ColourInfo.GradientHorizontal(colours.Yellow.Opacity(0.8f), colours.Yellow.Opacity(0)); - defaultIndicator.Alpha = 0f; + if (!defaultIndicatorColour.HasValue) + defaultIndicatorColour = colours.Yellow; + defaultIndicator.SetIndicatorColour(DefaultIndicatorColour); AddInternal(defaultIndicator); } } @@ -122,11 +135,14 @@ namespace osu.Game.Overlays.Settings { internal readonly Bindable Bindable = new Bindable(); + private Color4 indicatorColour; + private bool hovering; public SettingsItemDefaultIndicator() { - Bindable.ValueChanged += value => updateAlpha(); + Bindable.ValueChanged += value => UpdateState(); + Bindable.DisabledChanged += disabled => UpdateState(); RelativeSizeAxes = Axes.Y; Width = SettingsOverlay.CONTENT_MARGINS; @@ -141,25 +157,36 @@ namespace osu.Game.Overlays.Settings protected override bool OnClick(InputState state) { - Bindable.SetDefault(); + if (!Bindable.Disabled) + Bindable.SetDefault(); return true; } protected override bool OnHover(InputState state) { hovering = true; - updateAlpha(); + UpdateState(); return true; } protected override void OnHoverLost(InputState state) { hovering = false; - updateAlpha(); + UpdateState(); } - private void updateAlpha() => - Alpha = Bindable.IsDefault ? 0f : hovering ? 1f : 0.5f; + internal void SetIndicatorColour(Color4 indicatorColour) + { + this.indicatorColour = indicatorColour; + UpdateState(); + } + + internal void UpdateState() + { + var colour = Bindable.Disabled ? Color4.Gray : indicatorColour; + Alpha = Bindable.IsDefault ? 0f : (hovering && !Bindable.Disabled) ? 1f : 0.5f; + Colour = ColourInfo.GradientHorizontal(colour.Opacity(0.8f), colour.Opacity(0)); + } } } }