mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
Make DrawableSlider contain the slider body
This commit is contained in:
@ -79,7 +79,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
||||
List<Vector2> curve = drawableSlider.Body.CurrentCurve;
|
||||
|
||||
var positionOnCurve = isRepeatAtEnd ? end : start;
|
||||
Position = positionOnCurve + drawableSlider.HitObject.StackOffset;
|
||||
Position = positionOnCurve - curve[0] + drawableSlider.HitObject.StackOffset;
|
||||
|
||||
if (curve.Count < 2)
|
||||
return;
|
||||
|
@ -30,6 +30,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
||||
{
|
||||
slider = s;
|
||||
|
||||
Position = s.StackedPosition;
|
||||
|
||||
DrawableSliderTail tail;
|
||||
Container<DrawableSliderTick> ticks;
|
||||
Container<DrawableRepeatPoint> repeatPoints;
|
||||
@ -39,20 +41,20 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
||||
Body = new SliderBody(s)
|
||||
{
|
||||
AccentColour = AccentColour,
|
||||
Position = s.StackedPosition,
|
||||
PathWidth = s.Scale * 64,
|
||||
},
|
||||
ticks = new Container<DrawableSliderTick>(),
|
||||
repeatPoints = new Container<DrawableRepeatPoint>(),
|
||||
ticks = new Container<DrawableSliderTick> { RelativeSizeAxes = Axes.Both },
|
||||
repeatPoints = new Container<DrawableRepeatPoint> { RelativeSizeAxes = Axes.Both },
|
||||
Ball = new SliderBall(s)
|
||||
{
|
||||
BypassAutoSizeAxes = Axes.Both,
|
||||
Scale = new Vector2(s.Scale),
|
||||
AccentColour = AccentColour,
|
||||
AlwaysPresent = true,
|
||||
Alpha = 0
|
||||
},
|
||||
HeadCircle = new DrawableHitCircle(s.HeadCircle),
|
||||
tail = new DrawableSliderTail(s.TailCircle)
|
||||
HeadCircle = new DrawableHitCircle(s.HeadCircle) { Position = s.HeadCircle.StackedPosition },
|
||||
tail = new DrawableSliderTail(s.TailCircle) { Position = s.TailCircle.StackedPosition }
|
||||
};
|
||||
|
||||
components.Add(Body);
|
||||
@ -112,6 +114,13 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
||||
foreach (var c in components.OfType<ISliderProgress>()) c.UpdateProgress(completionProgress);
|
||||
foreach (var c in components.OfType<ITrackSnaking>()) c.UpdateSnakingPosition(slider.Curve.PositionAt(Body.SnakedStart ?? 0), slider.Curve.PositionAt(Body.SnakedEnd ?? 0));
|
||||
foreach (var t in components.OfType<IRequireTracking>()) t.Tracking = Ball.Tracking;
|
||||
|
||||
Size = Body.Size;
|
||||
OriginPosition = Body.PathOffset;
|
||||
|
||||
foreach (var obj in NestedHitObjects)
|
||||
obj.RelativeAnchorPosition = Vector2.Divide(OriginPosition, Body.DrawSize);
|
||||
Ball.RelativeAnchorPosition = Vector2.Divide(OriginPosition, Body.DrawSize);
|
||||
}
|
||||
|
||||
protected override void CheckForJudgements(bool userTriggered, double timeOffset)
|
||||
|
@ -19,8 +19,12 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
||||
public DrawableSliderTail(HitCircle hitCircle)
|
||||
: base(hitCircle)
|
||||
{
|
||||
AlwaysPresent = true;
|
||||
Origin = Anchor.Centre;
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
FillMode = FillMode.Fit;
|
||||
|
||||
AlwaysPresent = true;
|
||||
}
|
||||
|
||||
protected override void CheckForJudgements(bool userTriggered, double timeOffset)
|
||||
|
@ -29,6 +29,13 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
||||
set { path.PathWidth = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Offset in absolute coordinates from the start of the curve.
|
||||
/// </summary>
|
||||
public Vector2 PathOffset { get; private set; }
|
||||
|
||||
public readonly List<Vector2> CurrentCurve = new List<Vector2>();
|
||||
|
||||
public readonly Bindable<bool> SnakingIn = new Bindable<bool>();
|
||||
public readonly Bindable<bool> SnakingOut = new Bindable<bool>();
|
||||
|
||||
@ -75,6 +82,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
||||
|
||||
private int textureWidth => (int)PathWidth * 2;
|
||||
|
||||
private Vector2 topLeftOffset;
|
||||
|
||||
private readonly Slider slider;
|
||||
public SliderBody(Slider s)
|
||||
{
|
||||
@ -84,6 +93,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
||||
{
|
||||
container = new BufferedContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
CacheDrawnFrameBuffer = true,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
@ -107,11 +117,11 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
||||
|
||||
if (updateSnaking(p0, p1))
|
||||
{
|
||||
// Autosizing does not give us the desired behaviour here.
|
||||
// We want the container to have the same size as the slider,
|
||||
// and to be positioned such that the slider head is at (0,0).
|
||||
container.Size = path.Size;
|
||||
container.Position = -path.PositionInBoundingBox(slider.Curve.PositionAt(0) - CurrentCurve[0]);
|
||||
// The path is generated such that its size encloses it. This change of size causes the path
|
||||
// to move around while snaking, so we need to offset it to make sure it maintains the
|
||||
// same position as when it is fully snaked.
|
||||
var newTopLeftOffset = path.PositionInBoundingBox(Vector2.Zero);
|
||||
path.Position = topLeftOffset - newTopLeftOffset;
|
||||
|
||||
container.ForceRedraw();
|
||||
}
|
||||
@ -121,6 +131,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
||||
private void load()
|
||||
{
|
||||
reloadTexture();
|
||||
computeSize();
|
||||
}
|
||||
|
||||
private void reloadTexture()
|
||||
@ -164,7 +175,19 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
||||
path.Texture = texture;
|
||||
}
|
||||
|
||||
public readonly List<Vector2> CurrentCurve = new List<Vector2>();
|
||||
private void computeSize()
|
||||
{
|
||||
// Generate the entire curve
|
||||
slider.Curve.GetPathToProgress(CurrentCurve, 0, 1);
|
||||
foreach (Vector2 p in CurrentCurve)
|
||||
path.AddVertex(p);
|
||||
|
||||
Size = path.Size;
|
||||
|
||||
topLeftOffset = path.PositionInBoundingBox(Vector2.Zero);
|
||||
PathOffset = path.PositionInBoundingBox(CurrentCurve[0]);
|
||||
}
|
||||
|
||||
private bool updateSnaking(double p0, double p1)
|
||||
{
|
||||
if (SnakedStart == p0 && SnakedEnd == p1) return false;
|
||||
@ -176,7 +199,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
||||
|
||||
path.ClearVertices();
|
||||
foreach (Vector2 p in CurrentCurve)
|
||||
path.AddVertex(p - CurrentCurve[0]);
|
||||
path.AddVertex(p);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ namespace osu.Game.Rulesets.Osu.Objects
|
||||
HeadCircle = new HitCircle
|
||||
{
|
||||
StartTime = StartTime,
|
||||
Position = StackedPosition,
|
||||
Position = this.PositionAt(0),
|
||||
IndexInCurrentCombo = IndexInCurrentCombo,
|
||||
ComboColour = ComboColour,
|
||||
Samples = Samples,
|
||||
@ -109,7 +109,7 @@ namespace osu.Game.Rulesets.Osu.Objects
|
||||
TailCircle = new HitCircle
|
||||
{
|
||||
StartTime = EndTime,
|
||||
Position = StackedEndPosition,
|
||||
Position = this.PositionAt(1),
|
||||
IndexInCurrentCombo = IndexInCurrentCombo,
|
||||
ComboColour = ComboColour
|
||||
};
|
||||
@ -156,7 +156,7 @@ namespace osu.Game.Rulesets.Osu.Objects
|
||||
SpanIndex = span,
|
||||
SpanStartTime = spanStartTime,
|
||||
StartTime = spanStartTime + timeProgress * SpanDuration,
|
||||
Position = Curve.PositionAt(distanceProgress),
|
||||
Position = Curve.PositionAt(distanceProgress) - Curve.PositionAt(0),
|
||||
StackHeight = StackHeight,
|
||||
Scale = Scale,
|
||||
ComboColour = ComboColour,
|
||||
@ -175,7 +175,7 @@ namespace osu.Game.Rulesets.Osu.Objects
|
||||
RepeatIndex = repeatIndex,
|
||||
SpanDuration = SpanDuration,
|
||||
StartTime = StartTime + repeat * SpanDuration,
|
||||
Position = Curve.PositionAt(repeat % 2),
|
||||
Position = Curve.PositionAt(repeat % 2) - Curve.PositionAt(0),
|
||||
StackHeight = StackHeight,
|
||||
Scale = Scale,
|
||||
ComboColour = ComboColour,
|
||||
@ -184,4 +184,10 @@ namespace osu.Game.Rulesets.Osu.Objects
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class SliderExtensions
|
||||
{
|
||||
public static Vector2 PositionAt(this Slider slider, double progress)
|
||||
=> ((IHasCurve)slider).PositionAt(progress) - slider.Curve.PositionAt(0);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user