2020-04-30 03:27:02 +08:00
|
|
|
|
// 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 System;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio.Track;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Animations;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using osu.Game.Skinning;
|
2020-05-01 06:19:12 +08:00
|
|
|
|
using osuTK;
|
2020-04-30 03:27:02 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Taiko.UI
|
|
|
|
|
{
|
|
|
|
|
public sealed class TaikoMascotAnimation : BeatSyncedContainer
|
|
|
|
|
{
|
|
|
|
|
private readonly TextureAnimation textureAnimation;
|
|
|
|
|
|
|
|
|
|
private int currentFrame;
|
|
|
|
|
|
2020-05-14 08:44:21 +08:00
|
|
|
|
public double DisplayTime;
|
|
|
|
|
|
2020-04-30 03:27:02 +08:00
|
|
|
|
public TaikoMascotAnimation(TaikoMascotAnimationState state)
|
|
|
|
|
{
|
|
|
|
|
InternalChild = textureAnimation = createTextureAnimation(state).With(animation =>
|
|
|
|
|
{
|
|
|
|
|
animation.Origin = animation.Anchor = Anchor.BottomLeft;
|
2020-05-13 02:26:11 +08:00
|
|
|
|
animation.Scale = new Vector2(0.51f); // close enough to stable
|
2020-04-30 03:27:02 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
Origin = Anchor = Anchor.BottomLeft;
|
2020-05-01 04:51:22 +08:00
|
|
|
|
|
|
|
|
|
// needs to be always present to prevent the animation clock consuming time spent when not present.
|
2020-04-30 06:14:27 +08:00
|
|
|
|
AlwaysPresent = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Completed => !textureAnimation.IsPlaying || textureAnimation.PlaybackPosition >= textureAnimation.Duration;
|
|
|
|
|
|
|
|
|
|
public override void Show()
|
|
|
|
|
{
|
|
|
|
|
base.Show();
|
2020-05-14 08:44:21 +08:00
|
|
|
|
DisplayTime = Time.Current;
|
2020-04-30 06:14:27 +08:00
|
|
|
|
textureAnimation.Seek(0);
|
2020-04-30 03:27:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-23 12:49:18 +08:00
|
|
|
|
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, ChannelAmplitudes amplitudes)
|
2020-04-30 03:27:02 +08:00
|
|
|
|
{
|
|
|
|
|
// assume that if the animation is playing on its own, it's independent from the beat and doesn't need to be touched.
|
|
|
|
|
if (textureAnimation.FrameCount == 0 || textureAnimation.IsPlaying)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
textureAnimation.GotoFrame(currentFrame);
|
|
|
|
|
currentFrame = (currentFrame + 1) % textureAnimation.FrameCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static TextureAnimation createTextureAnimation(TaikoMascotAnimationState state)
|
|
|
|
|
{
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case TaikoMascotAnimationState.Clear:
|
|
|
|
|
return new ClearMascotTextureAnimation();
|
|
|
|
|
|
|
|
|
|
case TaikoMascotAnimationState.Idle:
|
|
|
|
|
case TaikoMascotAnimationState.Kiai:
|
|
|
|
|
case TaikoMascotAnimationState.Fail:
|
|
|
|
|
return new ManualMascotTextureAnimation(state);
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(state), $"Mascot animations for state {state} are not supported");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class ManualMascotTextureAnimation : TextureAnimation
|
|
|
|
|
{
|
|
|
|
|
private readonly TaikoMascotAnimationState state;
|
|
|
|
|
|
|
|
|
|
public ManualMascotTextureAnimation(TaikoMascotAnimationState state)
|
|
|
|
|
{
|
|
|
|
|
this.state = state;
|
|
|
|
|
|
|
|
|
|
IsPlaying = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-06-07 23:42:34 +08:00
|
|
|
|
private void load(ISkinSource source)
|
2020-04-30 03:27:02 +08:00
|
|
|
|
{
|
2022-11-03 10:28:39 +08:00
|
|
|
|
ISkin? skin = source.FindProvider(s => getAnimationFrame(s, state, 0) != null);
|
2021-06-07 23:42:34 +08:00
|
|
|
|
|
|
|
|
|
if (skin == null) return;
|
|
|
|
|
|
2020-04-30 03:27:02 +08:00
|
|
|
|
for (int frameIndex = 0; true; frameIndex++)
|
|
|
|
|
{
|
|
|
|
|
var texture = getAnimationFrame(skin, state, frameIndex);
|
|
|
|
|
|
|
|
|
|
if (texture == null)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
AddFrame(texture);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class ClearMascotTextureAnimation : TextureAnimation
|
|
|
|
|
{
|
|
|
|
|
private const float clear_animation_speed = 1000 / 10f;
|
|
|
|
|
|
|
|
|
|
private static readonly int[] clear_animation_sequence = { 0, 1, 2, 3, 4, 5, 6, 5, 6, 5, 4, 3, 2, 1, 0 };
|
|
|
|
|
|
|
|
|
|
public ClearMascotTextureAnimation()
|
|
|
|
|
{
|
|
|
|
|
DefaultFrameLength = clear_animation_speed;
|
2020-04-30 06:14:27 +08:00
|
|
|
|
Loop = false;
|
2020-04-30 03:27:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-06-07 23:42:34 +08:00
|
|
|
|
private void load(ISkinSource source)
|
2020-04-30 03:27:02 +08:00
|
|
|
|
{
|
2022-11-02 16:07:19 +08:00
|
|
|
|
ISkin? skin = source.FindProvider(s => getAnimationFrame(s, TaikoMascotAnimationState.Clear, 0) != null);
|
2021-06-07 23:42:34 +08:00
|
|
|
|
|
|
|
|
|
if (skin == null) return;
|
|
|
|
|
|
2021-10-27 12:04:41 +08:00
|
|
|
|
foreach (int frameIndex in clear_animation_sequence)
|
2020-04-30 03:27:02 +08:00
|
|
|
|
{
|
|
|
|
|
var texture = getAnimationFrame(skin, TaikoMascotAnimationState.Clear, frameIndex);
|
|
|
|
|
|
|
|
|
|
if (texture == null)
|
2020-04-30 03:52:09 +08:00
|
|
|
|
// as per https://osu.ppy.sh/help/wiki/Skinning/osu!taiko#pippidon
|
|
|
|
|
break;
|
2020-04-30 03:27:02 +08:00
|
|
|
|
|
|
|
|
|
AddFrame(texture);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 16:07:19 +08:00
|
|
|
|
private static Texture? getAnimationFrame(ISkin skin, TaikoMascotAnimationState state, int frameIndex)
|
2020-07-25 18:03:54 +08:00
|
|
|
|
{
|
2022-06-20 20:39:47 +08:00
|
|
|
|
var texture = skin.GetTexture($"pippidon{state.ToString().ToLowerInvariant()}{frameIndex}");
|
2020-07-25 18:03:54 +08:00
|
|
|
|
|
|
|
|
|
if (frameIndex == 0 && texture == null)
|
2022-06-20 20:39:47 +08:00
|
|
|
|
texture = skin.GetTexture($"pippidon{state.ToString().ToLowerInvariant()}");
|
2020-07-25 18:03:54 +08:00
|
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
|
}
|
2020-04-30 03:27:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|