2021-06-22 09:39:32 +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.
|
|
|
|
|
2021-07-08 17:49:32 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2021-06-22 10:39:04 +08:00
|
|
|
using System.Linq;
|
2021-06-22 09:39:32 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Game.Rulesets.Catch.Objects;
|
2021-07-08 17:49:32 +08:00
|
|
|
using osu.Game.Rulesets.Catch.UI;
|
2021-06-22 09:39:32 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
|
|
|
using osuTK;
|
2021-07-21 14:47:16 +08:00
|
|
|
using Direction = osu.Framework.Graphics.Direction;
|
2021-06-22 09:39:32 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.Edit
|
|
|
|
{
|
|
|
|
public class CatchSelectionHandler : EditorSelectionHandler
|
|
|
|
{
|
2021-06-23 09:18:44 +08:00
|
|
|
protected ScrollingHitObjectContainer HitObjectContainer => (ScrollingHitObjectContainer)playfield.HitObjectContainer;
|
|
|
|
|
2021-06-22 09:39:32 +08:00
|
|
|
[Resolved]
|
|
|
|
private Playfield playfield { get; set; }
|
|
|
|
|
|
|
|
public override bool HandleMovement(MoveSelectionEvent<HitObject> moveEvent)
|
|
|
|
{
|
|
|
|
var blueprint = moveEvent.Blueprint;
|
|
|
|
Vector2 originalPosition = HitObjectContainer.ToLocalSpace(blueprint.ScreenSpaceSelectionPoint);
|
|
|
|
Vector2 targetPosition = HitObjectContainer.ToLocalSpace(blueprint.ScreenSpaceSelectionPoint + moveEvent.ScreenSpaceDelta);
|
|
|
|
|
2021-07-09 11:58:08 +08:00
|
|
|
float deltaX = targetPosition.X - originalPosition.X;
|
2021-07-22 15:52:47 +08:00
|
|
|
deltaX = limitMovement(deltaX, SelectedItems);
|
2021-07-08 17:49:32 +08:00
|
|
|
|
|
|
|
if (deltaX == 0)
|
|
|
|
{
|
2021-07-10 17:22:54 +08:00
|
|
|
// Even if there is no positional change, there may be a time change.
|
2021-07-08 17:49:32 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-06-22 09:39:32 +08:00
|
|
|
EditorBeatmap.PerformOnSelection(h =>
|
|
|
|
{
|
2021-07-22 13:07:32 +08:00
|
|
|
if (!(h is CatchHitObject catchObject)) return;
|
2021-06-22 09:39:32 +08:00
|
|
|
|
2021-07-22 13:07:32 +08:00
|
|
|
catchObject.OriginalX += deltaX;
|
2021-06-22 10:39:04 +08:00
|
|
|
|
2021-06-23 09:19:39 +08:00
|
|
|
// Move the nested hit objects to give an instant result before nested objects are recreated.
|
2021-07-22 13:07:32 +08:00
|
|
|
foreach (var nested in catchObject.NestedHitObjects.OfType<CatchHitObject>())
|
2021-06-22 16:35:30 +08:00
|
|
|
nested.OriginalX += deltaX;
|
2021-06-22 09:39:32 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2021-07-08 17:49:32 +08:00
|
|
|
|
2021-07-21 14:47:16 +08:00
|
|
|
public override bool HandleFlip(Direction direction)
|
|
|
|
{
|
2021-07-22 15:52:47 +08:00
|
|
|
var selectionRange = CatchHitObjectUtils.GetPositionRange(SelectedItems);
|
2021-07-21 14:47:16 +08:00
|
|
|
|
|
|
|
bool changed = false;
|
|
|
|
EditorBeatmap.PerformOnSelection(h =>
|
|
|
|
{
|
2021-07-22 13:07:32 +08:00
|
|
|
if (h is CatchHitObject catchObject)
|
|
|
|
changed |= handleFlip(selectionRange, catchObject);
|
2021-07-21 14:47:16 +08:00
|
|
|
});
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2021-07-22 16:00:08 +08:00
|
|
|
public override bool HandleReverse()
|
|
|
|
{
|
|
|
|
double selectionStartTime = SelectedItems.Min(h => h.StartTime);
|
|
|
|
double selectionEndTime = SelectedItems.Max(h => h.GetEndTime());
|
|
|
|
|
|
|
|
EditorBeatmap.PerformOnSelection(hitObject =>
|
|
|
|
{
|
|
|
|
hitObject.StartTime = selectionEndTime - (hitObject.GetEndTime() - selectionStartTime);
|
|
|
|
|
|
|
|
if (hitObject is JuiceStream juiceStream)
|
|
|
|
{
|
|
|
|
juiceStream.Path.Reverse(out Vector2 positionalOffset);
|
|
|
|
juiceStream.OriginalX += positionalOffset.X;
|
|
|
|
juiceStream.LegacyConvertedY += positionalOffset.Y;
|
|
|
|
EditorBeatmap.Update(juiceStream);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-07-21 14:47:16 +08:00
|
|
|
protected override void OnSelectionChanged()
|
|
|
|
{
|
|
|
|
base.OnSelectionChanged();
|
|
|
|
|
2021-07-22 15:52:47 +08:00
|
|
|
var selectionRange = CatchHitObjectUtils.GetPositionRange(SelectedItems);
|
|
|
|
SelectionBox.CanFlipX = selectionRange.Length > 0 && SelectedItems.Any(h => h is CatchHitObject && !(h is BananaShower));
|
2021-07-22 16:00:08 +08:00
|
|
|
SelectionBox.CanReverse = SelectedItems.Count > 1 || SelectedItems.Any(h => h is JuiceStream);
|
2021-07-21 14:47:16 +08:00
|
|
|
}
|
|
|
|
|
2021-07-09 11:58:08 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Limit positional movement of the objects by the constraint that moved objects should stay in bounds.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="deltaX">The positional movement.</param>
|
|
|
|
/// <param name="movingObjects">The objects to be moved.</param>
|
|
|
|
/// <returns>The positional movement with the restriction applied.</returns>
|
|
|
|
private float limitMovement(float deltaX, IEnumerable<HitObject> movingObjects)
|
|
|
|
{
|
2021-07-21 14:37:42 +08:00
|
|
|
var range = CatchHitObjectUtils.GetPositionRange(movingObjects);
|
2021-07-09 11:58:08 +08:00
|
|
|
// To make an object with position `x` stay in bounds after `deltaX` movement, `0 <= x + deltaX <= WIDTH` should be satisfied.
|
|
|
|
// Subtracting `x`, we get `-x <= deltaX <= WIDTH - x`.
|
|
|
|
// We only need to apply the inequality to extreme values of `x`.
|
2021-07-21 14:37:42 +08:00
|
|
|
float lowerBound = -range.Min;
|
|
|
|
float upperBound = CatchPlayfield.WIDTH - range.Max;
|
2021-07-09 11:58:08 +08:00
|
|
|
// The inequality may be unsatisfiable if the objects were already out of bounds.
|
|
|
|
// In that case, don't move objects at all.
|
2021-07-10 17:23:38 +08:00
|
|
|
if (lowerBound > upperBound)
|
2021-07-09 11:58:08 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return Math.Clamp(deltaX, lowerBound, upperBound);
|
|
|
|
}
|
2021-07-21 14:47:16 +08:00
|
|
|
|
|
|
|
private bool handleFlip(PositionRange selectionRange, CatchHitObject hitObject)
|
|
|
|
{
|
|
|
|
switch (hitObject)
|
|
|
|
{
|
|
|
|
case BananaShower _:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case JuiceStream juiceStream:
|
|
|
|
juiceStream.OriginalX = selectionRange.GetFlippedPosition(juiceStream.OriginalX);
|
|
|
|
|
|
|
|
foreach (var point in juiceStream.Path.ControlPoints)
|
|
|
|
point.Position.Value *= new Vector2(-1, 1);
|
|
|
|
|
|
|
|
EditorBeatmap.Update(juiceStream);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
hitObject.OriginalX = selectionRange.GetFlippedPosition(hitObject.OriginalX);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2021-06-22 09:39:32 +08:00
|
|
|
}
|
|
|
|
}
|