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 osu.Framework.Graphics;
|
2020-11-19 23:11:31 +08:00
|
|
|
using osu.Framework.Graphics.Pooling;
|
2019-11-25 18:01:24 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2019-11-01 14:39:23 +08:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
|
|
|
|
{
|
2019-11-05 22:20:46 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Visualises the <see cref="FollowPoint"/>s between two <see cref="DrawableOsuHitObject"/>s.
|
|
|
|
/// </summary>
|
2020-11-19 23:11:31 +08:00
|
|
|
public class FollowPointConnection : PoolableDrawable
|
2019-11-01 14:39:23 +08:00
|
|
|
{
|
|
|
|
// Todo: These shouldn't be constants
|
2020-11-19 23:11:31 +08:00
|
|
|
public const int SPACING = 32;
|
|
|
|
public const double PREEMPT = 800;
|
2019-11-01 14:39:23 +08:00
|
|
|
|
2020-11-19 23:11:31 +08:00
|
|
|
public FollowPointRenderer.FollowPointLifetimeEntry Entry;
|
|
|
|
public DrawablePool<FollowPoint> Pool;
|
2019-11-01 14:39:23 +08:00
|
|
|
|
2020-11-20 14:31:04 +08:00
|
|
|
protected override void PrepareForUse()
|
|
|
|
{
|
|
|
|
base.PrepareForUse();
|
|
|
|
|
|
|
|
Entry.Invalidated += onEntryInvalidated;
|
|
|
|
|
|
|
|
refreshPoints();
|
|
|
|
}
|
|
|
|
|
2020-11-19 23:11:31 +08:00
|
|
|
protected override void FreeAfterUse()
|
2019-11-01 14:39:23 +08:00
|
|
|
{
|
2020-11-19 23:11:31 +08:00
|
|
|
base.FreeAfterUse();
|
2020-11-20 14:31:04 +08:00
|
|
|
|
|
|
|
Entry.Invalidated -= onEntryInvalidated;
|
|
|
|
|
|
|
|
// Return points to the pool.
|
2020-11-19 23:11:31 +08:00
|
|
|
ClearInternal(false);
|
2020-11-20 14:31:04 +08:00
|
|
|
|
|
|
|
Entry = null;
|
2019-11-01 14:39:23 +08:00
|
|
|
}
|
|
|
|
|
2020-11-20 14:31:04 +08:00
|
|
|
private void onEntryInvalidated() => refreshPoints();
|
|
|
|
|
|
|
|
private void refreshPoints()
|
2020-02-23 03:05:37 +08:00
|
|
|
{
|
2020-11-20 14:31:04 +08:00
|
|
|
ClearInternal(false);
|
2019-11-01 18:21:39 +08:00
|
|
|
|
2020-11-19 23:11:31 +08:00
|
|
|
OsuHitObject start = Entry.Start;
|
|
|
|
OsuHitObject end = Entry.End;
|
2019-11-01 14:39:23 +08:00
|
|
|
|
2020-11-19 23:11:31 +08:00
|
|
|
double startTime = start.GetEndTime();
|
2020-02-23 03:05:37 +08:00
|
|
|
|
2020-11-19 23:11:31 +08:00
|
|
|
if (end == null || end.NewCombo || start is Spinner || end is Spinner)
|
2019-11-01 14:39:23 +08:00
|
|
|
return;
|
|
|
|
|
2020-11-19 23:11:31 +08:00
|
|
|
Vector2 startPosition = start.StackedEndPosition;
|
|
|
|
Vector2 endPosition = end.StackedPosition;
|
|
|
|
double endTime = end.StartTime;
|
2019-11-01 14:39:23 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2020-02-23 03:05:37 +08:00
|
|
|
double finalTransformEndTime = startTime;
|
|
|
|
|
2020-11-19 23:11:31 +08:00
|
|
|
for (int d = (int)(SPACING * 1.5); d < distance - SPACING; d += SPACING)
|
2019-11-01 14:39:23 +08:00
|
|
|
{
|
|
|
|
float fraction = (float)d / distance;
|
|
|
|
Vector2 pointStartPosition = startPosition + (fraction - 0.1f) * distanceVector;
|
|
|
|
Vector2 pointEndPosition = startPosition + fraction * distanceVector;
|
|
|
|
double fadeOutTime = startTime + fraction * duration;
|
2020-11-19 23:11:31 +08:00
|
|
|
double fadeInTime = fadeOutTime - PREEMPT;
|
2019-11-01 14:39:23 +08:00
|
|
|
|
|
|
|
FollowPoint fp;
|
|
|
|
|
2020-11-19 23:11:31 +08:00
|
|
|
AddInternal(fp = Pool.Get());
|
2020-11-05 14:01:45 +08:00
|
|
|
|
2020-11-19 23:11:31 +08:00
|
|
|
fp.ClearTransforms();
|
2020-03-18 23:34:24 +08:00
|
|
|
fp.Position = pointStartPosition;
|
|
|
|
fp.Rotation = rotation;
|
|
|
|
fp.Alpha = 0;
|
2020-11-19 23:11:31 +08:00
|
|
|
fp.Scale = new Vector2(1.5f * end.Scale);
|
2020-02-24 11:24:15 +08:00
|
|
|
|
2020-03-27 17:03:02 +08:00
|
|
|
fp.AnimationStartTime = fadeInTime;
|
|
|
|
|
2019-11-01 14:39:23 +08:00
|
|
|
using (fp.BeginAbsoluteSequence(fadeInTime))
|
|
|
|
{
|
2020-11-19 23:11:31 +08:00
|
|
|
fp.FadeIn(end.TimeFadeIn);
|
|
|
|
fp.ScaleTo(end.Scale, end.TimeFadeIn, Easing.Out);
|
|
|
|
fp.MoveTo(pointEndPosition, end.TimeFadeIn, Easing.Out);
|
|
|
|
fp.Delay(fadeOutTime - fadeInTime).FadeOut(end.TimeFadeIn);
|
2019-11-05 22:03:05 +08:00
|
|
|
|
2020-11-19 23:11:31 +08:00
|
|
|
finalTransformEndTime = fadeOutTime + end.TimeFadeIn;
|
2020-02-23 03:05:37 +08:00
|
|
|
}
|
2019-11-01 14:39:23 +08:00
|
|
|
}
|
2020-02-23 03:05:37 +08:00
|
|
|
|
2020-02-24 11:24:15 +08:00
|
|
|
// todo: use Expire() on FollowPoints and take lifetime from them when https://github.com/ppy/osu-framework/issues/3300 is fixed.
|
2020-11-19 23:11:31 +08:00
|
|
|
Entry.LifetimeEnd = finalTransformEndTime;
|
2019-11-01 14:39:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|