mirror of
https://github.com/ppy/osu.git
synced 2025-02-28 17:02:55 +08:00
Fix blueprints behaving incorrectly
This commit is contained in:
parent
ab0ce46362
commit
085acf29a0
@ -6,7 +6,6 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Rulesets.Mania.Edit.Blueprints.Components;
|
||||
using osu.Game.Rulesets.Mania.Objects;
|
||||
using osu.Game.Rulesets.Mania.UI;
|
||||
using osuTK;
|
||||
|
||||
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 tailPiece;
|
||||
|
||||
private PlacementState state;
|
||||
|
||||
public HoldNotePlacementBlueprint()
|
||||
: base(new HoldNote())
|
||||
{
|
||||
@ -36,15 +33,10 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
|
||||
{
|
||||
base.Update();
|
||||
|
||||
switch (state)
|
||||
if (Column != null)
|
||||
{
|
||||
case PlacementState.Start:
|
||||
headPiece.Position = tailPiece.Position = SnappedMousePosition;
|
||||
headPiece.Width = tailPiece.Width = SnappedWidth;
|
||||
break;
|
||||
case PlacementState.End:
|
||||
tailPiece.Position = new Vector2(headPiece.Position.X, SnappedMousePosition.Y);
|
||||
break;
|
||||
headPiece.Y = PositionAt(HitObject.StartTime);
|
||||
tailPiece.Y = PositionAt(HitObject.EndTime);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
protected override bool OnMouseDown(MouseDownEvent e)
|
||||
private double originalStartTime;
|
||||
|
||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||
{
|
||||
Column column;
|
||||
if ((column = ColumnAt(e.ScreenSpaceMousePosition)) == null)
|
||||
return base.OnMouseDown(e);
|
||||
base.OnMouseMove(e);
|
||||
|
||||
HitObject.StartTime = TimeAt(e.ScreenSpaceMousePosition);
|
||||
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)
|
||||
if (PlacementBegun)
|
||||
{
|
||||
var tmp = endTime;
|
||||
endTime = HitObject.StartTime;
|
||||
HitObject.StartTime = tmp;
|
||||
var endTime = TimeAt(e.ScreenSpaceMousePosition);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private enum PlacementState
|
||||
{
|
||||
Start,
|
||||
End
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Mania.Objects;
|
||||
@ -13,11 +14,14 @@ using osuTK;
|
||||
|
||||
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
|
||||
{
|
||||
protected new T HitObject => (T)base.HitObject;
|
||||
|
||||
protected Column Column;
|
||||
|
||||
/// <summary>
|
||||
/// The current mouse position, snapped to the closest column.
|
||||
/// </summary>
|
||||
@ -40,31 +44,49 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
|
||||
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)
|
||||
{
|
||||
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
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected double TimeAt(Vector2 screenSpacePosition)
|
||||
{
|
||||
var column = ColumnAt(screenSpacePosition);
|
||||
if (column == null)
|
||||
if (Column == null)
|
||||
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
|
||||
// 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)
|
||||
hitObjectPos = hitObjectContainer.DrawHeight - hitObjectPos;
|
||||
|
||||
@ -74,21 +96,22 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
|
||||
hitObjectContainer.DrawHeight);
|
||||
}
|
||||
|
||||
protected Column ColumnAt(Vector2 screenSpacePosition)
|
||||
=> composer.ColumnAt(applyPositionOffset(screenSpacePosition));
|
||||
|
||||
private Vector2 applyPositionOffset(Vector2 position)
|
||||
protected float PositionAt(double time)
|
||||
{
|
||||
switch (scrollingInfo.Direction.Value)
|
||||
{
|
||||
case ScrollingDirection.Up:
|
||||
position.Y -= NotePiece.NOTE_HEIGHT / 2;
|
||||
break;
|
||||
case ScrollingDirection.Down:
|
||||
position.Y += NotePiece.NOTE_HEIGHT / 2;
|
||||
break;
|
||||
}
|
||||
var pos = scrollingInfo.Algorithm.PositionAt(time,
|
||||
EditorClock.CurrentTime,
|
||||
scrollingInfo.TimeRange.Value,
|
||||
Column.HitObjectContainer.DrawHeight);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,8 @@
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Rulesets.Mania.Edit.Blueprints.Components;
|
||||
using osu.Game.Rulesets.Mania.Objects;
|
||||
using osu.Game.Rulesets.Mania.UI;
|
||||
|
||||
namespace osu.Game.Rulesets.Mania.Edit.Blueprints
|
||||
{
|
||||
@ -28,19 +26,5 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
|
||||
Width = SnappedWidth;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user