Schedule drag events for now

This commit is contained in:
Dean Herbert 2021-10-15 19:52:29 +09:00
parent 30c3fcb4ea
commit c47497923a

View File

@ -13,6 +13,7 @@ using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Threading;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics; using osu.Game.Graphics;
@ -371,58 +372,66 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
return true; return true;
} }
private ScheduledDelegate dragOperation;
protected override void OnDrag(DragEvent e) protected override void OnDrag(DragEvent e)
{ {
base.OnDrag(e); base.OnDrag(e);
OnDragHandled?.Invoke(e); // schedule is temporary to ensure we don't process multiple times on a single update frame. we need to find a better method of doing this.
// without it, a hitobject's endtime may not always be in a valid state (ie. sliders, which needs to recompute their path).
if (timeline.SnapScreenSpacePositionToValidTime(e.ScreenSpaceMousePosition).Time is double time) dragOperation?.Cancel();
dragOperation = Scheduler.Add(() =>
{ {
switch (hitObject) OnDragHandled?.Invoke(e);
if (timeline.SnapScreenSpacePositionToValidTime(e.ScreenSpaceMousePosition).Time is double time)
{ {
case IHasRepeats repeatHitObject: switch (hitObject)
double proposedDuration = time - hitObject.StartTime; {
case IHasRepeats repeatHitObject:
double proposedDuration = time - hitObject.StartTime;
if (e.CurrentState.Keyboard.ShiftPressed) if (e.CurrentState.Keyboard.ShiftPressed)
{ {
if (hitObject.DifficultyControlPoint == DifficultyControlPoint.DEFAULT) if (hitObject.DifficultyControlPoint == DifficultyControlPoint.DEFAULT)
hitObject.DifficultyControlPoint = new DifficultyControlPoint(); hitObject.DifficultyControlPoint = new DifficultyControlPoint();
var newVelocity = hitObject.DifficultyControlPoint.SliderVelocity * (repeatHitObject.Duration / proposedDuration); var newVelocity = hitObject.DifficultyControlPoint.SliderVelocity * (repeatHitObject.Duration / proposedDuration);
if (Precision.AlmostEquals(newVelocity, hitObject.DifficultyControlPoint.SliderVelocity)) if (Precision.AlmostEquals(newVelocity, hitObject.DifficultyControlPoint.SliderVelocity))
return;
hitObject.DifficultyControlPoint.SliderVelocity = newVelocity;
beatmap.Update(hitObject);
}
else
{
// find the number of repeats which can fit in the requested time.
var lengthOfOneRepeat = repeatHitObject.Duration / (repeatHitObject.RepeatCount + 1);
var proposedCount = Math.Max(0, (int)Math.Round(proposedDuration / lengthOfOneRepeat) - 1);
if (proposedCount == repeatHitObject.RepeatCount)
return;
repeatHitObject.RepeatCount = proposedCount;
beatmap.Update(hitObject);
}
break;
case IHasDuration endTimeHitObject:
var snappedTime = Math.Max(hitObject.StartTime, beatSnapProvider.SnapTime(time));
if (endTimeHitObject.EndTime == snappedTime || Precision.AlmostEquals(snappedTime, hitObject.StartTime, beatmap.GetBeatLengthAtTime(snappedTime)))
return; return;
hitObject.DifficultyControlPoint.SliderVelocity = newVelocity; endTimeHitObject.Duration = snappedTime - hitObject.StartTime;
beatmap.Update(hitObject); beatmap.Update(hitObject);
} break;
else }
{
// find the number of repeats which can fit in the requested time.
var lengthOfOneRepeat = repeatHitObject.Duration / (repeatHitObject.RepeatCount + 1);
var proposedCount = Math.Max(0, (int)Math.Round(proposedDuration / lengthOfOneRepeat) - 1);
if (proposedCount == repeatHitObject.RepeatCount)
return;
repeatHitObject.RepeatCount = proposedCount;
beatmap.Update(hitObject);
}
break;
case IHasDuration endTimeHitObject:
var snappedTime = Math.Max(hitObject.StartTime, beatSnapProvider.SnapTime(time));
if (endTimeHitObject.EndTime == snappedTime || Precision.AlmostEquals(snappedTime, hitObject.StartTime, beatmap.GetBeatLengthAtTime(snappedTime)))
return;
endTimeHitObject.Duration = snappedTime - hitObject.StartTime;
beatmap.Update(hitObject);
break;
} }
} });
} }
protected override void OnDragEnd(DragEndEvent e) protected override void OnDragEnd(DragEndEvent e)