From d44293990d18425fd4e2e12525c11d14835ec4e7 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 29 Apr 2023 16:30:54 +0800 Subject: [PATCH 1/3] Should add the setting button as default if not in the ruleset HUD. This rules should apply to all skin transformers. --- .../Default/KaraokeDefaultSkinTransformer.cs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/osu.Game.Rulesets.Karaoke/Skinning/Default/KaraokeDefaultSkinTransformer.cs b/osu.Game.Rulesets.Karaoke/Skinning/Default/KaraokeDefaultSkinTransformer.cs index a7cda0dd1..608b58c16 100644 --- a/osu.Game.Rulesets.Karaoke/Skinning/Default/KaraokeDefaultSkinTransformer.cs +++ b/osu.Game.Rulesets.Karaoke/Skinning/Default/KaraokeDefaultSkinTransformer.cs @@ -1,8 +1,12 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. +using System.Linq; using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; +using osu.Game.Rulesets.Karaoke.UI.HUD; using osu.Game.Skinning; namespace osu.Game.Rulesets.Karaoke.Skinning.Default @@ -19,5 +23,50 @@ public KaraokeDefaultSkinTransformer(ISkin skin, IBeatmap beatmap) public override IBindable? GetConfig(TLookup lookup) => karaokeSkin.GetConfig(lookup); + + public override Drawable? GetDrawableComponent(ISkinComponentLookup lookup) + { + switch (lookup) + { + case SkinComponentsContainerLookup containerLookup: + // Only handle ruleset level defaults for now. + if (containerLookup.Ruleset == null) + return base.GetDrawableComponent(lookup); + + switch (containerLookup.Target) + { + case SkinComponentsContainerLookup.TargetArea.MainHUDComponents: + // see the fall-back strategy in the SkinManager.AllSources. + // will receive the: + // 1. Legacy beatmap skin. + // 2. default skin(e.g. argon skin) -> container will not be null only if skin is edited. + // 3. triangle skin + + // component will not be null only if skin is edited. + var component = base.GetDrawableComponent(lookup) as Container; + + // todo: technically can return non-null container if current skin is triangle skin. + // but have no idea why still not showing the setting button. + if (component != null && !component.Children.OfType().Any()) + { + // should add the setting button if not in the ruleset hud. + component.Add(new SettingButtonsDisplay + { + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + }); + } + + return component; + + case SkinComponentsContainerLookup.TargetArea.SongSelect: + default: + return base.GetDrawableComponent(lookup); + } + + default: + return base.GetDrawableComponent(lookup); + } + } } } From e43b2d0a70c9ea94ef3a89f02acd2f4f92c736ed Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 29 Apr 2023 16:31:32 +0800 Subject: [PATCH 2/3] Remove the logic in the legacy skin transformers. --- .../Legacy/KaraokeLegacySkinTransformer.cs | 34 ------------------- 1 file changed, 34 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs b/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs index 465ccad75..2b3108f55 100644 --- a/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs +++ b/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs @@ -6,10 +6,8 @@ using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Game.Beatmaps; -using osu.Game.Rulesets.Karaoke.UI.HUD; using osu.Game.Rulesets.Scoring; using osu.Game.Skinning; -using Container = osu.Framework.Graphics.Containers.Container; namespace osu.Game.Rulesets.Karaoke.Skinning.Legacy { @@ -31,22 +29,6 @@ public KaraokeLegacySkinTransformer(ISkin source, IBeatmap beatmap) { switch (lookup) { - case SkinComponentsContainerLookup targetComponent: - switch (targetComponent.Target) - { - case SkinComponentsContainerLookup.TargetArea.MainHUDComponents: - var components = base.GetDrawableComponent(lookup) as Container ?? getTargetComponentsContainerFromOtherPlace(); - components?.Add(new SettingButtonsDisplay - { - Anchor = Anchor.CentreRight, - Origin = Anchor.CentreRight, - }); - return components; - - default: - return base.GetDrawableComponent(lookup); - } - case GameplaySkinComponentLookup resultComponent: return getResult(resultComponent.Component); @@ -67,13 +49,6 @@ public KaraokeLegacySkinTransformer(ISkin source, IBeatmap beatmap) default: return base.GetDrawableComponent(lookup); } - - Container? getTargetComponentsContainerFromOtherPlace() => - Skin switch - { - LegacySkin legacySkin => new TempLegacySkin(legacySkin.SkinInfo.Value).GetDrawableComponent(lookup) as Container, - _ => throw new InvalidCastException() - }; } private Drawable? getResult(HitResult result) @@ -84,14 +59,5 @@ public KaraokeLegacySkinTransformer(ISkin source, IBeatmap beatmap) public override IBindable? GetConfig(TLookup lookup) => karaokeSkin.GetConfig(lookup); - - // it's a temp class for just getting SkinnableTarget.MainHUDComponents - private class TempLegacySkin : LegacySkin - { - public TempLegacySkin(SkinInfo skin) - : base(skin, null, null) - { - } - } } } From 431c8a05b92edb8264ccb31d3970105edc48ac82 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 29 Apr 2023 16:50:56 +0800 Subject: [PATCH 3/3] Legacy skin should inherit the default skin transformer for able to inherit the base logic. --- .../Skinning/Legacy/KaraokeClassicSkinTransformer.cs | 4 ++-- .../Skinning/Legacy/KaraokeLegacySkinTransformer.cs | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeClassicSkinTransformer.cs b/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeClassicSkinTransformer.cs index ba876fe50..3b271be56 100644 --- a/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeClassicSkinTransformer.cs +++ b/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeClassicSkinTransformer.cs @@ -8,8 +8,8 @@ namespace osu.Game.Rulesets.Karaoke.Skinning.Legacy { public class KaraokeClassicSkinTransformer : KaraokeLegacySkinTransformer { - public KaraokeClassicSkinTransformer(ISkin source, IBeatmap beatmap) - : base(source, beatmap) + public KaraokeClassicSkinTransformer(ISkin skin, IBeatmap beatmap) + : base(skin, beatmap) { } } diff --git a/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs b/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs index 2b3108f55..2d847e745 100644 --- a/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs +++ b/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs @@ -6,18 +6,24 @@ using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Game.Beatmaps; +using osu.Game.Rulesets.Karaoke.Skinning.Default; using osu.Game.Rulesets.Scoring; using osu.Game.Skinning; namespace osu.Game.Rulesets.Karaoke.Skinning.Legacy { - public class KaraokeLegacySkinTransformer : LegacySkinTransformer + /// + /// Not inherit the because: + /// 1. Karaoke ruleset does not have the legacy skin. + /// 2. There's not much logic in the + /// + public class KaraokeLegacySkinTransformer : KaraokeDefaultSkinTransformer { private readonly Lazy isLegacySkin; private readonly KaraokeBeatmapSkin karaokeSkin; - public KaraokeLegacySkinTransformer(ISkin source, IBeatmap beatmap) - : base(source) + public KaraokeLegacySkinTransformer(ISkin skin, IBeatmap beatmap) + : base(skin, beatmap) { // we should get config by default karaoke skin. // if has resource or texture, then try to get from legacy skin.