1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-28 20:47:22 +08:00

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 @@ namespace osu.Game.Rulesets.Catch.Skinning.Legacy
return null; return null;
case CatchSkinComponents.Catcher: case CatchSkinComponents.Catcher:
if (this.GetAnimation(@"fruit-ryuuta", true, true) != null || // New elements will be ignored when the old element exists.
this.GetAnimation(@"fruit-catcher-idle", true, true) != null) if (GetTexture(@"fruit-ryuuta") != null ||
return new LegacyCatcher(); 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; return null;

View File

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