From 109a366722bb6f46a5d3304da7a6742faa988fb8 Mon Sep 17 00:00:00 2001 From: ekrctb Date: Tue, 8 Jun 2021 21:58:39 +0900 Subject: [PATCH] Use separate classes for old and new catcher legacy skin element - Fix catcher texture animation is reset for legacy old catcher skin --- .../Legacy/CatchLegacySkinTransformer.cs | 11 ++++-- .../{LegacyCatcher.cs => LegacyCatcherNew.cs} | 25 ++++++------- .../Skinning/Legacy/LegacyCatcherOld.cs | 37 +++++++++++++++++++ 3 files changed, 56 insertions(+), 17 deletions(-) rename osu.Game.Rulesets.Catch/Skinning/Legacy/{LegacyCatcher.cs => LegacyCatcherNew.cs} (75%) create mode 100644 osu.Game.Rulesets.Catch/Skinning/Legacy/LegacyCatcherOld.cs diff --git a/osu.Game.Rulesets.Catch/Skinning/Legacy/CatchLegacySkinTransformer.cs b/osu.Game.Rulesets.Catch/Skinning/Legacy/CatchLegacySkinTransformer.cs index 2713f17789..6a9a3c43a2 100644 --- a/osu.Game.Rulesets.Catch/Skinning/Legacy/CatchLegacySkinTransformer.cs +++ b/osu.Game.Rulesets.Catch/Skinning/Legacy/CatchLegacySkinTransformer.cs @@ -66,9 +66,14 @@ namespace osu.Game.Rulesets.Catch.Skinning.Legacy 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; diff --git a/osu.Game.Rulesets.Catch/Skinning/Legacy/LegacyCatcher.cs b/osu.Game.Rulesets.Catch/Skinning/Legacy/LegacyCatcherNew.cs similarity index 75% rename from osu.Game.Rulesets.Catch/Skinning/Legacy/LegacyCatcher.cs rename to osu.Game.Rulesets.Catch/Skinning/Legacy/LegacyCatcherNew.cs index 4bf5dd9dd8..4e662869c9 100644 --- a/osu.Game.Rulesets.Catch/Skinning/Legacy/LegacyCatcher.cs +++ b/osu.Game.Rulesets.Catch/Skinning/Legacy/LegacyCatcherNew.cs @@ -1,7 +1,9 @@ // Copyright (c) ppy Pty Ltd . 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 @@ using osuTK; namespace osu.Game.Rulesets.Catch.Skinning.Legacy { - public class LegacyCatcher : CompositeDrawable, ICatcherPiece + public class LegacyCatcherNew : CompositeDrawable, ICatcherPiece { public Bindable CurrentState { get; } = new Bindable(); @@ -25,7 +27,7 @@ namespace osu.Game.Rulesets.Catch.Skinning.Legacy private Drawable currentDrawable; - public LegacyCatcher() + public LegacyCatcherNew() { RelativeSizeAxes = Axes.Both; } @@ -35,27 +37,22 @@ namespace osu.Game.Rulesets.Catch.Skinning.Legacy { 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()) { + 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); } diff --git a/osu.Game.Rulesets.Catch/Skinning/Legacy/LegacyCatcherOld.cs b/osu.Game.Rulesets.Catch/Skinning/Legacy/LegacyCatcherOld.cs new file mode 100644 index 0000000000..c426856c27 --- /dev/null +++ b/osu.Game.Rulesets.Catch/Skinning/Legacy/LegacyCatcherOld.cs @@ -0,0 +1,37 @@ +// Copyright (c) ppy Pty Ltd . 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; + }); + } + } +}