From c50adc80b02b0b7411a549f44bc2a4bf1d609d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Sch=C3=BCrz?= Date: Tue, 8 Oct 2024 20:56:17 +0200 Subject: [PATCH] Add `SetStartTimeCommand` --- .../Components/PathControlPointVisualiser.cs | 12 ++++++--- .../Edit/Commands/SetStartTimeCommand.cs | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 osu.Game/Screens/Edit/Commands/SetStartTimeCommand.cs diff --git a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointVisualiser.cs b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointVisualiser.cs index 239bd1100a..bbde4d01e7 100644 --- a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointVisualiser.cs +++ b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointVisualiser.cs @@ -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; diff --git a/osu.Game/Screens/Edit/Commands/SetStartTimeCommand.cs b/osu.Game/Screens/Edit/Commands/SetStartTimeCommand.cs new file mode 100644 index 0000000000..54d34a6079 --- /dev/null +++ b/osu.Game/Screens/Edit/Commands/SetStartTimeCommand.cs @@ -0,0 +1,27 @@ +// Copyright (c) ppy Pty Ltd . 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); + } +}