1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 02:42:54 +08:00

Merge pull request #12437 from peppy/fix-editor-placement-commit-false

Fix placement blueprints not being correctly removed after a rolled back placement
This commit is contained in:
Dan Balasescu 2021-04-16 16:25:05 +09:00 committed by GitHub
commit d3acbcced7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 27 deletions

View File

@ -82,7 +82,7 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{
base.UpdateTimeAndPosition(result);
if (PlacementActive)
if (PlacementActive == PlacementState.Active)
{
if (result.Time is double endTime)
{

View File

@ -52,7 +52,7 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{
base.UpdateTimeAndPosition(result);
if (!PlacementActive)
if (PlacementActive == PlacementState.Waiting)
Column = result.Playfield as Column;
}
}

View File

@ -30,7 +30,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
private InputManager inputManager;
private PlacementState state;
private SliderPlacementState state;
private PathControlPoint segmentStart;
private PathControlPoint cursor;
private int currentSegmentLength;
@ -58,7 +58,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
controlPointVisualiser = new PathControlPointVisualiser(HitObject, false)
};
setState(PlacementState.Initial);
setState(SliderPlacementState.Initial);
}
protected override void LoadComplete()
@ -73,12 +73,12 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
switch (state)
{
case PlacementState.Initial:
case SliderPlacementState.Initial:
BeginPlacement();
HitObject.Position = ToLocalSpace(result.ScreenSpacePosition);
break;
case PlacementState.Body:
case SliderPlacementState.Body:
updateCursor();
break;
}
@ -91,11 +91,11 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
switch (state)
{
case PlacementState.Initial:
case SliderPlacementState.Initial:
beginCurve();
break;
case PlacementState.Body:
case SliderPlacementState.Body:
if (canPlaceNewControlPoint(out var lastPoint))
{
// Place a new point by detatching the current cursor.
@ -121,7 +121,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
protected override void OnMouseUp(MouseUpEvent e)
{
if (state == PlacementState.Body && e.Button == MouseButton.Right)
if (state == SliderPlacementState.Body && e.Button == MouseButton.Right)
endCurve();
base.OnMouseUp(e);
}
@ -129,7 +129,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
private void beginCurve()
{
BeginPlacement(commitStart: true);
setState(PlacementState.Body);
setState(SliderPlacementState.Body);
}
private void endCurve()
@ -219,12 +219,12 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
tailCirclePiece.UpdateFrom(HitObject.TailCircle);
}
private void setState(PlacementState newState)
private void setState(SliderPlacementState newState)
{
state = newState;
}
private enum PlacementState
private enum SliderPlacementState
{
Initial,
Body,

View File

@ -72,7 +72,7 @@ namespace osu.Game.Rulesets.Taiko.Edit.Blueprints
{
base.UpdateTimeAndPosition(result);
if (PlacementActive)
if (PlacementActive == PlacementState.Active)
{
if (result.Time is double dragTime)
{

View File

@ -25,7 +25,7 @@ namespace osu.Game.Rulesets.Edit
/// <summary>
/// Whether the <see cref="HitObject"/> is currently mid-placement, but has not necessarily finished being placed.
/// </summary>
public bool PlacementActive { get; private set; }
public PlacementState PlacementActive { get; private set; }
/// <summary>
/// The <see cref="HitObject"/> that is being placed.
@ -72,7 +72,8 @@ namespace osu.Game.Rulesets.Edit
protected void BeginPlacement(bool commitStart = false)
{
placementHandler.BeginPlacement(HitObject);
PlacementActive |= commitStart;
if (commitStart)
PlacementActive = PlacementState.Active;
}
/// <summary>
@ -82,10 +83,19 @@ namespace osu.Game.Rulesets.Edit
/// <param name="commit">Whether the object should be committed.</param>
public void EndPlacement(bool commit)
{
if (!PlacementActive)
BeginPlacement();
switch (PlacementActive)
{
case PlacementState.Finished:
return;
case PlacementState.Waiting:
// ensure placement was started before ending to make state handling simpler.
BeginPlacement();
break;
}
placementHandler.EndPlacement(HitObject, commit);
PlacementActive = false;
PlacementActive = PlacementState.Finished;
}
/// <summary>
@ -94,7 +104,7 @@ namespace osu.Game.Rulesets.Edit
/// <param name="result">The snap result information.</param>
public virtual void UpdateTimeAndPosition(SnapResult result)
{
if (!PlacementActive)
if (PlacementActive == PlacementState.Waiting)
HitObject.StartTime = result.Time ?? EditorClock?.CurrentTime ?? Time.Current;
}
@ -125,5 +135,12 @@ namespace osu.Game.Rulesets.Edit
return false;
}
}
public enum PlacementState
{
Waiting,
Active,
Finished
}
}
}

View File

@ -196,7 +196,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
private void refreshTool()
{
removePlacement();
createPlacement();
ensurePlacementCreated();
}
private void updatePlacementPosition()
@ -215,15 +215,26 @@ namespace osu.Game.Screens.Edit.Compose.Components
{
base.Update();
if (Composer.CursorInPlacementArea)
createPlacement();
else if (currentPlacement?.PlacementActive == false)
removePlacement();
if (currentPlacement != null)
{
updatePlacementPosition();
switch (currentPlacement.PlacementActive)
{
case PlacementBlueprint.PlacementState.Waiting:
if (!Composer.CursorInPlacementArea)
removePlacement();
break;
case PlacementBlueprint.PlacementState.Finished:
removePlacement();
break;
}
}
if (Composer.CursorInPlacementArea)
ensurePlacementCreated();
if (currentPlacement != null)
updatePlacementPosition();
}
protected sealed override SelectionBlueprint CreateBlueprintFor(HitObject hitObject)
@ -249,7 +260,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
NewCombo.Value = TernaryState.False;
}
private void createPlacement()
private void ensurePlacementCreated()
{
if (currentPlacement != null) return;