1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 23:23:52 +08:00

Fix EditablePath.UpdateHitObjectFromPath() not automatically updating object

This is important because the editable path conversions heavily depend
on the value of `JuiceStream.Velocity` being correct. The value is only
guaranteed to be correct after an `ApplyDefaults()` call, which is
triggered by updating the object via `EditorBeatmap`.
This commit is contained in:
Bartłomiej Dach 2024-07-22 14:47:33 +02:00
parent 1d91201c43
commit 56af009e77
No known key found for this signature in database
2 changed files with 15 additions and 13 deletions

View File

@ -13,6 +13,7 @@ using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.UI.Scrolling; using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Screens.Edit;
using osuTK; using osuTK;
namespace osu.Game.Rulesets.Catch.Edit.Blueprints.Components namespace osu.Game.Rulesets.Catch.Edit.Blueprints.Components
@ -42,6 +43,9 @@ namespace osu.Game.Rulesets.Catch.Edit.Blueprints.Components
[Resolved] [Resolved]
private IBeatSnapProvider? beatSnapProvider { get; set; } private IBeatSnapProvider? beatSnapProvider { get; set; }
[Resolved]
protected EditorBeatmap? EditorBeatmap { get; private set; }
protected EditablePath(Func<float, double> positionToTime) protected EditablePath(Func<float, double> positionToTime)
{ {
PositionToTime = positionToTime; PositionToTime = positionToTime;
@ -112,6 +116,7 @@ namespace osu.Game.Rulesets.Catch.Edit.Blueprints.Components
double endTime = hitObject.StartTime + path.Duration; double endTime = hitObject.StartTime + path.Duration;
double snappedEndTime = beatSnapProvider.SnapTime(endTime, hitObject.StartTime); double snappedEndTime = beatSnapProvider.SnapTime(endTime, hitObject.StartTime);
hitObject.Path.ExpectedDistance.Value = (snappedEndTime - hitObject.StartTime) * hitObject.Velocity; hitObject.Path.ExpectedDistance.Value = (snappedEndTime - hitObject.StartTime) * hitObject.Velocity;
EditorBeatmap?.Update(hitObject);
} }
public Vector2 ToRelativePosition(Vector2 screenSpacePosition) public Vector2 ToRelativePosition(Vector2 screenSpacePosition)

View File

@ -4,13 +4,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Screens.Edit;
using osuTK; using osuTK;
using osuTK.Input; using osuTK.Input;
@ -25,9 +23,6 @@ namespace osu.Game.Rulesets.Catch.Edit.Blueprints.Components
// To handle when the editor is scrolled while dragging. // To handle when the editor is scrolled while dragging.
private Vector2 dragStartPosition; private Vector2 dragStartPosition;
[Resolved]
private IEditorChangeHandler? changeHandler { get; set; }
public SelectionEditablePath(JuiceStream juiceStream, Func<float, double> positionToTime) public SelectionEditablePath(JuiceStream juiceStream, Func<float, double> positionToTime)
: base(positionToTime) : base(positionToTime)
{ {
@ -36,12 +31,14 @@ namespace osu.Game.Rulesets.Catch.Edit.Blueprints.Components
public void AddVertex(Vector2 relativePosition) public void AddVertex(Vector2 relativePosition)
{ {
changeHandler?.BeginChange(); EditorBeatmap?.BeginChange();
double time = Math.Max(0, PositionToTime(relativePosition.Y)); double time = Math.Max(0, PositionToTime(relativePosition.Y));
int index = AddVertex(time, relativePosition.X); int index = AddVertex(time, relativePosition.X);
UpdateHitObjectFromPath(juiceStream); UpdateHitObjectFromPath(juiceStream);
selectOnly(index); selectOnly(index);
changeHandler?.EndChange();
EditorBeatmap?.EndChange();
} }
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => InternalChildren.Any(d => d.ReceivePositionalInputAt(screenSpacePos)); public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => InternalChildren.Any(d => d.ReceivePositionalInputAt(screenSpacePos));
@ -54,10 +51,10 @@ namespace osu.Game.Rulesets.Catch.Edit.Blueprints.Components
if (e.Button == MouseButton.Right && e.ShiftPressed) if (e.Button == MouseButton.Right && e.ShiftPressed)
{ {
changeHandler?.BeginChange(); EditorBeatmap?.BeginChange();
RemoveVertex(index); RemoveVertex(index);
UpdateHitObjectFromPath(juiceStream); UpdateHitObjectFromPath(juiceStream);
changeHandler?.EndChange(); EditorBeatmap?.EndChange();
return true; return true;
} }
@ -85,7 +82,7 @@ namespace osu.Game.Rulesets.Catch.Edit.Blueprints.Components
for (int i = 0; i < VertexCount; i++) for (int i = 0; i < VertexCount; i++)
VertexStates[i].VertexBeforeChange = Vertices[i]; VertexStates[i].VertexBeforeChange = Vertices[i];
changeHandler?.BeginChange(); EditorBeatmap?.BeginChange();
return true; return true;
} }
@ -99,7 +96,7 @@ namespace osu.Game.Rulesets.Catch.Edit.Blueprints.Components
protected override void OnDragEnd(DragEndEvent e) protected override void OnDragEnd(DragEndEvent e)
{ {
changeHandler?.EndChange(); EditorBeatmap?.EndChange();
} }
private int getMouseTargetVertex(Vector2 screenSpacePosition) private int getMouseTargetVertex(Vector2 screenSpacePosition)
@ -129,7 +126,7 @@ namespace osu.Game.Rulesets.Catch.Edit.Blueprints.Components
private void deleteSelectedVertices() private void deleteSelectedVertices()
{ {
changeHandler?.BeginChange(); EditorBeatmap?.BeginChange();
for (int i = VertexCount - 1; i >= 0; i--) for (int i = VertexCount - 1; i >= 0; i--)
{ {
@ -139,7 +136,7 @@ namespace osu.Game.Rulesets.Catch.Edit.Blueprints.Components
UpdateHitObjectFromPath(juiceStream); UpdateHitObjectFromPath(juiceStream);
changeHandler?.EndChange(); EditorBeatmap?.EndChange();
} }
} }
} }