2019-01-24 16:43:03 +08:00
|
|
|
// 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.
|
2018-11-16 16:12:24 +08:00
|
|
|
|
2019-11-20 20:19:49 +08:00
|
|
|
using System;
|
2018-11-16 16:12:24 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2020-05-27 22:15:16 +08:00
|
|
|
using osu.Game.Rulesets.Edit;
|
2018-11-26 15:08:56 +08:00
|
|
|
using osu.Game.Rulesets.Mania.Edit.Blueprints;
|
2018-11-16 16:12:24 +08:00
|
|
|
using osu.Game.Rulesets.Mania.Objects;
|
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.Edit
|
|
|
|
{
|
2018-11-19 15:58:11 +08:00
|
|
|
public class ManiaSelectionHandler : SelectionHandler
|
2018-11-16 16:12:24 +08:00
|
|
|
{
|
|
|
|
[Resolved]
|
|
|
|
private IScrollingInfo scrollingInfo { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
2020-05-27 22:15:16 +08:00
|
|
|
private HitObjectComposer composer { get; set; }
|
2018-11-16 16:12:24 +08:00
|
|
|
|
2019-11-06 16:27:41 +08:00
|
|
|
public override bool HandleMovement(MoveSelectionEvent moveEvent)
|
2018-11-16 16:12:24 +08:00
|
|
|
{
|
2019-10-08 18:08:23 +08:00
|
|
|
var maniaBlueprint = (ManiaSelectionBlueprint)moveEvent.Blueprint;
|
2019-10-21 16:04:56 +08:00
|
|
|
int lastColumn = maniaBlueprint.DrawableObject.HitObject.Column;
|
2019-10-08 17:57:03 +08:00
|
|
|
|
2019-10-08 18:08:23 +08:00
|
|
|
performColumnMovement(lastColumn, moveEvent);
|
2018-11-26 15:08:56 +08:00
|
|
|
|
2019-11-06 16:27:41 +08:00
|
|
|
return true;
|
2018-11-26 15:08:56 +08:00
|
|
|
}
|
|
|
|
|
2019-10-08 18:08:23 +08:00
|
|
|
private void performColumnMovement(int lastColumn, MoveSelectionEvent moveEvent)
|
2018-11-16 16:12:24 +08:00
|
|
|
{
|
2020-05-27 22:15:16 +08:00
|
|
|
var maniaPlayfield = ((ManiaHitObjectComposer)composer).Playfield;
|
|
|
|
|
|
|
|
var currentColumn = maniaPlayfield.GetColumnByPosition(moveEvent.ScreenSpacePosition);
|
2019-10-08 17:57:03 +08:00
|
|
|
if (currentColumn == null)
|
2018-11-16 16:12:24 +08:00
|
|
|
return;
|
|
|
|
|
2019-10-08 17:57:03 +08:00
|
|
|
int columnDelta = currentColumn.Index - lastColumn;
|
2018-11-16 16:12:24 +08:00
|
|
|
if (columnDelta == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int minColumn = int.MaxValue;
|
|
|
|
int maxColumn = int.MinValue;
|
|
|
|
|
|
|
|
foreach (var obj in SelectedHitObjects.OfType<ManiaHitObject>())
|
|
|
|
{
|
|
|
|
if (obj.Column < minColumn)
|
|
|
|
minColumn = obj.Column;
|
|
|
|
if (obj.Column > maxColumn)
|
|
|
|
maxColumn = obj.Column;
|
|
|
|
}
|
|
|
|
|
2020-05-27 22:15:16 +08:00
|
|
|
columnDelta = Math.Clamp(columnDelta, -minColumn, maniaPlayfield.TotalColumns - 1 - maxColumn);
|
2018-11-16 16:12:24 +08:00
|
|
|
|
|
|
|
foreach (var obj in SelectedHitObjects.OfType<ManiaHitObject>())
|
|
|
|
obj.Column += columnDelta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|