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
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
2019-11-06 16:27:41 +08:00
|
|
|
using osuTK;
|
2018-11-16 16:12:24 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Edit
|
|
|
|
{
|
2018-11-19 15:58:11 +08:00
|
|
|
public class OsuSelectionHandler : SelectionHandler
|
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-11-06 16:27:41 +08:00
|
|
|
Vector2 minPosition = new Vector2(float.MaxValue, float.MaxValue);
|
|
|
|
Vector2 maxPosition = new Vector2(float.MinValue, float.MinValue);
|
|
|
|
|
|
|
|
// Go through all hitobjects to make sure they would remain in the bounds of the editor after movement, before any movement is attempted
|
|
|
|
foreach (var h in SelectedHitObjects.OfType<OsuHitObject>())
|
|
|
|
{
|
|
|
|
if (h is Spinner)
|
|
|
|
{
|
|
|
|
// Spinners don't support position adjustments
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stacking is not considered
|
|
|
|
minPosition = Vector2.ComponentMin(minPosition, Vector2.ComponentMin(h.EndPosition + moveEvent.InstantDelta, h.Position + moveEvent.InstantDelta));
|
|
|
|
maxPosition = Vector2.ComponentMax(maxPosition, Vector2.ComponentMax(h.EndPosition + moveEvent.InstantDelta, h.Position + moveEvent.InstantDelta));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (minPosition.X < 0 || minPosition.Y < 0 || maxPosition.X > DrawWidth || maxPosition.Y > DrawHeight)
|
|
|
|
return false;
|
|
|
|
|
2018-11-16 16:12:24 +08:00
|
|
|
foreach (var h in SelectedHitObjects.OfType<OsuHitObject>())
|
|
|
|
{
|
|
|
|
if (h is Spinner)
|
|
|
|
{
|
|
|
|
// Spinners don't support position adjustments
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-10-08 18:08:23 +08:00
|
|
|
h.Position += moveEvent.InstantDelta;
|
2018-11-16 16:12:24 +08:00
|
|
|
}
|
2018-11-26 15:08:56 +08:00
|
|
|
|
2019-11-06 16:27:41 +08:00
|
|
|
return true;
|
2018-11-16 16:12:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|