diff --git a/osu.Game.Tests/Visual/Settings/TestSceneRestoreDefaultValueButton.cs b/osu.Game.Tests/Visual/Settings/TestSceneRestoreDefaultValueButton.cs new file mode 100644 index 0000000000..0716907315 --- /dev/null +++ b/osu.Game.Tests/Visual/Settings/TestSceneRestoreDefaultValueButton.cs @@ -0,0 +1,53 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Game.Graphics; +using osu.Game.Overlays; +using osuTK; + +namespace osu.Game.Tests.Visual.Settings +{ + public class TestSceneRestoreDefaultValueButton : OsuTestScene + { + [Resolved] + private OsuColour colours { get; set; } + + [Test] + public void TestBasic() + { + RestoreDefaultValueButton restoreDefaultValueButton = null; + + AddStep("create button", () => Child = new Container + { + RelativeSizeAxes = Axes.Both, + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = colours.GreySeafoam + }, + restoreDefaultValueButton = new RestoreDefaultValueButton + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Current = new BindableBool(), + } + } + }); + AddSliderStep("set scale", 1, 4, 1, scale => + { + if (restoreDefaultValueButton != null) + restoreDefaultValueButton.Scale = new Vector2(scale); + }); + AddToggleStep("toggle default state", state => restoreDefaultValueButton.Current.Value = state); + AddToggleStep("toggle disabled state", state => restoreDefaultValueButton.Current.Disabled = state); + } + } +} diff --git a/osu.Game/Graphics/OsuColour.cs b/osu.Game/Graphics/OsuColour.cs index af2bb26871..40d163635a 100644 --- a/osu.Game/Graphics/OsuColour.cs +++ b/osu.Game/Graphics/OsuColour.cs @@ -235,11 +235,18 @@ namespace osu.Game.Graphics /// public readonly Color4 Blue3 = Color4Extensions.FromHex(@"3399cc"); + public readonly Color4 Lime0 = Color4Extensions.FromHex(@"ccff99"); + /// /// Equivalent to 's . /// public readonly Color4 Lime1 = Color4Extensions.FromHex(@"b2ff66"); + /// + /// Equivalent to 's . + /// + public readonly Color4 Lime3 = Color4Extensions.FromHex(@"7fcc33"); + /// /// Equivalent to 's . /// diff --git a/osu.Game/Overlays/RestoreDefaultValueButton.cs b/osu.Game/Overlays/RestoreDefaultValueButton.cs index 87a294cc10..de600e8172 100644 --- a/osu.Game/Overlays/RestoreDefaultValueButton.cs +++ b/osu.Game/Overlays/RestoreDefaultValueButton.cs @@ -3,10 +3,8 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; -using osuTK.Graphics; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; -using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.UserInterface; @@ -14,6 +12,7 @@ using osu.Framework.Input.Events; using osu.Framework.Localisation; using osu.Game.Graphics; using osu.Game.Graphics.UserInterface; +using osuTK; namespace osu.Game.Overlays { @@ -45,30 +44,21 @@ namespace osu.Game.Overlays } } - private bool hovering; + [Resolved] + private OsuColour colours { get; set; } - public RestoreDefaultValueButton() - { - Height = 1; - - RelativeSizeAxes = Axes.Y; - Width = SettingsPanel.CONTENT_MARGINS; - } + private const float size = 4; [BackgroundDependencyLoader] private void load(OsuColour colour) { - BackgroundColour = colour.Yellow; - Content.Width = 0.33f; - Content.CornerRadius = 3; - Content.EdgeEffect = new EdgeEffectParameters - { - Colour = BackgroundColour.Opacity(0.1f), - Type = EdgeEffectType.Glow, - Radius = 2, - }; + BackgroundColour = colour.Lime1; + Size = new Vector2(3 * size); + + Content.RelativeSizeAxes = Axes.None; + Content.Size = new Vector2(size); + Content.CornerRadius = size / 2; - Padding = new MarginPadding { Vertical = 1.5f }; Alpha = 0f; Action += () => @@ -81,39 +71,55 @@ namespace osu.Game.Overlays protected override void LoadComplete() { base.LoadComplete(); - - // avoid unnecessary transforms on first display. - Alpha = currentAlpha; - Background.Colour = currentColour; + updateState(); + FinishTransforms(true); } public LocalisableString 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 float currentAlpha => current.IsDefault ? 0f : hovering && !current.Disabled ? 1f : 0.65f; - private ColourInfo currentColour => current.Disabled ? Color4.Gray : BackgroundColour; + private const double fade_duration = 200; private void updateState() { if (current == null) return; - this.FadeTo(currentAlpha, 200, Easing.OutQuint); - Background.FadeColour(currentColour, 200, Easing.OutQuint); + Enabled.Value = !Current.Disabled; + + if (!Current.Disabled) + { + this.FadeTo(Current.IsDefault ? 0 : 1, fade_duration, Easing.OutQuint); + Background.FadeColour(IsHovered ? colours.Lime0 : colours.Lime1, fade_duration, Easing.OutQuint); + Content.TweenEdgeEffectTo(new EdgeEffectParameters + { + Colour = (IsHovered ? colours.Lime1 : colours.Lime3).Opacity(0.4f), + Radius = IsHovered ? 8 : 4, + Type = EdgeEffectType.Glow + }, fade_duration, Easing.OutQuint); + } + else + { + Background.FadeColour(colours.Lime3, fade_duration, Easing.OutQuint); + Content.TweenEdgeEffectTo(new EdgeEffectParameters + { + Colour = colours.Lime3.Opacity(0.4f).Opacity(0.1f), + Radius = 2, + Type = EdgeEffectType.Glow + }, fade_duration, Easing.OutQuint); + } } } }