2019-11-01 14:39:23 +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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using JetBrains.Annotations;
|
2019-11-01 18:22:07 +08:00
|
|
|
using osu.Framework.Bindables;
|
2019-11-01 14:39:23 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
|
|
|
|
{
|
|
|
|
public class FollowPointGroup : CompositeDrawable
|
|
|
|
{
|
|
|
|
// Todo: These shouldn't be constants
|
|
|
|
private const int spacing = 32;
|
|
|
|
private const double preempt = 800;
|
|
|
|
|
2019-11-01 18:22:07 +08:00
|
|
|
public readonly Bindable<double> StartTime = new Bindable<double>();
|
|
|
|
|
2019-11-01 14:39:23 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The <see cref="DrawableOsuHitObject"/> which <see cref="FollowPoint"/>s will exit from.
|
|
|
|
/// </summary>
|
|
|
|
[NotNull]
|
|
|
|
public readonly DrawableOsuHitObject Start;
|
|
|
|
|
2019-11-01 18:22:07 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new <see cref="FollowPointGroup"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="start">The <see cref="DrawableOsuHitObject"/> which <see cref="FollowPoint"/>s will exit from.</param>
|
|
|
|
public FollowPointGroup([NotNull] DrawableOsuHitObject start)
|
2019-11-01 14:39:23 +08:00
|
|
|
{
|
|
|
|
Start = start;
|
2019-11-01 18:22:07 +08:00
|
|
|
|
2019-11-01 14:39:23 +08:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
2019-11-01 18:22:07 +08:00
|
|
|
|
|
|
|
StartTime.BindTo(Start.HitObject.StartTimeBindable);
|
2019-11-01 14:39:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2019-11-01 18:21:39 +08:00
|
|
|
bindEvents(Start);
|
2019-11-01 14:39:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private DrawableOsuHitObject end;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The <see cref="DrawableOsuHitObject"/> which <see cref="FollowPoint"/>s will enter.
|
|
|
|
/// </summary>
|
|
|
|
[CanBeNull]
|
|
|
|
public DrawableOsuHitObject End
|
|
|
|
{
|
|
|
|
get => end;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
end = value;
|
|
|
|
|
|
|
|
if (end != null)
|
2019-11-01 18:21:39 +08:00
|
|
|
bindEvents(end);
|
2019-11-01 14:39:23 +08:00
|
|
|
|
2019-11-01 18:21:39 +08:00
|
|
|
refresh();
|
2019-11-01 14:39:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-01 18:21:39 +08:00
|
|
|
private void bindEvents(DrawableOsuHitObject drawableObject)
|
2019-11-01 14:39:23 +08:00
|
|
|
{
|
2019-11-01 18:21:39 +08:00
|
|
|
drawableObject.HitObject.PositionBindable.BindValueChanged(_ => scheduleRefresh());
|
|
|
|
drawableObject.HitObject.DefaultsApplied += scheduleRefresh;
|
2019-11-01 14:39:23 +08:00
|
|
|
}
|
|
|
|
|
2019-11-01 18:21:39 +08:00
|
|
|
private void scheduleRefresh() => Scheduler.AddOnce(refresh);
|
|
|
|
|
|
|
|
private void refresh()
|
2019-11-01 14:39:23 +08:00
|
|
|
{
|
|
|
|
ClearInternal();
|
|
|
|
|
|
|
|
if (End == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
OsuHitObject osuStart = Start.HitObject;
|
|
|
|
OsuHitObject osuEnd = End.HitObject;
|
|
|
|
|
|
|
|
if (osuEnd.NewCombo)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (osuStart is Spinner || osuEnd is Spinner)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Vector2 startPosition = osuStart.EndPosition;
|
|
|
|
Vector2 endPosition = osuEnd.Position;
|
|
|
|
double startTime = (osuStart as IHasEndTime)?.EndTime ?? osuStart.StartTime;
|
|
|
|
double endTime = osuEnd.StartTime;
|
|
|
|
|
|
|
|
Vector2 distanceVector = endPosition - startPosition;
|
|
|
|
int distance = (int)distanceVector.Length;
|
|
|
|
float rotation = (float)(Math.Atan2(distanceVector.Y, distanceVector.X) * (180 / Math.PI));
|
|
|
|
double duration = endTime - startTime;
|
|
|
|
|
|
|
|
for (int d = (int)(spacing * 1.5); d < distance - spacing; d += spacing)
|
|
|
|
{
|
|
|
|
float fraction = (float)d / distance;
|
|
|
|
Vector2 pointStartPosition = startPosition + (fraction - 0.1f) * distanceVector;
|
|
|
|
Vector2 pointEndPosition = startPosition + fraction * distanceVector;
|
|
|
|
double fadeOutTime = startTime + fraction * duration;
|
|
|
|
double fadeInTime = fadeOutTime - preempt;
|
|
|
|
|
|
|
|
FollowPoint fp;
|
|
|
|
|
|
|
|
AddInternal(fp = new FollowPoint
|
|
|
|
{
|
|
|
|
Position = pointStartPosition,
|
|
|
|
Rotation = rotation,
|
|
|
|
Alpha = 0,
|
|
|
|
Scale = new Vector2(1.5f * osuEnd.Scale),
|
|
|
|
});
|
|
|
|
|
|
|
|
using (fp.BeginAbsoluteSequence(fadeInTime))
|
|
|
|
{
|
2019-11-01 21:08:50 +08:00
|
|
|
// See: Expire calls are separated due to https://github.com/ppy/osu-framework/issues/2941
|
|
|
|
|
|
|
|
fp.FadeIn(osuEnd.TimeFadeIn).Expire(true);
|
2019-11-01 14:39:23 +08:00
|
|
|
|
2019-11-01 21:08:50 +08:00
|
|
|
fp.ScaleTo(osuEnd.Scale, osuEnd.TimeFadeIn, Easing.Out)
|
|
|
|
.MoveTo(pointEndPosition, osuEnd.TimeFadeIn, Easing.Out)
|
|
|
|
.Delay(fadeOutTime - fadeInTime).FadeOut(osuEnd.TimeFadeIn)
|
|
|
|
.Expire();
|
|
|
|
}
|
2019-11-01 14:39:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|