mirror of
https://github.com/ppy/osu.git
synced 2024-12-05 10:33:22 +08:00
Use commands for moving HitObjects in OsuSelectionHandler
This commit is contained in:
parent
fe9e84b47d
commit
508701f4dd
@ -17,6 +17,8 @@ using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Rulesets.Osu.Beatmaps;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Rulesets.Osu.UI;
|
||||
using osu.Game.Screens.Edit;
|
||||
using osu.Game.Screens.Edit.Commands;
|
||||
using osu.Game.Screens.Edit.Compose.Components;
|
||||
using osu.Game.Utils;
|
||||
using osuTK;
|
||||
@ -51,6 +53,9 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
return false;
|
||||
}
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private EditorCommandHandler? commandManager { get; set; }
|
||||
|
||||
public override bool HandleMovement(MoveSelectionEvent<HitObject> moveEvent)
|
||||
{
|
||||
var hitObjects = selectedMovableObjects;
|
||||
@ -70,12 +75,10 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
if (hitObjects.Any(h => Precision.AlmostEquals(localDelta, -h.StackOffset)))
|
||||
return true;
|
||||
|
||||
// this will potentially move the selection out of bounds...
|
||||
foreach (var h in hitObjects)
|
||||
h.Position += localDelta;
|
||||
localDelta = moveSelectionInBounds(localDelta);
|
||||
|
||||
// but this will be corrected.
|
||||
moveSelectionInBounds();
|
||||
foreach (var h in hitObjects)
|
||||
commandManager.SafeSubmit(new MoveCommand(h, h.Position + localDelta));
|
||||
|
||||
// manually update stacking.
|
||||
// this intentionally bypasses the editor `UpdateState()` / beatmap processor flow for performance reasons,
|
||||
@ -105,7 +108,7 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
foreach (var h in hitObjects)
|
||||
{
|
||||
if (moreThanOneObject)
|
||||
h.StartTime = endTime - (h.GetEndTime() - startTime);
|
||||
commandManager.SafeSubmit(new SetStartTimeCommand(h, endTime - (h.GetEndTime() - startTime)));
|
||||
|
||||
if (h is Slider slider)
|
||||
{
|
||||
@ -187,26 +190,23 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
|
||||
public override SelectionScaleHandler CreateScaleHandler() => new OsuSelectionScaleHandler();
|
||||
|
||||
private void moveSelectionInBounds()
|
||||
private Vector2 moveSelectionInBounds(Vector2 delta)
|
||||
{
|
||||
var hitObjects = selectedMovableObjects;
|
||||
|
||||
Quad quad = GeometryUtils.GetSurroundingQuad(hitObjects);
|
||||
|
||||
Vector2 delta = Vector2.Zero;
|
||||
if (quad.TopLeft.X + delta.X < 0)
|
||||
delta.X -= quad.TopLeft.X + delta.X;
|
||||
if (quad.TopLeft.Y + delta.Y < 0)
|
||||
delta.Y -= quad.TopLeft.Y + delta.Y;
|
||||
|
||||
if (quad.TopLeft.X < 0)
|
||||
delta.X -= quad.TopLeft.X;
|
||||
if (quad.TopLeft.Y < 0)
|
||||
delta.Y -= quad.TopLeft.Y;
|
||||
if (quad.BottomRight.X + delta.X > DrawWidth)
|
||||
delta.X -= quad.BottomRight.X + delta.X - DrawWidth;
|
||||
if (quad.BottomRight.Y + delta.Y > DrawHeight)
|
||||
delta.Y -= quad.BottomRight.Y + delta.Y - DrawHeight;
|
||||
|
||||
if (quad.BottomRight.X > DrawWidth)
|
||||
delta.X -= quad.BottomRight.X - DrawWidth;
|
||||
if (quad.BottomRight.Y > DrawHeight)
|
||||
delta.Y -= quad.BottomRight.Y - DrawHeight;
|
||||
|
||||
foreach (var h in hitObjects)
|
||||
h.Position += delta;
|
||||
return delta;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -309,6 +309,13 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
EditorBeatmap.EndChange();
|
||||
}
|
||||
|
||||
protected override void OnOperationEnded()
|
||||
{
|
||||
base.OnOperationEnded();
|
||||
|
||||
commandManager?.Commit();
|
||||
}
|
||||
|
||||
protected override IEnumerable<MenuItem> GetContextMenuItemsForSelection(IEnumerable<SelectionBlueprint<HitObject>> selection)
|
||||
{
|
||||
foreach (var item in base.GetContextMenuItemsForSelection(selection))
|
||||
|
@ -42,7 +42,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
private IPositionSnapProvider snapProvider { get; set; }
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private IEditorChangeHandler changeHandler { get; set; }
|
||||
private EditorCommandHandler commandHandler { get; set; }
|
||||
|
||||
protected readonly BindableList<T> SelectedItems = new BindableList<T>();
|
||||
|
||||
@ -190,7 +190,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
if (movementBlueprints != null)
|
||||
{
|
||||
isDraggingBlueprint = true;
|
||||
changeHandler?.BeginChange();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -218,7 +217,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
if (isDraggingBlueprint)
|
||||
{
|
||||
DragOperationCompleted();
|
||||
changeHandler?.EndChange();
|
||||
commandHandler?.Commit();
|
||||
}
|
||||
|
||||
DragBox.Hide();
|
||||
|
@ -52,7 +52,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
protected SelectionBox SelectionBox { get; private set; } = null!;
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
protected IEditorChangeHandler? ChangeHandler { get; private set; }
|
||||
protected EditorCommandHandler? CommandHandler { get; private set; }
|
||||
|
||||
public SelectionRotationHandler RotationHandler { get; private set; } = null!;
|
||||
|
||||
@ -105,7 +105,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
/// </summary>
|
||||
protected virtual void OnOperationBegan()
|
||||
{
|
||||
ChangeHandler?.BeginChange();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -113,7 +112,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
/// </summary>
|
||||
protected virtual void OnOperationEnded()
|
||||
{
|
||||
ChangeHandler?.EndChange();
|
||||
CommandHandler?.Commit();
|
||||
}
|
||||
|
||||
#region User Input Handling
|
||||
@ -188,16 +187,14 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
switch (e.Action)
|
||||
{
|
||||
case GlobalAction.EditorFlipHorizontally:
|
||||
ChangeHandler?.BeginChange();
|
||||
handled = HandleFlip(Direction.Horizontal, true);
|
||||
ChangeHandler?.EndChange();
|
||||
CommandHandler?.Commit();
|
||||
|
||||
return handled;
|
||||
|
||||
case GlobalAction.EditorFlipVertically:
|
||||
ChangeHandler?.BeginChange();
|
||||
handled = HandleFlip(Direction.Vertical, true);
|
||||
ChangeHandler?.EndChange();
|
||||
CommandHandler?.Commit();
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user