mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 07:33:20 +08:00
Use ControlPointVisualiser instead of custom implementation
This commit is contained in:
parent
08b16be3b8
commit
5998d6454b
@ -1,92 +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.Framework.Allocation;
|
||||
using osu.Framework.Caching;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Lines;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks.Components
|
||||
{
|
||||
public class SliderControlPoint : CompositeDrawable
|
||||
{
|
||||
private readonly Path path;
|
||||
private readonly CircularContainer marker;
|
||||
|
||||
private OsuColour colours;
|
||||
|
||||
public SliderControlPoint()
|
||||
{
|
||||
Size = new Vector2(5);
|
||||
Origin = Anchor.Centre;
|
||||
|
||||
NextPoint = Position;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
path = new SmoothPath
|
||||
{
|
||||
BypassAutoSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
PathWidth = 1,
|
||||
},
|
||||
marker = new CircularContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Masking = true,
|
||||
Child = new Box { RelativeSizeAxes = Axes.Both }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
this.colours = colours;
|
||||
|
||||
marker.Colour = colours.YellowDark;
|
||||
}
|
||||
|
||||
public bool SegmentSeparator
|
||||
{
|
||||
set => marker.Colour = value ? colours.Red : colours.YellowDark;
|
||||
}
|
||||
|
||||
private Vector2 nextPoint;
|
||||
|
||||
public Vector2 NextPoint
|
||||
{
|
||||
set
|
||||
{
|
||||
nextPoint = value;
|
||||
pathCache.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
validatePath();
|
||||
}
|
||||
|
||||
private Cached pathCache = new Cached();
|
||||
|
||||
private void validatePath()
|
||||
{
|
||||
if (pathCache.IsValid)
|
||||
return;
|
||||
|
||||
path.ClearVertices();
|
||||
path.AddVertex(nextPoint - Position);
|
||||
path.AddVertex(Vector2.Zero);
|
||||
path.OriginPosition = path.PositionInBoundingBox(Vector2.Zero);
|
||||
|
||||
pathCache.Validate();
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
@ -23,8 +22,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks
|
||||
{
|
||||
public new Objects.Slider HitObject => (Objects.Slider)base.HitObject;
|
||||
|
||||
private Container<SliderControlPoint> controlPointContainer;
|
||||
|
||||
private readonly List<Segment> segments = new List<Segment>();
|
||||
private Vector2 cursor;
|
||||
|
||||
@ -45,7 +42,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks
|
||||
new SliderBodyPiece(HitObject),
|
||||
new SliderCirclePiece(HitObject, SliderPosition.Start),
|
||||
new SliderCirclePiece(HitObject, SliderPosition.End),
|
||||
controlPointContainer = new Container<SliderControlPoint> { RelativeSizeAxes = Axes.Both }
|
||||
new ControlPointVisualiser(HitObject),
|
||||
};
|
||||
|
||||
setState(PlacementState.Initial);
|
||||
@ -60,7 +57,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks
|
||||
return true;
|
||||
case PlacementState.Body:
|
||||
cursor = e.MousePosition - HitObject.Position;
|
||||
controlPointContainer.Last().NextPoint = e.MousePosition;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -85,8 +81,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks
|
||||
break;
|
||||
}
|
||||
|
||||
controlPointContainer.Add(new SliderControlPoint { Position = e.MousePosition });
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -100,7 +94,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks
|
||||
protected override bool OnDoubleClick(DoubleClickEvent e)
|
||||
{
|
||||
segments.Add(new Segment(segments[segments.Count - 1].ControlPoints.Last()));
|
||||
controlPointContainer.Last().SegmentSeparator = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user