1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 20:13:21 +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; }
[Resolved(CanBeNull = true)]
private FreehandSliderSettingsProvider freehandSettingsProvider { get; set; }
private FreehandSliderToolboxGroup freehandToolboxGroup { get; set; }
private readonly IncrementalBSplineBuilder bSplineBuilder = new IncrementalBSplineBuilder();
@ -80,16 +80,16 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
base.LoadComplete();
inputManager = GetContainingInputManager();
if (freehandSettingsProvider != null)
if (freehandToolboxGroup != null)
{
freehandSettingsProvider.Tolerance.BindValueChanged(e =>
freehandToolboxGroup.Tolerance.BindValueChanged(e =>
{
if (bSplineBuilder.Tolerance != e.NewValue)
bSplineBuilder.Tolerance = e.NewValue;
updateSliderPathFromBSplineBuilder();
});
freehandSettingsProvider.CornerThreshold.BindValueChanged(e =>
freehandToolboxGroup.CornerThreshold.BindValueChanged(e =>
{
if (bSplineBuilder.CornerThreshold != e.NewValue)
bSplineBuilder.CornerThreshold = e.NewValue;

View File

@ -5,15 +5,14 @@ using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Utils;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Edit;
namespace osu.Game.Rulesets.Osu.Edit
{
public partial class FreehandSliderSettingsProvider : EditorToolboxGroup
public partial class FreehandSliderToolboxGroup : EditorToolboxGroup
{
public FreehandSliderSettingsProvider()
public FreehandSliderToolboxGroup()
: base("slider")
{
}
@ -32,13 +31,14 @@ namespace osu.Game.Rulesets.Osu.Edit
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,
MaxValue = 100
};
private readonly BindableInt sliderCornerThreshold = new BindableInt(40)
private readonly BindableInt displayCornerThreshold = new BindableInt(40)
{
MinValue = 5,
MaxValue = 100
@ -54,55 +54,47 @@ namespace osu.Game.Rulesets.Osu.Edit
{
toleranceSlider = new ExpandableSlider<int>
{
Current = sliderTolerance
Current = displayTolerance
},
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()
{
base.LoadComplete();
sliderTolerance.BindValueChanged(v =>
displayTolerance.BindValueChanged(tolerance =>
{
float newValue = v.NewValue / 33f;
if (!Precision.AlmostEquals(newValue, Tolerance.Value))
Tolerance.Value = newValue;
});
Tolerance.BindValueChanged(v =>
toleranceSlider.ContractedLabelText = $"C. P. S.: {tolerance.NewValue:N0}";
toleranceSlider.ExpandedLabelText = $"Control Point Spacing: {tolerance.NewValue:N0}";
Tolerance.Value = displayToInternalTolerance(tolerance.NewValue);
}, true);
displayCornerThreshold.BindValueChanged(threshold =>
{
int newValue = (int)Math.Round(v.NewValue * 33f);
if (sliderTolerance.Value != newValue)
sliderTolerance.Value = newValue;
});
sliderCornerThreshold.BindValueChanged(v =>
{
float newValue = v.NewValue / 100f;
if (!Precision.AlmostEquals(newValue, CornerThreshold.Value))
CornerThreshold.Value = newValue;
});
CornerThreshold.BindValueChanged(v =>
{
int newValue = (int)Math.Round(v.NewValue * 100f);
if (sliderCornerThreshold.Value != newValue)
sliderCornerThreshold.Value = newValue;
});
cornerThresholdSlider.ContractedLabelText = $"C. T.: {threshold.NewValue:N0}";
cornerThresholdSlider.ExpandedLabelText = $"Corner Threshold: {threshold.NewValue:N0}";
CornerThreshold.Value = displayToInternalCornerThreshold(threshold.NewValue);
}, true);
Tolerance.BindValueChanged(tolerance =>
displayTolerance.Value = internalToDisplayTolerance(tolerance.NewValue)
);
CornerThreshold.BindValueChanged(threshold =>
displayCornerThreshold.Value = internalToDisplayCornerThreshold(threshold.NewValue)
);
float displayToInternalTolerance(float v) => v / 33f;
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();
[Cached]
protected readonly FreehandSliderSettingsProvider FreehandlSliderToolboxGroup = new FreehandSliderSettingsProvider();
protected readonly FreehandSliderToolboxGroup FreehandlSliderToolboxGroup = new FreehandSliderToolboxGroup();
[BackgroundDependencyLoader]
private void load()