2021-06-22 01:39:32 +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.
|
|
|
|
|
2021-07-08 09:49:32 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2021-06-22 02:39:04 +00:00
|
|
|
using System.Linq;
|
2021-06-22 01:39:32 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Game.Rulesets.Catch.Objects;
|
2021-07-08 09:49:32 +00:00
|
|
|
using osu.Game.Rulesets.Catch.UI;
|
2021-06-22 01:39:32 +00: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 06:47:16 +00:00
|
|
|
using Direction = osu.Framework.Graphics.Direction;
|
2021-06-22 01:39:32 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.Edit
|
|
|
|
{
|
|
|
|
public partial class CatchSelectionHandler : EditorSelectionHandler
|
|
|
|
{
|
2021-06-23 01:18:44 +00:00
|
|
|
protected ScrollingHitObjectContainer HitObjectContainer => (ScrollingHitObjectContainer)playfield.HitObjectContainer;
|
|
|
|
|
2021-06-22 01:39:32 +00:00
|
|
|
[Resolved]
|
2023-01-15 07:00:34 +00:00
|
|
|
private Playfield playfield { get; set; } = null!;
|
2021-06-22 01:39:32 +00:00
|
|
|
|
|
|
|
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 03:58:08 +00:00
|
|
|
float deltaX = targetPosition.X - originalPosition.X;
|
2021-07-22 07:52:47 +00:00
|
|
|
deltaX = limitMovement(deltaX, SelectedItems);
|
2021-07-08 09:49:32 +00:00
|
|
|
|
|
|
|
if (deltaX == 0)
|
|
|
|
{
|
2021-07-10 09:22:54 +00:00
|
|
|
// Even if there is no positional change, there may be a time change.
|
2021-07-08 09:49:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-06-22 01:39:32 +00:00
|
|
|
EditorBeatmap.PerformOnSelection(h =>
|
|
|
|
{
|
2021-07-22 05:07:32 +00:00
|
|
|
if (!(h is CatchHitObject catchObject)) return;
|
2021-06-22 01:39:32 +00:00
|
|
|
|
2021-07-22 05:07:32 +00:00
|
|
|
catchObject.OriginalX += deltaX;
|
2021-06-22 02:39:04 +00:00
|
|
|
|
2021-06-23 01:19:39 +00:00
|
|
|
// Move the nested hit objects to give an instant result before nested objects are recreated.
|
2021-07-22 05:07:32 +00:00
|
|
|
foreach (var nested in catchObject.NestedHitObjects.OfType<CatchHitObject>())
|
2021-06-22 08:35:30 +00:00
|
|
|
nested.OriginalX += deltaX;
|
2021-06-22 01:39:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2021-07-08 09:49:32 +00:00
|
|
|
|
2022-01-05 07:46:34 +00:00
|
|
|
public override bool HandleFlip(Direction direction, bool flipOverOrigin)
|
2021-07-21 06:47:16 +00:00
|
|
|
{
|
2022-01-06 05:39:00 +00:00
|
|
|
if (SelectedItems.Count == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// This could be implemented in the future if there's a requirement for it.
|
|
|
|
if (direction == Direction.Vertical)
|
2022-01-05 07:56:54 +00:00
|
|
|
return false;
|
|
|
|
|
2021-07-22 07:52:47 +00:00
|
|
|
var selectionRange = CatchHitObjectUtils.GetPositionRange(SelectedItems);
|
2021-07-21 06:47:16 +00:00
|
|
|
|
|
|
|
bool changed = false;
|
2022-01-05 07:56:54 +00:00
|
|
|
|
2021-07-21 06:47:16 +00:00
|
|
|
EditorBeatmap.PerformOnSelection(h =>
|
|
|
|
{
|
2021-07-22 05:07:32 +00:00
|
|
|
if (h is CatchHitObject catchObject)
|
2022-01-05 07:46:34 +00:00
|
|
|
changed |= handleFlip(selectionRange, catchObject, flipOverOrigin);
|
2021-07-21 06:47:16 +00:00
|
|
|
});
|
2022-01-05 07:56:54 +00:00
|
|
|
|
2021-07-21 06:47:16 +00:00
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2021-07-22 08:00:08 +00: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 06:47:16 +00:00
|
|
|
protected override void OnSelectionChanged()
|
|
|
|
{
|
|
|
|
base.OnSelectionChanged();
|
|
|
|
|
2021-07-22 07:52:47 +00:00
|
|
|
var selectionRange = CatchHitObjectUtils.GetPositionRange(SelectedItems);
|
|
|
|
SelectionBox.CanFlipX = selectionRange.Length > 0 && SelectedItems.Any(h => h is CatchHitObject && !(h is BananaShower));
|
2021-07-22 08:00:08 +00:00
|
|
|
SelectionBox.CanReverse = SelectedItems.Count > 1 || SelectedItems.Any(h => h is JuiceStream);
|
2021-07-21 06:47:16 +00:00
|
|
|
}
|
|
|
|
|
2021-07-09 03:58:08 +00: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 06:37:42 +00:00
|
|
|
var range = CatchHitObjectUtils.GetPositionRange(movingObjects);
|
2021-07-09 03:58:08 +00: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 06:37:42 +00:00
|
|
|
float lowerBound = -range.Min;
|
|
|
|
float upperBound = CatchPlayfield.WIDTH - range.Max;
|
2021-07-09 03:58:08 +00: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 09:23:38 +00:00
|
|
|
if (lowerBound > upperBound)
|
2021-07-09 03:58:08 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return Math.Clamp(deltaX, lowerBound, upperBound);
|
|
|
|
}
|
2021-07-21 06:47:16 +00:00
|
|
|
|
2022-01-05 07:46:34 +00:00
|
|
|
private bool handleFlip(PositionRange selectionRange, CatchHitObject hitObject, bool flipOverOrigin)
|
2021-07-21 06:47:16 +00:00
|
|
|
{
|
|
|
|
switch (hitObject)
|
|
|
|
{
|
2022-06-24 12:25:23 +00:00
|
|
|
case BananaShower:
|
2021-07-21 06:47:16 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
case JuiceStream juiceStream:
|
2022-01-05 07:46:34 +00:00
|
|
|
juiceStream.OriginalX = getFlippedPosition(juiceStream.OriginalX);
|
2021-07-21 06:47:16 +00:00
|
|
|
|
|
|
|
foreach (var point in juiceStream.Path.ControlPoints)
|
2021-08-25 16:42:57 +00:00
|
|
|
point.Position *= new Vector2(-1, 1);
|
2021-07-21 06:47:16 +00:00
|
|
|
|
|
|
|
EditorBeatmap.Update(juiceStream);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2022-01-05 07:46:34 +00:00
|
|
|
hitObject.OriginalX = getFlippedPosition(hitObject.OriginalX);
|
2021-07-21 06:47:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
2022-01-05 07:46:34 +00:00
|
|
|
|
|
|
|
float getFlippedPosition(float original) => flipOverOrigin ? CatchPlayfield.WIDTH - original : selectionRange.GetFlippedPosition(original);
|
2021-07-21 06:47:16 +00:00
|
|
|
}
|
2021-06-22 01:39:32 +00:00
|
|
|
}
|
|
|
|
}
|