mirror of
https://github.com/ppy/osu
synced 2025-03-02 09:30:57 +00:00
Improve animation of popup dialog buttons
This commit is contained in:
parent
a883ff63bc
commit
680b2653ae
@ -1,9 +1,12 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Overlays.Dialog;
|
using osu.Game.Overlays.Dialog;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
@ -11,13 +14,22 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TestScenePopupDialog : OsuTestScene
|
public class TestScenePopupDialog : OsuTestScene
|
||||||
{
|
{
|
||||||
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
|
{
|
||||||
|
typeof(PopupDialogOkButton),
|
||||||
|
typeof(PopupDialogCancelButton),
|
||||||
|
typeof(PopupDialogButton),
|
||||||
|
typeof(DialogButton),
|
||||||
|
};
|
||||||
|
|
||||||
public TestScenePopupDialog()
|
public TestScenePopupDialog()
|
||||||
{
|
{
|
||||||
Add(new TestPopupDialog
|
AddStep("new popup", () =>
|
||||||
{
|
Add(new TestPopupDialog
|
||||||
RelativeSizeAxes = Axes.Both,
|
{
|
||||||
State = { Value = Framework.Graphics.Containers.Visibility.Visible },
|
RelativeSizeAxes = Axes.Both,
|
||||||
});
|
State = { Value = Framework.Graphics.Containers.Visibility.Visible },
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestPopupDialog : PopupDialog
|
private class TestPopupDialog : PopupDialog
|
||||||
|
@ -20,6 +20,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
{
|
{
|
||||||
public class DialogButton : OsuClickableContainer
|
public class DialogButton : OsuClickableContainer
|
||||||
{
|
{
|
||||||
|
private const float idle_width = 0.8f;
|
||||||
private const float hover_width = 0.9f;
|
private const float hover_width = 0.9f;
|
||||||
private const float hover_duration = 500;
|
private const float hover_duration = 500;
|
||||||
private const float glow_fade_duration = 250;
|
private const float glow_fade_duration = 250;
|
||||||
@ -99,7 +100,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Width = 0.8f,
|
Width = idle_width,
|
||||||
Masking = true,
|
Masking = true,
|
||||||
MaskingSmoothness = 2,
|
MaskingSmoothness = 2,
|
||||||
EdgeEffect = new EdgeEffectParameters
|
EdgeEffect = new EdgeEffectParameters
|
||||||
@ -199,14 +200,18 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => backgroundContainer.ReceivePositionalInputAt(screenSpacePos);
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => backgroundContainer.ReceivePositionalInputAt(screenSpacePos);
|
||||||
|
|
||||||
|
private bool clicked;
|
||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
protected override bool OnClick(ClickEvent e)
|
||||||
{
|
{
|
||||||
|
clicked = true;
|
||||||
colourContainer.ResizeTo(new Vector2(1.5f, 1f), click_duration, Easing.In);
|
colourContainer.ResizeTo(new Vector2(1.5f, 1f), click_duration, Easing.In);
|
||||||
flash();
|
flash();
|
||||||
|
|
||||||
this.Delay(click_duration).Schedule(delegate
|
this.Delay(click_duration).Schedule(delegate
|
||||||
{
|
{
|
||||||
colourContainer.ResizeTo(new Vector2(0.8f, 1f));
|
clicked = false;
|
||||||
|
colourContainer.ResizeTo(new Vector2(idle_width, 1f));
|
||||||
spriteText.Spacing = Vector2.Zero;
|
spriteText.Spacing = Vector2.Zero;
|
||||||
glowContainer.FadeOut();
|
glowContainer.FadeOut();
|
||||||
});
|
});
|
||||||
@ -230,6 +235,8 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
private void selectionChanged(ValueChangedEvent<bool> args)
|
private void selectionChanged(ValueChangedEvent<bool> args)
|
||||||
{
|
{
|
||||||
|
if (clicked) return;
|
||||||
|
|
||||||
if (args.NewValue)
|
if (args.NewValue)
|
||||||
{
|
{
|
||||||
spriteText.TransformSpacingTo(hoverSpacing, hover_duration, Easing.OutElastic);
|
spriteText.TransformSpacingTo(hoverSpacing, hover_duration, Easing.OutElastic);
|
||||||
@ -238,7 +245,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
colourContainer.ResizeTo(new Vector2(0.8f, 1f), hover_duration, Easing.OutElastic);
|
colourContainer.ResizeTo(new Vector2(idle_width, 1f), hover_duration, Easing.OutElastic);
|
||||||
spriteText.TransformSpacingTo(Vector2.Zero, hover_duration, Easing.OutElastic);
|
spriteText.TransformSpacingTo(Vector2.Zero, hover_duration, Easing.OutElastic);
|
||||||
glowContainer.FadeOut(glow_fade_duration, Easing.Out);
|
glowContainer.FadeOut(glow_fade_duration, Easing.Out);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user