2022-04-28 02:49:37 +00:00
|
|
|
// 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 osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2022-05-03 07:30:32 +00:00
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
2022-04-28 02:49:37 +00:00
|
|
|
using osu.Framework.Graphics;
|
2022-05-03 01:44:55 +00:00
|
|
|
using osu.Framework.Input.Bindings;
|
2022-04-28 02:49:37 +00:00
|
|
|
using osu.Framework.Input.Events;
|
2022-05-03 07:30:32 +00:00
|
|
|
using osu.Framework.Localisation;
|
2022-04-28 02:49:37 +00:00
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-05-03 01:44:55 +00:00
|
|
|
using osu.Game.Input.Bindings;
|
2022-05-03 07:30:32 +00:00
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osu.Game.Overlays.OSD;
|
2022-04-28 02:49:37 +00:00
|
|
|
using osu.Game.Overlays.Settings.Sections;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Edit
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Represents a <see cref="HitObjectComposer{TObject}"/> for rulesets with the concept of distances between objects.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="TObject">The base type of supported objects.</typeparam>
|
|
|
|
[Cached(typeof(IDistanceSnapProvider))]
|
2022-05-03 01:44:55 +00:00
|
|
|
public abstract class DistancedHitObjectComposer<TObject> : HitObjectComposer<TObject>, IDistanceSnapProvider, IKeyBindingHandler<GlobalAction>
|
2022-04-28 02:49:37 +00:00
|
|
|
where TObject : HitObject
|
|
|
|
{
|
2022-04-29 05:02:07 +00:00
|
|
|
protected Bindable<double> DistanceSpacingMultiplier { get; } = new BindableDouble(1.0)
|
2022-04-28 02:49:37 +00:00
|
|
|
{
|
2022-04-29 05:02:07 +00:00
|
|
|
MinValue = 0.1,
|
|
|
|
MaxValue = 6.0,
|
|
|
|
Precision = 0.01,
|
2022-04-28 02:49:37 +00:00
|
|
|
};
|
|
|
|
|
2022-04-29 05:02:07 +00:00
|
|
|
IBindable<double> IDistanceSnapProvider.DistanceSpacingMultiplier => DistanceSpacingMultiplier;
|
2022-04-28 02:49:37 +00:00
|
|
|
|
|
|
|
protected ExpandingToolboxContainer RightSideToolboxContainer { get; private set; }
|
|
|
|
|
2022-04-29 05:02:07 +00:00
|
|
|
private ExpandableSlider<double, SizeSlider<double>> distanceSpacingSlider;
|
2022-04-28 02:49:37 +00:00
|
|
|
private bool distanceSpacingScrollActive;
|
|
|
|
|
2022-05-03 07:30:32 +00:00
|
|
|
[Resolved]
|
|
|
|
private OnScreenDisplay onScreenDisplay { get; set; }
|
|
|
|
|
2022-04-28 02:49:37 +00:00
|
|
|
protected DistancedHitObjectComposer(Ruleset ruleset)
|
|
|
|
: base(ruleset)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
AddInternal(RightSideToolboxContainer = new ExpandingToolboxContainer
|
|
|
|
{
|
2022-04-28 02:50:55 +00:00
|
|
|
Alpha = DistanceSpacingMultiplier.Disabled ? 0 : 1,
|
2022-04-28 02:49:37 +00:00
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
Child = new EditorToolboxGroup("snapping")
|
|
|
|
{
|
2022-04-29 05:02:07 +00:00
|
|
|
Child = distanceSpacingSlider = new ExpandableSlider<double, SizeSlider<double>>
|
2022-04-28 02:49:37 +00:00
|
|
|
{
|
|
|
|
Current = { BindTarget = DistanceSpacingMultiplier },
|
|
|
|
KeyboardStep = 0.1f,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-04-28 02:50:55 +00:00
|
|
|
if (!DistanceSpacingMultiplier.Disabled)
|
2022-04-28 02:49:37 +00:00
|
|
|
{
|
2022-04-28 02:50:55 +00:00
|
|
|
DistanceSpacingMultiplier.Value = EditorBeatmap.BeatmapInfo.DistanceSpacing;
|
|
|
|
DistanceSpacingMultiplier.BindValueChanged(v =>
|
|
|
|
{
|
|
|
|
distanceSpacingSlider.ContractedLabelText = $"D. S. ({v.NewValue:0.##x})";
|
|
|
|
distanceSpacingSlider.ExpandedLabelText = $"Distance Spacing ({v.NewValue:0.##x})";
|
2022-05-03 07:30:32 +00:00
|
|
|
|
|
|
|
if (v.NewValue != v.OldValue)
|
|
|
|
onScreenDisplay.Display(new DistanceSpacingToast(v.NewValue.ToLocalisableString(@"0.##x")));
|
|
|
|
|
2022-04-28 02:50:55 +00:00
|
|
|
EditorBeatmap.BeatmapInfo.DistanceSpacing = v.NewValue;
|
|
|
|
}, true);
|
|
|
|
}
|
2022-04-28 02:49:37 +00:00
|
|
|
}
|
|
|
|
|
2022-05-03 01:44:55 +00:00
|
|
|
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
2022-04-28 02:49:37 +00:00
|
|
|
{
|
2022-05-03 01:44:55 +00:00
|
|
|
if (!DistanceSpacingMultiplier.Disabled && e.Action == GlobalAction.EditorDistanceSpacing)
|
2022-04-28 02:49:37 +00:00
|
|
|
{
|
|
|
|
distanceSpacingScrollActive = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-05-03 01:44:55 +00:00
|
|
|
return false;
|
2022-04-28 02:49:37 +00:00
|
|
|
}
|
|
|
|
|
2022-05-03 01:44:55 +00:00
|
|
|
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
2022-04-28 02:49:37 +00:00
|
|
|
{
|
2022-05-03 01:44:55 +00:00
|
|
|
if (!DistanceSpacingMultiplier.Disabled && e.Action == GlobalAction.EditorDistanceSpacing)
|
2022-04-28 02:49:37 +00:00
|
|
|
distanceSpacingScrollActive = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnScroll(ScrollEvent e)
|
|
|
|
{
|
|
|
|
if (distanceSpacingScrollActive)
|
|
|
|
{
|
|
|
|
DistanceSpacingMultiplier.Value += e.ScrollDelta.Y * (e.IsPrecise ? 0.01f : 0.1f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return base.OnScroll(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual float GetBeatSnapDistanceAt(HitObject referenceObject)
|
|
|
|
{
|
2022-04-28 07:54:38 +00:00
|
|
|
return (float)(100 * EditorBeatmap.Difficulty.SliderMultiplier * referenceObject.DifficultyControlPoint.SliderVelocity / BeatSnapProvider.BeatDivisor);
|
2022-04-28 02:49:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public virtual float DurationToDistance(HitObject referenceObject, double duration)
|
|
|
|
{
|
|
|
|
double beatLength = BeatSnapProvider.GetBeatLengthAtTime(referenceObject.StartTime);
|
|
|
|
return (float)(duration / beatLength * GetBeatSnapDistanceAt(referenceObject));
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual double DistanceToDuration(HitObject referenceObject, float distance)
|
|
|
|
{
|
|
|
|
double beatLength = BeatSnapProvider.GetBeatLengthAtTime(referenceObject.StartTime);
|
|
|
|
return distance / GetBeatSnapDistanceAt(referenceObject) * beatLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual double GetSnappedDurationFromDistance(HitObject referenceObject, float distance)
|
|
|
|
=> BeatSnapProvider.SnapTime(referenceObject.StartTime + DistanceToDuration(referenceObject, distance), referenceObject.StartTime) - referenceObject.StartTime;
|
|
|
|
|
|
|
|
public virtual float GetSnappedDistanceFromDistance(HitObject referenceObject, float distance)
|
|
|
|
{
|
|
|
|
double startTime = referenceObject.StartTime;
|
|
|
|
|
|
|
|
double actualDuration = startTime + DistanceToDuration(referenceObject, distance);
|
|
|
|
|
|
|
|
double snappedEndTime = BeatSnapProvider.SnapTime(actualDuration, startTime);
|
|
|
|
|
|
|
|
double beatLength = BeatSnapProvider.GetBeatLengthAtTime(startTime);
|
|
|
|
|
|
|
|
// we don't want to exceed the actual duration and snap to a point in the future.
|
|
|
|
// as we are snapping to beat length via SnapTime (which will round-to-nearest), check for snapping in the forward direction and reverse it.
|
|
|
|
if (snappedEndTime > actualDuration + 1)
|
|
|
|
snappedEndTime -= beatLength;
|
|
|
|
|
|
|
|
return DurationToDistance(referenceObject, snappedEndTime - startTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected class ExpandingToolboxContainer : ExpandingContainer
|
|
|
|
{
|
|
|
|
protected override double HoverExpansionDelay => 250;
|
|
|
|
|
|
|
|
public ExpandingToolboxContainer()
|
|
|
|
: base(130, 250)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
Padding = new MarginPadding { Left = 10 };
|
|
|
|
|
|
|
|
FillFlow.Spacing = new Vector2(10);
|
|
|
|
}
|
|
|
|
}
|
2022-05-03 07:30:32 +00:00
|
|
|
|
|
|
|
private class DistanceSpacingToast : Toast
|
|
|
|
{
|
|
|
|
public DistanceSpacingToast(LocalisableString value)
|
|
|
|
: base("Distance Spacing", value, string.Empty)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2022-04-28 02:49:37 +00:00
|
|
|
}
|
|
|
|
}
|