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;
|
2020-11-05 14:01:45 +08:00
|
|
|
using System.Diagnostics;
|
2019-11-01 14:39:23 +08:00
|
|
|
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;
|
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>
|
2019-11-06 15:33:42 +08:00
|
|
|
public class FollowPointConnection : CompositeDrawable
|
2019-11-01 14:39:23 +08:00
|
|
|
{
|
|
|
|
// Todo: These shouldn't be constants
|
|
|
|
private const int spacing = 32;
|
|
|
|
private const double preempt = 800;
|
|
|
|
|
2020-02-23 03:05:37 +08:00
|
|
|
public override bool RemoveWhenNotAlive => false;
|
|
|
|
|
2019-11-05 22:20:46 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The start time of <see cref="Start"/>.
|
|
|
|
/// </summary>
|
2020-02-02 05:50:29 +08:00
|
|
|
public readonly Bindable<double> StartTime = new BindableDouble();
|
2019-11-01 18:22:07 +08:00
|
|
|
|
2019-11-01 14:39:23 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The <see cref="DrawableOsuHitObject"/> which <see cref="FollowPoint"/>s will exit from.
|
|
|
|
/// </summary>
|
|
|
|
[NotNull]
|
2020-11-05 14:01:45 +08:00
|
|
|
public readonly OsuHitObject Start;
|
2019-11-01 14:39:23 +08:00
|
|
|
|
2019-11-01 18:22:07 +08:00
|
|
|
/// <summary>
|
2019-11-06 15:33:42 +08:00
|
|
|
/// Creates a new <see cref="FollowPointConnection"/>.
|
2019-11-01 18:22:07 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="start">The <see cref="DrawableOsuHitObject"/> which <see cref="FollowPoint"/>s will exit from.</param>
|
2020-11-05 14:01:45 +08:00
|
|
|
public FollowPointConnection([NotNull] OsuHitObject 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
|
|
|
|
2020-11-05 14:01:45 +08:00
|
|
|
StartTime.BindTo(start.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
|
|
|
}
|
|
|
|
|
2020-11-05 14:01:45 +08:00
|
|
|
private OsuHitObject end;
|
2019-11-01 14:39:23 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The <see cref="DrawableOsuHitObject"/> which <see cref="FollowPoint"/>s will enter.
|
|
|
|
/// </summary>
|
|
|
|
[CanBeNull]
|
2020-11-05 14:01:45 +08:00
|
|
|
public OsuHitObject End
|
2019-11-01 14:39:23 +08:00
|
|
|
{
|
|
|
|
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-05 21:50:38 +08:00
|
|
|
if (IsLoaded)
|
|
|
|
scheduleRefresh();
|
|
|
|
else
|
|
|
|
refresh();
|
2019-11-01 14:39:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-05 14:01:45 +08:00
|
|
|
private void bindEvents(OsuHitObject obj)
|
2019-11-01 14:39:23 +08:00
|
|
|
{
|
2020-11-05 14:01:45 +08:00
|
|
|
obj.PositionBindable.BindValueChanged(_ => scheduleRefresh());
|
|
|
|
obj.DefaultsApplied += _ => scheduleRefresh();
|
2019-11-01 14:39:23 +08:00
|
|
|
}
|
|
|
|
|
2020-02-23 03:05:37 +08:00
|
|
|
private void scheduleRefresh()
|
|
|
|
{
|
|
|
|
Scheduler.AddOnce(refresh);
|
|
|
|
}
|
2019-11-01 18:21:39 +08:00
|
|
|
|
|
|
|
private void refresh()
|
2019-11-01 14:39:23 +08:00
|
|
|
{
|
2020-11-05 14:01:45 +08:00
|
|
|
double startTime = Start.GetEndTime();
|
2019-11-01 14:39:23 +08:00
|
|
|
|
2020-02-23 03:05:37 +08:00
|
|
|
LifetimeStart = startTime;
|
|
|
|
|
2020-11-05 14:01:45 +08:00
|
|
|
if (End == null || End.NewCombo || Start is Spinner || End is Spinner)
|
2020-02-23 03:05:37 +08:00
|
|
|
{
|
|
|
|
// ensure we always set a lifetime for full LifetimeManagementContainer benefits
|
|
|
|
LifetimeEnd = LifetimeStart;
|
2019-11-01 14:39:23 +08:00
|
|
|
return;
|
2020-02-23 03:05:37 +08:00
|
|
|
}
|
2019-11-01 14:39:23 +08:00
|
|
|
|
2020-11-05 14:01:45 +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-24 11:24:15 +08:00
|
|
|
double? firstTransformStartTime = null;
|
2020-02-23 03:05:37 +08:00
|
|
|
double finalTransformEndTime = startTime;
|
|
|
|
|
2020-03-18 23:34:24 +08:00
|
|
|
int point = 0;
|
|
|
|
|
2020-03-27 17:03:02 +08:00
|
|
|
ClearInternal();
|
|
|
|
|
2019-11-01 14:39:23 +08:00
|
|
|
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;
|
|
|
|
|
2020-03-27 17:03:02 +08:00
|
|
|
AddInternal(fp = new FollowPoint());
|
2020-03-18 23:34:24 +08:00
|
|
|
|
2020-11-05 14:01:45 +08:00
|
|
|
Debug.Assert(End != null);
|
|
|
|
|
2020-03-18 23:34:24 +08:00
|
|
|
fp.Position = pointStartPosition;
|
|
|
|
fp.Rotation = rotation;
|
|
|
|
fp.Alpha = 0;
|
2020-11-05 14:01:45 +08:00
|
|
|
fp.Scale = new Vector2(1.5f * End.Scale);
|
2019-11-01 14:39:23 +08:00
|
|
|
|
2020-06-03 15:48:44 +08:00
|
|
|
firstTransformStartTime ??= fadeInTime;
|
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-05 14:01:45 +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-05 14:01:45 +08:00
|
|
|
finalTransformEndTime = fadeOutTime + End.TimeFadeIn;
|
2020-02-23 03:05:37 +08:00
|
|
|
}
|
2020-03-18 23:34:24 +08:00
|
|
|
|
|
|
|
point++;
|
2019-11-01 14:39:23 +08:00
|
|
|
}
|
2020-02-23 03:05:37 +08:00
|
|
|
|
2020-03-18 23:34:24 +08:00
|
|
|
int excessPoints = InternalChildren.Count - point;
|
|
|
|
for (int i = 0; i < excessPoints; i++)
|
|
|
|
RemoveInternal(InternalChildren[^1]);
|
|
|
|
|
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.
|
|
|
|
LifetimeStart = firstTransformStartTime ?? startTime;
|
2020-02-23 03:05:37 +08:00
|
|
|
LifetimeEnd = finalTransformEndTime;
|
2019-11-01 14:39:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|