2021-05-14 15:01:17 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2021-05-15 01:24:08 +00:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2021-05-14 15:01:17 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
|
using osu.Game.Graphics;
|
2021-05-24 11:34:47 +00:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-05-14 15:01:17 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
2021-05-24 11:34:47 +00:00
|
|
|
|
public class RestoreDefaultValueButton<T> : OsuButton, IHasTooltip, IHasCurrentValue<T>
|
2021-05-14 15:01:17 +00:00
|
|
|
|
{
|
|
|
|
|
public override bool IsPresent => base.IsPresent || Scheduler.HasPendingTasks;
|
|
|
|
|
|
2021-05-15 01:40:42 +00:00
|
|
|
|
private readonly BindableWithCurrent<T> current = new BindableWithCurrent<T>();
|
2021-05-14 15:01:17 +00:00
|
|
|
|
|
2021-05-15 01:24:08 +00:00
|
|
|
|
public Bindable<T> Current
|
2021-05-14 15:01:17 +00:00
|
|
|
|
{
|
2021-05-15 01:24:08 +00:00
|
|
|
|
get => current.Current;
|
2021-05-17 18:44:47 +00:00
|
|
|
|
set => current.Current = value;
|
2021-05-14 15:01:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 buttonColour;
|
|
|
|
|
|
|
|
|
|
private bool hovering;
|
|
|
|
|
|
|
|
|
|
public RestoreDefaultValueButton()
|
|
|
|
|
{
|
2021-05-24 11:34:47 +00:00
|
|
|
|
Height = 1;
|
|
|
|
|
|
2021-05-14 15:01:17 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
Width = SettingsPanel.CONTENT_MARGINS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colour)
|
|
|
|
|
{
|
2021-05-24 11:34:47 +00:00
|
|
|
|
BackgroundColour = colour.Yellow;
|
2021-05-14 15:01:17 +00:00
|
|
|
|
buttonColour = colour.Yellow;
|
2021-05-24 11:34:47 +00:00
|
|
|
|
Content.Width = 0.33f;
|
|
|
|
|
Content.CornerRadius = 3;
|
|
|
|
|
Content.EdgeEffect = new EdgeEffectParameters
|
2021-05-14 15:01:17 +00:00
|
|
|
|
{
|
2021-05-24 11:34:47 +00:00
|
|
|
|
Colour = buttonColour.Opacity(0.1f),
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
|
Radius = 2,
|
2021-05-14 15:01:17 +00:00
|
|
|
|
};
|
2021-05-24 11:34:47 +00:00
|
|
|
|
|
|
|
|
|
Padding = new MarginPadding { Vertical = 1.5f };
|
|
|
|
|
Alpha = 0f;
|
|
|
|
|
|
2021-05-24 12:08:34 +00:00
|
|
|
|
Action += () =>
|
|
|
|
|
{
|
|
|
|
|
if (!current.Disabled) current.SetDefault();
|
|
|
|
|
};
|
2021-05-14 15:01:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2021-05-17 18:44:47 +00:00
|
|
|
|
|
|
|
|
|
Current.ValueChanged += _ => UpdateState();
|
|
|
|
|
Current.DisabledChanged += _ => UpdateState();
|
|
|
|
|
Current.DefaultChanged += _ => UpdateState();
|
|
|
|
|
|
2021-05-14 15:01:17 +00:00
|
|
|
|
UpdateState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string TooltipText => "revert to default";
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
|
{
|
|
|
|
|
hovering = true;
|
|
|
|
|
UpdateState();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
|
{
|
|
|
|
|
hovering = false;
|
|
|
|
|
UpdateState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateState() => Scheduler.AddOnce(updateState);
|
|
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
|
{
|
2021-05-15 01:24:08 +00:00
|
|
|
|
if (current == null)
|
2021-05-14 15:01:17 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2021-05-15 01:24:08 +00:00
|
|
|
|
this.FadeTo(current.IsDefault ? 0f :
|
|
|
|
|
hovering && !current.Disabled ? 1f : 0.65f, 200, Easing.OutQuint);
|
|
|
|
|
this.FadeColour(current.Disabled ? Color4.Gray : buttonColour, 200, Easing.OutQuint);
|
2021-05-14 15:01:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-17 18:44:47 +00:00
|
|
|
|
}
|