mirror of
https://github.com/ppy/osu.git
synced 2024-12-16 23:42:54 +08:00
9c62c90cfc
Until now, the implementation of the overrides in `SelectionBlueprint` have been confusing to the point where I would just implement by trial-and-error (or copying from an existing implementation). This was due to a combination of using "object" space coordinates (ie. the thing the `Blueprint` is operating on) and screen-space coordinates. This change switches all event related coordinates to screen-space, which is how we already handle rotation/scale operations. With the introduction of other editor types where the related objects are drawables, this also makes a lot more sense.
68 lines
2.3 KiB
C#
68 lines
2.3 KiB
C#
// 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;
|
|
using System.Linq;
|
|
using osu.Framework.Allocation;
|
|
using osu.Game.Rulesets.Edit;
|
|
using osu.Game.Rulesets.Mania.Edit.Blueprints;
|
|
using osu.Game.Rulesets.Mania.Objects;
|
|
using osu.Game.Rulesets.Objects;
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
|
|
|
namespace osu.Game.Rulesets.Mania.Edit
|
|
{
|
|
public class ManiaSelectionHandler : EditorSelectionHandler
|
|
{
|
|
[Resolved]
|
|
private IScrollingInfo scrollingInfo { get; set; }
|
|
|
|
[Resolved]
|
|
private HitObjectComposer composer { get; set; }
|
|
|
|
public override bool HandleMovement(MoveSelectionEvent<HitObject> moveEvent)
|
|
{
|
|
var maniaBlueprint = (ManiaSelectionBlueprint)moveEvent.Blueprint;
|
|
int lastColumn = maniaBlueprint.DrawableObject.HitObject.Column;
|
|
|
|
performColumnMovement(lastColumn, moveEvent);
|
|
|
|
return true;
|
|
}
|
|
|
|
private void performColumnMovement(int lastColumn, MoveSelectionEvent<HitObject> moveEvent)
|
|
{
|
|
var maniaPlayfield = ((ManiaHitObjectComposer)composer).Playfield;
|
|
|
|
var currentColumn = maniaPlayfield.GetColumnByPosition(moveEvent.Blueprint.ScreenSpaceSelectionPoint + moveEvent.ScreenSpaceDelta);
|
|
if (currentColumn == null)
|
|
return;
|
|
|
|
int columnDelta = currentColumn.Index - lastColumn;
|
|
if (columnDelta == 0)
|
|
return;
|
|
|
|
int minColumn = int.MaxValue;
|
|
int maxColumn = int.MinValue;
|
|
|
|
// find min/max in an initial pass before actually performing the movement.
|
|
foreach (var obj in EditorBeatmap.SelectedHitObjects.OfType<ManiaHitObject>())
|
|
{
|
|
if (obj.Column < minColumn)
|
|
minColumn = obj.Column;
|
|
if (obj.Column > maxColumn)
|
|
maxColumn = obj.Column;
|
|
}
|
|
|
|
columnDelta = Math.Clamp(columnDelta, -minColumn, maniaPlayfield.TotalColumns - 1 - maxColumn);
|
|
|
|
EditorBeatmap.PerformOnSelection(h =>
|
|
{
|
|
if (h is ManiaHitObject maniaObj)
|
|
maniaObj.Column += columnDelta;
|
|
});
|
|
}
|
|
}
|
|
}
|