mirror of
https://github.com/osukey/osukey.git
synced 2025-05-05 21:57:24 +09: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.Graphics.Textures;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Skinning;
|
||||||
|
|
||||||
namespace osu.Game.Storyboards.Drawables
|
namespace osu.Game.Storyboards.Drawables
|
||||||
{
|
{
|
||||||
@ -17,6 +18,12 @@ namespace osu.Game.Storyboards.Drawables
|
|||||||
{
|
{
|
||||||
public StoryboardSprite Sprite { get; }
|
public StoryboardSprite Sprite { get; }
|
||||||
|
|
||||||
|
private ISkinSource currentSkin;
|
||||||
|
|
||||||
|
private TextureStore storyboardTextureStore;
|
||||||
|
|
||||||
|
private string texturePath;
|
||||||
|
|
||||||
private bool flipH;
|
private bool flipH;
|
||||||
|
|
||||||
public bool FlipH
|
public bool FlipH
|
||||||
@ -114,14 +121,36 @@ namespace osu.Game.Storyboards.Drawables
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[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 (skin != null)
|
||||||
if (path == null)
|
{
|
||||||
return;
|
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);
|
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…
x
Reference in New Issue
Block a user