1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-20 09:03:00 +08:00

Add support for changing animation start time after load

This commit is contained in:
Bartłomiej Dach 2020-11-21 20:06:30 +01:00
parent 81d0b42930
commit 240c1b0aef
5 changed files with 23 additions and 6 deletions

View File

@ -1,6 +1,7 @@
// 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.Bindables;
using osuTK;
using osuTK.Graphics;
using osu.Framework.Extensions.Color4Extensions;
@ -47,6 +48,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
});
}
public double AnimationStartTime { get; set; }
public Bindable<double> AnimationStartTime { get; } = new BindableDouble();
IBindable<double> IAnimationTimeReference.AnimationStartTime => AnimationStartTime;
}
}

View File

@ -80,7 +80,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
fp.Alpha = 0;
fp.Scale = new Vector2(1.5f * end.Scale);
fp.AnimationStartTime = fadeInTime;
fp.AnimationStartTime.Value = fadeInTime;
using (fp.BeginAbsoluteSequence(fadeInTime))
{

View File

@ -39,7 +39,7 @@ namespace osu.Game.Tests.NonVisual.Skinning
AddAssert("frame count correct", () => animation.FrameCount == frame_count);
assertPlaybackPosition(0);
AddStep("set start time to 1000", () => animationTimeReference.AnimationStartTime = 1000);
AddStep("set start time to 1000", () => animationTimeReference.AnimationStartTime.Value = 1000);
assertPlaybackPosition(-1000);
AddStep("set current time to 500", () => animationTimeReference.ManualClock.CurrentTime = 500);
@ -67,7 +67,8 @@ namespace osu.Game.Tests.NonVisual.Skinning
{
public ManualClock ManualClock { get; }
public IFrameBasedClock Clock { get; }
public double AnimationStartTime { get; set; }
public Bindable<double> AnimationStartTime { get; } = new BindableDouble();
IBindable<double> IAnimationTimeReference.AnimationStartTime => AnimationStartTime;
public TestAnimationTimeReference()
{

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics.OpenGL.Textures;
using osu.Framework.Timing;
@ -25,6 +26,6 @@ namespace osu.Game.Skinning
/// <summary>
/// The time which animations should be started from, relative to <see cref="Clock"/>.
/// </summary>
double AnimationStartTime { get; }
IBindable<double> AnimationStartTime { get; }
}
}

View File

@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Animations;
using osu.Framework.Graphics.OpenGL.Textures;
@ -70,6 +71,8 @@ namespace osu.Game.Skinning
[Resolved(canBeNull: true)]
private IAnimationTimeReference timeReference { get; set; }
private readonly Bindable<double> animationStartTime = new BindableDouble();
public SkinnableTextureAnimation(bool startAtCurrentTime = true)
: base(startAtCurrentTime)
{
@ -82,8 +85,18 @@ namespace osu.Game.Skinning
if (timeReference != null)
{
Clock = timeReference.Clock;
PlaybackPosition = timeReference.Clock.CurrentTime - timeReference.AnimationStartTime;
((IBindable<double>)animationStartTime).BindTo(timeReference.AnimationStartTime);
}
animationStartTime.BindValueChanged(_ => updatePlaybackPosition(), true);
}
private void updatePlaybackPosition()
{
if (timeReference == null)
return;
PlaybackPosition = timeReference.Clock.CurrentTime - timeReference.AnimationStartTime.Value;
}
}