Merge branch 'master' into fix-red-point-placement

This commit is contained in:
Dean Herbert
2020-04-13 20:56:50 +09:00
committed by GitHub
67 changed files with 1855 additions and 293 deletions

View File

@ -16,22 +16,25 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
/// </summary>
public class PathControlPointConnectionPiece : CompositeDrawable
{
public PathControlPoint ControlPoint;
public readonly PathControlPoint ControlPoint;
private readonly Path path;
private readonly Slider slider;
private readonly int controlPointIndex;
private IBindable<Vector2> sliderPosition;
private IBindable<int> pathVersion;
public PathControlPointConnectionPiece(Slider slider, PathControlPoint controlPoint)
public PathControlPointConnectionPiece(Slider slider, int controlPointIndex)
{
this.slider = slider;
ControlPoint = controlPoint;
this.controlPointIndex = controlPointIndex;
Origin = Anchor.Centre;
AutoSizeAxes = Axes.Both;
ControlPoint = slider.Path.ControlPoints[controlPointIndex];
InternalChild = path = new SmoothPath
{
Anchor = Anchor.Centre,
@ -61,13 +64,12 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
path.ClearVertices();
int index = slider.Path.ControlPoints.IndexOf(ControlPoint) + 1;
if (index == 0 || index == slider.Path.ControlPoints.Count)
int nextIndex = controlPointIndex + 1;
if (nextIndex == 0 || nextIndex == slider.Path.ControlPoints.Count)
return;
path.AddVertex(Vector2.Zero);
path.AddVertex(slider.Path.ControlPoints[index].Position.Value - ControlPoint.Position.Value);
path.AddVertex(slider.Path.ControlPoints[nextIndex].Position.Value - ControlPoint.Position.Value);
path.OriginPosition = path.PositionInBoundingBox(Vector2.Zero);
}

View File

@ -12,6 +12,7 @@ using osu.Game.Graphics;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Edit;
using osuTK;
using osuTK.Graphics;
using osuTK.Input;
@ -33,6 +34,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
private readonly Container marker;
private readonly Drawable markerRing;
[Resolved(CanBeNull = true)]
private IEditorChangeHandler changeHandler { get; set; }
[Resolved(CanBeNull = true)]
private IDistanceSnapProvider snapProvider { get; set; }
@ -137,7 +141,16 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
protected override bool OnClick(ClickEvent e) => RequestSelection != null;
protected override bool OnDragStart(DragStartEvent e) => e.Button == MouseButton.Left;
protected override bool OnDragStart(DragStartEvent e)
{
if (e.Button == MouseButton.Left)
{
changeHandler?.BeginChange();
return true;
}
return false;
}
protected override void OnDrag(DragEvent e)
{
@ -158,6 +171,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
ControlPoint.Position.Value += e.Delta;
}
protected override void OnDragEnd(DragEndEvent e) => changeHandler?.EndChange();
/// <summary>
/// Updates the state of the circular control point marker.
/// </summary>

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using Humanizer;
using osu.Framework.Bindables;
@ -24,17 +25,14 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
public class PathControlPointVisualiser : CompositeDrawable, IKeyBindingHandler<PlatformAction>, IHasContextMenu
{
internal readonly Container<PathControlPointPiece> Pieces;
internal readonly Container<PathControlPointConnectionPiece> Connections;
private readonly Container<PathControlPointConnectionPiece> connections;
private readonly IBindableList<PathControlPoint> controlPoints = new BindableList<PathControlPoint>();
private readonly Slider slider;
private readonly bool allowSelection;
private InputManager inputManager;
private IBindableList<PathControlPoint> controlPoints;
public Action<List<PathControlPoint>> RemoveControlPointsRequested;
public PathControlPointVisualiser(Slider slider, bool allowSelection)
@ -46,7 +44,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
InternalChildren = new Drawable[]
{
connections = new Container<PathControlPointConnectionPiece> { RelativeSizeAxes = Axes.Both },
Connections = new Container<PathControlPointConnectionPiece> { RelativeSizeAxes = Axes.Both },
Pieces = new Container<PathControlPointPiece> { RelativeSizeAxes = Axes.Both }
};
}
@ -57,33 +55,38 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
inputManager = GetContainingInputManager();
controlPoints = slider.Path.ControlPoints.GetBoundCopy();
controlPoints.ItemsAdded += addControlPoints;
controlPoints.ItemsRemoved += removeControlPoints;
addControlPoints(controlPoints);
controlPoints.CollectionChanged += onControlPointsChanged;
controlPoints.BindTo(slider.Path.ControlPoints);
}
private void addControlPoints(IEnumerable<PathControlPoint> controlPoints)
private void onControlPointsChanged(object sender, NotifyCollectionChangedEventArgs e)
{
foreach (var point in controlPoints)
switch (e.Action)
{
Pieces.Add(new PathControlPointPiece(slider, point).With(d =>
{
if (allowSelection)
d.RequestSelection = selectPiece;
}));
case NotifyCollectionChangedAction.Add:
for (int i = 0; i < e.NewItems.Count; i++)
{
var point = (PathControlPoint)e.NewItems[i];
connections.Add(new PathControlPointConnectionPiece(slider, point));
}
}
Pieces.Add(new PathControlPointPiece(slider, point).With(d =>
{
if (allowSelection)
d.RequestSelection = selectPiece;
}));
private void removeControlPoints(IEnumerable<PathControlPoint> controlPoints)
{
foreach (var point in controlPoints)
{
Pieces.RemoveAll(p => p.ControlPoint == point);
connections.RemoveAll(c => c.ControlPoint == point);
Connections.Add(new PathControlPointConnectionPiece(slider, e.NewStartingIndex + i));
}
break;
case NotifyCollectionChangedAction.Remove:
foreach (var point in e.OldItems.Cast<PathControlPoint>())
{
Pieces.RemoveAll(p => p.ControlPoint == point);
Connections.RemoveAll(c => c.ControlPoint == point);
}
break;
}
}

View File

@ -38,6 +38,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
[Resolved(CanBeNull = true)]
private EditorBeatmap editorBeatmap { get; set; }
[Resolved(CanBeNull = true)]
private IEditorChangeHandler changeHandler { get; set; }
public SliderSelectionBlueprint(DrawableSlider slider)
: base(slider)
{
@ -92,7 +95,16 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
private int? placementControlPointIndex;
protected override bool OnDragStart(DragStartEvent e) => placementControlPointIndex != null;
protected override bool OnDragStart(DragStartEvent e)
{
if (placementControlPointIndex != null)
{
changeHandler?.BeginChange();
return true;
}
return false;
}
protected override void OnDrag(DragEvent e)
{
@ -103,7 +115,11 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
protected override void OnDragEnd(DragEndEvent e)
{
placementControlPointIndex = null;
if (placementControlPointIndex != null)
{
placementControlPointIndex = null;
changeHandler?.EndChange();
}
}
private BindableList<PathControlPoint> controlPoints => HitObject.Path.ControlPoints;