Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move combo counter to ruleset-specific HUD components container #26249

Merged
merged 13 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Linq;
using NUnit.Framework;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics.Containers;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Skinning;
Expand All @@ -19,7 +18,7 @@ public partial class TestSceneCatchPlayerLegacySkin : LegacySkinPlayerTestScene
protected override Ruleset CreatePlayerRuleset() => new CatchRuleset();

[Test]
public void TestLegacyHUDComboCounterHidden([Values] bool withModifiedSkin)
public void TestLegacyHUDComboCounterNotExistent([Values] bool withModifiedSkin)
{
if (withModifiedSkin)
{
Expand All @@ -29,10 +28,7 @@ public void TestLegacyHUDComboCounterHidden([Values] bool withModifiedSkin)
CreateTest();
}

AddAssert("legacy HUD combo counter hidden", () =>
{
return Player.ChildrenOfType<LegacyComboCounter>().All(c => c.ChildrenOfType<Container>().Single().Alpha == 0f);
});
AddAssert("legacy HUD combo counter not added", () => !Player.ChildrenOfType<LegacyComboCounter>().Any());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace osu.Game.Rulesets.Catch.Skinning.Argon
{
public class CatchArgonSkinTransformer : SkinTransformer
public class CatchArgonSkinTransformer : ArgonSkinTransformer
{
public CatchArgonSkinTransformer(ISkin skin)
: base(skin)
Expand Down
102 changes: 46 additions & 56 deletions osu.Game.Rulesets.Catch/Skinning/Legacy/CatchLegacySkinTransformer.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT 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.Skinning;
using osuTK.Graphics;

Expand All @@ -28,76 +26,68 @@ public CatchLegacySkinTransformer(ISkin skin)

public override Drawable? GetDrawableComponent(ISkinComponentLookup lookup)
{
if (lookup is SkinComponentsContainerLookup containerLookup)
switch (lookup)
{
switch (containerLookup.Target)
{
case SkinComponentsContainerLookup.TargetArea.MainHUDComponents:
var components = base.GetDrawableComponent(lookup) as Container;

if (providesComboCounter && components != null)
{
// catch may provide its own combo counter; hide the default.
// todo: this should be done in an elegant way per ruleset, defining which HUD skin components should be displayed.
foreach (var legacyComboCounter in components.OfType<LegacyComboCounter>())
legacyComboCounter.HiddenByRulesetImplementation = false;
}

return components;
}
}
case SkinComponentsContainerLookup containerLookup:
switch (containerLookup.Target)
{
case SkinComponentsContainerLookup.TargetArea.MainHUDComponents when containerLookup.Ruleset != null:
// todo: remove CatchSkinComponents.CatchComboCounter and refactor LegacyCatchComboCounter to be added here instead.
return Skin.GetDrawableComponent(lookup);
}

if (lookup is CatchSkinComponentLookup catchSkinComponent)
{
switch (catchSkinComponent.Component)
{
case CatchSkinComponents.Fruit:
if (hasPear)
return new LegacyFruitPiece();
break;

return null;
case CatchSkinComponentLookup catchSkinComponent:
switch (catchSkinComponent.Component)
{
case CatchSkinComponents.Fruit:
if (hasPear)
return new LegacyFruitPiece();

case CatchSkinComponents.Banana:
if (GetTexture("fruit-bananas") != null)
return new LegacyBananaPiece();
return null;

return null;
case CatchSkinComponents.Banana:
if (GetTexture("fruit-bananas") != null)
return new LegacyBananaPiece();

case CatchSkinComponents.Droplet:
if (GetTexture("fruit-drop") != null)
return new LegacyDropletPiece();
return null;

return null;
case CatchSkinComponents.Droplet:
if (GetTexture("fruit-drop") != null)
return new LegacyDropletPiece();

case CatchSkinComponents.Catcher:
decimal version = GetConfig<SkinConfiguration.LegacySetting, decimal>(SkinConfiguration.LegacySetting.Version)?.Value ?? 1;
return null;

if (version < 2.3m)
{
if (hasOldStyleCatcherSprite())
return new LegacyCatcherOld();
}
case CatchSkinComponents.Catcher:
decimal version = GetConfig<SkinConfiguration.LegacySetting, decimal>(SkinConfiguration.LegacySetting.Version)?.Value ?? 1;

if (hasNewStyleCatcherSprite())
return new LegacyCatcherNew();
if (version < 2.3m)
{
if (hasOldStyleCatcherSprite())
return new LegacyCatcherOld();
}

return null;
if (hasNewStyleCatcherSprite())
return new LegacyCatcherNew();

case CatchSkinComponents.CatchComboCounter:
if (providesComboCounter)
return new LegacyCatchComboCounter();
return null;

return null;
case CatchSkinComponents.CatchComboCounter:
if (providesComboCounter)
return new LegacyCatchComboCounter();

case CatchSkinComponents.HitExplosion:
if (hasOldStyleCatcherSprite() || hasNewStyleCatcherSprite())
return new LegacyHitExplosion();
return null;

return null;
case CatchSkinComponents.HitExplosion:
if (hasOldStyleCatcherSprite() || hasNewStyleCatcherSprite())
return new LegacyHitExplosion();

return null;

default:
throw new UnsupportedSkinComponentException(lookup);
}
default:
throw new UnsupportedSkinComponentException(lookup);
}
}

return base.GetDrawableComponent(lookup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace osu.Game.Rulesets.Osu.Skinning.Argon
{
public class OsuArgonSkinTransformer : SkinTransformer
public class OsuArgonSkinTransformer : ArgonSkinTransformer
{
public OsuArgonSkinTransformer(ISkin skin)
: base(skin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

namespace osu.Game.Rulesets.Taiko.Skinning.Argon
{
public class TaikoArgonSkinTransformer : SkinTransformer
public class TaikoArgonSkinTransformer : ArgonSkinTransformer
{
public TaikoArgonSkinTransformer(ISkin skin)
: base(skin)
{
}

public override Drawable? GetDrawableComponent(ISkinComponentLookup component)
public override Drawable? GetDrawableComponent(ISkinComponentLookup lookup)
{
switch (component)
switch (lookup)
{
case GameplaySkinComponentLookup<HitResult> resultComponent:
// This should eventually be moved to a skin setting, when supported.
Expand Down Expand Up @@ -75,7 +75,7 @@ public TaikoArgonSkinTransformer(ISkin skin)
break;
}

return base.GetDrawableComponent(component);
return base.GetDrawableComponent(lookup);
}
}
}
84 changes: 84 additions & 0 deletions osu.Game.Tests/Visual/Gameplay/TestSceneSkinEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Framework.Testing;
using osu.Game.Database;
using osu.Game.Overlays;
using osu.Game.Overlays.Settings;
using osu.Game.Overlays.SkinEditor;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Play.HUD;
using osu.Game.Screens.Play.HUD.HitErrorMeters;
using osu.Game.Skinning;
using osu.Game.Skinning.Components;
Expand All @@ -39,13 +41,17 @@ public partial class TestSceneSkinEditor : PlayerTestScene
[Cached]
public readonly EditorClipboard Clipboard = new EditorClipboard();

[Resolved]
private SkinManager skins { get; set; } = null!;

private SkinComponentsContainer targetContainer => Player.ChildrenOfType<SkinComponentsContainer>().First();

[SetUpSteps]
public override void SetUpSteps()
{
base.SetUpSteps();

AddStep("reset skin", () => skins.CurrentSkinInfo.SetDefault());
AddUntilStep("wait for hud load", () => targetContainer.ComponentsLoaded);

AddStep("reload skin editor", () =>
Expand Down Expand Up @@ -369,6 +375,84 @@ public void TestCopyPaste()
() => Is.EqualTo(3));
}

private SkinComponentsContainer globalHUDTarget => Player.ChildrenOfType<SkinComponentsContainer>()
.Single(c => c.Lookup.Target == SkinComponentsContainerLookup.TargetArea.MainHUDComponents && c.Lookup.Ruleset == null);

private SkinComponentsContainer rulesetHUDTarget => Player.ChildrenOfType<SkinComponentsContainer>()
.Single(c => c.Lookup.Target == SkinComponentsContainerLookup.TargetArea.MainHUDComponents && c.Lookup.Ruleset != null);

[Test]
public void TestMigrationArgon()
{
AddUntilStep("wait for load", () => globalHUDTarget.ComponentsLoaded);
AddStep("add combo to global hud target", () =>
{
globalHUDTarget.Add(new ArgonComboCounter
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
});
});

Live<SkinInfo> modifiedSkin = null!;

AddStep("select another skin", () =>
{
modifiedSkin = skins.CurrentSkinInfo.Value;
skins.CurrentSkinInfo.SetDefault();
});
AddStep("modify version", () => modifiedSkin.PerformWrite(s => s.LayoutVersion = 0));
AddStep("select skin again", () => skins.CurrentSkinInfo.Value = modifiedSkin);
AddAssert("global hud target does not contain combo", () => !globalHUDTarget.Components.Any(c => c is ArgonComboCounter));
AddAssert("ruleset hud target contains both combos", () =>
{
var target = rulesetHUDTarget;

return target.Components.Count == 2 &&
target.Components[0] is ArgonComboCounter one && one.Anchor == Anchor.BottomLeft && one.Origin == Anchor.BottomLeft &&
target.Components[1] is ArgonComboCounter two && two.Anchor == Anchor.Centre && two.Origin == Anchor.Centre;
});
AddStep("save skin", () => skinEditor.Save());
AddAssert("version updated", () => modifiedSkin.PerformRead(s => s.LayoutVersion) == SkinInfo.LATEST_LAYOUT_VERSION);
}

[Test]
public void TestMigrationLegacy()
{
AddStep("select legacy skin", () => skins.CurrentSkinInfo.Value = skins.DefaultClassicSkin.SkinInfo);

AddUntilStep("wait for load", () => globalHUDTarget.ComponentsLoaded);
AddStep("add combo to global hud target", () =>
{
globalHUDTarget.Add(new LegacyComboCounter
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
});
});

Live<SkinInfo> modifiedSkin = null!;

AddStep("select another skin", () =>
{
modifiedSkin = skins.CurrentSkinInfo.Value;
skins.CurrentSkinInfo.SetDefault();
});
AddStep("modify version", () => modifiedSkin.PerformWrite(s => s.LayoutVersion = 0));
AddStep("select skin again", () => skins.CurrentSkinInfo.Value = modifiedSkin);
AddAssert("global hud target does not contain combo", () => !globalHUDTarget.Components.Any(c => c is LegacyComboCounter));
AddAssert("ruleset hud target contains both combos", () =>
{
var target = rulesetHUDTarget;

return target.Components.Count == 2 &&
target.Components[0] is LegacyComboCounter one && one.Anchor == Anchor.BottomLeft && one.Origin == Anchor.BottomLeft &&
target.Components[1] is LegacyComboCounter two && two.Anchor == Anchor.Centre && two.Origin == Anchor.Centre;
});
AddStep("save skin", () => skinEditor.Save());
AddAssert("version updated", () => modifiedSkin.PerformRead(s => s.LayoutVersion) == SkinInfo.LATEST_LAYOUT_VERSION);
}

protected override Ruleset CreatePlayerRuleset() => new OsuRuleset();

private partial class TestSkinEditorChangeHandler : SkinEditorChangeHandler
Expand Down
13 changes: 0 additions & 13 deletions osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableComboCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play.HUD;
Expand All @@ -28,17 +27,5 @@ public void TestComboCounterIncrementing()

AddStep("reset combo", () => scoreProcessor.Combo.Value = 0);
}

[Test]
public void TestLegacyComboCounterHiddenByRulesetImplementation()
{
AddToggleStep("toggle legacy hidden by ruleset", visible =>
{
foreach (var legacyCounter in this.ChildrenOfType<LegacyComboCounter>())
legacyCounter.HiddenByRulesetImplementation = visible;
});

AddRepeatStep("increase combo", () => scoreProcessor.Combo.Value++, 10);
}
}
}
3 changes: 2 additions & 1 deletion osu.Game/Database/RealmAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ public class RealmAccess : IDisposable
/// 39 2023-12-19 Migrate any EndTimeObjectCount and TotalObjectCount values of 0 to -1 to better identify non-calculated values.
/// 40 2023-12-21 Add ScoreInfo.Version to keep track of which build scores were set on.
/// 41 2024-04-17 Add ScoreInfo.TotalScoreWithoutMods for future mod multiplier rebalances.
/// 42 2024-06-25 Add SkinInfo.LayoutVersion to allow performing migrations of components on structural changes.
/// </summary>
private const int schema_version = 41;
private const int schema_version = 42;

/// <summary>
/// Lock object which is held during <see cref="BlockAllOperations"/> sections, blocking realm retrieval during blocking periods.
Expand Down
14 changes: 13 additions & 1 deletion osu.Game/Rulesets/Ruleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,19 @@ public virtual LegacyMods ConvertToLegacyMods(Mod[] mods)
/// <param name="skin">The source skin.</param>
/// <param name="beatmap">The current beatmap.</param>
/// <returns>A skin with a transformer applied, or null if no transformation is provided by this ruleset.</returns>
public virtual ISkin? CreateSkinTransformer(ISkin skin, IBeatmap beatmap) => null;
public virtual ISkin? CreateSkinTransformer(ISkin skin, IBeatmap beatmap)
{
switch (skin)
{
case LegacySkin:
return new LegacySkinTransformer(skin);

case ArgonSkin:
return new ArgonSkinTransformer(skin);
}
bdach marked this conversation as resolved.
Show resolved Hide resolved

return null;
}

protected Ruleset()
{
Expand Down
Loading
Loading