2017-02-10 15:10:24 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-03-09 13:24:16 +08:00
|
|
|
|
using OpenTK;
|
2017-04-27 17:07:10 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-04-18 15:05:58 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2017-02-10 15:10:24 +08:00
|
|
|
|
|
2017-04-18 15:05:58 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
|
2017-02-10 15:10:24 +08:00
|
|
|
|
{
|
2017-02-12 14:29:36 +08:00
|
|
|
|
public class FollowPointRenderer : ConnectionRenderer<OsuHitObject>
|
2017-02-10 15:10:24 +08:00
|
|
|
|
{
|
2017-02-12 15:31:43 +08:00
|
|
|
|
private int pointDistance = 32;
|
2017-02-10 17:24:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines how much space there is between points.
|
|
|
|
|
/// </summary>
|
2017-02-12 15:31:43 +08:00
|
|
|
|
public int PointDistance
|
|
|
|
|
{
|
|
|
|
|
get { return pointDistance; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (pointDistance == value) return;
|
|
|
|
|
pointDistance = value;
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-10 17:24:31 +08:00
|
|
|
|
|
2017-02-12 15:31:43 +08:00
|
|
|
|
private int preEmpt = 800;
|
2017-02-10 17:24:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Follow points to the next hitobject start appearing for this many milliseconds before an hitobject's end time.
|
|
|
|
|
/// </summary>
|
2017-02-12 15:31:43 +08:00
|
|
|
|
public int PreEmpt
|
|
|
|
|
{
|
|
|
|
|
get { return preEmpt; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (preEmpt == value) return;
|
|
|
|
|
preEmpt = value;
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-10 15:10:24 +08:00
|
|
|
|
|
2017-02-12 15:31:43 +08:00
|
|
|
|
private IEnumerable<OsuHitObject> hitObjects;
|
|
|
|
|
public override IEnumerable<OsuHitObject> HitObjects
|
2017-02-10 15:10:24 +08:00
|
|
|
|
{
|
2017-02-12 15:31:43 +08:00
|
|
|
|
get { return hitObjects; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
hitObjects = value;
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-04 00:02:33 +08:00
|
|
|
|
public override bool RemoveCompletedTransforms => false;
|
|
|
|
|
|
2017-02-12 15:31:43 +08:00
|
|
|
|
private void update()
|
|
|
|
|
{
|
|
|
|
|
Clear();
|
2017-11-04 00:02:33 +08:00
|
|
|
|
|
2017-02-12 15:31:43 +08:00
|
|
|
|
if (hitObjects == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-02-12 14:29:36 +08:00
|
|
|
|
OsuHitObject prevHitObject = null;
|
|
|
|
|
foreach (var currHitObject in hitObjects)
|
2017-02-10 15:10:24 +08:00
|
|
|
|
{
|
2017-02-12 14:29:36 +08:00
|
|
|
|
if (prevHitObject != null && !currHitObject.NewCombo && !(prevHitObject is Spinner) && !(currHitObject is Spinner))
|
2017-02-10 15:10:24 +08:00
|
|
|
|
{
|
|
|
|
|
Vector2 startPosition = prevHitObject.EndPosition;
|
|
|
|
|
Vector2 endPosition = currHitObject.Position;
|
2017-03-13 18:15:25 +08:00
|
|
|
|
double startTime = (prevHitObject as IHasEndTime)?.EndTime ?? prevHitObject.StartTime;
|
2017-02-10 15:10:24 +08:00
|
|
|
|
double endTime = currHitObject.StartTime;
|
|
|
|
|
|
|
|
|
|
Vector2 distanceVector = endPosition - startPosition;
|
|
|
|
|
int distance = (int)distanceVector.Length;
|
|
|
|
|
float rotation = (float)Math.Atan2(distanceVector.Y, distanceVector.X);
|
|
|
|
|
double duration = endTime - startTime;
|
|
|
|
|
|
|
|
|
|
for (int d = (int)(PointDistance * 1.5); d < distance - PointDistance; d += PointDistance)
|
|
|
|
|
{
|
2017-03-07 09:59:19 +08:00
|
|
|
|
float fraction = (float)d / distance;
|
2017-02-10 15:10:24 +08:00
|
|
|
|
Vector2 pointStartPosition = startPosition + (fraction - 0.1f) * distanceVector;
|
|
|
|
|
Vector2 pointEndPosition = startPosition + fraction * distanceVector;
|
|
|
|
|
double fadeOutTime = startTime + fraction * duration;
|
|
|
|
|
double fadeInTime = fadeOutTime - PreEmpt;
|
|
|
|
|
|
2017-04-27 17:07:10 +08:00
|
|
|
|
FollowPoint fp;
|
|
|
|
|
|
|
|
|
|
Add(fp = new FollowPoint
|
2017-02-10 15:10:24 +08:00
|
|
|
|
{
|
|
|
|
|
Position = pointStartPosition,
|
|
|
|
|
Rotation = rotation,
|
2017-04-27 17:07:10 +08:00
|
|
|
|
Alpha = 0,
|
|
|
|
|
Scale = new Vector2(1.5f),
|
2017-02-10 15:10:24 +08:00
|
|
|
|
});
|
2017-04-27 17:07:10 +08:00
|
|
|
|
|
|
|
|
|
using (fp.BeginAbsoluteSequence(fadeInTime))
|
|
|
|
|
{
|
|
|
|
|
fp.FadeIn(DrawableOsuHitObject.TIME_FADEIN);
|
2017-07-23 02:50:25 +08:00
|
|
|
|
fp.ScaleTo(1, DrawableOsuHitObject.TIME_FADEIN, Easing.Out);
|
2017-04-27 17:07:10 +08:00
|
|
|
|
|
2017-07-23 02:50:25 +08:00
|
|
|
|
fp.MoveTo(pointEndPosition, DrawableOsuHitObject.TIME_FADEIN, Easing.Out);
|
2017-04-27 17:07:10 +08:00
|
|
|
|
|
2017-07-17 22:05:24 +08:00
|
|
|
|
fp.Delay(fadeOutTime - fadeInTime).FadeOut(DrawableOsuHitObject.TIME_FADEIN);
|
2017-04-27 17:07:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fp.Expire(true);
|
2017-02-10 15:10:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-12 14:29:36 +08:00
|
|
|
|
prevHitObject = currHitObject;
|
2017-02-10 15:10:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|