mirror of
https://github.com/ppy/osu.git
synced 2025-03-28 02:27:19 +08:00
Merge pull request #7803 from peppy/fix-blueprint-outside-container
Fix blueprint showing even when mouse outside of container
This commit is contained in:
commit
08d0a08d54
@ -52,7 +52,7 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
|
|||||||
{
|
{
|
||||||
base.UpdatePosition(screenSpacePosition);
|
base.UpdatePosition(screenSpacePosition);
|
||||||
|
|
||||||
if (PlacementBegun)
|
if (PlacementActive)
|
||||||
{
|
{
|
||||||
var endTime = TimeAt(screenSpacePosition);
|
var endTime = TimeAt(screenSpacePosition);
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
|
|||||||
|
|
||||||
public override void UpdatePosition(Vector2 screenSpacePosition)
|
public override void UpdatePosition(Vector2 screenSpacePosition)
|
||||||
{
|
{
|
||||||
if (!PlacementBegun)
|
if (!PlacementActive)
|
||||||
Column = ColumnAt(screenSpacePosition);
|
Column = ColumnAt(screenSpacePosition);
|
||||||
|
|
||||||
if (Column == null) return;
|
if (Column == null) return;
|
||||||
|
@ -126,7 +126,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
|
|||||||
|
|
||||||
private void beginCurve()
|
private void beginCurve()
|
||||||
{
|
{
|
||||||
BeginPlacement();
|
BeginPlacement(commitStart: true);
|
||||||
setState(PlacementState.Body);
|
setState(PlacementState.Body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Spinners
|
|||||||
if (e.Button != MouseButton.Left)
|
if (e.Button != MouseButton.Left)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
BeginPlacement();
|
BeginPlacement(commitStart: true);
|
||||||
piece.FadeTo(1f, 150, Easing.OutQuint);
|
piece.FadeTo(1f, 150, Easing.OutQuint);
|
||||||
|
|
||||||
isPlacingEnd = true;
|
isPlacingEnd = true;
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
|
||||||
using osu.Framework;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -20,17 +18,12 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A blueprint which governs the creation of a new <see cref="HitObject"/> to actualisation.
|
/// A blueprint which governs the creation of a new <see cref="HitObject"/> to actualisation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class PlacementBlueprint : CompositeDrawable, IStateful<PlacementState>
|
public abstract class PlacementBlueprint : CompositeDrawable
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked when <see cref="State"/> has changed.
|
/// Whether the <see cref="HitObject"/> is currently mid-placement, but has not necessarily finished being placed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event Action<PlacementState> StateChanged;
|
public bool PlacementActive { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether the <see cref="HitObject"/> is currently being placed, but has not necessarily finished being placed.
|
|
||||||
/// </summary>
|
|
||||||
public bool PlacementBegun { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The <see cref="HitObject"/> that is being placed.
|
/// The <see cref="HitObject"/> that is being placed.
|
||||||
@ -53,8 +46,6 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
// This is required to allow the blueprint's position to be updated via OnMouseMove/Handle
|
// This is required to allow the blueprint's position to be updated via OnMouseMove/Handle
|
||||||
// on the same frame it is made visible via a PlacementState change.
|
// on the same frame it is made visible via a PlacementState change.
|
||||||
AlwaysPresent = true;
|
AlwaysPresent = true;
|
||||||
|
|
||||||
Alpha = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -67,48 +58,29 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
ApplyDefaultsToHitObject();
|
ApplyDefaultsToHitObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlacementState state;
|
|
||||||
|
|
||||||
public PlacementState State
|
|
||||||
{
|
|
||||||
get => state;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (state == value)
|
|
||||||
return;
|
|
||||||
|
|
||||||
state = value;
|
|
||||||
|
|
||||||
if (state == PlacementState.Shown)
|
|
||||||
Show();
|
|
||||||
else
|
|
||||||
Hide();
|
|
||||||
|
|
||||||
StateChanged?.Invoke(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Signals that the placement of <see cref="HitObject"/> has started.
|
/// Signals that the placement of <see cref="HitObject"/> has started.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="startTime">The start time of <see cref="HitObject"/> at the placement point. If null, the current clock time is used.</param>
|
/// <param name="startTime">The start time of <see cref="HitObject"/> at the placement point. If null, the current clock time is used.</param>
|
||||||
protected void BeginPlacement(double? startTime = null)
|
/// <param name="commitStart">Whether this call is committing a value for HitObject.StartTime and continuing with further adjustments.</param>
|
||||||
|
protected void BeginPlacement(double? startTime = null, bool commitStart = false)
|
||||||
{
|
{
|
||||||
HitObject.StartTime = startTime ?? EditorClock.CurrentTime;
|
HitObject.StartTime = startTime ?? EditorClock.CurrentTime;
|
||||||
placementHandler.BeginPlacement(HitObject);
|
placementHandler.BeginPlacement(HitObject);
|
||||||
PlacementBegun = true;
|
PlacementActive |= commitStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Signals that the placement of <see cref="HitObject"/> has finished.
|
/// Signals that the placement of <see cref="HitObject"/> has finished.
|
||||||
/// This will destroy this <see cref="PlacementBlueprint"/>, and add the <see cref="HitObject"/> to the <see cref="Beatmap"/>.
|
/// This will destroy this <see cref="PlacementBlueprint"/>, and add the HitObject.StartTime to the <see cref="Beatmap"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="commit">Whether the object should be committed.</param>
|
/// <param name="commit">Whether the object should be committed.</param>
|
||||||
public void EndPlacement(bool commit)
|
public void EndPlacement(bool commit)
|
||||||
{
|
{
|
||||||
if (!PlacementBegun)
|
if (!PlacementActive)
|
||||||
BeginPlacement();
|
BeginPlacement();
|
||||||
placementHandler.EndPlacement(HitObject, commit);
|
placementHandler.EndPlacement(HitObject, commit);
|
||||||
|
PlacementActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -142,10 +114,4 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum PlacementState
|
|
||||||
{
|
|
||||||
Hidden,
|
|
||||||
Shown,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -62,20 +62,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void refreshTool()
|
private void refreshTool()
|
||||||
{
|
{
|
||||||
placementBlueprintContainer.Clear();
|
removePlacement();
|
||||||
|
createPlacement();
|
||||||
currentPlacement?.EndPlacement(false);
|
|
||||||
currentPlacement = null;
|
|
||||||
|
|
||||||
var blueprint = CurrentTool?.CreatePlacementBlueprint();
|
|
||||||
|
|
||||||
if (blueprint != null)
|
|
||||||
{
|
|
||||||
placementBlueprintContainer.Child = currentPlacement = blueprint;
|
|
||||||
|
|
||||||
// Fixes a 1-frame position discrepancy due to the first mouse move event happening in the next frame
|
|
||||||
updatePlacementPosition(inputManager.CurrentState.Mouse.Position);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePlacementPosition(Vector2 screenSpacePosition)
|
private void updatePlacementPosition(Vector2 screenSpacePosition)
|
||||||
@ -103,18 +91,16 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
if (currentPlacement != null)
|
if (composer.CursorInPlacementArea)
|
||||||
{
|
createPlacement();
|
||||||
if (composer.CursorInPlacementArea)
|
else if (currentPlacement?.PlacementActive == false)
|
||||||
currentPlacement.State = PlacementState.Shown;
|
removePlacement();
|
||||||
else if (currentPlacement?.PlacementBegun == false)
|
|
||||||
currentPlacement.State = PlacementState.Hidden;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected sealed override SelectionBlueprint CreateBlueprintFor(HitObject hitObject)
|
protected sealed override SelectionBlueprint CreateBlueprintFor(HitObject hitObject)
|
||||||
{
|
{
|
||||||
var drawable = drawableHitObjects.FirstOrDefault(d => d.HitObject == hitObject);
|
var drawable = drawableHitObjects.FirstOrDefault(d => d.HitObject == hitObject);
|
||||||
|
|
||||||
if (drawable == null)
|
if (drawable == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@ -129,6 +115,30 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
base.AddBlueprintFor(hitObject);
|
base.AddBlueprintFor(hitObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createPlacement()
|
||||||
|
{
|
||||||
|
if (currentPlacement != null) return;
|
||||||
|
|
||||||
|
var blueprint = CurrentTool?.CreatePlacementBlueprint();
|
||||||
|
|
||||||
|
if (blueprint != null)
|
||||||
|
{
|
||||||
|
placementBlueprintContainer.Child = currentPlacement = blueprint;
|
||||||
|
|
||||||
|
// Fixes a 1-frame position discrepancy due to the first mouse move event happening in the next frame
|
||||||
|
updatePlacementPosition(inputManager.CurrentState.Mouse.Position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removePlacement()
|
||||||
|
{
|
||||||
|
if (currentPlacement == null) return;
|
||||||
|
|
||||||
|
currentPlacement.EndPlacement(false);
|
||||||
|
currentPlacement.Expire();
|
||||||
|
currentPlacement = null;
|
||||||
|
}
|
||||||
|
|
||||||
private HitObjectCompositionTool currentTool;
|
private HitObjectCompositionTool currentTool;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -137,6 +147,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
public HitObjectCompositionTool CurrentTool
|
public HitObjectCompositionTool CurrentTool
|
||||||
{
|
{
|
||||||
get => currentTool;
|
get => currentTool;
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (currentTool == value)
|
if (currentTool == value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user