mirror of
https://github.com/ppy/osu.git
synced 2025-01-07 23:15:45 +08:00
Add SetStartTimeCommand
This commit is contained in:
parent
fb5d3deb91
commit
c50adc80b0
@ -26,6 +26,7 @@ using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Screens.Edit;
|
||||
using osu.Game.Screens.Edit.Commands;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
|
||||
@ -409,6 +410,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
changeHandler?.BeginChange();
|
||||
}
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private EditorCommandHandler commandHandler { get; set; }
|
||||
|
||||
public void DragInProgress(DragEvent e)
|
||||
{
|
||||
Vector2[] oldControlPoints = hitObject.Path.ControlPoints.Select(cp => cp.Position).ToArray();
|
||||
@ -423,8 +427,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
|
||||
Vector2 movementDelta = Parent!.ToLocalSpace(result?.ScreenSpacePosition ?? newHeadPosition) - hitObject.Position;
|
||||
|
||||
hitObject.Position += movementDelta;
|
||||
hitObject.StartTime = result?.Time ?? hitObject.StartTime;
|
||||
commandHandler.SafeSubmit(new MoveCommand(hitObject, hitObject.Position + movementDelta));
|
||||
commandHandler.SafeSubmit(new SetStartTimeCommand(hitObject, result?.Time ?? hitObject.StartTime));
|
||||
|
||||
for (int i = 1; i < hitObject.Path.ControlPoints.Count; i++)
|
||||
{
|
||||
@ -459,8 +463,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
for (int i = 0; i < hitObject.Path.ControlPoints.Count; i++)
|
||||
hitObject.Path.ControlPoints[i].Position = oldControlPoints[i];
|
||||
|
||||
hitObject.Position = oldPosition;
|
||||
hitObject.StartTime = oldStartTime;
|
||||
commandHandler.SafeSubmit(new MoveCommand(hitObject, oldPosition));
|
||||
commandHandler.SafeSubmit(new SetStartTimeCommand(hitObject, oldStartTime));
|
||||
// Snap the path length again to undo the invalid length.
|
||||
hitObject.SnapTo(distanceSnapProvider);
|
||||
return;
|
||||
|
27
osu.Game/Screens/Edit/Commands/SetStartTimeCommand.cs
Normal file
27
osu.Game/Screens/Edit/Commands/SetStartTimeCommand.cs
Normal file
@ -0,0 +1,27 @@
|
||||
// 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.Utils;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Commands
|
||||
{
|
||||
public class SetStartTimeCommand : IEditorCommand
|
||||
{
|
||||
public readonly HitObject Target;
|
||||
|
||||
public readonly double StartTime;
|
||||
|
||||
public SetStartTimeCommand(HitObject target, double startTime)
|
||||
{
|
||||
Target = target;
|
||||
StartTime = startTime;
|
||||
}
|
||||
|
||||
public void Apply() => Target.StartTime = StartTime;
|
||||
|
||||
public IEditorCommand CreateUndo() => new SetStartTimeCommand(Target, Target.StartTime);
|
||||
|
||||
public bool IsRedundant => Precision.AlmostEquals(StartTime, Target.StartTime);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user