mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 13:22:55 +08:00
Restyle default value indicator
This commit is contained in:
parent
92a3658753
commit
818f35c35f
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -235,11 +235,18 @@ namespace osu.Game.Graphics
|
||||
/// </summary>
|
||||
public readonly Color4 Blue3 = Color4Extensions.FromHex(@"3399cc");
|
||||
|
||||
public readonly Color4 Lime0 = Color4Extensions.FromHex(@"ccff99");
|
||||
|
||||
/// <summary>
|
||||
/// Equivalent to <see cref="OverlayColourProvider.Lime"/>'s <see cref="OverlayColourProvider.Colour1"/>.
|
||||
/// </summary>
|
||||
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>
|
||||
/// Equivalent to <see cref="OverlayColourProvider.Orange"/>'s <see cref="OverlayColourProvider.Colour1"/>.
|
||||
/// </summary>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user