mirror of
https://github.com/ppy/osu
synced 2024-12-14 02:46:27 +00:00
Allow storyboard animations to load textures from skins
This commit is contained in:
parent
cf76d77762
commit
f41fc71e42
@ -2,6 +2,8 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using osuTK;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -10,13 +12,22 @@ using osu.Framework.Graphics.Animations;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Skinning;
|
||||
|
||||
namespace osu.Game.Storyboards.Drawables
|
||||
{
|
||||
public class DrawableStoryboardAnimation : TextureAnimation, IFlippable, IVectorScalable
|
||||
public class DrawableStoryboardAnimation : SkinReloadableDrawable, IFlippable, IVectorScalable
|
||||
{
|
||||
public StoryboardAnimation Animation { get; }
|
||||
|
||||
private TextureAnimation drawableTextureAnimation;
|
||||
|
||||
[Resolved]
|
||||
private TextureStore storyboardTextureStore { get; set; }
|
||||
|
||||
private readonly List<string> texturePathsRaw = new List<string>();
|
||||
private readonly List<string> texturePaths = new List<string>();
|
||||
|
||||
private bool flipH;
|
||||
|
||||
public bool FlipH
|
||||
@ -108,28 +119,48 @@ namespace osu.Game.Storyboards.Drawables
|
||||
Animation = animation;
|
||||
Origin = animation.Origin;
|
||||
Position = animation.InitialPosition;
|
||||
Loop = animation.LoopType == AnimationLoopType.LoopForever;
|
||||
|
||||
LifetimeStart = animation.StartTime;
|
||||
LifetimeEnd = animation.EndTime;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(IBindable<WorkingBeatmap> beatmap, TextureStore textureStore)
|
||||
private void load(IBindable<WorkingBeatmap> beatmap)
|
||||
{
|
||||
InternalChild = drawableTextureAnimation = new TextureAnimation
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Loop = Animation.LoopType == AnimationLoopType.LoopForever
|
||||
};
|
||||
|
||||
for (var frame = 0; frame < Animation.FrameCount; frame++)
|
||||
{
|
||||
var framePath = Animation.Path.Replace(".", frame + ".");
|
||||
texturePathsRaw.Add(Path.GetFileNameWithoutExtension(framePath));
|
||||
|
||||
var path = beatmap.Value.BeatmapSetInfo.Files.Find(f => f.Filename.Equals(framePath, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
|
||||
if (path == null)
|
||||
continue;
|
||||
|
||||
var texture = textureStore.Get(path);
|
||||
AddFrame(texture, Animation.FrameDelay);
|
||||
texturePaths.Add(path);
|
||||
}
|
||||
|
||||
Animation.ApplyTransforms(this);
|
||||
}
|
||||
|
||||
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
|
||||
{
|
||||
base.SkinChanged(skin, allowFallback);
|
||||
|
||||
drawableTextureAnimation.ClearFrames();
|
||||
|
||||
for (var frame = 0; frame < Animation.FrameCount; frame++)
|
||||
{
|
||||
var texture = skin?.GetTexture(texturePathsRaw[frame]) ?? storyboardTextureStore?.Get(texturePaths[frame]);
|
||||
|
||||
if (texture == null)
|
||||
continue;
|
||||
|
||||
drawableTextureAnimation.AddFrame(texture, Animation.FrameDelay);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user