1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-28 21:45:37 +08:00

Fix blueprints behaving incorrectly

This commit is contained in:
Dean Herbert 2018-11-29 19:29:36 +09:00
parent ab0ce46362
commit 085acf29a0
3 changed files with 64 additions and 79 deletions

View File

@ -6,7 +6,6 @@ using osu.Framework.Graphics;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Rulesets.Mania.Edit.Blueprints.Components; using osu.Game.Rulesets.Mania.Edit.Blueprints.Components;
using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.UI;
using osuTK; using osuTK;
namespace osu.Game.Rulesets.Mania.Edit.Blueprints namespace osu.Game.Rulesets.Mania.Edit.Blueprints
@ -17,8 +16,6 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
private readonly EditNotePiece headPiece; private readonly EditNotePiece headPiece;
private readonly EditNotePiece tailPiece; private readonly EditNotePiece tailPiece;
private PlacementState state;
public HoldNotePlacementBlueprint() public HoldNotePlacementBlueprint()
: base(new HoldNote()) : base(new HoldNote())
{ {
@ -36,15 +33,10 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{ {
base.Update(); base.Update();
switch (state) if (Column != null)
{ {
case PlacementState.Start: headPiece.Y = PositionAt(HitObject.StartTime);
headPiece.Position = tailPiece.Position = SnappedMousePosition; tailPiece.Y = PositionAt(HitObject.EndTime);
headPiece.Width = tailPiece.Width = SnappedWidth;
break;
case PlacementState.End:
tailPiece.Position = new Vector2(headPiece.Position.X, SnappedMousePosition.Y);
break;
} }
var topPosition = new Vector2(headPiece.DrawPosition.X, Math.Min(headPiece.DrawPosition.Y, tailPiece.DrawPosition.Y)); var topPosition = new Vector2(headPiece.DrawPosition.X, Math.Min(headPiece.DrawPosition.Y, tailPiece.DrawPosition.Y));
@ -55,42 +47,28 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
bodyPiece.Height = (bottomPosition - topPosition).Y; bodyPiece.Height = (bottomPosition - topPosition).Y;
} }
protected override bool OnMouseDown(MouseDownEvent e) private double originalStartTime;
protected override bool OnMouseMove(MouseMoveEvent e)
{ {
Column column; base.OnMouseMove(e);
if ((column = ColumnAt(e.ScreenSpaceMousePosition)) == null)
return base.OnMouseDown(e);
HitObject.StartTime = TimeAt(e.ScreenSpaceMousePosition); if (PlacementBegun)
HitObject.Column = column.Index;
BeginPlacement();
state = PlacementState.End;
return true;
}
protected override bool OnMouseUp(MouseUpEvent e)
{
var endTime = TimeAt(e.ScreenSpaceMousePosition);
if (endTime < HitObject.StartTime)
{ {
var tmp = endTime; var endTime = TimeAt(e.ScreenSpaceMousePosition);
endTime = HitObject.StartTime;
HitObject.StartTime = tmp; HitObject.StartTime = endTime < originalStartTime ? endTime : originalStartTime;
HitObject.Duration = Math.Abs(endTime - originalStartTime);
}
else
{
headPiece.Width = tailPiece.Width = SnappedWidth;
headPiece.X = tailPiece.X = SnappedMousePosition.X;
originalStartTime = HitObject.StartTime = TimeAt(e.ScreenSpaceMousePosition);
} }
HitObject.Duration = endTime - HitObject.StartTime;
EndPlacement();
return true; return true;
} }
private enum PlacementState
{
Start,
End
}
} }
} }

View File

@ -3,6 +3,7 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Objects;
@ -13,11 +14,14 @@ using osuTK;
namespace osu.Game.Rulesets.Mania.Edit.Blueprints namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{ {
public abstract class ManiaPlacementBlueprint<T> : PlacementBlueprint public abstract class ManiaPlacementBlueprint<T> : PlacementBlueprint,
IRequireHighFrequencyMousePosition // the playfield could be moving behind us
where T : ManiaHitObject where T : ManiaHitObject
{ {
protected new T HitObject => (T)base.HitObject; protected new T HitObject => (T)base.HitObject;
protected Column Column;
/// <summary> /// <summary>
/// The current mouse position, snapped to the closest column. /// The current mouse position, snapped to the closest column.
/// </summary> /// </summary>
@ -40,31 +44,49 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
RelativeSizeAxes = Axes.None; RelativeSizeAxes = Axes.None;
} }
protected override bool OnMouseDown(MouseDownEvent e)
{
if (Column == null)
return base.OnMouseDown(e);
HitObject.StartTime = TimeAt(e.ScreenSpaceMousePosition);
HitObject.Column = Column.Index;
BeginPlacement();
return true;
}
protected override bool OnMouseUp(MouseUpEvent e)
{
EndPlacement();
return base.OnMouseUp(e);
}
protected override bool OnMouseMove(MouseMoveEvent e) protected override bool OnMouseMove(MouseMoveEvent e)
{ {
Column column = ColumnAt(e.ScreenSpaceMousePosition); if (!PlacementBegun)
Column = ColumnAt(e.ScreenSpaceMousePosition);
if (column == null) return false; if (Column == null) return false;
SnappedWidth = column.DrawWidth; SnappedWidth = Column.DrawWidth;
// Snap to the column // Snap to the column
var parentPos = Parent.ToLocalSpace(column.ToScreenSpace(new Vector2(column.DrawWidth / 2, 0))); var parentPos = Parent.ToLocalSpace(Column.ToScreenSpace(new Vector2(Column.DrawWidth / 2, 0)));
SnappedMousePosition = new Vector2(parentPos.X, e.MousePosition.Y); SnappedMousePosition = new Vector2(parentPos.X, e.MousePosition.Y);
return true; return true;
} }
protected double TimeAt(Vector2 screenSpacePosition) protected double TimeAt(Vector2 screenSpacePosition)
{ {
var column = ColumnAt(screenSpacePosition); if (Column == null)
if (column == null)
return 0; return 0;
var hitObjectContainer = column.HitObjectContainer; var hitObjectContainer = Column.HitObjectContainer;
// If we're scrolling downwards, a position of 0 is actually further away from the hit target // If we're scrolling downwards, a position of 0 is actually further away from the hit target
// so we need to flip the vertical coordinate in the hitobject container's space // so we need to flip the vertical coordinate in the hitobject container's space
var hitObjectPos = column.HitObjectContainer.ToLocalSpace(applyPositionOffset(screenSpacePosition)).Y; var hitObjectPos = Column.HitObjectContainer.ToLocalSpace(applyPositionOffset(screenSpacePosition, false)).Y;
if (scrollingInfo.Direction.Value == ScrollingDirection.Down) if (scrollingInfo.Direction.Value == ScrollingDirection.Down)
hitObjectPos = hitObjectContainer.DrawHeight - hitObjectPos; hitObjectPos = hitObjectContainer.DrawHeight - hitObjectPos;
@ -74,21 +96,22 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
hitObjectContainer.DrawHeight); hitObjectContainer.DrawHeight);
} }
protected Column ColumnAt(Vector2 screenSpacePosition) protected float PositionAt(double time)
=> composer.ColumnAt(applyPositionOffset(screenSpacePosition));
private Vector2 applyPositionOffset(Vector2 position)
{ {
switch (scrollingInfo.Direction.Value) var pos = scrollingInfo.Algorithm.PositionAt(time,
{ EditorClock.CurrentTime,
case ScrollingDirection.Up: scrollingInfo.TimeRange.Value,
position.Y -= NotePiece.NOTE_HEIGHT / 2; Column.HitObjectContainer.DrawHeight);
break;
case ScrollingDirection.Down:
position.Y += NotePiece.NOTE_HEIGHT / 2;
break;
}
return applyPositionOffset(Column.HitObjectContainer.ToSpaceOfOtherDrawable(new Vector2(0, pos), Parent), true).Y;
}
protected Column ColumnAt(Vector2 screenSpacePosition)
=> composer.ColumnAt(applyPositionOffset(screenSpacePosition, false));
private Vector2 applyPositionOffset(Vector2 position, bool reverse)
{
position.Y += (scrollingInfo.Direction.Value == ScrollingDirection.Up && !reverse ? -1 : 1) * NotePiece.NOTE_HEIGHT / 2;
return position; return position;
} }
} }

View File

@ -2,10 +2,8 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Mania.Edit.Blueprints.Components; using osu.Game.Rulesets.Mania.Edit.Blueprints.Components;
using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.UI;
namespace osu.Game.Rulesets.Mania.Edit.Blueprints namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{ {
@ -28,19 +26,5 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
Width = SnappedWidth; Width = SnappedWidth;
Position = SnappedMousePosition; Position = SnappedMousePosition;
} }
protected override bool OnClick(ClickEvent e)
{
Column column;
if ((column = ColumnAt(e.ScreenSpaceMousePosition)) == null)
return base.OnClick(e);
HitObject.StartTime = TimeAt(e.ScreenSpaceMousePosition);
HitObject.Column = column.Index;
EndPlacement();
return true;
}
} }
} }