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

Allow the default indicator colour to be specified, and fix bug where disabled bindables could be reset

This commit is contained in:
Shane Woolcock 2017-10-21 16:05:37 +10:30
parent b4d575fbcd
commit 840ba9f48e

View File

@ -36,6 +36,18 @@ namespace osu.Game.Overlays.Settings
public bool ShowsDefaultIndicator = true; 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 public virtual string LabelText
{ {
get { return text?.Text ?? string.Empty; } get { return text?.Text ?? string.Empty; }
@ -112,8 +124,9 @@ namespace osu.Game.Overlays.Settings
if (defaultIndicator != null) if (defaultIndicator != null)
{ {
defaultIndicator.Colour = ColourInfo.GradientHorizontal(colours.Yellow.Opacity(0.8f), colours.Yellow.Opacity(0)); if (!defaultIndicatorColour.HasValue)
defaultIndicator.Alpha = 0f; defaultIndicatorColour = colours.Yellow;
defaultIndicator.SetIndicatorColour(DefaultIndicatorColour);
AddInternal(defaultIndicator); AddInternal(defaultIndicator);
} }
} }
@ -122,11 +135,14 @@ namespace osu.Game.Overlays.Settings
{ {
internal readonly Bindable<T> Bindable = new Bindable<T>(); internal readonly Bindable<T> Bindable = new Bindable<T>();
private Color4 indicatorColour;
private bool hovering; private bool hovering;
public SettingsItemDefaultIndicator() public SettingsItemDefaultIndicator()
{ {
Bindable.ValueChanged += value => updateAlpha(); Bindable.ValueChanged += value => UpdateState();
Bindable.DisabledChanged += disabled => UpdateState();
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;
Width = SettingsOverlay.CONTENT_MARGINS; Width = SettingsOverlay.CONTENT_MARGINS;
@ -141,25 +157,36 @@ namespace osu.Game.Overlays.Settings
protected override bool OnClick(InputState state) protected override bool OnClick(InputState state)
{ {
Bindable.SetDefault(); if (!Bindable.Disabled)
Bindable.SetDefault();
return true; return true;
} }
protected override bool OnHover(InputState state) protected override bool OnHover(InputState state)
{ {
hovering = true; hovering = true;
updateAlpha(); UpdateState();
return true; return true;
} }
protected override void OnHoverLost(InputState state) protected override void OnHoverLost(InputState state)
{ {
hovering = false; hovering = false;
updateAlpha(); UpdateState();
} }
private void updateAlpha() => internal void SetIndicatorColour(Color4 indicatorColour)
Alpha = Bindable.IsDefault ? 0f : hovering ? 1f : 0.5f; {
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));
}
} }
} }
} }