1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-10 21:40:34 +08:00

Fix double-clicking difficulty adjust sliders not resetting the value to default correctly

- Closes https://github.com/ppy/osu/issues/31888
- Supersedes / closes https://github.com/ppy/osu/pull/32060
This commit is contained in:
Bartłomiej Dach 2025-02-24 09:18:19 +01:00
parent f4b427ee66
commit 1f562ab47d
No known key found for this signature in database
3 changed files with 30 additions and 20 deletions

View File

@ -3,7 +3,6 @@
using System.Linq; using System.Linq;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
@ -63,13 +62,7 @@ namespace osu.Game.Rulesets.Osu.Mods
private partial class ApproachRateSettingsControl : DifficultyAdjustSettingsControl private partial class ApproachRateSettingsControl : DifficultyAdjustSettingsControl
{ {
protected override RoundedSliderBar<float> CreateSlider(BindableNumber<float> current) => protected override RoundedSliderBar<float> CreateSlider(BindableNumber<float> current) => new ApproachRateSlider();
new ApproachRateSlider
{
RelativeSizeAxes = Axes.X,
Current = current,
KeyboardStep = 0.1f,
};
/// <summary> /// <summary>
/// A slider bar with more detailed approach rate info for its given value /// A slider bar with more detailed approach rate info for its given value

View File

@ -10,6 +10,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; 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.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Overlays; using osu.Game.Overlays;
using Vector2 = osuTK.Vector2; using Vector2 = osuTK.Vector2;
@ -52,10 +53,21 @@ namespace osu.Game.Graphics.UserInterface
} }
} }
/// <summary>
/// The action to use to reset the value of <see cref="SliderBar{T}.Current"/> to the default.
/// Triggered on double click.
/// </summary>
public Action ResetToDefault { get; internal set; }
public RoundedSliderBar() public RoundedSliderBar()
{ {
Height = Nub.HEIGHT; Height = Nub.HEIGHT;
RangePadding = Nub.DEFAULT_EXPANDED_SIZE / 2; RangePadding = Nub.DEFAULT_EXPANDED_SIZE / 2;
ResetToDefault = () =>
{
if (!Current.Disabled)
Current.SetDefault();
};
Children = new Drawable[] Children = new Drawable[]
{ {
new Container new Container
@ -102,11 +114,7 @@ namespace osu.Game.Graphics.UserInterface
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
RelativePositionAxes = Axes.X, RelativePositionAxes = Axes.X,
Current = { Value = true }, Current = { Value = true },
OnDoubleClicked = () => OnDoubleClicked = () => ResetToDefault.Invoke(),
{
if (!Current.Disabled)
Current.SetDefault();
},
}, },
}, },
hoverClickSounds = new HoverClickSounds() hoverClickSounds = new HoverClickSounds()

View File

@ -31,12 +31,7 @@ namespace osu.Game.Rulesets.Mods
protected sealed override Drawable CreateControl() => new SliderControl(sliderDisplayCurrent, CreateSlider); protected sealed override Drawable CreateControl() => new SliderControl(sliderDisplayCurrent, CreateSlider);
protected virtual RoundedSliderBar<float> CreateSlider(BindableNumber<float> current) => new RoundedSliderBar<float> protected virtual RoundedSliderBar<float> CreateSlider(BindableNumber<float> current) => new RoundedSliderBar<float>();
{
RelativeSizeAxes = Axes.X,
Current = current,
KeyboardStep = 0.1f,
};
/// <summary> /// <summary>
/// Guards against beatmap values displayed on slider bars being transferred to user override. /// Guards against beatmap values displayed on slider bars being transferred to user override.
@ -111,7 +106,21 @@ namespace osu.Game.Rulesets.Mods
{ {
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
createSlider(currentNumber) createSlider(currentNumber).With(slider =>
{
slider.RelativeSizeAxes = Axes.X;
slider.Current = currentNumber;
slider.KeyboardStep = 0.1f;
// this looks redundant, but isn't because of the various games this component plays
// (`Current` is nullable and represents the underlying setting value,
// `currentNumber` is not nullable and represents what is getting displayed,
// therefore without this, double-clicking the slider would reset `currentNumber` to its bogus default of 0).
slider.ResetToDefault = () =>
{
if (!Current.Disabled)
Current.SetDefault();
};
})
}; };
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;