1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-24 10:07:28 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Objects/Drawables/Connections/FollowPointRenderer.cs

121 lines
4.0 KiB
C#
Raw Normal View History

// 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-04-13 17:19:50 +08:00
using System;
using System.Collections.Generic;
2018-11-20 15:51:59 +08:00
using osuTK;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Game.Rulesets.Objects.Types;
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
{
public class FollowPointRenderer : ConnectionRenderer<OsuHitObject>
{
private int pointDistance = 32;
2018-04-13 17:19:50 +08:00
/// <summary>
/// Determines how much space there is between points.
/// </summary>
public int PointDistance
{
get => pointDistance;
2018-04-13 17:19:50 +08:00
set
{
if (pointDistance == value) return;
2018-04-13 17:19:50 +08:00
pointDistance = value;
update();
}
}
private int preEmpt = 800;
2018-04-13 17:19:50 +08:00
/// <summary>
/// Follow points to the next hitobject start appearing for this many milliseconds before an hitobject's end time.
/// </summary>
public int PreEmpt
{
get => preEmpt;
2018-04-13 17:19:50 +08:00
set
{
if (preEmpt == value) return;
2018-04-13 17:19:50 +08:00
preEmpt = value;
update();
}
}
private IEnumerable<OsuHitObject> hitObjects;
2018-04-13 17:19:50 +08:00
public override IEnumerable<OsuHitObject> HitObjects
{
get => hitObjects;
2018-04-13 17:19:50 +08:00
set
{
hitObjects = value;
update();
}
}
public override bool RemoveCompletedTransforms => false;
private void update()
{
ClearInternal();
2018-04-13 17:19:50 +08:00
if (hitObjects == null)
return;
OsuHitObject prevHitObject = null;
foreach (var currHitObject in hitObjects)
{
if (prevHitObject != null && !currHitObject.NewCombo && !(prevHitObject is Spinner) && !(currHitObject is Spinner))
{
Vector2 startPosition = prevHitObject.EndPosition;
Vector2 endPosition = currHitObject.Position;
double startTime = (prevHitObject as IHasEndTime)?.EndTime ?? prevHitObject.StartTime;
double endTime = currHitObject.StartTime;
Vector2 distanceVector = endPosition - startPosition;
int distance = (int)distanceVector.Length;
2018-07-30 05:21:05 +08:00
float rotation = (float)(Math.Atan2(distanceVector.Y, distanceVector.X) * (180 / Math.PI));
2018-04-13 17:19:50 +08:00
double duration = endTime - startTime;
for (int d = (int)(PointDistance * 1.5); d < distance - PointDistance; d += PointDistance)
{
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
2018-04-13 17:19:50 +08:00
{
Position = pointStartPosition,
Rotation = rotation,
Alpha = 0,
Scale = new Vector2(1.5f),
});
using (fp.BeginAbsoluteSequence(fadeInTime))
{
fp.FadeIn(currHitObject.TimeFadeIn);
fp.ScaleTo(1, currHitObject.TimeFadeIn, Easing.Out);
2018-04-13 17:19:50 +08:00
fp.MoveTo(pointEndPosition, currHitObject.TimeFadeIn, Easing.Out);
2018-04-13 17:19:50 +08:00
fp.Delay(fadeOutTime - fadeInTime).FadeOut(currHitObject.TimeFadeIn);
2018-04-13 17:19:50 +08:00
}
fp.Expire(true);
}
}
2018-04-13 17:19:50 +08:00
prevHitObject = currHitObject;
}
}
}
}