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 various shortcomings in juice stream selection blueprint #28999

Merged
merged 4 commits into from
Jul 23, 2024
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 @@ -158,14 +158,14 @@ public void TestAddVertex()
float[] positions = { 200, 200 };
addBlueprintStep(times, positions, 0.2);

addAddVertexSteps(500, 150);
addVertexCheckStep(3, 1, 500, 150);
addAddVertexSteps(500, 180);
addVertexCheckStep(3, 1, 500, 180);

addAddVertexSteps(90, 200);
addVertexCheckStep(4, 1, times[0], positions[0]);

addAddVertexSteps(750, 180);
addVertexCheckStep(5, 4, 750, 180);
addAddVertexSteps(750, 200);
addVertexCheckStep(5, 4, 750, 200);
Comment on lines +161 to +168
Copy link
Collaborator Author

@bdach bdach Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these test "fixes" appear arbitrary - that is because they are. They would fail after the rest of the changes, and as far as I can tell that is just a manifestation of #28915 that wasn't there before due to the lack of inline UpdateHitObjectFromPath() calls. I would ask to look away from this for now while I attempt to figure out what is going on over there (it is not easy, 99% chance it is floating point hell).

AddAssert("duration is changed", () => Precision.AlmostEquals(hitObject.Duration, 800 - times[0], 1e-3));
}

Expand Down Expand Up @@ -265,7 +265,7 @@ private void addDeleteVertexSteps(double time, float x)
AddStep("delete vertex", () =>
{
InputManager.PressKey(Key.ShiftLeft);
InputManager.Click(MouseButton.Left);
InputManager.Click(MouseButton.Right);
InputManager.ReleaseKey(Key.ShiftLeft);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Screens.Edit;
using osuTK;
using osuTK.Input;
Expand All @@ -19,22 +20,28 @@ public partial class SelectionEditablePath : EditablePath, IHasContextMenu
{
public MenuItem[] ContextMenuItems => getContextMenuItems().ToArray();

private readonly JuiceStream juiceStream;

// To handle when the editor is scrolled while dragging.
private Vector2 dragStartPosition;

[Resolved]
private IEditorChangeHandler? changeHandler { get; set; }

public SelectionEditablePath(Func<float, double> positionToTime)
public SelectionEditablePath(JuiceStream juiceStream, Func<float, double> positionToTime)
: base(positionToTime)
{
this.juiceStream = juiceStream;
}

public void AddVertex(Vector2 relativePosition)
{
changeHandler?.BeginChange();
double time = Math.Max(0, PositionToTime(relativePosition.Y));
int index = AddVertex(time, relativePosition.X);
UpdateHitObjectFromPath(juiceStream);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calls are required to actually make undo/redo work, because without this call, nothing in the actual beatmap changes, and changeHandler?.EndChange() ends up being a no-op.

selectOnly(index);
changeHandler?.EndChange();
}

public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => InternalChildren.Any(d => d.ReceivePositionalInputAt(screenSpacePos));
Expand All @@ -45,9 +52,13 @@ protected override bool OnMouseDown(MouseDownEvent e)
if (index == -1 || VertexStates[index].IsFixed)
return false;

if (e.Button == MouseButton.Left && e.ShiftPressed)
if (e.Button == MouseButton.Right && e.ShiftPressed)
{
changeHandler?.BeginChange();
RemoveVertex(index);
UpdateHitObjectFromPath(juiceStream);
changeHandler?.EndChange();

return true;
}

Expand Down Expand Up @@ -118,11 +129,17 @@ private void selectOnly(int index)

private void deleteSelectedVertices()
{
changeHandler?.BeginChange();

for (int i = VertexCount - 1; i >= 0; i--)
{
if (VertexStates[i].IsSelected)
RemoveVertex(i);
}

UpdateHitObjectFromPath(juiceStream);

changeHandler?.EndChange();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osuTK;

namespace osu.Game.Rulesets.Catch.Edit.Blueprints.Components
{
public partial class VertexPiece : Circle
{
private VertexState state = new VertexState();

[Resolved]
private OsuColour osuColour { get; set; } = null!;

Expand All @@ -24,7 +27,32 @@ public VertexPiece()

public void UpdateFrom(VertexState state)
{
Colour = state.IsSelected ? osuColour.Yellow.Lighten(1) : osuColour.Yellow;
this.state = state;
updateMarkerDisplay();
}

protected override bool OnHover(HoverEvent e)
{
updateMarkerDisplay();
return false;
}

protected override void OnHoverLost(HoverLostEvent e)
{
updateMarkerDisplay();
}

/// <summary>
/// Updates the state of the circular control point marker.
/// </summary>
private void updateMarkerDisplay()
{
var colour = osuColour.Yellow;

if (IsHovered || state.IsSelected)
colour = colour.Lighten(1);

Colour = colour;
Alpha = state.IsFixed ? 0.5f : 1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public JuiceStreamSelectionBlueprint(JuiceStream hitObject)
{
scrollingPath = new ScrollingPath(),
nestedOutlineContainer = new NestedOutlineContainer(),
editablePath = new SelectionEditablePath(positionToTime)
editablePath = new SelectionEditablePath(hitObject, positionToTime)
};
}

Expand Down
Loading