Skip to content

Commit

Permalink
Support simultaneously moving multiple Touch notes
Browse files Browse the repository at this point in the history
  • Loading branch information
Flutterish authored and LumpBloom7 committed May 11, 2021
1 parent 5c2b8ad commit 3915e05
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions osu.Game.Rulesets.Sentakki/Edit/SentakkiSelectionHandler.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Bindables;
Expand Down Expand Up @@ -68,26 +69,13 @@ public override bool HandleMovement(MoveSelectionEvent<HitObject> moveEvent)
}
return true;
}

if (SelectedBlueprints.Count > 1)
return false;

switch (moveEvent.Blueprint.Item)
else if (SelectedBlueprints.All(bp => bp.Item is Touch))
{
case Touch t:
Vector2 HitObjectPosition = t.Position;
HitObjectPosition += this.ScreenSpaceDeltaToParentSpace(moveEvent.ScreenSpaceDelta);

if (Vector2.Distance(Vector2.Zero, HitObjectPosition) > 250)
{
var currentAngle = Vector2.Zero.GetDegreesFromPosition(HitObjectPosition);
HitObjectPosition = SentakkiExtensions.GetCircularPosition(250, currentAngle);
}

t.Position = HitObjectPosition;
break;
// Special movement handling to ensure that all touch notes are within 250 units from the playfield centre
moveTouchNotes(this.ScreenSpaceDeltaToParentSpace(moveEvent.ScreenSpaceDelta));
return true;
}
return true;
return false;
}

private void setBreakState(bool state)
Expand Down Expand Up @@ -195,5 +183,28 @@ void commit()

return new OsuMenuItem(SlidePaths.VALIDPATHS[ID].Item1.EndLane.ToString(), MenuItemType.Standard, commit);
}

private void moveTouchNotes(Vector2 dragDelta)
{
const float boundary_radius = 250;

float dragDistance(Vector2 origin, Vector2 destination)
=> MathF.Min((destination - origin).Length, circleIntersectionDistance(origin, destination));

float circleIntersectionDistance(Vector2 centre, Vector2 direction)
{
direction.Normalize();
var b = (direction.X * centre.X) + (direction.Y * centre.Y);
var c = centre.LengthSquared - (boundary_radius * boundary_radius);
return MathF.Sqrt((b * b) - c) - b;
}

var touches = SelectedBlueprints.Select(bp => bp.Item as Touch).ToList();
var centre = touches.Aggregate(Vector2.Zero, (a, b) => a + b.Position) / touches.Count;
var cappedDragDelta = touches.Min(t => dragDistance(t.Position - centre, t.Position + dragDelta));

foreach (var touch in touches)
touch.Position = touch.Position - centre + (cappedDragDelta * (dragDelta + centre).Normalized());
}
}
}

0 comments on commit 3915e05

Please sign in to comment.