mirror of
https://github.com/osukey/osukey.git
synced 2025-07-03 01:09:57 +09:00
Allow to adjust slider velocity on multiple objects simultaneously
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
// 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 osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
@ -49,9 +51,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
public class DifficultyEditPopover : OsuPopover
|
||||
{
|
||||
private readonly HitObject hitObject;
|
||||
private readonly DifficultyControlPoint point;
|
||||
|
||||
private SliderWithTextBoxInput<double> sliderVelocitySlider;
|
||||
private IndeterminateSliderWithTextBoxInput<double> sliderVelocitySlider;
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private EditorBeatmap beatmap { get; set; }
|
||||
@ -59,7 +60,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
public DifficultyEditPopover(HitObject hitObject)
|
||||
{
|
||||
this.hitObject = hitObject;
|
||||
point = hitObject.DifficultyControlPoint;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -74,9 +74,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
sliderVelocitySlider = new SliderWithTextBoxInput<double>("Velocity")
|
||||
sliderVelocitySlider = new IndeterminateSliderWithTextBoxInput<double>("Velocity", new DifficultyControlPoint().SliderVelocityBindable)
|
||||
{
|
||||
Current = new DifficultyControlPoint().SliderVelocityBindable,
|
||||
KeyboardStep = 0.1f
|
||||
},
|
||||
new OsuTextFlowContainer
|
||||
@ -89,17 +88,37 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
}
|
||||
};
|
||||
|
||||
var selectedPointBindable = point.SliderVelocityBindable;
|
||||
// if the piece belongs to a currently selected object, assume that the user wants to change all selected objects.
|
||||
// if the piece belongs to an unselected object, operate on that object alone, independently of the selection.
|
||||
var relevantObjects = (beatmap.SelectedHitObjects.Contains(hitObject) ? beatmap.SelectedHitObjects : hitObject.Yield()).ToArray();
|
||||
var relevantControlPoints = relevantObjects.Select(h => h.DifficultyControlPoint).ToArray();
|
||||
|
||||
// there may be legacy control points, which contain infinite precision for compatibility reasons (see LegacyDifficultyControlPoint).
|
||||
// generally that level of precision could only be set by externally editing the .osu file, so at the point
|
||||
// a user is looking to update this within the editor it should be safe to obliterate this additional precision.
|
||||
double expectedPrecision = new DifficultyControlPoint().SliderVelocityBindable.Precision;
|
||||
if (selectedPointBindable.Precision < expectedPrecision)
|
||||
selectedPointBindable.Precision = expectedPrecision;
|
||||
// even if there are multiple objects selected, we can still display a value if they all have the same value.
|
||||
var selectedPointBindable = relevantControlPoints.Select(point => point.SliderVelocity).Distinct().Count() == 1 ? relevantControlPoints.First().SliderVelocityBindable : null;
|
||||
|
||||
sliderVelocitySlider.Current = selectedPointBindable;
|
||||
sliderVelocitySlider.Current.BindValueChanged(_ => beatmap?.Update(hitObject));
|
||||
if (selectedPointBindable != null)
|
||||
{
|
||||
// there may be legacy control points, which contain infinite precision for compatibility reasons (see LegacyDifficultyControlPoint).
|
||||
// generally that level of precision could only be set by externally editing the .osu file, so at the point
|
||||
// a user is looking to update this within the editor it should be safe to obliterate this additional precision.
|
||||
sliderVelocitySlider.Current.Value = selectedPointBindable.Value;
|
||||
}
|
||||
|
||||
sliderVelocitySlider.Current.BindValueChanged(val =>
|
||||
{
|
||||
if (val.NewValue == null)
|
||||
return;
|
||||
|
||||
beatmap.BeginChange();
|
||||
|
||||
foreach (var h in relevantObjects)
|
||||
{
|
||||
h.DifficultyControlPoint.SliderVelocity = val.NewValue.Value;
|
||||
beatmap.Update(h);
|
||||
}
|
||||
|
||||
beatmap.EndChange();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user