mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 17:52:56 +08:00
Merge pull request #17238 from frenzibyte/storyboard-skinnable-sprite-size
Fix `SkinnableSprite`s in storyboards not autosizing to the textures
This commit is contained in:
commit
4037910cb3
@ -1,11 +1,13 @@
|
|||||||
// 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 System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Osu;
|
using osu.Game.Rulesets.Osu;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
@ -22,6 +24,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
[Cached]
|
[Cached]
|
||||||
private Storyboard storyboard { get; set; } = new Storyboard();
|
private Storyboard storyboard { get; set; } = new Storyboard();
|
||||||
|
|
||||||
|
private IEnumerable<DrawableStoryboardSprite> sprites => this.ChildrenOfType<DrawableStoryboardSprite>();
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestSkinSpriteDisallowedByDefault()
|
public void TestSkinSpriteDisallowedByDefault()
|
||||||
{
|
{
|
||||||
@ -41,9 +45,11 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
|
|
||||||
AddStep("allow skin lookup", () => storyboard.UseSkinSprites = true);
|
AddStep("allow skin lookup", () => storyboard.UseSkinSprites = true);
|
||||||
|
|
||||||
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.Centre, Vector2.Zero)));
|
AddStep("create sprites", () => SetContents(_ => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
|
||||||
|
|
||||||
assertSpritesFromSkin(true);
|
assertSpritesFromSkin(true);
|
||||||
|
|
||||||
|
AddAssert("skinnable sprite has correct size", () => sprites.Any(s => Precision.AlmostEquals(s.ChildrenOfType<SkinnableSprite>().Single().Size, new Vector2(128, 128))));
|
||||||
}
|
}
|
||||||
|
|
||||||
private DrawableStoryboardSprite createSprite(string lookupName, Anchor origin, Vector2 initialPosition)
|
private DrawableStoryboardSprite createSprite(string lookupName, Anchor origin, Vector2 initialPosition)
|
||||||
@ -57,7 +63,6 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
|
|
||||||
private void assertSpritesFromSkin(bool fromSkin) =>
|
private void assertSpritesFromSkin(bool fromSkin) =>
|
||||||
AddAssert($"sprites are {(fromSkin ? "from skin" : "from storyboard")}",
|
AddAssert($"sprites are {(fromSkin ? "from skin" : "from storyboard")}",
|
||||||
() => this.ChildrenOfType<DrawableStoryboardSprite>()
|
() => sprites.All(sprite => sprite.ChildrenOfType<SkinnableSprite>().Any() == fromSkin));
|
||||||
.All(sprite => sprite.ChildrenOfType<SkinnableSprite>().Any() == fromSkin));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,13 @@ namespace osu.Game.Storyboards
|
|||||||
drawable = new Sprite { Texture = textureStore.Get(storyboardPath) };
|
drawable = new Sprite { Texture = textureStore.Get(storyboardPath) };
|
||||||
// if the texture isn't available locally in the beatmap, some storyboards choose to source from the underlying skin lookup hierarchy.
|
// if the texture isn't available locally in the beatmap, some storyboards choose to source from the underlying skin lookup hierarchy.
|
||||||
else if (UseSkinSprites)
|
else if (UseSkinSprites)
|
||||||
drawable = new SkinnableSprite(path);
|
{
|
||||||
|
drawable = new SkinnableSprite(path)
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.None,
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return drawable;
|
return drawable;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user