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 11 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
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,14 @@ public CatchLegacySkinTransformer(ISkin skin)

// Modifications for global components.
if (containerLookup.Ruleset == null)
{
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;
}
return base.GetDrawableComponent(lookup) as Container;

// Skin has configuration.
if (base.GetDrawableComponent(lookup) is Drawable d)
return d;

// Our own ruleset components default.
// todo: remove CatchSkinComponents.CatchComboCounter and refactor LegacyCatchComboCounter to be added here instead.
return new DefaultSkinComponentsContainer(container =>
{
var keyCounter = container.OfType<LegacyKeyCounterDisplay>().FirstOrDefault();
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);
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
95 changes: 95 additions & 0 deletions osu.Game.Tests/Visual/Gameplay/TestSceneSkinEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@
using System.Text;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
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;
using osu.Game.Tests.Resources;
using osuTK;
using osuTK.Input;

Expand All @@ -39,13 +43,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 +377,93 @@ 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()
{
Live<SkinInfo> importedSkin = null!;

AddStep("import old argon skin", () => skins.CurrentSkinInfo.Value = importedSkin = importSkinFromArchives(@"argon-layout-version-0.osk").SkinInfo);
AddUntilStep("wait for load", () => globalHUDTarget.ComponentsLoaded && rulesetHUDTarget.ComponentsLoaded);
AddAssert("no combo in global target", () => !globalHUDTarget.Components.OfType<ArgonComboCounter>().Any());
AddAssert("combo placed in ruleset target", () => rulesetHUDTarget.Components.OfType<ArgonComboCounter>().Count() == 1);

AddStep("add combo to global target", () => globalHUDTarget.Add(new ArgonComboCounter
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(2f),
}));
AddStep("save skin", () => skins.Save(skins.CurrentSkin.Value));

AddStep("select another skin", () => skins.CurrentSkinInfo.SetDefault());
AddStep("select skin again", () => skins.CurrentSkinInfo.Value = importedSkin);
AddUntilStep("wait for load", () => globalHUDTarget.ComponentsLoaded && rulesetHUDTarget.ComponentsLoaded);
AddAssert("combo placed in global target", () => globalHUDTarget.Components.OfType<ArgonComboCounter>().Count() == 1);
AddAssert("combo placed in ruleset target", () => rulesetHUDTarget.Components.OfType<ArgonComboCounter>().Count() == 1);
}

[Test]
public void TestMigrationTriangles()
{
Live<SkinInfo> importedSkin = null!;

AddStep("import old triangles skin", () => skins.CurrentSkinInfo.Value = importedSkin = importSkinFromArchives(@"triangles-layout-version-0.osk").SkinInfo);
AddUntilStep("wait for load", () => globalHUDTarget.ComponentsLoaded && rulesetHUDTarget.ComponentsLoaded);
AddAssert("no combo in global target", () => !globalHUDTarget.Components.OfType<DefaultComboCounter>().Any());
AddAssert("combo placed in ruleset target", () => rulesetHUDTarget.Components.OfType<DefaultComboCounter>().Count() == 1);

AddStep("add combo to global target", () => globalHUDTarget.Add(new DefaultComboCounter
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(2f),
}));
AddStep("save skin", () => skins.Save(skins.CurrentSkin.Value));

AddStep("select another skin", () => skins.CurrentSkinInfo.SetDefault());
AddStep("select skin again", () => skins.CurrentSkinInfo.Value = importedSkin);
AddUntilStep("wait for load", () => globalHUDTarget.ComponentsLoaded && rulesetHUDTarget.ComponentsLoaded);
AddAssert("combo placed in global target", () => globalHUDTarget.Components.OfType<DefaultComboCounter>().Count() == 1);
AddAssert("combo placed in ruleset target", () => rulesetHUDTarget.Components.OfType<DefaultComboCounter>().Count() == 1);
}

[Test]
public void TestMigrationLegacy()
{
Live<SkinInfo> importedSkin = null!;

AddStep("import old classic skin", () => skins.CurrentSkinInfo.Value = importedSkin = importSkinFromArchives(@"classic-layout-version-0.osk").SkinInfo);
AddUntilStep("wait for load", () => globalHUDTarget.ComponentsLoaded && rulesetHUDTarget.ComponentsLoaded);
AddAssert("no combo in global target", () => !globalHUDTarget.Components.OfType<LegacyComboCounter>().Any());
AddAssert("combo placed in ruleset target", () => rulesetHUDTarget.Components.OfType<LegacyComboCounter>().Count() == 1);

AddStep("add combo to global target", () => globalHUDTarget.Add(new LegacyComboCounter
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(2f),
}));
AddStep("save skin", () => skins.Save(skins.CurrentSkin.Value));

AddStep("select another skin", () => skins.CurrentSkinInfo.SetDefault());
AddStep("select skin again", () => skins.CurrentSkinInfo.Value = importedSkin);
AddUntilStep("wait for load", () => globalHUDTarget.ComponentsLoaded && rulesetHUDTarget.ComponentsLoaded);
AddAssert("combo placed in global target", () => globalHUDTarget.Components.OfType<LegacyComboCounter>().Count() == 1);
AddAssert("combo placed in ruleset target", () => rulesetHUDTarget.Components.OfType<LegacyComboCounter>().Count() == 1);
}

private Skin importSkinFromArchives(string filename)
{
var imported = skins.Import(new ImportTask(TestResources.OpenResource($@"Archives/{filename}"), filename)).GetResultSafely();
return imported.PerformRead(skinInfo => skins.GetSkin(skinInfo));
}

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);
}
}
}
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);
}

return null;
}

protected Ruleset()
{
Expand Down
16 changes: 2 additions & 14 deletions osu.Game/Skinning/ArgonSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,14 @@ public ArgonSkin(SkinInfo skin, IStorageResourceProvider resources)
return songSelectComponents;

case SkinComponentsContainerLookup.TargetArea.MainHUDComponents:
var skinnableTargetWrapper = new DefaultSkinComponentsContainer(container =>
var mainHUDComponents = new DefaultSkinComponentsContainer(container =>
{
var health = container.OfType<ArgonHealthDisplay>().FirstOrDefault();
var healthLine = container.OfType<BoxElement>().FirstOrDefault();
var wedgePieces = container.OfType<ArgonWedgePiece>().ToArray();
var score = container.OfType<ArgonScoreCounter>().FirstOrDefault();
var accuracy = container.OfType<ArgonAccuracyCounter>().FirstOrDefault();
var performancePoints = container.OfType<ArgonPerformancePointsCounter>().FirstOrDefault();
var combo = container.OfType<ArgonComboCounter>().FirstOrDefault();
var songProgress = container.OfType<ArgonSongProgress>().FirstOrDefault();
var keyCounter = container.OfType<ArgonKeyCounterDisplay>().FirstOrDefault();

Expand Down Expand Up @@ -203,13 +202,6 @@ public ArgonSkin(SkinInfo skin, IStorageResourceProvider resources)
keyCounter.Origin = Anchor.BottomRight;
keyCounter.Position = new Vector2(-(hitError.Width + padding), -(padding * 2 + song_progress_offset_height));
}

if (combo != null && hitError != null)
{
combo.Anchor = Anchor.BottomLeft;
combo.Origin = Anchor.BottomLeft;
combo.Position = new Vector2((hitError.Width + padding), -(padding * 2 + song_progress_offset_height));
}
}
}
})
Expand Down Expand Up @@ -239,18 +231,14 @@ public ArgonSkin(SkinInfo skin, IStorageResourceProvider resources)
{
Scale = new Vector2(0.8f),
},
new ArgonComboCounter
{
Scale = new Vector2(1.3f)
},
new BarHitErrorMeter(),
new BarHitErrorMeter(),
new ArgonSongProgress(),
new ArgonKeyCounterDisplay(),
}
};

return skinnableTargetWrapper;
return mainHUDComponents;
}

return null;
Expand Down
40 changes: 40 additions & 0 deletions osu.Game/Skinning/ArgonSkinTransformer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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 osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Screens.Play.HUD;
using osuTK;

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

public override Drawable? GetDrawableComponent(ISkinComponentLookup lookup)
{
if (lookup is SkinComponentsContainerLookup containerLookup
&& containerLookup.Target == SkinComponentsContainerLookup.TargetArea.MainHUDComponents
&& containerLookup.Ruleset != null)
{
return base.GetDrawableComponent(lookup) ?? new Container
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've hopefully resolved conflicts, but I still have a lot of questions.

Will start with a simple question: why is this here now? Why does ArgonSkinTransformer have to exist? Transformers were supposed to allow rulesets to do things, but you have changed what transformer means now, as this is being instantiated by Ruleset.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On further reading and understanding of this PR, the probable answer is "because I wanted to be able to provide a per-skin default for cases where a ruleset doesn't do anything special", does that sound right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frenzibyte I've applied 60d3834 which removes this stuff. please give it 5 minutes and let me know if it makes sense within that time limit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frenzibyte I've applied 60d3834 which removes this stuff. please give it 5 minutes and let me know if it makes sense within that time limit.

I...don't know. It looks correct, but I feel it's introducing another level of complexity to the lookup system in my head / when parsing this mentally. I wouldn't say that the way I had it is better, though.

This is all cheap talk and I cannot easily imagine how it can be put to code, but, it definitely feels like there should be two methods:

  1. Skin.GetDrawableComponent, which tries to look up user configuration, then fall back to...
  2. Skin.GetDefaultDrawableComponent, which returns default skin implementation, and that can be transformed by a skin transformer somehow.

I'm proposing this for Skin specifically because it is the class that introduces the concept of "user configuration".

Copy link
Member

@peppy peppy Aug 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all cheap talk and I cannot easily imagine how it can be put to code, but, it definitely feels like there should be two methods

Yep, in previous discussions with smoogi this was unanimously agreed upon, but I'm not doing that here. It will be a separate step after all your changes are merged.

I don't see any complexity being added here. I'm just explicitly defining which early returns are due to "skin has user layout".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as it's all temporary until a split happens then I'm fine looking away, I can't easily explain why this feels complicated in my head.

{
RelativeSizeAxes = Axes.Both,
Child = new ArgonComboCounter
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Position = new Vector2(36, -66),
Scale = new Vector2(1.3f),
},
};
}

return base.GetDrawableComponent(lookup);
}
}
}
12 changes: 0 additions & 12 deletions osu.Game/Skinning/LegacyComboCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,6 @@ public partial class LegacyComboCounter : CompositeDrawable, ISerialisableDrawab

private readonly Container counterContainer;

/// <summary>
/// Hides the combo counter internally without affecting its <see cref="SerialisedDrawableInfo"/>.
/// </summary>
/// <remarks>
/// This is used for rulesets that provide their own combo counter and don't want this HUD one to be visible,
/// without potentially affecting the user's selected skin.
/// </remarks>
public bool HiddenByRulesetImplementation
{
set => counterContainer.Alpha = value ? 1 : 0;
}

public bool UsesFixedAnchor { get; set; }

public LegacyComboCounter()
Expand Down
Loading
Loading