mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Add support for changing animation start time after load
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
|
|||||||
fp.Alpha = 0;
|
fp.Alpha = 0;
|
||||||
fp.Scale = new Vector2(1.5f * end.Scale);
|
fp.Scale = new Vector2(1.5f * end.Scale);
|
||||||
|
|
||||||
fp.AnimationStartTime = fadeInTime;
|
fp.AnimationStartTime.Value = fadeInTime;
|
||||||
|
|
||||||
using (fp.BeginAbsoluteSequence(fadeInTime))
|
using (fp.BeginAbsoluteSequence(fadeInTime))
|
||||||
{
|
{
|
||||||
|
@ -39,7 +39,7 @@ namespace osu.Game.Tests.NonVisual.Skinning
|
|||||||
AddAssert("frame count correct", () => animation.FrameCount == frame_count);
|
AddAssert("frame count correct", () => animation.FrameCount == frame_count);
|
||||||
assertPlaybackPosition(0);
|
assertPlaybackPosition(0);
|
||||||
|
|
||||||
AddStep("set start time to 1000", () => animationTimeReference.AnimationStartTime = 1000);
|
AddStep("set start time to 1000", () => animationTimeReference.AnimationStartTime.Value = 1000);
|
||||||
assertPlaybackPosition(-1000);
|
assertPlaybackPosition(-1000);
|
||||||
|
|
||||||
AddStep("set current time to 500", () => animationTimeReference.ManualClock.CurrentTime = 500);
|
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 ManualClock ManualClock { get; }
|
||||||
public IFrameBasedClock Clock { get; }
|
public IFrameBasedClock Clock { get; }
|
||||||
public double AnimationStartTime { get; set; }
|
public Bindable<double> AnimationStartTime { get; } = new BindableDouble();
|
||||||
|
IBindable<double> IAnimationTimeReference.AnimationStartTime => AnimationStartTime;
|
||||||
|
|
||||||
public TestAnimationTimeReference()
|
public TestAnimationTimeReference()
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics.OpenGL.Textures;
|
using osu.Framework.Graphics.OpenGL.Textures;
|
||||||
using osu.Framework.Timing;
|
using osu.Framework.Timing;
|
||||||
|
|
||||||
@ -25,6 +26,6 @@ namespace osu.Game.Skinning
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The time which animations should be started from, relative to <see cref="Clock"/>.
|
/// The time which animations should be started from, relative to <see cref="Clock"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
double AnimationStartTime { get; }
|
IBindable<double> AnimationStartTime { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Animations;
|
using osu.Framework.Graphics.Animations;
|
||||||
using osu.Framework.Graphics.OpenGL.Textures;
|
using osu.Framework.Graphics.OpenGL.Textures;
|
||||||
@ -70,6 +71,8 @@ namespace osu.Game.Skinning
|
|||||||
[Resolved(canBeNull: true)]
|
[Resolved(canBeNull: true)]
|
||||||
private IAnimationTimeReference timeReference { get; set; }
|
private IAnimationTimeReference timeReference { get; set; }
|
||||||
|
|
||||||
|
private readonly Bindable<double> animationStartTime = new BindableDouble();
|
||||||
|
|
||||||
public SkinnableTextureAnimation(bool startAtCurrentTime = true)
|
public SkinnableTextureAnimation(bool startAtCurrentTime = true)
|
||||||
: base(startAtCurrentTime)
|
: base(startAtCurrentTime)
|
||||||
{
|
{
|
||||||
@ -82,8 +85,18 @@ namespace osu.Game.Skinning
|
|||||||
if (timeReference != null)
|
if (timeReference != null)
|
||||||
{
|
{
|
||||||
Clock = timeReference.Clock;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user