1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 14:27:25 +08:00

Merge pull request #28421 from bdach/mania-editor-flip-controls

Implement flip operations in mania editor
This commit is contained in:
Dean Herbert 2024-06-08 00:10:16 +09:00 committed by GitHub
commit 1045742321
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 159 additions and 0 deletions

View File

@ -0,0 +1,96 @@
// 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 System.Linq;
using NUnit.Framework;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Screens.Edit.Compose.Components;
using osu.Game.Tests.Beatmaps;
using osu.Game.Tests.Visual;
using osuTK.Input;
namespace osu.Game.Rulesets.Mania.Tests.Editor
{
public partial class TestSceneManiaSelectionHandler : EditorTestScene
{
protected override Ruleset CreateEditorRuleset() => new ManiaRuleset();
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => new TestBeatmap(ruleset, false);
[Test]
public void TestHorizontalFlipOverSelection()
{
ManiaHitObject first = null!, second = null!, third = null!;
AddStep("create objects", () =>
{
EditorBeatmap.Add(first = new Note { StartTime = 250, Column = 2 });
EditorBeatmap.Add(second = new HoldNote { StartTime = 750, Duration = 1500, Column = 1 });
EditorBeatmap.Add(third = new Note { StartTime = 1250, Column = 3 });
});
AddStep("select everything", () => EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects));
AddStep("flip horizontally over selection", () =>
{
InputManager.MoveMouseTo(this.ChildrenOfType<SelectionBoxButton>().First());
InputManager.Click(MouseButton.Left);
});
AddAssert("first object stayed in place", () => first.Column, () => Is.EqualTo(2));
AddAssert("second object flipped", () => second.Column, () => Is.EqualTo(3));
AddAssert("third object flipped", () => third.Column, () => Is.EqualTo(1));
}
[Test]
public void TestHorizontalFlipOverPlayfield()
{
ManiaHitObject first = null!, second = null!, third = null!;
AddStep("create objects", () =>
{
EditorBeatmap.Add(first = new Note { StartTime = 250, Column = 2 });
EditorBeatmap.Add(second = new HoldNote { StartTime = 750, Duration = 1500, Column = 1 });
EditorBeatmap.Add(third = new Note { StartTime = 1250, Column = 3 });
});
AddStep("select everything", () => EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects));
AddStep("flip horizontally", () =>
{
InputManager.PressKey(Key.ControlLeft);
InputManager.Key(Key.H);
InputManager.ReleaseKey(Key.ControlLeft);
});
AddAssert("first object flipped", () => first.Column, () => Is.EqualTo(1));
AddAssert("second object flipped", () => second.Column, () => Is.EqualTo(2));
AddAssert("third object flipped", () => third.Column, () => Is.EqualTo(0));
}
[Test]
public void TestVerticalFlip()
{
ManiaHitObject first = null!, second = null!, third = null!;
AddStep("create objects", () =>
{
EditorBeatmap.Add(first = new Note { StartTime = 250, Column = 2 });
EditorBeatmap.Add(second = new HoldNote { StartTime = 750, Duration = 1500, Column = 1 });
EditorBeatmap.Add(third = new Note { StartTime = 1250, Column = 3 });
});
AddStep("select everything", () => EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects));
AddStep("flip vertically", () =>
{
InputManager.PressKey(Key.ControlLeft);
InputManager.Key(Key.J);
InputManager.ReleaseKey(Key.ControlLeft);
});
AddAssert("first object flipped", () => first.StartTime, () => Is.EqualTo(2250));
AddAssert("second object flipped", () => second.StartTime, () => Is.EqualTo(250));
AddAssert("third object flipped", () => third.StartTime, () => Is.EqualTo(1250));
}
}
}

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
@ -16,6 +17,16 @@ namespace osu.Game.Rulesets.Mania.Edit
[Resolved] [Resolved]
private HitObjectComposer composer { get; set; } = null!; private HitObjectComposer composer { get; set; } = null!;
protected override void OnSelectionChanged()
{
base.OnSelectionChanged();
var selectedObjects = SelectedItems.OfType<ManiaHitObject>().ToArray();
SelectionBox.CanFlipX = canFlipX(selectedObjects);
SelectionBox.CanFlipY = canFlipY(selectedObjects);
}
public override bool HandleMovement(MoveSelectionEvent<HitObject> moveEvent) public override bool HandleMovement(MoveSelectionEvent<HitObject> moveEvent)
{ {
var hitObjectBlueprint = (HitObjectSelectionBlueprint)moveEvent.Blueprint; var hitObjectBlueprint = (HitObjectSelectionBlueprint)moveEvent.Blueprint;
@ -26,6 +37,58 @@ namespace osu.Game.Rulesets.Mania.Edit
return true; return true;
} }
public override bool HandleFlip(Direction direction, bool flipOverOrigin)
{
var selectedObjects = SelectedItems.OfType<ManiaHitObject>().ToArray();
var maniaPlayfield = ((ManiaHitObjectComposer)composer).Playfield;
if (selectedObjects.Length == 0)
return false;
switch (direction)
{
case Direction.Horizontal:
if (!canFlipX(selectedObjects))
return false;
int firstColumn = flipOverOrigin ? 0 : selectedObjects.Min(ho => ho.Column);
int lastColumn = flipOverOrigin ? (int)EditorBeatmap.BeatmapInfo.Difficulty.CircleSize - 1 : selectedObjects.Max(ho => ho.Column);
EditorBeatmap.PerformOnSelection(hitObject =>
{
var maniaObject = (ManiaHitObject)hitObject;
maniaPlayfield.Remove(maniaObject);
maniaObject.Column = firstColumn + (lastColumn - maniaObject.Column);
maniaPlayfield.Add(maniaObject);
});
return true;
case Direction.Vertical:
if (!canFlipY(selectedObjects))
return false;
double selectionStartTime = selectedObjects.Min(ho => ho.StartTime);
double selectionEndTime = selectedObjects.Max(ho => ho.GetEndTime());
EditorBeatmap.PerformOnSelection(hitObject =>
{
hitObject.StartTime = selectionStartTime + (selectionEndTime - hitObject.GetEndTime());
});
return true;
default:
throw new ArgumentOutOfRangeException(nameof(direction), direction, "Cannot flip over the supplied direction.");
}
}
private static bool canFlipX(ManiaHitObject[] selectedObjects)
=> selectedObjects.Select(ho => ho.Column).Distinct().Count() > 1;
private static bool canFlipY(ManiaHitObject[] selectedObjects)
=> selectedObjects.Length > 1 && selectedObjects.Min(ho => ho.StartTime) < selectedObjects.Max(ho => ho.GetEndTime());
private void performColumnMovement(int lastColumn, MoveSelectionEvent<HitObject> moveEvent) private void performColumnMovement(int lastColumn, MoveSelectionEvent<HitObject> moveEvent)
{ {
var maniaPlayfield = ((ManiaHitObjectComposer)composer).Playfield; var maniaPlayfield = ((ManiaHitObjectComposer)composer).Playfield;