1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 01:27:29 +08:00

Merge pull request #25163 from Joehuu/double-click-slider-nub-default

Add ability to revert slider settings to default when double-clicking nub
This commit is contained in:
Dean Herbert 2023-10-18 16:23:05 +09:00 committed by GitHub
commit bf4aa3c118
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 112 additions and 5 deletions

View File

@ -0,0 +1,59 @@
// 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 System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osuTK.Input;
namespace osu.Game.Tests.Visual.UserInterface
{
public partial class TestSceneRoundedSliderBar : OsuManualInputManagerTestScene
{
[Cached]
private OverlayColourProvider colourProvider { get; set; } = new OverlayColourProvider(OverlayColourScheme.Purple);
private readonly BindableDouble current = new BindableDouble(5)
{
Precision = 0.1f,
MinValue = 0,
MaxValue = 15
};
private RoundedSliderBar<double> slider = null!;
[BackgroundDependencyLoader]
private void load()
{
Child = slider = new RoundedSliderBar<double>
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Current = current,
RelativeSizeAxes = Axes.X,
Width = 0.4f
};
}
[Test]
public void TestNubDoubleClickRevertToDefault()
{
AddStep("set slider to 1", () => slider.Current.Value = 1);
AddStep("move mouse to nub", () => InputManager.MoveMouseTo(slider.ChildrenOfType<Nub>().Single()));
AddStep("double click nub", () =>
{
InputManager.Click(MouseButton.Left);
InputManager.Click(MouseButton.Left);
});
AddAssert("slider is default", () => slider.Current.IsDefault);
}
}
}

View File

@ -1,15 +1,19 @@
// 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.Linq;
using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays; using osu.Game.Overlays;
using osuTK.Input;
namespace osu.Game.Tests.Visual.UserInterface namespace osu.Game.Tests.Visual.UserInterface
{ {
public partial class TestSceneShearedSliderBar : OsuTestScene public partial class TestSceneShearedSliderBar : OsuManualInputManagerTestScene
{ {
[Cached] [Cached]
private OverlayColourProvider colourProvider { get; set; } = new OverlayColourProvider(OverlayColourScheme.Purple); private OverlayColourProvider colourProvider { get; set; } = new OverlayColourProvider(OverlayColourScheme.Purple);
@ -21,10 +25,12 @@ namespace osu.Game.Tests.Visual.UserInterface
MaxValue = 15 MaxValue = 15
}; };
private ShearedSliderBar<double> slider = null!;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
Child = new ShearedSliderBar<double> Child = slider = new ShearedSliderBar<double>
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -33,5 +39,21 @@ namespace osu.Game.Tests.Visual.UserInterface
Width = 0.4f Width = 0.4f
}; };
} }
[Test]
public void TestNubDoubleClickRevertToDefault()
{
AddStep("set slider to 1", () => slider.Current.Value = 1);
AddStep("move mouse to nub", () => InputManager.MoveMouseTo(slider.ChildrenOfType<ShearedNub>().Single()));
AddStep("double click nub", () =>
{
InputManager.Click(MouseButton.Left);
InputManager.Click(MouseButton.Left);
});
AddAssert("slider is default", () => slider.Current.IsDefault);
}
} }
} }

View File

@ -93,11 +93,12 @@ namespace osu.Game.Graphics.UserInterface
nubContainer = new Container nubContainer = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Child = Nub = new Nub Child = Nub = new SliderNub
{ {
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
RelativePositionAxes = Axes.X, RelativePositionAxes = Axes.X,
Current = { Value = true } Current = { Value = true },
OnDoubleClicked = () => Current.SetDefault(),
}, },
}, },
hoverClickSounds = new HoverClickSounds() hoverClickSounds = new HoverClickSounds()
@ -166,5 +167,18 @@ namespace osu.Game.Graphics.UserInterface
{ {
Nub.MoveToX(value, 250, Easing.OutQuint); Nub.MoveToX(value, 250, Easing.OutQuint);
} }
public partial class SliderNub : Nub
{
public Action? OnDoubleClicked { get; init; }
protected override bool OnClick(ClickEvent e) => true;
protected override bool OnDoubleClick(DoubleClickEvent e)
{
OnDoubleClicked?.Invoke();
return true;
}
}
} }
} }

View File

@ -10,6 +10,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Overlays; using osu.Game.Overlays;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -18,6 +19,8 @@ namespace osu.Game.Graphics.UserInterface
{ {
public partial class ShearedNub : Container, IHasCurrentValue<bool>, IHasAccentColour public partial class ShearedNub : Container, IHasCurrentValue<bool>, IHasAccentColour
{ {
public Action? OnDoubleClicked { get; init; }
protected const float BORDER_WIDTH = 3; protected const float BORDER_WIDTH = 3;
public const int HEIGHT = 30; public const int HEIGHT = 30;
@ -179,5 +182,13 @@ namespace osu.Game.Graphics.UserInterface
main.TransformTo(nameof(BorderThickness), BORDER_WIDTH, duration, Easing.OutQuint); main.TransformTo(nameof(BorderThickness), BORDER_WIDTH, duration, Easing.OutQuint);
} }
} }
protected override bool OnClick(ClickEvent e) => true;
protected override bool OnDoubleClick(DoubleClickEvent e)
{
OnDoubleClicked?.Invoke();
return true;
}
} }
} }

View File

@ -100,7 +100,8 @@ namespace osu.Game.Graphics.UserInterface
X = -SHEAR.X * HEIGHT / 2f, X = -SHEAR.X * HEIGHT / 2f,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
RelativePositionAxes = Axes.X, RelativePositionAxes = Axes.X,
Current = { Value = true } Current = { Value = true },
OnDoubleClicked = () => Current.SetDefault(),
}, },
}, },
hoverClickSounds = new HoverClickSounds() hoverClickSounds = new HoverClickSounds()