diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index 316e8e55e8..02003eb87b 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -27,6 +27,7 @@ using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI.Scrolling; using osu.Game.Screens.Edit; +using osu.Game.Screens.Edit.Commands; using osu.Game.Screens.Edit.Components.RadioButtons; using osu.Game.Screens.Edit.Components.TernaryButtons; using osu.Game.Screens.Edit.Compose; @@ -483,20 +484,23 @@ namespace osu.Game.Rulesets.Edit EditorBeatmap.PlacementObject.Value = hitObject; } + [Resolved(canBeNull: true)] + private EditorCommandHandler commandHandler { get; set; } + public void EndPlacement(HitObject hitObject, bool commit) { EditorBeatmap.PlacementObject.Value = null; if (commit) { - EditorBeatmap.Add(hitObject); + commandHandler.SafeSubmit(new AddHitObjectCommand(EditorBeatmap, hitObject), true); if (autoSeekOnPlacement.Value && EditorClock.CurrentTime < hitObject.StartTime) EditorClock.SeekSmoothlyTo(hitObject.StartTime); } } - public void Delete(HitObject hitObject) => EditorBeatmap.Remove(hitObject); + public void Delete(HitObject hitObject) => commandHandler.SafeSubmit(new RemoveHitObjectCommand(EditorBeatmap, hitObject)); #endregion diff --git a/osu.Game/Screens/Edit/Commands/AddHitObjectCommand.cs b/osu.Game/Screens/Edit/Commands/AddHitObjectCommand.cs new file mode 100644 index 0000000000..7a353d13be --- /dev/null +++ b/osu.Game/Screens/Edit/Commands/AddHitObjectCommand.cs @@ -0,0 +1,24 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Game.Rulesets.Objects; + +namespace osu.Game.Screens.Edit.Commands +{ + public class AddHitObjectCommand : IEditorCommand + { + public EditorBeatmap Beatmap; + + public HitObject HitObject; + + public AddHitObjectCommand(EditorBeatmap beatmap, HitObject hitObject) + { + Beatmap = beatmap; + HitObject = hitObject; + } + + public void Apply() => Beatmap.Add(HitObject); + + public IEditorCommand CreateUndo() => new RemoveHitObjectCommand(Beatmap, HitObject); + } +} diff --git a/osu.Game/Screens/Edit/Commands/RemoveHitObjectCommand.cs b/osu.Game/Screens/Edit/Commands/RemoveHitObjectCommand.cs new file mode 100644 index 0000000000..a647107b0a --- /dev/null +++ b/osu.Game/Screens/Edit/Commands/RemoveHitObjectCommand.cs @@ -0,0 +1,24 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Game.Rulesets.Objects; + +namespace osu.Game.Screens.Edit.Commands +{ + public class RemoveHitObjectCommand : IEditorCommand + { + public EditorBeatmap Beatmap; + + public HitObject HitObject; + + public RemoveHitObjectCommand(EditorBeatmap beatmap, HitObject hitObject) + { + Beatmap = beatmap; + HitObject = hitObject; + } + + public void Apply() => Beatmap.Remove(HitObject); + + public IEditorCommand CreateUndo() => new AddHitObjectCommand(Beatmap, HitObject); + } +}