mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 08:32:57 +08:00
Allow storyboard sprites to load textures from skins
This commit is contained in:
parent
c0cfd136dd
commit
19a0eaade9
@ -10,6 +10,7 @@ using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Skinning;
|
||||
|
||||
namespace osu.Game.Storyboards.Drawables
|
||||
{
|
||||
@ -17,6 +18,12 @@ namespace osu.Game.Storyboards.Drawables
|
||||
{
|
||||
public StoryboardSprite Sprite { get; }
|
||||
|
||||
private ISkinSource currentSkin;
|
||||
|
||||
private TextureStore storyboardTextureStore;
|
||||
|
||||
private string texturePath;
|
||||
|
||||
private bool flipH;
|
||||
|
||||
public bool FlipH
|
||||
@ -114,14 +121,36 @@ namespace osu.Game.Storyboards.Drawables
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(IBindable<WorkingBeatmap> beatmap, TextureStore textureStore)
|
||||
private void load(ISkinSource skin, IBindable<WorkingBeatmap> beatmap, TextureStore textureStore)
|
||||
{
|
||||
var path = beatmap.Value.BeatmapSetInfo?.Files?.Find(f => f.Filename.Equals(Sprite.Path, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
|
||||
if (path == null)
|
||||
return;
|
||||
if (skin != null)
|
||||
{
|
||||
currentSkin = skin;
|
||||
skin.SourceChanged += onChange;
|
||||
}
|
||||
|
||||
storyboardTextureStore = textureStore;
|
||||
|
||||
texturePath = beatmap.Value.BeatmapSetInfo?.Files?.Find(f => f.Filename.Equals(Sprite.Path, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
|
||||
|
||||
skinChanged();
|
||||
|
||||
Texture = textureStore.Get(path);
|
||||
Sprite.ApplyTransforms(this);
|
||||
}
|
||||
|
||||
private void onChange() =>
|
||||
// schedule required to avoid calls after disposed.
|
||||
// note that this has the side-effect of components only performing a possible texture change when they are alive.
|
||||
Scheduler.AddOnce(skinChanged);
|
||||
|
||||
private void skinChanged()
|
||||
{
|
||||
var newTexture = currentSkin?.GetTexture(Sprite.Path) ?? storyboardTextureStore?.Get(texturePath);
|
||||
|
||||
if (Texture == newTexture) return;
|
||||
|
||||
Size = Vector2.Zero; // Sprite size needs to be recalculated (e.g. aspect ratio of combo number textures may differ between skins)
|
||||
Texture = newTexture;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user