Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to revert slider settings to default when double-clicking nub #25163

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 59 additions & 0 deletions osu.Game.Tests/Visual/UserInterface/TestSceneRoundedSliderBar.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
26 changes: 24 additions & 2 deletions osu.Game.Tests/Visual/UserInterface/TestSceneShearedSliderBar.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// 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 TestSceneShearedSliderBar : OsuTestScene
public partial class TestSceneShearedSliderBar : OsuManualInputManagerTestScene
{
[Cached]
private OverlayColourProvider colourProvider { get; set; } = new OverlayColourProvider(OverlayColourScheme.Purple);
Expand All @@ -21,10 +25,12 @@ public partial class TestSceneShearedSliderBar : OsuTestScene
MaxValue = 15
};

private ShearedSliderBar<double> slider = null!;

[BackgroundDependencyLoader]
private void load()
{
Child = new ShearedSliderBar<double>
Child = slider = new ShearedSliderBar<double>
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Expand All @@ -33,5 +39,21 @@ private void load()
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);
}
}
}
18 changes: 16 additions & 2 deletions osu.Game/Graphics/UserInterface/RoundedSliderBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ public RoundedSliderBar()
nubContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Child = Nub = new Nub
Child = Nub = new SliderNub
{
Origin = Anchor.TopCentre,
RelativePositionAxes = Axes.X,
Current = { Value = true }
Current = { Value = true },
OnDoubleClicked = () => Current.SetDefault(),
},
},
hoverClickSounds = new HoverClickSounds()
Expand Down Expand Up @@ -166,5 +167,18 @@ protected override void UpdateValue(float value)
{
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;
}
}
}
}
11 changes: 11 additions & 0 deletions osu.Game/Graphics/UserInterface/ShearedNub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Overlays;
using osuTK;
using osuTK.Graphics;
Expand All @@ -18,6 +19,8 @@ namespace osu.Game.Graphics.UserInterface
{
public partial class ShearedNub : Container, IHasCurrentValue<bool>, IHasAccentColour
{
public Action? OnDoubleClicked { get; init; }

protected const float BORDER_WIDTH = 3;

public const int HEIGHT = 30;
Expand Down Expand Up @@ -179,5 +182,13 @@ private void onCurrentValueChanged(ValueChangedEvent<bool> filled)
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;
}
}
}
3 changes: 2 additions & 1 deletion osu.Game/Graphics/UserInterface/ShearedSliderBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public ShearedSliderBar()
X = -SHEAR.X * HEIGHT / 2f,
Origin = Anchor.TopCentre,
RelativePositionAxes = Axes.X,
Current = { Value = true }
Current = { Value = true },
OnDoubleClicked = () => Current.SetDefault(),
},
},
hoverClickSounds = new HoverClickSounds()
Expand Down