mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 18:52:55 +08:00
Combine implementation of time-to-position lookup
This commit is contained in:
parent
63b5f1a376
commit
69db62b78a
@ -49,6 +49,8 @@ namespace osu.Game.Rulesets.Mania.Tests
|
||||
|
||||
public Column ColumnAt(Vector2 screenSpacePosition) => column;
|
||||
|
||||
public Vector2 ScreenSpacePositionAtTime(double time, Column column = null) => Vector2.Zero;
|
||||
|
||||
public int TotalColumns => 1;
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,8 @@ namespace osu.Game.Rulesets.Mania.Tests
|
||||
|
||||
public Column ColumnAt(Vector2 screenSpacePosition) => column;
|
||||
|
||||
public Vector2 ScreenSpacePositionAtTime(double time, Column column = null) => Vector2.Zero;
|
||||
|
||||
public int TotalColumns => 1;
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,9 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
|
||||
private readonly EditNotePiece headPiece;
|
||||
private readonly EditNotePiece tailPiece;
|
||||
|
||||
[Resolved]
|
||||
private IManiaHitObjectComposer composer { get; set; }
|
||||
|
||||
public HoldNotePlacementBlueprint()
|
||||
: base(new HoldNote())
|
||||
{
|
||||
@ -39,8 +42,8 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
|
||||
|
||||
if (Column != null)
|
||||
{
|
||||
headPiece.Y = positionAt(HitObject.StartTime);
|
||||
tailPiece.Y = positionAt(HitObject.EndTime);
|
||||
headPiece.Y = Parent.ToLocalSpace(composer.ScreenSpacePositionAtTime(HitObject.StartTime, Column)).Y;
|
||||
tailPiece.Y = Parent.ToLocalSpace(composer.ScreenSpacePositionAtTime(HitObject.EndTime, Column)).Y;
|
||||
}
|
||||
|
||||
var topPosition = new Vector2(headPiece.DrawPosition.X, Math.Min(headPiece.DrawPosition.Y, tailPiece.DrawPosition.Y));
|
||||
@ -86,21 +89,5 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
|
||||
originalStartTime = HitObject.StartTime = startTime;
|
||||
}
|
||||
}
|
||||
|
||||
[Resolved]
|
||||
private IScrollingInfo scrollingInfo { get; set; }
|
||||
|
||||
private float positionAt(double time)
|
||||
{
|
||||
var pos = scrollingInfo.Algorithm.PositionAt(time,
|
||||
EditorClock.CurrentTime,
|
||||
scrollingInfo.TimeRange.Value,
|
||||
Column.HitObjectContainer.DrawHeight);
|
||||
|
||||
if (scrollingInfo.Direction.Value == ScrollingDirection.Down)
|
||||
pos = Column.HitObjectContainer.DrawHeight - pos;
|
||||
|
||||
return Column.HitObjectContainer.ToSpaceOfOtherDrawable(new Vector2(0, pos), Parent).Y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ namespace osu.Game.Rulesets.Mania.Edit
|
||||
{
|
||||
Column ColumnAt(Vector2 screenSpacePosition);
|
||||
|
||||
Vector2 ScreenSpacePositionAtTime(double time, Column column = null);
|
||||
|
||||
int TotalColumns { get; }
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +53,7 @@ namespace osu.Game.Rulesets.Mania.Edit
|
||||
|
||||
var hoc = column.HitObjectContainer;
|
||||
|
||||
// convert to local space of column so we can snap and fetch correct location.
|
||||
Vector2 localPosition = hoc.ToLocalSpace(screenSpacePosition);
|
||||
|
||||
var scrollInfo = drawableRuleset.ScrollingInfo;
|
||||
@ -65,24 +66,31 @@ namespace osu.Game.Rulesets.Mania.Edit
|
||||
localPosition.Y = hoc.DrawHeight - localPosition.Y;
|
||||
}
|
||||
|
||||
double targetTime = scrollInfo.Algorithm.TimeAt(localPosition.Y,
|
||||
EditorClock.CurrentTime,
|
||||
scrollInfo.TimeRange.Value,
|
||||
hoc.DrawHeight);
|
||||
double targetTime = scrollInfo.Algorithm.TimeAt(localPosition.Y, EditorClock.CurrentTime, scrollInfo.TimeRange.Value, hoc.DrawHeight);
|
||||
|
||||
// apply beat snapping
|
||||
targetTime = BeatSnapProvider.SnapTime(targetTime);
|
||||
|
||||
localPosition = new Vector2(
|
||||
hoc.DrawWidth / 2,
|
||||
scrollInfo.Algorithm.PositionAt(targetTime, EditorClock.CurrentTime, scrollInfo.TimeRange.Value, hoc.DrawHeight));
|
||||
// convert back to screen space
|
||||
screenSpacePosition = ScreenSpacePositionAtTime(targetTime, column);
|
||||
|
||||
return new ManiaSnapResult(screenSpacePosition, targetTime, column);
|
||||
}
|
||||
|
||||
public Vector2 ScreenSpacePositionAtTime(double time, Column column = null)
|
||||
{
|
||||
var hoc = (column ?? Playfield.GetColumn(0)).HitObjectContainer;
|
||||
var scrollInfo = drawableRuleset.ScrollingInfo;
|
||||
|
||||
var pos = scrollInfo.Algorithm.PositionAt(time, EditorClock.CurrentTime, scrollInfo.TimeRange.Value, hoc.DrawHeight);
|
||||
|
||||
if (scrollInfo.Direction.Value == ScrollingDirection.Down)
|
||||
{
|
||||
// reapply the above.
|
||||
localPosition.Y = hoc.DrawHeight - localPosition.Y;
|
||||
// as explained above
|
||||
pos = hoc.DrawHeight - pos;
|
||||
}
|
||||
|
||||
return new ManiaSnapResult(hoc.ToScreenSpace(localPosition), BeatSnapProvider.SnapTime(targetTime), column);
|
||||
return hoc.ToScreenSpace(new Vector2(hoc.DrawWidth / 2, pos));
|
||||
}
|
||||
|
||||
protected override DrawableRuleset<ManiaHitObject> CreateDrawableRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList<Mod> mods = null)
|
||||
|
Loading…
Reference in New Issue
Block a user