mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 15:16:38 +09:00
Snap placement blueprint to columns
This commit is contained in:
@ -3,6 +3,8 @@
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Mania.Objects;
|
||||
using osu.Game.Rulesets.Mania.UI;
|
||||
@ -16,6 +18,11 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
|
||||
{
|
||||
protected new T HitObject => (T)base.HitObject;
|
||||
|
||||
/// <summary>
|
||||
/// The current mouse position, snapped to the closest column.
|
||||
/// </summary>
|
||||
protected Vector2 SnappedMousePosition { get; private set; }
|
||||
|
||||
[Resolved]
|
||||
private IManiaHitObjectComposer composer { get; set; }
|
||||
|
||||
@ -28,6 +35,31 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
|
||||
RelativeSizeAxes = Axes.None;
|
||||
}
|
||||
|
||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||
{
|
||||
updateSnappedPosition(e);
|
||||
return true;
|
||||
}
|
||||
|
||||
private ScheduledDelegate scheduledSnappedPositionUpdate;
|
||||
|
||||
private void updateSnappedPosition(MouseMoveEvent e)
|
||||
{
|
||||
scheduledSnappedPositionUpdate?.Cancel();
|
||||
scheduledSnappedPositionUpdate = Schedule(() =>
|
||||
{
|
||||
Column column = ColumnAt(e.ScreenSpaceMousePosition);
|
||||
if (column == null)
|
||||
SnappedMousePosition = e.MousePosition;
|
||||
else
|
||||
{
|
||||
// Snap to the column
|
||||
var parentPos = Parent.ToLocalSpace(column.ToScreenSpace(new Vector2(column.DrawWidth / 2, 0)));
|
||||
SnappedMousePosition = new Vector2(parentPos.X, e.MousePosition.Y);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected double TimeAt(Vector2 screenSpacePosition)
|
||||
{
|
||||
var column = ColumnAt(screenSpacePosition);
|
||||
|
@ -22,10 +22,11 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
|
||||
InternalChild = new EditNotePiece { RelativeSizeAxes = Axes.X };
|
||||
}
|
||||
|
||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||
protected override void Update()
|
||||
{
|
||||
Position = e.MousePosition;
|
||||
return true;
|
||||
base.Update();
|
||||
|
||||
Position = SnappedMousePosition;
|
||||
}
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
|
Reference in New Issue
Block a user