Merge pull request #7803 from peppy/fix-blueprint-outside-container

Fix blueprint showing even when mouse outside of container
This commit is contained in:
Dan Balasescu 2020-02-13 17:54:28 +09:00 committed by GitHub
commit 08d0a08d54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 68 deletions

View File

@ -52,7 +52,7 @@ public override void UpdatePosition(Vector2 screenSpacePosition)
{
base.UpdatePosition(screenSpacePosition);
if (PlacementBegun)
if (PlacementActive)
{
var endTime = TimeAt(screenSpacePosition);

View File

@ -62,7 +62,7 @@ protected override void OnMouseUp(MouseUpEvent e)
public override void UpdatePosition(Vector2 screenSpacePosition)
{
if (!PlacementBegun)
if (!PlacementActive)
Column = ColumnAt(screenSpacePosition);
if (Column == null) return;

View File

@ -126,7 +126,7 @@ protected override bool OnDoubleClick(DoubleClickEvent e)
private void beginCurve()
{
BeginPlacement();
BeginPlacement(commitStart: true);
setState(PlacementState.Body);
}

View File

@ -52,7 +52,7 @@ protected override bool OnMouseDown(MouseDownEvent e)
if (e.Button != MouseButton.Left)
return false;
BeginPlacement();
BeginPlacement(commitStart: true);
piece.FadeTo(1f, 150, Easing.OutQuint);
isPlacingEnd = true;

View File

@ -1,8 +1,6 @@
// 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.
using System;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -20,17 +18,12 @@ namespace osu.Game.Rulesets.Edit
/// <summary>
/// A blueprint which governs the creation of a new <see cref="HitObject"/> to actualisation.
/// </summary>
public abstract class PlacementBlueprint : CompositeDrawable, IStateful<PlacementState>
public abstract class PlacementBlueprint : CompositeDrawable
{
/// <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>
public event Action<PlacementState> StateChanged;
/// <summary>
/// Whether the <see cref="HitObject"/> is currently being placed, but has not necessarily finished being placed.
/// </summary>
public bool PlacementBegun { get; private set; }
public bool PlacementActive { get; private set; }
/// <summary>
/// The <see cref="HitObject"/> that is being placed.
@ -53,8 +46,6 @@ protected PlacementBlueprint(HitObject hitObject)
// 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.
AlwaysPresent = true;
Alpha = 0;
}
[BackgroundDependencyLoader]
@ -67,48 +58,29 @@ private void load(IBindable<WorkingBeatmap> beatmap, IAdjustableClock clock)
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>
/// Signals that the placement of <see cref="HitObject"/> has started.
/// </summary>
/// <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;
placementHandler.BeginPlacement(HitObject);
PlacementBegun = true;
PlacementActive |= commitStart;
}
/// <summary>
/// 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>
/// <param name="commit">Whether the object should be committed.</param>
public void EndPlacement(bool commit)
{
if (!PlacementBegun)
if (!PlacementActive)
BeginPlacement();
placementHandler.EndPlacement(HitObject, commit);
PlacementActive = false;
}
/// <summary>
@ -142,10 +114,4 @@ protected override bool Handle(UIEvent e)
}
}
}
public enum PlacementState
{
Hidden,
Shown,
}
}

View File

@ -62,20 +62,8 @@ protected override void LoadComplete()
/// </summary>
private void refreshTool()
{
placementBlueprintContainer.Clear();
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);
}
removePlacement();
createPlacement();
}
private void updatePlacementPosition(Vector2 screenSpacePosition)
@ -103,18 +91,16 @@ protected override void Update()
{
base.Update();
if (currentPlacement != null)
{
if (composer.CursorInPlacementArea)
currentPlacement.State = PlacementState.Shown;
else if (currentPlacement?.PlacementBegun == false)
currentPlacement.State = PlacementState.Hidden;
}
if (composer.CursorInPlacementArea)
createPlacement();
else if (currentPlacement?.PlacementActive == false)
removePlacement();
}
protected sealed override SelectionBlueprint CreateBlueprintFor(HitObject hitObject)
{
var drawable = drawableHitObjects.FirstOrDefault(d => d.HitObject == hitObject);
if (drawable == null)
return null;
@ -129,6 +115,30 @@ protected override void AddBlueprintFor(HitObject 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;
/// <summary>
@ -137,6 +147,7 @@ protected override void AddBlueprintFor(HitObject hitObject)
public HitObjectCompositionTool CurrentTool
{
get => currentTool;
set
{
if (currentTool == value)