mirror of
https://github.com/ppy/osu
synced 2025-03-05 10:58:34 +00:00
Rename indicator class, add colour/fade easing, and add tooltip
This commit is contained in:
parent
448ff3bf38
commit
2e6a68d358
@ -9,6 +9,7 @@ using osu.Framework.Extensions.Color4Extensions;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Colour;
|
using osu.Framework.Graphics.Colour;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Cursor;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
@ -32,19 +33,19 @@ namespace osu.Game.Overlays.Settings
|
|||||||
|
|
||||||
private SpriteText text;
|
private SpriteText text;
|
||||||
|
|
||||||
private readonly SettingsItemDefaultIndicator<T> defaultIndicator = new SettingsItemDefaultIndicator<T>();
|
private readonly RestoreDefaultValueButton<T> restoreDefaultValueButton = new RestoreDefaultValueButton<T>();
|
||||||
|
|
||||||
public bool ShowsDefaultIndicator = true;
|
public bool ShowsDefaultIndicator = true;
|
||||||
|
|
||||||
private Color4? defaultIndicatorColour;
|
private Color4? restoreDefaultValueColour;
|
||||||
|
|
||||||
public Color4 DefaultIndicatorColour
|
public Color4 RestoreDefaultValueColour
|
||||||
{
|
{
|
||||||
get { return defaultIndicatorColour ?? Color4.White; }
|
get { return restoreDefaultValueColour ?? Color4.White; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
defaultIndicatorColour = value;
|
restoreDefaultValueColour = value;
|
||||||
defaultIndicator?.SetIndicatorColour(DefaultIndicatorColour);
|
restoreDefaultValueButton?.SetButtonColour(RestoreDefaultValueColour);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,8 +80,8 @@ namespace osu.Game.Overlays.Settings
|
|||||||
controlWithCurrent?.Current.BindTo(bindable);
|
controlWithCurrent?.Current.BindTo(bindable);
|
||||||
if (ShowsDefaultIndicator)
|
if (ShowsDefaultIndicator)
|
||||||
{
|
{
|
||||||
defaultIndicator.Bindable.BindTo(bindable);
|
restoreDefaultValueButton.Bindable.BindTo(bindable);
|
||||||
defaultIndicator.Bindable.TriggerChange();
|
restoreDefaultValueButton.Bindable.TriggerChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,24 +123,24 @@ namespace osu.Game.Overlays.Settings
|
|||||||
{
|
{
|
||||||
AddInternal(FlowContent);
|
AddInternal(FlowContent);
|
||||||
|
|
||||||
if (defaultIndicator != null)
|
if (restoreDefaultValueButton != null)
|
||||||
{
|
{
|
||||||
if (!defaultIndicatorColour.HasValue)
|
if (!restoreDefaultValueColour.HasValue)
|
||||||
defaultIndicatorColour = colours.Yellow;
|
restoreDefaultValueColour = colours.Yellow;
|
||||||
defaultIndicator.SetIndicatorColour(DefaultIndicatorColour);
|
restoreDefaultValueButton.SetButtonColour(RestoreDefaultValueColour);
|
||||||
AddInternal(defaultIndicator);
|
AddInternal(restoreDefaultValueButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SettingsItemDefaultIndicator<T> : Box
|
private class RestoreDefaultValueButton<T> : Box, IHasTooltip
|
||||||
{
|
{
|
||||||
internal readonly Bindable<T> Bindable = new Bindable<T>();
|
internal readonly Bindable<T> Bindable = new Bindable<T>();
|
||||||
|
|
||||||
private Color4 indicatorColour;
|
private Color4 buttonColour;
|
||||||
|
|
||||||
private bool hovering;
|
private bool hovering;
|
||||||
|
|
||||||
public SettingsItemDefaultIndicator()
|
public RestoreDefaultValueButton()
|
||||||
{
|
{
|
||||||
Bindable.ValueChanged += value => UpdateState();
|
Bindable.ValueChanged += value => UpdateState();
|
||||||
Bindable.DisabledChanged += disabled => UpdateState();
|
Bindable.DisabledChanged += disabled => UpdateState();
|
||||||
@ -149,6 +150,8 @@ namespace osu.Game.Overlays.Settings
|
|||||||
Alpha = 0f;
|
Alpha = 0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string TooltipText => "Revert to default";
|
||||||
|
|
||||||
public override bool HandleInput => true;
|
public override bool HandleInput => true;
|
||||||
|
|
||||||
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true;
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true;
|
||||||
@ -175,17 +178,17 @@ namespace osu.Game.Overlays.Settings
|
|||||||
UpdateState();
|
UpdateState();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void SetIndicatorColour(Color4 indicatorColour)
|
internal void SetButtonColour(Color4 buttonColour)
|
||||||
{
|
{
|
||||||
this.indicatorColour = indicatorColour;
|
this.buttonColour = buttonColour;
|
||||||
UpdateState();
|
UpdateState();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void UpdateState()
|
internal void UpdateState()
|
||||||
{
|
{
|
||||||
var colour = Bindable.Disabled ? Color4.Gray : indicatorColour;
|
var colour = Bindable.Disabled ? Color4.Gray : buttonColour;
|
||||||
Alpha = Bindable.IsDefault ? 0f : hovering && !Bindable.Disabled ? 1f : 0.5f;
|
this.FadeTo(Bindable.IsDefault ? 0f : hovering && !Bindable.Disabled ? 1f : 0.5f, 200, Easing.OutQuint);
|
||||||
Colour = ColourInfo.GradientHorizontal(colour.Opacity(0.8f), colour.Opacity(0));
|
this.FadeColour(ColourInfo.GradientHorizontal(colour.Opacity(0.8f), colour.Opacity(0)), 200, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user