2019-01-24 08:43:03 +00: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 08:12:24 +00:00
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
2019-11-06 08:27:41 +00:00
|
|
|
using osuTK;
|
2018-11-16 08:12:24 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Edit
|
|
|
|
{
|
2018-11-19 07:58:11 +00:00
|
|
|
public class OsuSelectionHandler : SelectionHandler
|
2018-11-16 08:12:24 +00:00
|
|
|
{
|
2019-11-06 08:27:41 +00:00
|
|
|
public override bool HandleMovement(MoveSelectionEvent moveEvent)
|
2018-11-16 08:12:24 +00:00
|
|
|
{
|
2019-11-06 08:27:41 +00: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 08:12:24 +00:00
|
|
|
foreach (var h in SelectedHitObjects.OfType<OsuHitObject>())
|
|
|
|
{
|
|
|
|
if (h is Spinner)
|
|
|
|
{
|
|
|
|
// Spinners don't support position adjustments
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-10-08 10:08:23 +00:00
|
|
|
h.Position += moveEvent.InstantDelta;
|
2018-11-16 08:12:24 +00:00
|
|
|
}
|
2018-11-26 07:08:56 +00:00
|
|
|
|
2019-11-06 08:27:41 +00:00
|
|
|
return true;
|
2018-11-16 08:12:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|