2019-01-24 16:43:03 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-10-25 14:49:45 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-07-25 17:22:56 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-12-17 17:16:25 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2018-10-25 14:49:45 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2020-12-04 19:21:53 +08:00
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-10-25 14:49:45 +08:00
|
|
|
|
|
2022-11-09 12:23:53 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Osu.Skinning
|
2018-10-25 14:49:45 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A <see cref="SliderBody"/> which changes its curve depending on the snaking progress.
|
|
|
|
|
/// </summary>
|
2021-09-01 14:10:24 +08:00
|
|
|
|
public abstract partial class SnakingSliderBody : SliderBody, ISliderProgress
|
2018-10-25 14:49:45 +08:00
|
|
|
|
{
|
|
|
|
|
public readonly List<Vector2> CurrentCurve = new List<Vector2>();
|
|
|
|
|
|
|
|
|
|
public readonly Bindable<bool> SnakingIn = new Bindable<bool>();
|
|
|
|
|
public readonly Bindable<bool> SnakingOut = new Bindable<bool>();
|
|
|
|
|
|
|
|
|
|
public double? SnakedStart { get; private set; }
|
|
|
|
|
public double? SnakedEnd { get; private set; }
|
|
|
|
|
|
2019-07-29 18:12:41 +08:00
|
|
|
|
public override float PathRadius
|
|
|
|
|
{
|
|
|
|
|
get => base.PathRadius;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (base.PathRadius == value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
base.PathRadius = value;
|
|
|
|
|
|
|
|
|
|
Refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-25 14:49:45 +08:00
|
|
|
|
public override Vector2 PathOffset => snakedPathOffset;
|
|
|
|
|
|
2023-01-11 04:16:34 +08:00
|
|
|
|
public override Vector2 PathEndOffset => snakedPathEndOffset;
|
|
|
|
|
|
2018-10-25 14:49:45 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The top-left position of the path when fully snaked.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Vector2 snakedPosition;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The offset of the path from <see cref="snakedPosition"/> when fully snaked.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Vector2 snakedPathOffset;
|
|
|
|
|
|
2023-01-11 04:16:34 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The offset of the end of path from <see cref="snakedPosition"/> when fully snaked.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Vector2 snakedPathEndOffset;
|
|
|
|
|
|
2022-11-09 12:36:52 +08:00
|
|
|
|
private DrawableSlider drawableSlider = null!;
|
2018-10-25 14:49:45 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2019-12-17 17:16:25 +08:00
|
|
|
|
private void load(DrawableHitObject drawableObject)
|
2018-10-25 14:49:45 +08:00
|
|
|
|
{
|
2020-11-05 13:40:48 +08:00
|
|
|
|
drawableSlider = (DrawableSlider)drawableObject;
|
2019-12-17 17:16:25 +08:00
|
|
|
|
|
2018-10-29 14:36:43 +08:00
|
|
|
|
Refresh();
|
2018-10-25 14:49:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateProgress(double completionProgress)
|
|
|
|
|
{
|
2022-11-09 12:36:52 +08:00
|
|
|
|
if (drawableSlider.HitObject == null)
|
2020-11-05 13:40:48 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2020-11-05 14:18:52 +08:00
|
|
|
|
Slider slider = drawableSlider.HitObject;
|
|
|
|
|
|
2021-10-27 12:04:41 +08:00
|
|
|
|
int span = slider.SpanAt(completionProgress);
|
|
|
|
|
double spanProgress = slider.ProgressAt(completionProgress);
|
2018-10-25 14:49:45 +08:00
|
|
|
|
|
|
|
|
|
double start = 0;
|
2020-11-05 14:18:52 +08:00
|
|
|
|
double end = SnakingIn.Value ? Math.Clamp((Time.Current - (slider.StartTime - slider.TimePreempt)) / (slider.TimePreempt / 3), 0, 1) : 1;
|
2018-10-25 14:49:45 +08:00
|
|
|
|
|
2020-11-05 14:18:52 +08:00
|
|
|
|
if (span >= slider.SpanCount() - 1)
|
2018-10-25 14:49:45 +08:00
|
|
|
|
{
|
2020-11-05 14:18:52 +08:00
|
|
|
|
if (Math.Min(span, slider.SpanCount() - 1) % 2 == 1)
|
2018-10-25 14:49:45 +08:00
|
|
|
|
{
|
|
|
|
|
start = 0;
|
2019-02-21 17:56:34 +08:00
|
|
|
|
end = SnakingOut.Value ? spanProgress : 1;
|
2018-10-25 14:49:45 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-02-21 17:56:34 +08:00
|
|
|
|
start = SnakingOut.Value ? spanProgress : 0;
|
2018-10-25 14:49:45 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setRange(start, end);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-29 14:36:43 +08:00
|
|
|
|
public void Refresh()
|
|
|
|
|
{
|
2022-11-09 12:36:52 +08:00
|
|
|
|
if (drawableSlider.HitObject == null)
|
2020-11-05 13:40:48 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2018-10-29 14:36:43 +08:00
|
|
|
|
// Generate the entire curve
|
2020-11-05 13:40:48 +08:00
|
|
|
|
drawableSlider.HitObject.Path.GetPathToProgress(CurrentCurve, 0, 1);
|
2018-10-29 14:36:43 +08:00
|
|
|
|
SetVertices(CurrentCurve);
|
|
|
|
|
|
2019-07-25 17:22:56 +08:00
|
|
|
|
// Force the body to be the final path size to avoid excessive autosize computations
|
|
|
|
|
Path.AutoSizeAxes = Axes.Both;
|
2018-10-29 14:36:43 +08:00
|
|
|
|
Size = Path.Size;
|
|
|
|
|
|
2019-07-25 17:22:56 +08:00
|
|
|
|
updatePathSize();
|
|
|
|
|
|
2018-10-29 14:36:43 +08:00
|
|
|
|
snakedPosition = Path.PositionInBoundingBox(Vector2.Zero);
|
|
|
|
|
snakedPathOffset = Path.PositionInBoundingBox(Path.Vertices[0]);
|
2023-01-11 04:16:34 +08:00
|
|
|
|
snakedPathEndOffset = Path.PositionInBoundingBox(Path.Vertices[^1]);
|
2018-10-29 14:36:43 +08:00
|
|
|
|
|
2021-10-27 12:04:41 +08:00
|
|
|
|
double lastSnakedStart = SnakedStart ?? 0;
|
|
|
|
|
double lastSnakedEnd = SnakedEnd ?? 0;
|
2018-10-29 14:36:43 +08:00
|
|
|
|
|
|
|
|
|
SnakedStart = null;
|
|
|
|
|
SnakedEnd = null;
|
|
|
|
|
|
|
|
|
|
setRange(lastSnakedStart, lastSnakedEnd);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-25 17:22:56 +08:00
|
|
|
|
public override void RecyclePath()
|
|
|
|
|
{
|
|
|
|
|
base.RecyclePath();
|
|
|
|
|
updatePathSize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updatePathSize()
|
|
|
|
|
{
|
|
|
|
|
// Force the path to its final size to avoid excessive framebuffer resizes
|
|
|
|
|
Path.AutoSizeAxes = Axes.None;
|
|
|
|
|
Path.Size = Size;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-25 14:49:45 +08:00
|
|
|
|
private void setRange(double p0, double p1)
|
|
|
|
|
{
|
|
|
|
|
if (p0 > p1)
|
2020-01-09 03:46:17 +08:00
|
|
|
|
(p0, p1) = (p1, p0);
|
2018-10-25 14:49:45 +08:00
|
|
|
|
|
|
|
|
|
if (SnakedStart == p0 && SnakedEnd == p1) return;
|
|
|
|
|
|
|
|
|
|
SnakedStart = p0;
|
|
|
|
|
SnakedEnd = p1;
|
|
|
|
|
|
2020-11-05 13:40:48 +08:00
|
|
|
|
drawableSlider.HitObject.Path.GetPathToProgress(CurrentCurve, p0, p1);
|
2018-10-25 14:49:45 +08:00
|
|
|
|
|
|
|
|
|
SetVertices(CurrentCurve);
|
|
|
|
|
|
|
|
|
|
// The bounding box of the path expands as it snakes, which in turn shifts the position of the path.
|
|
|
|
|
// Depending on the direction of expansion, it may appear as if the path is expanding towards the position of the slider
|
|
|
|
|
// rather than expanding out from the position of the slider.
|
|
|
|
|
// To remove this effect, the path's position is shifted towards its final snaked position
|
|
|
|
|
|
|
|
|
|
Path.Position = snakedPosition - Path.PositionInBoundingBox(Vector2.Zero);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|