From 80c814008f32b348d0cb6322ca4bb2f89607c440 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 9 Aug 2024 00:19:36 +0900 Subject: [PATCH] Update in line with new changes --- .../Legacy/CatchLegacySkinTransformer.cs | 3 +- .../Argon/ManiaArgonSkinTransformer.cs | 52 ++++++++-------- .../Legacy/LegacyManiaComboCounter.cs | 3 +- .../Legacy/ManiaLegacySkinTransformer.cs | 50 ++++++++-------- .../Legacy/OsuLegacySkinTransformer.cs | 59 ++++++++++--------- .../Visual/Gameplay/TestSceneSkinEditor.cs | 2 +- osu.Game/Skinning/LegacySkin.cs | 17 ++++-- 7 files changed, 97 insertions(+), 89 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Skinning/Legacy/CatchLegacySkinTransformer.cs b/osu.Game.Rulesets.Catch/Skinning/Legacy/CatchLegacySkinTransformer.cs index 44fc3ecc0747..df8c04638d5c 100644 --- a/osu.Game.Rulesets.Catch/Skinning/Legacy/CatchLegacySkinTransformer.cs +++ b/osu.Game.Rulesets.Catch/Skinning/Legacy/CatchLegacySkinTransformer.cs @@ -4,7 +4,6 @@ using System.Linq; using osu.Framework.Bindables; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; using osu.Game.Skinning; using osuTK; using osuTK.Graphics; @@ -37,7 +36,7 @@ public CatchLegacySkinTransformer(ISkin skin) // Modifications for global components. if (containerLookup.Ruleset == null) - return base.GetDrawableComponent(lookup) as Container; + return base.GetDrawableComponent(lookup); // Skin has configuration. if (base.GetDrawableComponent(lookup) is UserConfiguredLayoutContainer d) diff --git a/osu.Game.Rulesets.Mania/Skinning/Argon/ManiaArgonSkinTransformer.cs b/osu.Game.Rulesets.Mania/Skinning/Argon/ManiaArgonSkinTransformer.cs index b0a6086f2a96..f541cea0f587 100644 --- a/osu.Game.Rulesets.Mania/Skinning/Argon/ManiaArgonSkinTransformer.cs +++ b/osu.Game.Rulesets.Mania/Skinning/Argon/ManiaArgonSkinTransformer.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Diagnostics; using System.Linq; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -15,7 +14,7 @@ namespace osu.Game.Rulesets.Mania.Skinning.Argon { - public class ManiaArgonSkinTransformer : ArgonSkinTransformer + public class ManiaArgonSkinTransformer : SkinTransformer { private readonly ManiaBeatmap beatmap; @@ -30,32 +29,31 @@ public ManiaArgonSkinTransformer(ISkin skin, IBeatmap beatmap) switch (lookup) { case SkinComponentsContainerLookup containerLookup: - switch (containerLookup.Target) - { - case SkinComponentsContainerLookup.TargetArea.MainHUDComponents when containerLookup.Ruleset != null: - Debug.Assert(containerLookup.Ruleset.ShortName == ManiaRuleset.SHORT_NAME); - - var rulesetHUDComponents = Skin.GetDrawableComponent(lookup); - - rulesetHUDComponents ??= new DefaultSkinComponentsContainer(container => - { - var combo = container.ChildrenOfType().FirstOrDefault(); - - if (combo != null) - { - combo.Anchor = Anchor.TopCentre; - combo.Origin = Anchor.Centre; - combo.Y = 200; - } - }) - { - new ArgonManiaComboCounter(), - }; - - return rulesetHUDComponents; - } + if (containerLookup.Target != SkinComponentsContainerLookup.TargetArea.MainHUDComponents) + return base.GetDrawableComponent(lookup); - break; + // Only handle per ruleset defaults here. + if (containerLookup.Ruleset == null) + return base.GetDrawableComponent(lookup); + + // Skin has configuration. + if (base.GetDrawableComponent(lookup) is UserConfiguredLayoutContainer d) + return d; + + return new DefaultSkinComponentsContainer(container => + { + var combo = container.ChildrenOfType().FirstOrDefault(); + + if (combo != null) + { + combo.Anchor = Anchor.TopCentre; + combo.Origin = Anchor.Centre; + combo.Y = 200; + } + }) + { + new ArgonManiaComboCounter(), + }; case GameplaySkinComponentLookup resultComponent: // This should eventually be moved to a skin setting, when supported. diff --git a/osu.Game.Rulesets.Mania/Skinning/Legacy/LegacyManiaComboCounter.cs b/osu.Game.Rulesets.Mania/Skinning/Legacy/LegacyManiaComboCounter.cs index 00619834c8c5..a51a50c60407 100644 --- a/osu.Game.Rulesets.Mania/Skinning/Legacy/LegacyManiaComboCounter.cs +++ b/osu.Game.Rulesets.Mania/Skinning/Legacy/LegacyManiaComboCounter.cs @@ -3,7 +3,6 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; -using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Graphics; using osu.Game.Rulesets.UI.Scrolling; using osu.Game.Skinning; @@ -49,7 +48,7 @@ protected override void LoadComplete() private void updateAnchor() { // if the anchor isn't a vertical center, set top or bottom anchor based on scroll direction - if (!Anchor.HasFlagFast(Anchor.y1)) + if (!Anchor.HasFlag(Anchor.y1)) { Anchor &= ~(Anchor.y0 | Anchor.y2); Anchor |= direction.Value == ScrollingDirection.Up ? Anchor.y2 : Anchor.y0; diff --git a/osu.Game.Rulesets.Mania/Skinning/Legacy/ManiaLegacySkinTransformer.cs b/osu.Game.Rulesets.Mania/Skinning/Legacy/ManiaLegacySkinTransformer.cs index c539c239bdbd..6ac6f6ed1898 100644 --- a/osu.Game.Rulesets.Mania/Skinning/Legacy/ManiaLegacySkinTransformer.cs +++ b/osu.Game.Rulesets.Mania/Skinning/Legacy/ManiaLegacySkinTransformer.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using osu.Framework.Audio.Sample; using osu.Framework.Bindables; @@ -82,32 +81,31 @@ public override Drawable GetDrawableComponent(ISkinComponentLookup lookup) switch (lookup) { case SkinComponentsContainerLookup containerLookup: - switch (containerLookup.Target) - { - case SkinComponentsContainerLookup.TargetArea.MainHUDComponents when containerLookup.Ruleset != null: - Debug.Assert(containerLookup.Ruleset.ShortName == ManiaRuleset.SHORT_NAME); - - var rulesetHUDComponents = Skin.GetDrawableComponent(lookup); - - rulesetHUDComponents ??= new DefaultSkinComponentsContainer(container => - { - var combo = container.ChildrenOfType().FirstOrDefault(); - - if (combo != null) - { - combo.Anchor = Anchor.TopCentre; - combo.Origin = Anchor.Centre; - combo.Y = this.GetManiaSkinConfig(LegacyManiaSkinConfigurationLookups.ComboPosition)?.Value ?? 0; - } - }) - { - new LegacyManiaComboCounter(), - }; - - return rulesetHUDComponents; - } + if (containerLookup.Target != SkinComponentsContainerLookup.TargetArea.MainHUDComponents) + return base.GetDrawableComponent(lookup); + + // Modifications for global components. + if (containerLookup.Ruleset == null) + return base.GetDrawableComponent(lookup); - break; + // Skin has configuration. + if (base.GetDrawableComponent(lookup) is UserConfiguredLayoutContainer d) + return d; + + return new DefaultSkinComponentsContainer(container => + { + var combo = container.ChildrenOfType().FirstOrDefault(); + + if (combo != null) + { + combo.Anchor = Anchor.TopCentre; + combo.Origin = Anchor.Centre; + combo.Y = this.GetManiaSkinConfig(LegacyManiaSkinConfigurationLookups.ComboPosition)?.Value ?? 0; + } + }) + { + new LegacyManiaComboCounter(), + }; case GameplaySkinComponentLookup resultComponent: return getResult(resultComponent.Component); diff --git a/osu.Game.Rulesets.Osu/Skinning/Legacy/OsuLegacySkinTransformer.cs b/osu.Game.Rulesets.Osu/Skinning/Legacy/OsuLegacySkinTransformer.cs index 9a8eaa7d7d31..c2381fff88e6 100644 --- a/osu.Game.Rulesets.Osu/Skinning/Legacy/OsuLegacySkinTransformer.cs +++ b/osu.Game.Rulesets.Osu/Skinning/Legacy/OsuLegacySkinTransformer.cs @@ -45,6 +45,9 @@ public OsuLegacySkinTransformer(ISkin skin) switch (lookup) { case SkinComponentsContainerLookup containerLookup: + if (containerLookup.Target != SkinComponentsContainerLookup.TargetArea.MainHUDComponents) + return base.GetDrawableComponent(lookup); + // Only handle per ruleset defaults here. if (containerLookup.Ruleset == null) return base.GetDrawableComponent(lookup); @@ -53,34 +56,36 @@ public OsuLegacySkinTransformer(ISkin skin) if (base.GetDrawableComponent(lookup) is UserConfiguredLayoutContainer d) return d; - // Our own ruleset components default. - switch (containerLookup.Target) + return new DefaultSkinComponentsContainer(container => { - case SkinComponentsContainerLookup.TargetArea.MainHUDComponents: - return new DefaultSkinComponentsContainer(container => - { - var keyCounter = container.OfType().FirstOrDefault(); - - if (keyCounter != null) - { - // set the anchor to top right so that it won't squash to the return button to the top - keyCounter.Anchor = Anchor.CentreRight; - keyCounter.Origin = Anchor.CentreRight; - keyCounter.X = 0; - // 340px is the default height inherit from stable - keyCounter.Y = container.ToLocalSpace(new Vector2(0, container.ScreenSpaceDrawQuad.Centre.Y - 340f)).Y; - } - }) - { - Children = new Drawable[] - { - new LegacyComboCounter(), - new LegacyKeyCounterDisplay(), - } - }; - } - - return null; + var keyCounter = container.OfType().FirstOrDefault(); + + if (keyCounter != null) + { + // set the anchor to top right so that it won't squash to the return button to the top + keyCounter.Anchor = Anchor.CentreRight; + keyCounter.Origin = Anchor.CentreRight; + keyCounter.X = 0; + // 340px is the default height inherit from stable + keyCounter.Y = container.ToLocalSpace(new Vector2(0, container.ScreenSpaceDrawQuad.Centre.Y - 340f)).Y; + } + + var combo = container.OfType().FirstOrDefault(); + + if (combo != null) + { + combo.Anchor = Anchor.BottomLeft; + combo.Origin = Anchor.BottomLeft; + combo.Scale = new Vector2(1.28f); + } + }) + { + Children = new Drawable[] + { + new LegacyDefaultComboCounter(), + new LegacyKeyCounterDisplay(), + } + }; case OsuSkinComponentLookup osuComponent: switch (osuComponent.Component) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSkinEditor.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSkinEditor.cs index f44daa1ecbb5..7466442674cf 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSkinEditor.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSkinEditor.cs @@ -443,7 +443,7 @@ public void TestMigrationLegacy() AddAssert("no combo in global target", () => !globalHUDTarget.Components.OfType().Any()); AddAssert("combo placed in ruleset target", () => rulesetHUDTarget.Components.OfType().Count() == 1); - AddStep("add combo to global target", () => globalHUDTarget.Add(new LegacyComboCounter + AddStep("add combo to global target", () => globalHUDTarget.Add(new LegacyDefaultComboCounter { Anchor = Anchor.Centre, Origin = Anchor.Centre, diff --git a/osu.Game/Skinning/LegacySkin.cs b/osu.Game/Skinning/LegacySkin.cs index 2da09839e98d..8f6e634dd6c7 100644 --- a/osu.Game/Skinning/LegacySkin.cs +++ b/osu.Game/Skinning/LegacySkin.cs @@ -13,7 +13,6 @@ using osu.Framework.Bindables; using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Textures; using osu.Framework.IO.Stores; using osu.Game.Audio; @@ -24,6 +23,7 @@ using osu.Game.Rulesets.Scoring; using osu.Game.Screens.Play.HUD; using osu.Game.Screens.Play.HUD.HitErrorMeters; +using osuTK; using osuTK.Graphics; namespace osu.Game.Skinning @@ -367,10 +367,19 @@ protected override void ParseConfigurationStream(Stream stream) case SkinComponentsContainerLookup.TargetArea.MainHUDComponents: if (containerLookup.Ruleset != null) { - return new Container + return new DefaultSkinComponentsContainer(container => { - RelativeSizeAxes = Axes.Both, - Child = new LegacyComboCounter(), + var combo = container.OfType().FirstOrDefault(); + + if (combo != null) + { + combo.Anchor = Anchor.BottomLeft; + combo.Origin = Anchor.BottomLeft; + combo.Scale = new Vector2(1.28f); + } + }) + { + new LegacyDefaultComboCounter() }; }