Fix animated follow points not (re)animating after rewind

This commit is contained in:
Dean Herbert 2020-03-27 18:03:02 +09:00
parent a141e2e8b7
commit d36f5fb96f
4 changed files with 55 additions and 9 deletions

View File

@ -15,7 +15,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
/// <summary>
/// A single follow point positioned between two adjacent <see cref="DrawableOsuHitObject"/>s.
/// </summary>
public class FollowPoint : Container
public class FollowPoint : Container, IAnimationTimeReference
{
private const float width = 8;
@ -45,5 +45,7 @@ public FollowPoint()
}
}, confineMode: ConfineMode.NoScaling);
}
public double AnimationStartTime { get; set; }
}
}

View File

@ -116,6 +116,8 @@ private void refresh()
int point = 0;
ClearInternal();
for (int d = (int)(spacing * 1.5); d < distance - spacing; d += spacing)
{
float fraction = (float)d / distance;
@ -126,13 +128,7 @@ private void refresh()
FollowPoint fp;
if (InternalChildren.Count > point)
{
fp = (FollowPoint)InternalChildren[point];
fp.ClearTransforms();
}
else
AddInternal(fp = new FollowPoint());
AddInternal(fp = new FollowPoint());
fp.Position = pointStartPosition;
fp.Rotation = rotation;
@ -142,6 +138,8 @@ private void refresh()
if (firstTransformStartTime == null)
firstTransformStartTime = fadeInTime;
fp.AnimationStartTime = fadeInTime;
using (fp.BeginAbsoluteSequence(fadeInTime))
{
fp.FadeIn(osuEnd.TimeFadeIn);

View File

@ -0,0 +1,25 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Timing;
namespace osu.Game.Skinning
{
/// <summary>
/// Denotes an object which provides a reference time to start animations from.
/// </summary>
[Cached]
public interface IAnimationTimeReference
{
/// <summary>
/// The reference clock.
/// </summary>
IFrameBasedClock Clock { get; }
/// <summary>
/// The time which animations should be started from, relative to <see cref="Clock"/>.
/// </summary>
double AnimationStartTime { get; }
}
}

View File

@ -3,10 +3,12 @@
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Animations;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Timing;
namespace osu.Game.Skinning
{
@ -22,7 +24,7 @@ public static Drawable GetAnimation(this ISkin source, string componentName, boo
if (textures.Length > 0)
{
var animation = new TextureAnimation
var animation = new SkinnableTextureAnimation
{
DefaultFrameLength = getFrameLength(source, applyConfigFrameRate, textures),
Repeat = looping,
@ -53,6 +55,25 @@ IEnumerable<Texture> getTextures()
}
}
public class SkinnableTextureAnimation : TextureAnimation
{
[Resolved(canBeNull: true)]
private IAnimationTimeReference timeReference { get; set; }
public SkinnableTextureAnimation()
: base(false)
{
}
protected override void LoadComplete()
{
base.LoadComplete();
if (timeReference != null)
Clock = new FramedOffsetClock(timeReference.Clock) { Offset = -timeReference.AnimationStartTime };
}
}
private const double default_frame_time = 1000 / 60d;
private static double getFrameLength(ISkin source, bool applyConfigFrameRate, Texture[] textures)