Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix placement blueprints not being correctly removed after a rolled back placement #12437

Merged
merged 2 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public override void UpdateTimeAndPosition(SnapResult result)
{
base.UpdateTimeAndPosition(result);

if (PlacementActive)
if (PlacementActive == PlacementState.Active)
{
if (result.Time is double endTime)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override void UpdateTimeAndPosition(SnapResult result)
{
base.UpdateTimeAndPosition(result);

if (!PlacementActive)
if (PlacementActive == PlacementState.Waiting)
Column = result.Playfield as Column;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SliderPlacementBlueprint : PlacementBlueprint

private InputManager inputManager;

private PlacementState state;
private SliderPlacementState state;
private PathControlPoint segmentStart;
private PathControlPoint cursor;
private int currentSegmentLength;
Expand Down Expand Up @@ -58,7 +58,7 @@ private void load(OsuColour colours)
controlPointVisualiser = new PathControlPointVisualiser(HitObject, false)
};

setState(PlacementState.Initial);
setState(SliderPlacementState.Initial);
}

protected override void LoadComplete()
Expand All @@ -73,12 +73,12 @@ public override void UpdateTimeAndPosition(SnapResult result)

switch (state)
{
case PlacementState.Initial:
case SliderPlacementState.Initial:
BeginPlacement();
HitObject.Position = ToLocalSpace(result.ScreenSpacePosition);
break;

case PlacementState.Body:
case SliderPlacementState.Body:
updateCursor();
break;
}
Expand All @@ -91,11 +91,11 @@ protected override bool OnMouseDown(MouseDownEvent e)

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.
Expand All @@ -121,15 +121,15 @@ protected override bool OnMouseDown(MouseDownEvent e)

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);
}

private void beginCurve()
{
BeginPlacement(commitStart: true);
setState(PlacementState.Body);
setState(SliderPlacementState.Body);
}

private void endCurve()
Expand Down Expand Up @@ -219,12 +219,12 @@ private void updateSlider()
tailCirclePiece.UpdateFrom(HitObject.TailCircle);
}

private void setState(PlacementState newState)
private void setState(SliderPlacementState newState)
{
state = newState;
}

private enum PlacementState
private enum SliderPlacementState
{
Initial,
Body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override void UpdateTimeAndPosition(SnapResult result)
{
base.UpdateTimeAndPosition(result);

if (PlacementActive)
if (PlacementActive == PlacementState.Active)
{
if (result.Time is double dragTime)
{
Expand Down
29 changes: 23 additions & 6 deletions osu.Game/Rulesets/Edit/PlacementBlueprint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class PlacementBlueprint : CompositeDrawable
/// <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.
Expand Down Expand Up @@ -72,7 +72,8 @@ private void load(IBindable<WorkingBeatmap> beatmap)
protected void BeginPlacement(bool commitStart = false)
{
placementHandler.BeginPlacement(HitObject);
PlacementActive |= commitStart;
if (commitStart)
PlacementActive = PlacementState.Active;
}

/// <summary>
Expand All @@ -82,10 +83,19 @@ protected void BeginPlacement(bool commitStart = false)
/// <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>
Expand All @@ -94,7 +104,7 @@ public void EndPlacement(bool commit)
/// <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;
}

Expand Down Expand Up @@ -125,5 +135,12 @@ protected override bool Handle(UIEvent e)
return false;
}
}

public enum PlacementState
{
Waiting,
Active,
Finished
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private Drawable getIconForSample(string sampleName)
private void refreshTool()
{
removePlacement();
createPlacement();
ensurePlacementCreated();
}

private void updatePlacementPosition()
Expand All @@ -215,15 +215,26 @@ protected override void Update()
{
base.Update();

if (currentPlacement != null)
{
switch (currentPlacement.PlacementActive)
{
case PlacementBlueprint.PlacementState.Waiting:
if (!Composer.CursorInPlacementArea)
removePlacement();
break;

case PlacementBlueprint.PlacementState.Finished:
removePlacement();
break;
}
}

if (Composer.CursorInPlacementArea)
createPlacement();
else if (currentPlacement?.PlacementActive == false)
removePlacement();
ensurePlacementCreated();

if (currentPlacement != null)
{
updatePlacementPosition();
}
}

protected sealed override SelectionBlueprint CreateBlueprintFor(HitObject hitObject)
Expand All @@ -249,7 +260,7 @@ protected override void OnBlueprintAdded(HitObject hitObject)
NewCombo.Value = TernaryState.False;
}

private void createPlacement()
private void ensurePlacementCreated()
{
if (currentPlacement != null) return;

Expand Down