1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:07:52 +08:00

Refactor slider settings class

This commit is contained in:
Dean Herbert 2023-11-21 09:59:49 +09:00
parent 638c8f1adc
commit e9f371a581
No known key found for this signature in database
3 changed files with 38 additions and 46 deletions

View File

@ -46,7 +46,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
private IDistanceSnapProvider distanceSnapProvider { get; set; } private IDistanceSnapProvider distanceSnapProvider { get; set; }
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private FreehandSliderSettingsProvider freehandSettingsProvider { get; set; } private FreehandSliderToolboxGroup freehandToolboxGroup { get; set; }
private readonly IncrementalBSplineBuilder bSplineBuilder = new IncrementalBSplineBuilder(); private readonly IncrementalBSplineBuilder bSplineBuilder = new IncrementalBSplineBuilder();
@ -80,16 +80,16 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
base.LoadComplete(); base.LoadComplete();
inputManager = GetContainingInputManager(); inputManager = GetContainingInputManager();
if (freehandSettingsProvider != null) if (freehandToolboxGroup != null)
{ {
freehandSettingsProvider.Tolerance.BindValueChanged(e => freehandToolboxGroup.Tolerance.BindValueChanged(e =>
{ {
if (bSplineBuilder.Tolerance != e.NewValue) if (bSplineBuilder.Tolerance != e.NewValue)
bSplineBuilder.Tolerance = e.NewValue; bSplineBuilder.Tolerance = e.NewValue;
updateSliderPathFromBSplineBuilder(); updateSliderPathFromBSplineBuilder();
}); });
freehandSettingsProvider.CornerThreshold.BindValueChanged(e => freehandToolboxGroup.CornerThreshold.BindValueChanged(e =>
{ {
if (bSplineBuilder.CornerThreshold != e.NewValue) if (bSplineBuilder.CornerThreshold != e.NewValue)
bSplineBuilder.CornerThreshold = e.NewValue; bSplineBuilder.CornerThreshold = e.NewValue;

View File

@ -5,15 +5,14 @@ using System;
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.Utils;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
namespace osu.Game.Rulesets.Osu.Edit namespace osu.Game.Rulesets.Osu.Edit
{ {
public partial class FreehandSliderSettingsProvider : EditorToolboxGroup public partial class FreehandSliderToolboxGroup : EditorToolboxGroup
{ {
public FreehandSliderSettingsProvider() public FreehandSliderToolboxGroup()
: base("slider") : base("slider")
{ {
} }
@ -32,13 +31,14 @@ namespace osu.Game.Rulesets.Osu.Edit
Precision = 0.01f Precision = 0.01f
}; };
private readonly BindableInt sliderTolerance = new BindableInt(40) // We map internal ranges to a more standard range of values for display to the user.
private readonly BindableInt displayTolerance = new BindableInt(40)
{ {
MinValue = 5, MinValue = 5,
MaxValue = 100 MaxValue = 100
}; };
private readonly BindableInt sliderCornerThreshold = new BindableInt(40) private readonly BindableInt displayCornerThreshold = new BindableInt(40)
{ {
MinValue = 5, MinValue = 5,
MaxValue = 100 MaxValue = 100
@ -54,55 +54,47 @@ namespace osu.Game.Rulesets.Osu.Edit
{ {
toleranceSlider = new ExpandableSlider<int> toleranceSlider = new ExpandableSlider<int>
{ {
Current = sliderTolerance Current = displayTolerance
}, },
cornerThresholdSlider = new ExpandableSlider<int> cornerThresholdSlider = new ExpandableSlider<int>
{ {
Current = sliderCornerThreshold Current = displayCornerThreshold
} }
}; };
sliderTolerance.BindValueChanged(e =>
{
toleranceSlider.ContractedLabelText = $"C. P. S.: {e.NewValue:N0}";
toleranceSlider.ExpandedLabelText = $"Control Point Spacing: {e.NewValue:N0}";
}, true);
sliderCornerThreshold.BindValueChanged(e =>
{
cornerThresholdSlider.ContractedLabelText = $"C. T.: {e.NewValue:N0}";
cornerThresholdSlider.ExpandedLabelText = $"Corner Threshold: {e.NewValue:N0}";
}, true);
} }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
sliderTolerance.BindValueChanged(v => displayTolerance.BindValueChanged(tolerance =>
{ {
float newValue = v.NewValue / 33f; toleranceSlider.ContractedLabelText = $"C. P. S.: {tolerance.NewValue:N0}";
if (!Precision.AlmostEquals(newValue, Tolerance.Value)) toleranceSlider.ExpandedLabelText = $"Control Point Spacing: {tolerance.NewValue:N0}";
Tolerance.Value = newValue;
}); Tolerance.Value = displayToInternalTolerance(tolerance.NewValue);
Tolerance.BindValueChanged(v => }, true);
displayCornerThreshold.BindValueChanged(threshold =>
{ {
int newValue = (int)Math.Round(v.NewValue * 33f); cornerThresholdSlider.ContractedLabelText = $"C. T.: {threshold.NewValue:N0}";
if (sliderTolerance.Value != newValue) cornerThresholdSlider.ExpandedLabelText = $"Corner Threshold: {threshold.NewValue:N0}";
sliderTolerance.Value = newValue;
}); CornerThreshold.Value = displayToInternalCornerThreshold(threshold.NewValue);
sliderCornerThreshold.BindValueChanged(v => }, true);
{
float newValue = v.NewValue / 100f; Tolerance.BindValueChanged(tolerance =>
if (!Precision.AlmostEquals(newValue, CornerThreshold.Value)) displayTolerance.Value = internalToDisplayTolerance(tolerance.NewValue)
CornerThreshold.Value = newValue; );
}); CornerThreshold.BindValueChanged(threshold =>
CornerThreshold.BindValueChanged(v => displayCornerThreshold.Value = internalToDisplayCornerThreshold(threshold.NewValue)
{ );
int newValue = (int)Math.Round(v.NewValue * 100f);
if (sliderCornerThreshold.Value != newValue) float displayToInternalTolerance(float v) => v / 33f;
sliderCornerThreshold.Value = newValue; int internalToDisplayTolerance(float v) => (int)Math.Round(v * 33f);
});
float displayToInternalCornerThreshold(float v) => v / 100f;
int internalToDisplayCornerThreshold(float v) => (int)Math.Round(v * 100f);
} }
} }
} }

View File

@ -64,7 +64,7 @@ namespace osu.Game.Rulesets.Osu.Edit
protected readonly OsuDistanceSnapProvider DistanceSnapProvider = new OsuDistanceSnapProvider(); protected readonly OsuDistanceSnapProvider DistanceSnapProvider = new OsuDistanceSnapProvider();
[Cached] [Cached]
protected readonly FreehandSliderSettingsProvider FreehandlSliderToolboxGroup = new FreehandSliderSettingsProvider(); protected readonly FreehandSliderToolboxGroup FreehandlSliderToolboxGroup = new FreehandSliderToolboxGroup();
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()