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

Merge branch 'master' into no-drawable-speedchangevis

This commit is contained in:
Dean Herbert 2018-11-13 19:42:04 +09:00 committed by GitHub
commit 3caf0cb0d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 301 additions and 335 deletions

6
.gitignore vendored
View File

@ -252,7 +252,11 @@ paket-files/
.fake/ .fake/
# JetBrains Rider # JetBrains Rider
.idea/ .idea/.idea.osu/.idea/*.xml
.idea/.idea.osu/.idea/codeStyles/*.xml
.idea/.idea.osu/.idea/dataSources/*.xml
.idea/.idea.osu/.idea/dictionaries/*.xml
.idea/.idea.osu/*.iml
*.sln.iml *.sln.iml
# CodeRush # CodeRush

@ -1 +1 @@
Subproject commit 9ee64e369fe6fdafc6aed40f5a35b5f01eb82c53 Subproject commit 651e598b016b43e31ab1c1b29d5b30c92361b8d9

View File

@ -5,6 +5,7 @@ using System.Linq;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.UI; using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osu.Game.Tests.Visual; using osu.Game.Tests.Visual;
@ -37,13 +38,11 @@ namespace osu.Game.Rulesets.Catch.Tests
beatmap.HitObjects.Add(new JuiceStream beatmap.HitObjects.Add(new JuiceStream
{ {
X = 0.5f - width / 2, X = 0.5f - width / 2,
ControlPoints = new[] Path = new SliderPath(PathType.Linear, new[]
{ {
Vector2.Zero, Vector2.Zero,
new Vector2(width * CatchPlayfield.BASE_WIDTH, 0) new Vector2(width * CatchPlayfield.BASE_WIDTH, 0)
}, }),
PathType = PathType.Linear,
Distance = width * CatchPlayfield.BASE_WIDTH,
StartTime = i * 2000, StartTime = i * 2000,
NewCombo = i % 8 == 0 NewCombo = i % 8 == 0
}); });

View File

@ -34,9 +34,7 @@ namespace osu.Game.Rulesets.Catch.Beatmaps
{ {
StartTime = obj.StartTime, StartTime = obj.StartTime,
Samples = obj.Samples, Samples = obj.Samples,
ControlPoints = curveData.ControlPoints, Path = curveData.Path,
PathType = curveData.PathType,
Distance = curveData.Distance,
NodeSamples = curveData.NodeSamples, NodeSamples = curveData.NodeSamples,
RepeatCount = curveData.RepeatCount, RepeatCount = curveData.RepeatCount,
X = (positionData?.X ?? 0) / CatchPlayfield.BASE_WIDTH, X = (positionData?.X ?? 0) / CatchPlayfield.BASE_WIDTH,

View File

@ -10,7 +10,6 @@ using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Catch.UI; using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using OpenTK;
namespace osu.Game.Rulesets.Catch.Objects namespace osu.Game.Rulesets.Catch.Objects
{ {
@ -138,28 +137,18 @@ namespace osu.Game.Rulesets.Catch.Objects
public double Duration => EndTime - StartTime; public double Duration => EndTime - StartTime;
public double Distance private SliderPath path;
public SliderPath Path
{ {
get { return Path.Distance; } get => path;
set { Path.Distance = value; } set => path = value;
} }
public SliderPath Path { get; } = new SliderPath(); public double Distance => Path.Distance;
public Vector2[] ControlPoints
{
get { return Path.ControlPoints; }
set { Path.ControlPoints = value; }
}
public List<List<SampleInfo>> NodeSamples { get; set; } = new List<List<SampleInfo>>(); public List<List<SampleInfo>> NodeSamples { get; set; } = new List<List<SampleInfo>>();
public PathType PathType
{
get { return Path.PathType; }
set { Path.PathType = value; }
}
public double? LegacyLastTickOffset { get; set; } public double? LegacyLastTickOffset { get; set; }
} }
} }

View File

@ -5,7 +5,6 @@ using osu.Framework.Allocation;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Mania.Objects.Drawables;
using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces; using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces;
using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.Mania.UI;
@ -15,7 +14,7 @@ using OpenTK.Graphics;
namespace osu.Game.Rulesets.Mania.Edit.Blueprints namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{ {
public class HoldNoteSelectionBlueprint : SelectionBlueprint public class HoldNoteSelectionBlueprint : ManiaSelectionBlueprint
{ {
public new DrawableHoldNote HitObject => (DrawableHoldNote)base.HitObject; public new DrawableHoldNote HitObject => (DrawableHoldNote)base.HitObject;

View File

@ -0,0 +1,21 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects.Drawables;
namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{
public class ManiaSelectionBlueprint : SelectionBlueprint
{
public ManiaSelectionBlueprint(DrawableHitObject hitObject)
: base(hitObject)
{
}
public override void AdjustPosition(DragEvent dragEvent)
{
}
}
}

View File

@ -3,13 +3,12 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Mania.Objects.Drawables;
using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces; using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces;
namespace osu.Game.Rulesets.Mania.Edit.Blueprints namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{ {
public class NoteSelectionBlueprint : SelectionBlueprint public class NoteSelectionBlueprint : ManiaSelectionBlueprint
{ {
public NoteSelectionBlueprint(DrawableNote note) public NoteSelectionBlueprint(DrawableNote note)
: base(note) : base(note)

View File

@ -18,6 +18,7 @@ using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces; using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces;
@ -108,13 +109,12 @@ namespace osu.Game.Rulesets.Osu.Tests
{ {
StartTime = Time.Current + 1000, StartTime = Time.Current + 1000,
Position = new Vector2(239, 176), Position = new Vector2(239, 176),
ControlPoints = new[] Path = new SliderPath(PathType.PerfectCurve, new[]
{ {
Vector2.Zero, Vector2.Zero,
new Vector2(154, 28), new Vector2(154, 28),
new Vector2(52, -34) new Vector2(52, -34)
}, }, 700),
Distance = 700,
RepeatCount = repeats, RepeatCount = repeats,
NodeSamples = createEmptySamples(repeats), NodeSamples = createEmptySamples(repeats),
StackHeight = 10 StackHeight = 10
@ -141,12 +141,11 @@ namespace osu.Game.Rulesets.Osu.Tests
{ {
StartTime = Time.Current + 1000, StartTime = Time.Current + 1000,
Position = new Vector2(-(distance / 2), 0), Position = new Vector2(-(distance / 2), 0),
ControlPoints = new[] Path = new SliderPath(PathType.PerfectCurve, new[]
{ {
Vector2.Zero, Vector2.Zero,
new Vector2(distance, 0), new Vector2(distance, 0),
}, }, distance),
Distance = distance,
RepeatCount = repeats, RepeatCount = repeats,
NodeSamples = createEmptySamples(repeats), NodeSamples = createEmptySamples(repeats),
StackHeight = stackHeight StackHeight = stackHeight
@ -161,13 +160,12 @@ namespace osu.Game.Rulesets.Osu.Tests
{ {
StartTime = Time.Current + 1000, StartTime = Time.Current + 1000,
Position = new Vector2(-200, 0), Position = new Vector2(-200, 0),
ControlPoints = new[] Path = new SliderPath(PathType.PerfectCurve, new[]
{ {
Vector2.Zero, Vector2.Zero,
new Vector2(200, 200), new Vector2(200, 200),
new Vector2(400, 0) new Vector2(400, 0)
}, }, 600),
Distance = 600,
RepeatCount = repeats, RepeatCount = repeats,
NodeSamples = createEmptySamples(repeats) NodeSamples = createEmptySamples(repeats)
}; };
@ -181,10 +179,9 @@ namespace osu.Game.Rulesets.Osu.Tests
{ {
var slider = new Slider var slider = new Slider
{ {
PathType = PathType.Linear,
StartTime = Time.Current + 1000, StartTime = Time.Current + 1000,
Position = new Vector2(-200, 0), Position = new Vector2(-200, 0),
ControlPoints = new[] Path = new SliderPath(PathType.Linear, new[]
{ {
Vector2.Zero, Vector2.Zero,
new Vector2(150, 75), new Vector2(150, 75),
@ -192,8 +189,7 @@ namespace osu.Game.Rulesets.Osu.Tests
new Vector2(300, -200), new Vector2(300, -200),
new Vector2(400, 0), new Vector2(400, 0),
new Vector2(430, 0) new Vector2(430, 0)
}, }),
Distance = 793.4417,
RepeatCount = repeats, RepeatCount = repeats,
NodeSamples = createEmptySamples(repeats) NodeSamples = createEmptySamples(repeats)
}; };
@ -207,18 +203,16 @@ namespace osu.Game.Rulesets.Osu.Tests
{ {
var slider = new Slider var slider = new Slider
{ {
PathType = PathType.Bezier,
StartTime = Time.Current + 1000, StartTime = Time.Current + 1000,
Position = new Vector2(-200, 0), Position = new Vector2(-200, 0),
ControlPoints = new[] Path = new SliderPath(PathType.Bezier, new[]
{ {
Vector2.Zero, Vector2.Zero,
new Vector2(150, 75), new Vector2(150, 75),
new Vector2(200, 100), new Vector2(200, 100),
new Vector2(300, -200), new Vector2(300, -200),
new Vector2(430, 0) new Vector2(430, 0)
}, }),
Distance = 480,
RepeatCount = repeats, RepeatCount = repeats,
NodeSamples = createEmptySamples(repeats) NodeSamples = createEmptySamples(repeats)
}; };
@ -232,10 +226,9 @@ namespace osu.Game.Rulesets.Osu.Tests
{ {
var slider = new Slider var slider = new Slider
{ {
PathType = PathType.Linear,
StartTime = Time.Current + 1000, StartTime = Time.Current + 1000,
Position = new Vector2(0, 0), Position = new Vector2(0, 0),
ControlPoints = new[] Path = new SliderPath(PathType.Linear, new[]
{ {
Vector2.Zero, Vector2.Zero,
new Vector2(-200, 0), new Vector2(-200, 0),
@ -243,8 +236,7 @@ namespace osu.Game.Rulesets.Osu.Tests
new Vector2(0, -200), new Vector2(0, -200),
new Vector2(-200, -200), new Vector2(-200, -200),
new Vector2(0, -200) new Vector2(0, -200)
}, }),
Distance = 1000,
RepeatCount = repeats, RepeatCount = repeats,
NodeSamples = createEmptySamples(repeats) NodeSamples = createEmptySamples(repeats)
}; };
@ -264,15 +256,13 @@ namespace osu.Game.Rulesets.Osu.Tests
{ {
StartTime = Time.Current + 1000, StartTime = Time.Current + 1000,
Position = new Vector2(-100, 0), Position = new Vector2(-100, 0),
PathType = PathType.Catmull, Path = new SliderPath(PathType.Catmull, new[]
ControlPoints = new[]
{ {
Vector2.Zero, Vector2.Zero,
new Vector2(50, -50), new Vector2(50, -50),
new Vector2(150, 50), new Vector2(150, 50),
new Vector2(200, 0) new Vector2(200, 0)
}, }),
Distance = 300,
RepeatCount = repeats, RepeatCount = repeats,
NodeSamples = repeatSamples NodeSamples = repeatSamples
}; };

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders; using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders;
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components; using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components;
@ -35,14 +36,12 @@ namespace osu.Game.Rulesets.Osu.Tests
var slider = new Slider var slider = new Slider
{ {
Position = new Vector2(256, 192), Position = new Vector2(256, 192),
ControlPoints = new[] Path = new SliderPath(PathType.Bezier, new[]
{ {
Vector2.Zero, Vector2.Zero,
new Vector2(150, 150), new Vector2(150, 150),
new Vector2(300, 0) new Vector2(300, 0)
}, })
PathType = PathType.Bezier,
Distance = 350
}; };
slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty { CircleSize = 2 }); slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty { CircleSize = 2 });

View File

@ -35,9 +35,7 @@ namespace osu.Game.Rulesets.Osu.Beatmaps
{ {
StartTime = original.StartTime, StartTime = original.StartTime,
Samples = original.Samples, Samples = original.Samples,
ControlPoints = curveData.ControlPoints, Path = curveData.Path,
PathType = curveData.PathType,
Distance = curveData.Distance,
NodeSamples = curveData.NodeSamples, NodeSamples = curveData.NodeSamples,
RepeatCount = curveData.RepeatCount, RepeatCount = curveData.RepeatCount,
Position = positionData?.Position ?? Vector2.Zero, Position = positionData?.Position ?? Vector2.Zero,

View File

@ -1,14 +1,13 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles.Components; using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles.Components;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects.Drawables;
namespace osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles namespace osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles
{ {
public class HitCircleSelectionBlueprint : SelectionBlueprint public class HitCircleSelectionBlueprint : OsuSelectionBlueprint
{ {
public HitCircleSelectionBlueprint(DrawableHitCircle hitCircle) public HitCircleSelectionBlueprint(DrawableHitCircle hitCircle)
: base(hitCircle) : base(hitCircle)

View File

@ -0,0 +1,22 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects;
namespace osu.Game.Rulesets.Osu.Edit.Blueprints
{
public class OsuSelectionBlueprint : SelectionBlueprint
{
protected OsuHitObject OsuObject => (OsuHitObject)HitObject.HitObject;
public OsuSelectionBlueprint(DrawableHitObject hitObject)
: base(hitObject)
{
}
public override void AdjustPosition(DragEvent dragEvent) => OsuObject.Position += dragEvent.Delta;
}
}

View File

@ -1,7 +1,6 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -9,6 +8,7 @@ using osu.Framework.Graphics.Lines;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using OpenTK; using OpenTK;
@ -55,16 +55,16 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
{ {
base.Update(); base.Update();
Position = slider.StackedPosition + slider.ControlPoints[index]; Position = slider.StackedPosition + slider.Path.ControlPoints[index];
marker.Colour = isSegmentSeparator ? colours.Red : colours.Yellow; marker.Colour = isSegmentSeparator ? colours.Red : colours.Yellow;
path.ClearVertices(); path.ClearVertices();
if (index != slider.ControlPoints.Length - 1) if (index != slider.Path.ControlPoints.Length - 1)
{ {
path.AddVertex(Vector2.Zero); path.AddVertex(Vector2.Zero);
path.AddVertex(slider.ControlPoints[index + 1] - slider.ControlPoints[index]); path.AddVertex(slider.Path.ControlPoints[index + 1] - slider.Path.ControlPoints[index]);
} }
path.OriginPosition = path.PositionInBoundingBox(Vector2.Zero); path.OriginPosition = path.PositionInBoundingBox(Vector2.Zero);
@ -76,7 +76,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
protected override bool OnDrag(DragEvent e) protected override bool OnDrag(DragEvent e)
{ {
var newControlPoints = slider.ControlPoints.ToArray(); var newControlPoints = slider.Path.ControlPoints.ToArray();
if (index == 0) if (index == 0)
{ {
@ -96,8 +96,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
if (isSegmentSeparatorWithPrevious) if (isSegmentSeparatorWithPrevious)
newControlPoints[index - 1] = newControlPoints[index]; newControlPoints[index - 1] = newControlPoints[index];
slider.ControlPoints = newControlPoints; slider.Path = new SliderPath(slider.Path.Type, newControlPoints);
slider.Path.Calculate(true);
return true; return true;
} }
@ -106,8 +105,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
private bool isSegmentSeparator => isSegmentSeparatorWithNext || isSegmentSeparatorWithPrevious; private bool isSegmentSeparator => isSegmentSeparatorWithNext || isSegmentSeparatorWithPrevious;
private bool isSegmentSeparatorWithNext => index < slider.ControlPoints.Length - 1 && slider.ControlPoints[index + 1] == slider.ControlPoints[index]; private bool isSegmentSeparatorWithNext => index < slider.Path.ControlPoints.Length - 1 && slider.Path.ControlPoints[index + 1] == slider.Path.ControlPoints[index];
private bool isSegmentSeparatorWithPrevious => index > 0 && slider.ControlPoints[index - 1] == slider.ControlPoints[index]; private bool isSegmentSeparatorWithPrevious => index > 0 && slider.Path.ControlPoints[index - 1] == slider.Path.ControlPoints[index];
} }
} }

View File

@ -19,15 +19,15 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
InternalChild = pieces = new Container<PathControlPointPiece> { RelativeSizeAxes = Axes.Both }; InternalChild = pieces = new Container<PathControlPointPiece> { RelativeSizeAxes = Axes.Both };
slider.ControlPointsChanged += _ => updatePathControlPoints(); slider.PathChanged += _ => updatePathControlPoints();
updatePathControlPoints(); updatePathControlPoints();
} }
private void updatePathControlPoints() private void updatePathControlPoints()
{ {
while (slider.ControlPoints.Length > pieces.Count) while (slider.Path.ControlPoints.Length > pieces.Count)
pieces.Add(new PathControlPointPiece(slider, pieces.Count)); pieces.Add(new PathControlPointPiece(slider, pieces.Count));
while (slider.ControlPoints.Length < pieces.Count) while (slider.Path.ControlPoints.Length < pieces.Count)
pieces.Remove(pieces[pieces.Count - 1]); pieces.Remove(pieces[pieces.Count - 1]);
} }
} }

View File

@ -45,8 +45,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
{ {
base.Update(); base.Update();
slider.Path.Calculate();
var vertices = new List<Vector2>(); var vertices = new List<Vector2>();
slider.Path.GetPathToProgress(vertices, 0, 1); slider.Path.GetPathToProgress(vertices, 0, 1);

View File

@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
this.slider = slider; this.slider = slider;
this.position = position; this.position = position;
slider.ControlPointsChanged += _ => UpdatePosition(); slider.PathChanged += _ => UpdatePosition();
} }
protected override void UpdatePosition() protected override void UpdatePosition()

View File

@ -1,18 +1,22 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Rulesets.Edit; using osu.Framework.Input.Events;
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components; using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects.Drawables;
namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
{ {
public class SliderCircleSelectionBlueprint : SelectionBlueprint public class SliderCircleSelectionBlueprint : OsuSelectionBlueprint
{ {
private readonly Slider slider;
public SliderCircleSelectionBlueprint(DrawableOsuHitObject hitObject, Slider slider, SliderPosition position) public SliderCircleSelectionBlueprint(DrawableOsuHitObject hitObject, Slider slider, SliderPosition position)
: base(hitObject) : base(hitObject)
{ {
this.slider = slider;
InternalChild = new SliderCirclePiece(slider, position); InternalChild = new SliderCirclePiece(slider, position);
Select(); Select();
@ -20,5 +24,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
// Todo: This is temporary, since the slider circle masks don't do anything special yet. In the future they will handle input. // Todo: This is temporary, since the slider circle masks don't do anything special yet. In the future they will handle input.
public override bool HandlePositionalInput => false; public override bool HandlePositionalInput => false;
public override void AdjustPosition(DragEvent dragEvent) => slider.Position += dragEvent.Delta;
} }
} }

View File

@ -1,16 +1,15 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.MathUtils;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components; using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components;
using OpenTK; using OpenTK;
@ -119,12 +118,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
private void updateSlider() private void updateSlider()
{ {
for (int i = 0; i < segments.Count; i++) var newControlPoints = segments.SelectMany(s => s.ControlPoints).Concat(cursor.Yield()).ToArray();
segments[i].Calculate(i == segments.Count - 1 ? (Vector2?)cursor : null); HitObject.Path = new SliderPath(newControlPoints.Length > 2 ? PathType.Bezier : PathType.Linear, newControlPoints);
HitObject.ControlPoints = segments.SelectMany(s => s.ControlPoints).Concat(cursor.Yield()).ToArray();
HitObject.PathType = HitObject.ControlPoints.Length > 2 ? PathType.Bezier : PathType.Linear;
HitObject.Distance = segments.Sum(s => s.Distance);
} }
private void setState(PlacementState newState) private void setState(PlacementState newState)
@ -140,41 +135,12 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
private class Segment private class Segment
{ {
public float Distance { get; private set; }
public readonly List<Vector2> ControlPoints = new List<Vector2>(); public readonly List<Vector2> ControlPoints = new List<Vector2>();
public Segment(Vector2 offset) public Segment(Vector2 offset)
{ {
ControlPoints.Add(offset); ControlPoints.Add(offset);
} }
public void Calculate(Vector2? cursor = null)
{
Span<Vector2> allControlPoints = stackalloc Vector2[ControlPoints.Count + (cursor.HasValue ? 1 : 0)];
for (int i = 0; i < ControlPoints.Count; i++)
allControlPoints[i] = ControlPoints[i];
if (cursor.HasValue)
allControlPoints[allControlPoints.Length - 1] = cursor.Value;
List<Vector2> result;
switch (allControlPoints.Length)
{
case 1:
case 2:
result = PathApproximator.ApproximateLinear(allControlPoints);
break;
default:
result = PathApproximator.ApproximateBezier(allControlPoints);
break;
}
Distance = 0;
for (int i = 0; i < result.Count - 1; i++)
Distance += Vector2.Distance(result[i], result[i + 1]);
}
} }
} }
} }

View File

@ -2,7 +2,6 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components; using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects.Drawables;
@ -10,7 +9,7 @@ using OpenTK;
namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
{ {
public class SliderSelectionBlueprint : SelectionBlueprint public class SliderSelectionBlueprint : OsuSelectionBlueprint
{ {
private readonly SliderCircleSelectionBlueprint headBlueprint; private readonly SliderCircleSelectionBlueprint headBlueprint;

View File

@ -1,7 +1,7 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Rulesets.Edit; using osu.Framework.Input.Events;
using osu.Game.Rulesets.Osu.Edit.Blueprints.Spinners.Components; using osu.Game.Rulesets.Osu.Edit.Blueprints.Spinners.Components;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects.Drawables;
@ -9,7 +9,7 @@ using OpenTK;
namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Spinners namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Spinners
{ {
public class SpinnerSelectionBlueprint : SelectionBlueprint public class SpinnerSelectionBlueprint : OsuSelectionBlueprint
{ {
private readonly SpinnerPiece piece; private readonly SpinnerPiece piece;
@ -20,5 +20,10 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Spinners
} }
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => piece.ReceivePositionalInputAt(screenSpacePos); public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => piece.ReceivePositionalInputAt(screenSpacePos);
public override void AdjustPosition(DragEvent dragEvent)
{
// Spinners don't support position adjustments
}
} }
} }

View File

@ -32,12 +32,11 @@ namespace osu.Game.Rulesets.Osu.Mods
slider.NestedHitObjects.OfType<SliderTick>().ForEach(h => h.Position = new Vector2(h.Position.X, OsuPlayfield.BASE_SIZE.Y - h.Position.Y)); slider.NestedHitObjects.OfType<SliderTick>().ForEach(h => h.Position = new Vector2(h.Position.X, OsuPlayfield.BASE_SIZE.Y - h.Position.Y));
slider.NestedHitObjects.OfType<RepeatPoint>().ForEach(h => h.Position = new Vector2(h.Position.X, OsuPlayfield.BASE_SIZE.Y - h.Position.Y)); slider.NestedHitObjects.OfType<RepeatPoint>().ForEach(h => h.Position = new Vector2(h.Position.X, OsuPlayfield.BASE_SIZE.Y - h.Position.Y));
var newControlPoints = new Vector2[slider.ControlPoints.Length]; var newControlPoints = new Vector2[slider.Path.ControlPoints.Length];
for (int i = 0; i < slider.ControlPoints.Length; i++) for (int i = 0; i < slider.Path.ControlPoints.Length; i++)
newControlPoints[i] = new Vector2(slider.ControlPoints[i].X, -slider.ControlPoints[i].Y); newControlPoints[i] = new Vector2(slider.Path.ControlPoints[i].X, -slider.Path.ControlPoints[i].Y);
slider.ControlPoints = newControlPoints; slider.Path = new SliderPath(slider.Path.Type, newControlPoints, slider.Path.ExpectedDistance);
slider.Path?.Calculate(); // Recalculate the slider curve
} }
} }
} }

View File

@ -91,7 +91,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
Ball.Scale = new Vector2(HitObject.Scale); Ball.Scale = new Vector2(HitObject.Scale);
}; };
slider.ControlPointsChanged += _ => Body.Refresh(); slider.PathChanged += _ => Body.Refresh();
} }
public override Color4 AccentColour public override Color4 AccentColour

View File

@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
this.slider = slider; this.slider = slider;
h.PositionChanged += _ => updatePosition(); h.PositionChanged += _ => updatePosition();
slider.ControlPointsChanged += _ => updatePosition(); slider.PathChanged += _ => updatePosition();
updatePosition(); updatePosition();
} }

View File

@ -30,7 +30,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
AlwaysPresent = true; AlwaysPresent = true;
hitCircle.PositionChanged += _ => updatePosition(); hitCircle.PositionChanged += _ => updatePosition();
slider.ControlPointsChanged += _ => updatePosition(); slider.PathChanged += _ => updatePosition();
updatePosition(); updatePosition();
} }

View File

@ -7,11 +7,10 @@ using osu.Game.Rulesets.Objects;
using OpenTK; using OpenTK;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Edit.Types;
namespace osu.Game.Rulesets.Osu.Objects namespace osu.Game.Rulesets.Osu.Objects
{ {
public abstract class OsuHitObject : HitObject, IHasComboInformation, IHasEditablePosition public abstract class OsuHitObject : HitObject, IHasComboInformation, IHasPosition
{ {
public const double OBJECT_RADIUS = 64; public const double OBJECT_RADIUS = 64;
@ -100,8 +99,6 @@ namespace osu.Game.Rulesets.Osu.Objects
Scale = (1.0f - 0.7f * (difficulty.CircleSize - 5) / 5) / 2; Scale = (1.0f - 0.7f * (difficulty.CircleSize - 5) / 5) / 2;
} }
public virtual void OffsetPosition(Vector2 offset) => Position += offset;
protected override HitWindows CreateHitWindows() => new OsuHitWindows(); protected override HitWindows CreateHitWindows() => new OsuHitWindows();
} }
} }

View File

@ -22,7 +22,7 @@ namespace osu.Game.Rulesets.Osu.Objects
/// </summary> /// </summary>
private const float base_scoring_distance = 100; private const float base_scoring_distance = 100;
public event Action<Vector2[]> ControlPointsChanged; public event Action<SliderPath> PathChanged;
public double EndTime => StartTime + this.SpanCount() * Path.Distance / Velocity; public double EndTime => StartTime + this.SpanCount() * Path.Distance / Velocity;
public double Duration => EndTime - StartTime; public double Duration => EndTime - StartTime;
@ -52,35 +52,23 @@ namespace osu.Game.Rulesets.Osu.Objects
} }
} }
public SliderPath Path { get; } = new SliderPath(); private SliderPath path;
public Vector2[] ControlPoints public SliderPath Path
{ {
get => Path.ControlPoints; get => path;
set set
{ {
if (Path.ControlPoints == value) path = value;
return;
Path.ControlPoints = value;
ControlPointsChanged?.Invoke(value); PathChanged?.Invoke(value);
if (TailCircle != null) if (TailCircle != null)
TailCircle.Position = EndPosition; TailCircle.Position = EndPosition;
} }
} }
public PathType PathType public double Distance => Path.Distance;
{
get { return Path.PathType; }
set { Path.PathType = value; }
}
public double Distance
{
get { return Path.Distance; }
set { Path.Distance = value; }
}
public override Vector2 Position public override Vector2 Position
{ {
@ -166,7 +154,7 @@ namespace osu.Game.Rulesets.Osu.Objects
private void createSliderEnds() private void createSliderEnds()
{ {
HeadCircle = new SliderCircle(this) HeadCircle = new SliderCircle
{ {
StartTime = StartTime, StartTime = StartTime,
Position = Position, Position = Position,
@ -176,7 +164,7 @@ namespace osu.Game.Rulesets.Osu.Objects
ComboIndex = ComboIndex, ComboIndex = ComboIndex,
}; };
TailCircle = new SliderTailCircle(this) TailCircle = new SliderTailCircle
{ {
StartTime = EndTime, StartTime = EndTime,
Position = EndPosition, Position = EndPosition,

View File

@ -1,19 +1,9 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
namespace osu.Game.Rulesets.Osu.Objects namespace osu.Game.Rulesets.Osu.Objects
{ {
public class SliderCircle : HitCircle public class SliderCircle : HitCircle
{ {
private readonly Slider slider;
public SliderCircle(Slider slider)
{
this.slider = slider;
}
public override void OffsetPosition(Vector2 offset) => slider.OffsetPosition(offset);
} }
} }

View File

@ -8,11 +8,6 @@ namespace osu.Game.Rulesets.Osu.Objects
{ {
public class SliderTailCircle : SliderCircle public class SliderTailCircle : SliderCircle
{ {
public SliderTailCircle(Slider slider)
: base(slider)
{
}
public override Judgement CreateJudgement() => new OsuSliderTailJudgement(); public override Judgement CreateJudgement() => new OsuSliderTailJudgement();
} }
} }

View File

@ -7,7 +7,6 @@ using osu.Game.Rulesets.Objects.Types;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Osu.Judgements; using osu.Game.Rulesets.Osu.Judgements;
using OpenTK;
namespace osu.Game.Rulesets.Osu.Objects namespace osu.Game.Rulesets.Osu.Objects
{ {
@ -32,10 +31,5 @@ namespace osu.Game.Rulesets.Osu.Objects
} }
public override Judgement CreateJudgement() => new OsuJudgement(); public override Judgement CreateJudgement() => new OsuJudgement();
public override void OffsetPosition(Vector2 offset)
{
// for now we don't want to allow spinners to be moved around.
}
} }
} }

View File

@ -11,6 +11,7 @@ using OpenTK;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Edit; using osu.Game.Rulesets.Osu.Edit;
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles; using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles;
@ -53,12 +54,11 @@ namespace osu.Game.Tests.Visual
new Slider new Slider
{ {
Position = new Vector2(128, 256), Position = new Vector2(128, 256),
ControlPoints = new[] Path = new SliderPath(PathType.Linear, new[]
{ {
Vector2.Zero, Vector2.Zero,
new Vector2(216, 0), new Vector2(216, 0),
}, }),
Distance = 216,
Scale = 0.5f, Scale = 0.5f,
} }
}, },

View File

@ -64,7 +64,7 @@ namespace osu.Game.Rulesets.Edit
layerBelowRuleset.Child = new EditorPlayfieldBorder { RelativeSizeAxes = Axes.Both }; layerBelowRuleset.Child = new EditorPlayfieldBorder { RelativeSizeAxes = Axes.Both };
var layerAboveRuleset = CreateLayerContainer(); var layerAboveRuleset = CreateLayerContainer();
layerAboveRuleset.Child = new BlueprintContainer(); layerAboveRuleset.Child = blueprintContainer = new BlueprintContainer();
layerContainers.Add(layerBelowRuleset); layerContainers.Add(layerBelowRuleset);
layerContainers.Add(layerAboveRuleset); layerContainers.Add(layerAboveRuleset);

View File

@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.Edit
/// <summary> /// <summary>
/// A blueprint placed above a <see cref="DrawableHitObject"/> adding editing functionality. /// A blueprint placed above a <see cref="DrawableHitObject"/> adding editing functionality.
/// </summary> /// </summary>
public class SelectionBlueprint : CompositeDrawable, IStateful<SelectionState> public abstract class SelectionBlueprint : CompositeDrawable, IStateful<SelectionState>
{ {
/// <summary> /// <summary>
/// Invoked when this <see cref="SelectionBlueprint"/> has been selected. /// Invoked when this <see cref="SelectionBlueprint"/> has been selected.
@ -38,7 +38,7 @@ namespace osu.Game.Rulesets.Edit
/// <summary> /// <summary>
/// Invoked when this <see cref="SelectionBlueprint"/> has requested drag. /// Invoked when this <see cref="SelectionBlueprint"/> has requested drag.
/// </summary> /// </summary>
public event Action<SelectionBlueprint, Vector2, InputState> DragRequested; public event Action<DragEvent> DragRequested;
/// <summary> /// <summary>
/// The <see cref="DrawableHitObject"/> which this <see cref="SelectionBlueprint"/> applies to. /// The <see cref="DrawableHitObject"/> which this <see cref="SelectionBlueprint"/> applies to.
@ -49,7 +49,7 @@ namespace osu.Game.Rulesets.Edit
public override bool HandlePositionalInput => ShouldBeAlive; public override bool HandlePositionalInput => ShouldBeAlive;
public override bool RemoveWhenNotAlive => false; public override bool RemoveWhenNotAlive => false;
public SelectionBlueprint(DrawableHitObject hitObject) protected SelectionBlueprint(DrawableHitObject hitObject)
{ {
HitObject = hitObject; HitObject = hitObject;
@ -130,10 +130,12 @@ namespace osu.Game.Rulesets.Edit
protected override bool OnDrag(DragEvent e) protected override bool OnDrag(DragEvent e)
{ {
DragRequested?.Invoke(this, e.Delta, e.CurrentState); DragRequested?.Invoke(e);
return true; return true;
} }
public abstract void AdjustPosition(DragEvent dragEvent);
/// <summary> /// <summary>
/// The screen-space point that causes this <see cref="SelectionBlueprint"/> to be selected. /// The screen-space point that causes this <see cref="SelectionBlueprint"/> to be selected.
/// </summary> /// </summary>

View File

@ -1,13 +0,0 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Rulesets.Objects.Types;
using OpenTK;
namespace osu.Game.Rulesets.Edit.Types
{
public interface IHasEditablePosition : IHasPosition
{
void OffsetPosition(Vector2 offset);
}
}

View File

@ -50,9 +50,7 @@ namespace osu.Game.Rulesets.Objects.Legacy.Catch
X = position.X, X = position.X,
NewCombo = FirstObject || newCombo, NewCombo = FirstObject || newCombo,
ComboOffset = comboOffset, ComboOffset = comboOffset,
ControlPoints = controlPoints, Path = new SliderPath(pathType, controlPoints, length),
Distance = length,
PathType = pathType,
NodeSamples = nodeSamples, NodeSamples = nodeSamples,
RepeatCount = repeatCount RepeatCount = repeatCount
}; };

View File

@ -3,7 +3,6 @@
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using System.Collections.Generic; using System.Collections.Generic;
using OpenTK;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
@ -20,11 +19,9 @@ namespace osu.Game.Rulesets.Objects.Legacy
/// <summary> /// <summary>
/// <see cref="ConvertSlider"/>s don't need a curve since they're converted to ruleset-specific hitobjects. /// <see cref="ConvertSlider"/>s don't need a curve since they're converted to ruleset-specific hitobjects.
/// </summary> /// </summary>
public SliderPath Path { get; } = null; public SliderPath Path { get; set; }
public Vector2[] ControlPoints { get; set; }
public PathType PathType { get; set; }
public double Distance { get; set; } public double Distance => Path.Distance;
public List<List<SampleInfo>> NodeSamples { get; set; } public List<List<SampleInfo>> NodeSamples { get; set; }
public int RepeatCount { get; set; } public int RepeatCount { get; set; }

View File

@ -31,9 +31,7 @@ namespace osu.Game.Rulesets.Objects.Legacy.Mania
return new ConvertSlider return new ConvertSlider
{ {
X = position.X, X = position.X,
ControlPoints = controlPoints, Path = new SliderPath(pathType, controlPoints, length),
Distance = length,
PathType = pathType,
NodeSamples = nodeSamples, NodeSamples = nodeSamples,
RepeatCount = repeatCount RepeatCount = repeatCount
}; };

View File

@ -51,9 +51,7 @@ namespace osu.Game.Rulesets.Objects.Legacy.Osu
Position = position, Position = position,
NewCombo = FirstObject || newCombo, NewCombo = FirstObject || newCombo,
ComboOffset = comboOffset, ComboOffset = comboOffset,
ControlPoints = controlPoints, Path = new SliderPath(pathType, controlPoints, Math.Max(0, length)),
Distance = Math.Max(0, length),
PathType = pathType,
NodeSamples = nodeSamples, NodeSamples = nodeSamples,
RepeatCount = repeatCount RepeatCount = repeatCount
}; };

View File

@ -27,9 +27,7 @@ namespace osu.Game.Rulesets.Objects.Legacy.Taiko
{ {
return new ConvertSlider return new ConvertSlider
{ {
ControlPoints = controlPoints, Path = new SliderPath(pathType, controlPoints, length),
Distance = length,
PathType = pathType,
NodeSamples = nodeSamples, NodeSamples = nodeSamples,
RepeatCount = repeatCount RepeatCount = repeatCount
}; };

View File

@ -4,28 +4,140 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Newtonsoft.Json;
using osu.Framework.MathUtils; using osu.Framework.MathUtils;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using OpenTK; using OpenTK;
namespace osu.Game.Rulesets.Objects namespace osu.Game.Rulesets.Objects
{ {
public class SliderPath public struct SliderPath : IEquatable<SliderPath>
{ {
public double Distance; /// <summary>
/// The user-set distance of the path. If non-null, <see cref="Distance"/> will match this value,
/// and the path will be shortened/lengthened to match this length.
/// </summary>
public readonly double? ExpectedDistance;
public Vector2[] ControlPoints = Array.Empty<Vector2>(); /// <summary>
/// The type of path.
/// </summary>
public readonly PathType Type;
public PathType PathType = PathType.PerfectCurve; [JsonProperty]
private Vector2[] controlPoints;
public Vector2 Offset; private List<Vector2> calculatedPath;
private List<double> cumulativeLength;
private readonly List<Vector2> calculatedPath = new List<Vector2>(); private bool isInitialised;
private readonly List<double> cumulativeLength = new List<double>();
/// <summary>
/// Creates a new <see cref="SliderPath"/>.
/// </summary>
/// <param name="type">The type of path.</param>
/// <param name="controlPoints">The control points of the path.</param>
/// <param name="expectedDistance">A user-set distance of the path that may be shorter or longer than the true distance between all
/// <paramref name="controlPoints"/>. The path will be shortened/lengthened to match this length.
/// If null, the path will use the true distance between all <paramref name="controlPoints"/>.</param>
[JsonConstructor]
public SliderPath(PathType type, Vector2[] controlPoints, double? expectedDistance = null)
{
this = default;
this.controlPoints = controlPoints;
Type = type;
ExpectedDistance = expectedDistance;
ensureInitialised();
}
/// <summary>
/// The control points of the path.
/// </summary>
[JsonIgnore]
public ReadOnlySpan<Vector2> ControlPoints
{
get
{
ensureInitialised();
return controlPoints.AsSpan();
}
}
/// <summary>
/// The distance of the path after lengthening/shortening to account for <see cref="ExpectedDistance"/>.
/// </summary>
[JsonIgnore]
public double Distance
{
get
{
ensureInitialised();
return cumulativeLength.Count == 0 ? 0 : cumulativeLength[cumulativeLength.Count - 1];
}
}
/// <summary>
/// Computes the slider path until a given progress that ranges from 0 (beginning of the slider)
/// to 1 (end of the slider) and stores the generated path in the given list.
/// </summary>
/// <param name="path">The list to be filled with the computed path.</param>
/// <param name="p0">Start progress. Ranges from 0 (beginning of the slider) to 1 (end of the slider).</param>
/// <param name="p1">End progress. Ranges from 0 (beginning of the slider) to 1 (end of the slider).</param>
public void GetPathToProgress(List<Vector2> path, double p0, double p1)
{
ensureInitialised();
double d0 = progressToDistance(p0);
double d1 = progressToDistance(p1);
path.Clear();
int i = 0;
for (; i < calculatedPath.Count && cumulativeLength[i] < d0; ++i)
{
}
path.Add(interpolateVertices(i, d0));
for (; i < calculatedPath.Count && cumulativeLength[i] <= d1; ++i)
path.Add(calculatedPath[i]);
path.Add(interpolateVertices(i, d1));
}
/// <summary>
/// Computes the position on the slider at a given progress that ranges from 0 (beginning of the path)
/// to 1 (end of the path).
/// </summary>
/// <param name="progress">Ranges from 0 (beginning of the path) to 1 (end of the path).</param>
/// <returns></returns>
public Vector2 PositionAt(double progress)
{
ensureInitialised();
double d = progressToDistance(progress);
return interpolateVertices(indexOfDistance(d), d);
}
private void ensureInitialised()
{
if (isInitialised)
return;
isInitialised = true;
controlPoints = controlPoints ?? Array.Empty<Vector2>();
calculatedPath = new List<Vector2>();
cumulativeLength = new List<double>();
calculatePath();
calculateCumulativeLength();
}
private List<Vector2> calculateSubpath(ReadOnlySpan<Vector2> subControlPoints) private List<Vector2> calculateSubpath(ReadOnlySpan<Vector2> subControlPoints)
{ {
switch (PathType) switch (Type)
{ {
case PathType.Linear: case PathType.Linear:
return PathApproximator.ApproximateLinear(subControlPoints); return PathApproximator.ApproximateLinear(subControlPoints);
@ -66,7 +178,7 @@ namespace osu.Game.Rulesets.Objects
if (i == ControlPoints.Length - 1 || ControlPoints[i] == ControlPoints[i + 1]) if (i == ControlPoints.Length - 1 || ControlPoints[i] == ControlPoints[i + 1])
{ {
ReadOnlySpan<Vector2> cpSpan = ControlPoints.AsSpan().Slice(start, end - start); ReadOnlySpan<Vector2> cpSpan = ControlPoints.Slice(start, end - start);
foreach (Vector2 t in calculateSubpath(cpSpan)) foreach (Vector2 t in calculateSubpath(cpSpan))
if (calculatedPath.Count == 0 || calculatedPath.Last() != t) if (calculatedPath.Count == 0 || calculatedPath.Last() != t)
@ -77,49 +189,6 @@ namespace osu.Game.Rulesets.Objects
} }
} }
private void calculateCumulativeLengthAndTrimPath()
{
double l = 0;
cumulativeLength.Clear();
cumulativeLength.Add(l);
for (int i = 0; i < calculatedPath.Count - 1; ++i)
{
Vector2 diff = calculatedPath[i + 1] - calculatedPath[i];
double d = diff.Length;
// Shorten slider paths that are too long compared to what's
// in the .osu file.
if (Distance - l < d)
{
calculatedPath[i + 1] = calculatedPath[i] + diff * (float)((Distance - l) / d);
calculatedPath.RemoveRange(i + 2, calculatedPath.Count - 2 - i);
l = Distance;
cumulativeLength.Add(l);
break;
}
l += d;
cumulativeLength.Add(l);
}
// Lengthen slider paths that are too short compared to what's
// in the .osu file.
if (l < Distance && calculatedPath.Count > 1)
{
Vector2 diff = calculatedPath[calculatedPath.Count - 1] - calculatedPath[calculatedPath.Count - 2];
double d = diff.Length;
if (d <= 0)
return;
calculatedPath[calculatedPath.Count - 1] += diff * (float)((Distance - l) / d);
cumulativeLength[calculatedPath.Count - 1] = Distance;
}
}
private void calculateCumulativeLength() private void calculateCumulativeLength()
{ {
double l = 0; double l = 0;
@ -132,21 +201,33 @@ namespace osu.Game.Rulesets.Objects
Vector2 diff = calculatedPath[i + 1] - calculatedPath[i]; Vector2 diff = calculatedPath[i + 1] - calculatedPath[i];
double d = diff.Length; double d = diff.Length;
// Shorted slider paths that are too long compared to the expected distance
if (ExpectedDistance.HasValue && ExpectedDistance - l < d)
{
calculatedPath[i + 1] = calculatedPath[i] + diff * (float)((ExpectedDistance - l) / d);
calculatedPath.RemoveRange(i + 2, calculatedPath.Count - 2 - i);
l = ExpectedDistance.Value;
cumulativeLength.Add(l);
break;
}
l += d; l += d;
cumulativeLength.Add(l); cumulativeLength.Add(l);
} }
Distance = l; // Lengthen slider paths that are too short compared to the expected distance
} if (ExpectedDistance.HasValue && l < ExpectedDistance && calculatedPath.Count > 1)
public void Calculate(bool updateDistance = false)
{ {
calculatePath(); Vector2 diff = calculatedPath[calculatedPath.Count - 1] - calculatedPath[calculatedPath.Count - 2];
double d = diff.Length;
if (!updateDistance) if (d <= 0)
calculateCumulativeLengthAndTrimPath(); return;
else
calculateCumulativeLength(); calculatedPath[calculatedPath.Count - 1] += diff * (float)((ExpectedDistance - l) / d);
cumulativeLength[calculatedPath.Count - 1] = ExpectedDistance.Value;
}
} }
private int indexOfDistance(double d) private int indexOfDistance(double d)
@ -169,7 +250,7 @@ namespace osu.Game.Rulesets.Objects
if (i <= 0) if (i <= 0)
return calculatedPath.First(); return calculatedPath.First();
else if (i >= calculatedPath.Count) if (i >= calculatedPath.Count)
return calculatedPath.Last(); return calculatedPath.Last();
Vector2 p0 = calculatedPath[i - 1]; Vector2 p0 = calculatedPath[i - 1];
@ -186,47 +267,20 @@ namespace osu.Game.Rulesets.Objects
return p0 + (p1 - p0) * (float)w; return p0 + (p1 - p0) * (float)w;
} }
/// <summary> public bool Equals(SliderPath other)
/// Computes the slider path until a given progress that ranges from 0 (beginning of the slider)
/// to 1 (end of the slider) and stores the generated path in the given list.
/// </summary>
/// <param name="path">The list to be filled with the computed path.</param>
/// <param name="p0">Start progress. Ranges from 0 (beginning of the slider) to 1 (end of the slider).</param>
/// <param name="p1">End progress. Ranges from 0 (beginning of the slider) to 1 (end of the slider).</param>
public void GetPathToProgress(List<Vector2> path, double p0, double p1)
{ {
if (calculatedPath.Count == 0 && ControlPoints.Length > 0) if (ControlPoints == null && other.ControlPoints != null)
Calculate(); return false;
if (other.ControlPoints == null && ControlPoints != null)
return false;
double d0 = progressToDistance(p0); return ControlPoints.SequenceEqual(other.ControlPoints) && ExpectedDistance.Equals(other.ExpectedDistance) && Type == other.Type;
double d1 = progressToDistance(p1);
path.Clear();
int i = 0;
for (; i < calculatedPath.Count && cumulativeLength[i] < d0; ++i) { }
path.Add(interpolateVertices(i, d0) + Offset);
for (; i < calculatedPath.Count && cumulativeLength[i] <= d1; ++i)
path.Add(calculatedPath[i] + Offset);
path.Add(interpolateVertices(i, d1) + Offset);
} }
/// <summary> public override bool Equals(object obj)
/// Computes the position on the slider at a given progress that ranges from 0 (beginning of the path)
/// to 1 (end of the path).
/// </summary>
/// <param name="progress">Ranges from 0 (beginning of the path) to 1 (end of the path).</param>
/// <returns></returns>
public Vector2 PositionAt(double progress)
{ {
if (calculatedPath.Count == 0 && ControlPoints.Length > 0) if (ReferenceEquals(null, obj)) return false;
Calculate(); return obj is SliderPath other && Equals(other);
double d = progressToDistance(progress);
return interpolateVertices(indexOfDistance(d), d) + Offset;
} }
} }
} }

View File

@ -14,16 +14,6 @@ namespace osu.Game.Rulesets.Objects.Types
/// The curve. /// The curve.
/// </summary> /// </summary>
SliderPath Path { get; } SliderPath Path { get; }
/// <summary>
/// The control points that shape the curve.
/// </summary>
Vector2[] ControlPoints { get; }
/// <summary>
/// The type of curve.
/// </summary>
PathType PathType { get; }
} }
public static class HasCurveExtensions public static class HasCurveExtensions

View File

@ -12,7 +12,6 @@ using osu.Framework.Input.States;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Tools; using osu.Game.Rulesets.Edit.Tools;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using OpenTK;
namespace osu.Game.Screens.Edit.Compose.Components namespace osu.Game.Screens.Edit.Compose.Components
{ {
@ -165,7 +164,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
private void onSelectionRequested(SelectionBlueprint blueprint, InputState state) => selectionBox.HandleSelectionRequested(blueprint, state); private void onSelectionRequested(SelectionBlueprint blueprint, InputState state) => selectionBox.HandleSelectionRequested(blueprint, state);
private void onDragRequested(SelectionBlueprint blueprint, Vector2 delta, InputState state) => selectionBox.HandleDrag(blueprint, delta, state); private void onDragRequested(DragEvent dragEvent) => selectionBox.HandleDrag(dragEvent);
private class SelectionBlueprintContainer : Container<SelectionBlueprint> private class SelectionBlueprintContainer : Container<SelectionBlueprint>
{ {

View File

@ -12,7 +12,6 @@ using osu.Framework.Input.Events;
using osu.Framework.Input.States; using osu.Framework.Input.States;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Types;
using OpenTK; using OpenTK;
using OpenTK.Input; using OpenTK.Input;
@ -60,19 +59,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
#region User Input Handling #region User Input Handling
public void HandleDrag(SelectionBlueprint m, Vector2 delta, InputState state) public void HandleDrag(DragEvent dragEvent)
{ {
// Todo: Various forms of snapping // Todo: Various forms of snapping
foreach (var blueprint in selectedBlueprints) foreach (var blueprint in selectedBlueprints)
{ blueprint.AdjustPosition(dragEvent);
switch (blueprint.HitObject.HitObject)
{
case IHasEditablePosition editablePosition:
editablePosition.OffsetPosition(delta);
break;
}
}
} }
protected override bool OnKeyDown(KeyDownEvent e) protected override bool OnKeyDown(KeyDownEvent e)

View File

@ -18,7 +18,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.1.4" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.1.4" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" /> <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="ppy.osu.Framework" Version="2018.1105.0" /> <PackageReference Include="ppy.osu.Framework" Version="2018.1112.0" />
<PackageReference Include="SharpCompress" Version="0.22.0" /> <PackageReference Include="SharpCompress" Version="0.22.0" />
<PackageReference Include="NUnit" Version="3.11.0" /> <PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" /> <PackageReference Include="SharpRaven" Version="2.4.0" />