From 25101ecd2cfaf0634a6c4f65b1933d770f53c2a5 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 13 Nov 2018 14:13:29 +0900 Subject: [PATCH] Snap placement blueprint to columns --- .../Blueprints/ManiaPlacementBlueprint.cs | 32 +++++++++++++++++++ .../Edit/Blueprints/NotePlacementBlueprint.cs | 7 ++-- osu.Game.Rulesets.Mania/UI/Column.cs | 5 +++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs index 305c92671f..bfa07d0014 100644 --- a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs +++ b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs @@ -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; + /// + /// The current mouse position, snapped to the closest column. + /// + 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); diff --git a/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs b/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs index 1549b0ae45..0a904d962e 100644 --- a/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs +++ b/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs @@ -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) diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index da3ee8dddf..4c1929f182 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -13,6 +13,7 @@ using osu.Framework.Input.Bindings; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Mania.UI.Components; using osu.Game.Rulesets.UI.Scrolling; +using OpenTK; namespace osu.Game.Rulesets.Mania.UI { @@ -172,5 +173,9 @@ namespace osu.Game.Rulesets.Mania.UI } public bool OnReleased(ManiaAction action) => false; + + public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) + // This probably shouldn't exist as is, but the columns in the stage are separated by a 1px border + => DrawRectangle.Inflate(new Vector2(1, 0)).Contains(ToLocalSpace(screenSpacePos)); } }