Use separate classes for old and new catcher legacy skin element

- Fix catcher texture animation is reset for legacy old catcher skin
This commit is contained in:
ekrctb 2021-06-08 21:58:39 +09:00
parent 0192549d6c
commit 109a366722
3 changed files with 56 additions and 17 deletions

View File

@ -66,9 +66,14 @@ public override Drawable GetDrawableComponent(ISkinComponent component)
return null;
case CatchSkinComponents.Catcher:
if (this.GetAnimation(@"fruit-ryuuta", true, true) != null ||
this.GetAnimation(@"fruit-catcher-idle", true, true) != null)
return new LegacyCatcher();
// New elements will be ignored when the old element exists.
if (GetTexture(@"fruit-ryuuta") != null ||
GetTexture(@"fruit-ryuuta-0") != null)
return new LegacyCatcherOld();
if (GetTexture(@"fruit-catcher-idle") != null ||
GetTexture(@"fruit-catcher-idle-0") != null)
return new LegacyCatcherNew();
return null;

View File

@ -1,7 +1,9 @@
// 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 System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -15,7 +17,7 @@
namespace osu.Game.Rulesets.Catch.Skinning.Legacy
{
public class LegacyCatcher : CompositeDrawable, ICatcherPiece
public class LegacyCatcherNew : CompositeDrawable, ICatcherPiece
{
public Bindable<CatcherAnimationState> CurrentState { get; } = new Bindable<CatcherAnimationState>();
@ -25,7 +27,7 @@ public class LegacyCatcher : CompositeDrawable, ICatcherPiece
private Drawable currentDrawable;
public LegacyCatcher()
public LegacyCatcherNew()
{
RelativeSizeAxes = Axes.Both;
}
@ -35,27 +37,22 @@ private void load(ISkinSource skin, Bindable<CatcherAnimationState> currentState
{
CurrentState.BindTo(currentState);
AddRangeInternal(new[]
{
drawables[CatcherAnimationState.Idle] = getDrawableFor(@"fruit-catcher-idle"),
drawables[CatcherAnimationState.Fail] = getDrawableFor(@"fruit-catcher-fail"),
drawables[CatcherAnimationState.Kiai] = getDrawableFor(@"fruit-catcher-kiai"),
});
currentDrawable = drawables[CatcherAnimationState.Idle];
foreach (var d in drawables.Values)
foreach (var state in Enum.GetValues(typeof(CatcherAnimationState)).Cast<CatcherAnimationState>())
{
var d = getDrawableFor(state);
d.Anchor = Anchor.TopCentre;
d.Origin = Anchor.TopCentre;
d.RelativeSizeAxes = Axes.Both;
d.Size = Vector2.One;
d.FillMode = FillMode.Fit;
d.Alpha = 0;
AddInternal(drawables[state] = d);
}
Drawable getDrawableFor(string name) =>
skin.GetAnimation(name, true, true, true) ??
skin.GetAnimation(@"fruit-ryuuta", true, true, true) ??
currentDrawable = drawables[CatcherAnimationState.Idle];
Drawable getDrawableFor(CatcherAnimationState state) =>
skin.GetAnimation(@$"fruit-catcher-{state.ToString().ToLowerInvariant()}", true, true, true) ??
skin.GetAnimation(@"fruit-catcher-idle", true, true, true);
}

View File

@ -0,0 +1,37 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Animations;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Rulesets.Catch.Skinning.Legacy
{
public class LegacyCatcherOld : CompositeDrawable, ICatcherPiece
{
public Texture CurrentTexture => (InternalChild as TextureAnimation)?.CurrentFrame ?? (InternalChild as Sprite)?.Texture;
public LegacyCatcherOld()
{
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load(ISkinSource skin)
{
InternalChild = skin.GetAnimation(@"fruit-ryuuta", true, true, true).With(d =>
{
d.Anchor = Anchor.TopCentre;
d.Origin = Anchor.TopCentre;
d.RelativeSizeAxes = Axes.Both;
d.Size = Vector2.One;
d.FillMode = FillMode.Fit;
});
}
}
}