1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 13:47:24 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Edit/OsuSliderDrawingSettingsProvider.cs

67 lines
2.1 KiB
C#
Raw Normal View History

// 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;
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 OsuSliderDrawingSettingsProvider : Drawable, ISliderDrawingSettingsProvider
{
public BindableFloat Tolerance { get; } = new BindableFloat(0.1f)
{
MinValue = 0.05f,
MaxValue = 1f,
Precision = 0.01f
};
2023-11-11 22:02:06 +08:00
private readonly BindableInt sliderTolerance = new BindableInt(10)
{
MinValue = 5,
MaxValue = 100
};
private ExpandableSlider<int> toleranceSlider = null!;
public OsuSliderDrawingSettingsProvider()
{
sliderTolerance.BindValueChanged(v =>
{
float newValue = v.NewValue / 100f;
if (!Precision.AlmostEquals(newValue, Tolerance.Value, 1e-7f))
Tolerance.Value = newValue;
});
Tolerance.BindValueChanged(v =>
{
int newValue = (int)Math.Round(v.NewValue * 100f);
if (sliderTolerance.Value != newValue)
sliderTolerance.Value = newValue;
});
}
public void AttachToToolbox(ExpandingToolboxContainer toolboxContainer)
{
2023-11-11 22:02:06 +08:00
toolboxContainer.Add(new EditorToolboxGroup("drawing")
{
Children = new Drawable[]
{
toleranceSlider = new ExpandableSlider<int>
{
Current = sliderTolerance
}
}
});
sliderTolerance.BindValueChanged(e =>
{
2023-11-11 22:02:06 +08:00
toleranceSlider.ContractedLabelText = $"C. P. S.: {e.NewValue:N0}";
toleranceSlider.ExpandedLabelText = $"Control Point Spacing: {e.NewValue:N0}";
}, true);
}
}
}