Restyle default value indicator

This commit is contained in:
Bartłomiej Dach 2021-10-15 21:44:56 +02:00
parent 92a3658753
commit 818f35c35f
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
3 changed files with 96 additions and 30 deletions

View File

@ -0,0 +1,53 @@
// 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 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<bool> 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<bool>
{
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);
}
}
}

View File

@ -235,11 +235,18 @@ namespace osu.Game.Graphics
/// </summary> /// </summary>
public readonly Color4 Blue3 = Color4Extensions.FromHex(@"3399cc"); public readonly Color4 Blue3 = Color4Extensions.FromHex(@"3399cc");
public readonly Color4 Lime0 = Color4Extensions.FromHex(@"ccff99");
/// <summary> /// <summary>
/// Equivalent to <see cref="OverlayColourProvider.Lime"/>'s <see cref="OverlayColourProvider.Colour1"/>. /// Equivalent to <see cref="OverlayColourProvider.Lime"/>'s <see cref="OverlayColourProvider.Colour1"/>.
/// </summary> /// </summary>
public readonly Color4 Lime1 = Color4Extensions.FromHex(@"b2ff66"); public readonly Color4 Lime1 = Color4Extensions.FromHex(@"b2ff66");
/// <summary>
/// Equivalent to <see cref="OverlayColourProvider.Lime"/>'s <see cref="OverlayColourProvider.Colour3"/>.
/// </summary>
public readonly Color4 Lime3 = Color4Extensions.FromHex(@"7fcc33");
/// <summary> /// <summary>
/// Equivalent to <see cref="OverlayColourProvider.Orange"/>'s <see cref="OverlayColourProvider.Colour1"/>. /// Equivalent to <see cref="OverlayColourProvider.Orange"/>'s <see cref="OverlayColourProvider.Colour1"/>.
/// </summary> /// </summary>

View File

@ -3,10 +3,8 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osuTK.Graphics;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
@ -14,6 +12,7 @@ using osu.Framework.Input.Events;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osuTK;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
@ -45,30 +44,21 @@ namespace osu.Game.Overlays
} }
} }
private bool hovering; [Resolved]
private OsuColour colours { get; set; }
public RestoreDefaultValueButton() private const float size = 4;
{
Height = 1;
RelativeSizeAxes = Axes.Y;
Width = SettingsPanel.CONTENT_MARGINS;
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colour) private void load(OsuColour colour)
{ {
BackgroundColour = colour.Yellow; BackgroundColour = colour.Lime1;
Content.Width = 0.33f; Size = new Vector2(3 * size);
Content.CornerRadius = 3;
Content.EdgeEffect = new EdgeEffectParameters Content.RelativeSizeAxes = Axes.None;
{ Content.Size = new Vector2(size);
Colour = BackgroundColour.Opacity(0.1f), Content.CornerRadius = size / 2;
Type = EdgeEffectType.Glow,
Radius = 2,
};
Padding = new MarginPadding { Vertical = 1.5f };
Alpha = 0f; Alpha = 0f;
Action += () => Action += () =>
@ -81,39 +71,55 @@ namespace osu.Game.Overlays
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
updateState();
// avoid unnecessary transforms on first display. FinishTransforms(true);
Alpha = currentAlpha;
Background.Colour = currentColour;
} }
public LocalisableString TooltipText => "revert to default"; public LocalisableString TooltipText => "revert to default";
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
hovering = true;
UpdateState(); UpdateState();
return false; return false;
} }
protected override void OnHoverLost(HoverLostEvent e) protected override void OnHoverLost(HoverLostEvent e)
{ {
hovering = false;
UpdateState(); UpdateState();
} }
public void UpdateState() => Scheduler.AddOnce(updateState); public void UpdateState() => Scheduler.AddOnce(updateState);
private float currentAlpha => current.IsDefault ? 0f : hovering && !current.Disabled ? 1f : 0.65f; private const double fade_duration = 200;
private ColourInfo currentColour => current.Disabled ? Color4.Gray : BackgroundColour;
private void updateState() private void updateState()
{ {
if (current == null) if (current == null)
return; return;
this.FadeTo(currentAlpha, 200, Easing.OutQuint); Enabled.Value = !Current.Disabled;
Background.FadeColour(currentColour, 200, Easing.OutQuint);
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);
}
} }
} }
} }