1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 22:33:05 +08:00

Move positioning out of mania blueprints

This commit is contained in:
Dean Herbert 2020-05-20 19:23:17 +09:00
parent 62092e3f5b
commit 2f78866dfb
4 changed files with 26 additions and 60 deletions

View File

@ -74,8 +74,11 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
}
else
{
headPiece.Width = tailPiece.Width = SnappedWidth;
headPiece.X = tailPiece.X = SnappedMousePosition.X;
if (result is ManiaSnapResult maniaResult)
{
headPiece.Width = tailPiece.Width = maniaResult.Column.DrawWidth;
headPiece.X = tailPiece.X = ToLocalSpace(result.ScreenSpacePosition).X;
}
if (result.Time is double startTime)
originalStartTime = HitObject.StartTime = startTime;

View File

@ -23,16 +23,6 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
protected Column Column;
/// <summary>
/// The current mouse position, snapped to the closest column.
/// </summary>
protected Vector2 SnappedMousePosition { get; private set; }
/// <summary>
/// The width of the closest column to the current mouse position.
/// </summary>
protected float SnappedWidth { get; private set; }
[Resolved]
private IScrollingInfo scrollingInfo { get; set; }
@ -59,14 +49,6 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{
if (!PlacementActive)
Column = (result as ManiaSnapResult)?.Column;
if (Column == null) return;
SnappedWidth = Column.DrawWidth;
// Snap to the column
var parentPos = Parent.ToLocalSpace(Column.ToScreenSpace(new Vector2(Column.DrawWidth / 2, 0)));
SnappedMousePosition = new Vector2(parentPos.X, Parent.ToLocalSpace(result.ScreenSpacePosition).Y);
}
protected float PositionAt(double time)
@ -82,30 +64,6 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
return hitObjectToMousePosition(Column.HitObjectContainer.ToSpaceOfOtherDrawable(new Vector2(0, pos), Parent)).Y;
}
/// <summary>
/// Converts a mouse position to a hitobject position.
/// </summary>
/// <remarks>
/// Blueprints are centred on the mouse position, such that the hitobject position is anchored at the top or bottom of the blueprint depending on the scroll direction.
/// </remarks>
/// <param name="mousePosition">The mouse position.</param>
/// <returns>The resulting hitobject position, acnhored at the top or bottom of the blueprint depending on the scroll direction.</returns>
private Vector2 mouseToHitObjectPosition(Vector2 mousePosition)
{
switch (scrollingInfo.Direction.Value)
{
case ScrollingDirection.Up:
mousePosition.Y -= DefaultNotePiece.NOTE_HEIGHT / 2;
break;
case ScrollingDirection.Down:
mousePosition.Y += DefaultNotePiece.NOTE_HEIGHT / 2;
break;
}
return mousePosition;
}
/// <summary>
/// Converts a hitobject position to a mouse position.
/// </summary>

View File

@ -3,6 +3,7 @@
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Mania.Edit.Blueprints.Components;
using osu.Game.Rulesets.Mania.Objects;
using osuTK.Input;
@ -11,22 +12,25 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{
public class NotePlacementBlueprint : ManiaPlacementBlueprint<Note>
{
private readonly EditNotePiece piece;
public NotePlacementBlueprint()
: base(new Note())
{
Origin = Anchor.Centre;
RelativeSizeAxes = Axes.Both;
AutoSizeAxes = Axes.Y;
InternalChild = new EditNotePiece { RelativeSizeAxes = Axes.X };
InternalChild = piece = new EditNotePiece { Origin = Anchor.Centre };
}
protected override void Update()
public override void UpdatePosition(SnapResult result)
{
base.Update();
base.UpdatePosition(result);
Width = SnappedWidth;
Position = SnappedMousePosition;
if (result is ManiaSnapResult maniaResult)
{
piece.Width = maniaResult.Column.DrawWidth;
piece.Position = ToLocalSpace(result.ScreenSpacePosition);
}
}
protected override bool OnMouseDown(MouseDownEvent e)

View File

@ -55,7 +55,9 @@ namespace osu.Game.Rulesets.Mania.Edit
Vector2 localPosition = hoc.ToLocalSpace(screenSpacePosition);
if (drawableRuleset.ScrollingInfo.Direction.Value == ScrollingDirection.Down)
var scrollInfo = drawableRuleset.ScrollingInfo;
if (scrollInfo.Direction.Value == ScrollingDirection.Down)
{
// We're dealing with screen coordinates in which the position decreases towards the centre of the screen resulting in an increase in start time.
// The scrolling algorithm instead assumes a top anchor meaning an increase in time corresponds to an increase in position,
@ -63,19 +65,18 @@ namespace osu.Game.Rulesets.Mania.Edit
localPosition.Y = hoc.DrawHeight - localPosition.Y;
}
double targetTime = drawableRuleset.ScrollingInfo.Algorithm.TimeAt(localPosition.Y,
double targetTime = scrollInfo.Algorithm.TimeAt(localPosition.Y,
EditorClock.CurrentTime,
drawableRuleset.ScrollingInfo.TimeRange.Value,
scrollInfo.TimeRange.Value,
hoc.DrawHeight);
targetTime = BeatSnapProvider.SnapTime(targetTime);
screenSpacePosition.Y = hoc.ToScreenSpace(
new Vector2(0, drawableRuleset.ScrollingInfo.Algorithm.PositionAt(targetTime, EditorClock.CurrentTime, drawableRuleset.ScrollingInfo.TimeRange.Value,
hoc.DrawHeight))
).Y;
var localPos = new Vector2(
hoc.DrawWidth / 2,
scrollInfo.Algorithm.PositionAt(targetTime, EditorClock.CurrentTime, scrollInfo.TimeRange.Value, hoc.DrawHeight));
return new ManiaSnapResult(screenSpacePosition, BeatSnapProvider.SnapTime(targetTime), column);
return new ManiaSnapResult(hoc.ToScreenSpace(localPos), BeatSnapProvider.SnapTime(targetTime), column);
}
protected override DrawableRuleset<ManiaHitObject> CreateDrawableRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList<Mod> mods = null)