Implement horizontal flipping of hit objects in catch editor

This commit is contained in:
ekrctb 2021-07-21 15:47:16 +09:00
parent 4c8b9c168e
commit d2d3214d47
2 changed files with 45 additions and 0 deletions

View File

@ -12,6 +12,7 @@ using osu.Game.Rulesets.UI;
using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Screens.Edit.Compose.Components;
using osuTK;
using Direction = osu.Framework.Graphics.Direction;
namespace osu.Game.Rulesets.Catch.Edit
{
@ -51,6 +52,26 @@ namespace osu.Game.Rulesets.Catch.Edit
return true;
}
public override bool HandleFlip(Direction direction)
{
var selectionRange = CatchHitObjectUtils.GetPositionRange(EditorBeatmap.SelectedHitObjects);
bool changed = false;
EditorBeatmap.PerformOnSelection(h =>
{
if (h is CatchHitObject hitObject)
changed |= handleFlip(selectionRange, hitObject);
});
return changed;
}
protected override void OnSelectionChanged()
{
base.OnSelectionChanged();
SelectionBox.CanFlipX = true;
}
/// <summary>
/// Limit positional movement of the objects by the constraint that moved objects should stay in bounds.
/// </summary>
@ -72,5 +93,27 @@ namespace osu.Game.Rulesets.Catch.Edit
return Math.Clamp(deltaX, lowerBound, upperBound);
}
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;
}
}
}
}

View File

@ -28,6 +28,8 @@ namespace osu.Game.Rulesets.Catch.Edit
public static PositionRange Union(PositionRange a, PositionRange b) => new PositionRange(Math.Min(a.Min, b.Min), Math.Max(a.Max, b.Max));
public float GetFlippedPosition(float x) => Max - (x - Min);
public static readonly PositionRange EMPTY = new PositionRange(float.PositiveInfinity, float.NegativeInfinity);
}
}