1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 18:23:00 +08:00

Fix placement blueprints not receiving latest mouse position with touch input

This commit is contained in:
Salman Alshamrani 2024-10-13 11:00:29 -04:00
parent 86b240d131
commit f8c8184c5c
2 changed files with 40 additions and 6 deletions

View File

@ -295,8 +295,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
ensurePlacementCreated(); ensurePlacementCreated();
} }
private void updatePlacementPosition() private void updatePlacementTimeAndPosition()
{ {
if (CurrentPlacement == null)
return;
var snapResult = Composer.FindSnappedPositionAndTime(InputManager.CurrentState.Mouse.Position, CurrentPlacement.SnapType); var snapResult = Composer.FindSnappedPositionAndTime(InputManager.CurrentState.Mouse.Position, CurrentPlacement.SnapType);
// if no time was found from positional snapping, we should still quantize to the beat. // if no time was found from positional snapping, we should still quantize to the beat.
@ -329,8 +332,15 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (Composer.CursorInPlacementArea) if (Composer.CursorInPlacementArea)
ensurePlacementCreated(); ensurePlacementCreated();
if (CurrentPlacement != null) // updates the placement with the latest editor clock time.
updatePlacementPosition(); updatePlacementTimeAndPosition();
}
protected override bool OnMouseMove(MouseMoveEvent e)
{
// updates the placement with the latest mouse position.
updatePlacementTimeAndPosition();
return base.OnMouseMove(e);
} }
protected sealed override SelectionBlueprint<HitObject> CreateBlueprintFor(HitObject item) protected sealed override SelectionBlueprint<HitObject> CreateBlueprintFor(HitObject item)
@ -367,7 +377,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
placementBlueprintContainer.Child = CurrentPlacement = blueprint; placementBlueprintContainer.Child = CurrentPlacement = blueprint;
// Fixes a 1-frame position discrepancy due to the first mouse move event happening in the next frame // Fixes a 1-frame position discrepancy due to the first mouse move event happening in the next frame
updatePlacementPosition(); updatePlacementTimeAndPosition();
updatePlacementSamples(); updatePlacementSamples();

View File

@ -3,9 +3,11 @@
#nullable disable #nullable disable
using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Framework.Timing; using osu.Framework.Timing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
@ -24,6 +26,10 @@ namespace osu.Game.Tests.Visual
protected PlacementBlueprintTestScene() protected PlacementBlueprintTestScene()
{ {
base.Content.Add(HitObjectContainer = CreateHitObjectContainer().With(c => c.Clock = new FramedClock(new StopwatchClock()))); base.Content.Add(HitObjectContainer = CreateHitObjectContainer().With(c => c.Clock = new FramedClock(new StopwatchClock())));
base.Content.Add(new MouseMovementInterceptor
{
MouseMoved = updatePlacementTimeAndPosition,
});
} }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
@ -83,10 +89,11 @@ namespace osu.Game.Tests.Visual
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
updatePlacementTimeAndPosition();
CurrentBlueprint.UpdateTimeAndPosition(SnapForBlueprint(CurrentBlueprint));
} }
private void updatePlacementTimeAndPosition() => CurrentBlueprint.UpdateTimeAndPosition(SnapForBlueprint(CurrentBlueprint));
protected virtual SnapResult SnapForBlueprint(HitObjectPlacementBlueprint blueprint) => protected virtual SnapResult SnapForBlueprint(HitObjectPlacementBlueprint blueprint) =>
new SnapResult(InputManager.CurrentState.Mouse.Position, null); new SnapResult(InputManager.CurrentState.Mouse.Position, null);
@ -107,5 +114,22 @@ namespace osu.Game.Tests.Visual
protected abstract DrawableHitObject CreateHitObject(HitObject hitObject); protected abstract DrawableHitObject CreateHitObject(HitObject hitObject);
protected abstract HitObjectPlacementBlueprint CreateBlueprint(); protected abstract HitObjectPlacementBlueprint CreateBlueprint();
private partial class MouseMovementInterceptor : Drawable
{
public Action MouseMoved;
public MouseMovementInterceptor()
{
RelativeSizeAxes = Axes.Both;
Depth = float.MinValue;
}
protected override bool OnMouseMove(MouseMoveEvent e)
{
MouseMoved?.Invoke();
return base.OnMouseMove(e);
}
}
} }
} }