1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +08:00

Move GlobalSkinnableContainers to global scope

This commit is contained in:
Dean Herbert 2024-08-22 18:45:44 +09:00
parent 36b4013fa6
commit 9a21174582
No known key found for this signature in database
17 changed files with 58 additions and 52 deletions

View File

@ -46,7 +46,7 @@ namespace osu.Game.Rulesets.Catch.Skinning.Legacy
// Our own ruleset components default.
switch (containerLookup.Target)
{
case GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents:
case GlobalSkinnableContainers.MainHUDComponents:
// todo: remove CatchSkinComponents.CatchComboCounter and refactor LegacyCatchComboCounter to be added here instead.
return new DefaultSkinComponentsContainer(container =>
{

View File

@ -39,7 +39,7 @@ namespace osu.Game.Rulesets.Mania.Skinning.Argon
switch (containerLookup.Target)
{
case GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents:
case GlobalSkinnableContainers.MainHUDComponents:
return new DefaultSkinComponentsContainer(container =>
{
var combo = container.ChildrenOfType<ArgonManiaComboCounter>().FirstOrDefault();

View File

@ -95,7 +95,7 @@ namespace osu.Game.Rulesets.Mania.Skinning.Legacy
switch (containerLookup.Target)
{
case GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents:
case GlobalSkinnableContainers.MainHUDComponents:
return new DefaultSkinComponentsContainer(container =>
{
var combo = container.ChildrenOfType<LegacyManiaComboCounter>().FirstOrDefault();

View File

@ -60,7 +60,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
// Our own ruleset components default.
switch (containerLookup.Target)
{
case GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents:
case GlobalSkinnableContainers.MainHUDComponents:
return new DefaultSkinComponentsContainer(container =>
{
var keyCounter = container.OfType<LegacyKeyCounterDisplay>().FirstOrDefault();

View File

@ -107,7 +107,7 @@ namespace osu.Game.Tests.Skins
var skin = new TestSkin(new SkinInfo(), null, storage);
Assert.That(skin.LayoutInfos, Has.Count.EqualTo(2));
Assert.That(skin.LayoutInfos[GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents].AllDrawables.ToArray(), Has.Length.EqualTo(9));
Assert.That(skin.LayoutInfos[GlobalSkinnableContainers.MainHUDComponents].AllDrawables.ToArray(), Has.Length.EqualTo(9));
}
}
@ -120,8 +120,8 @@ namespace osu.Game.Tests.Skins
var skin = new TestSkin(new SkinInfo(), null, storage);
Assert.That(skin.LayoutInfos, Has.Count.EqualTo(2));
Assert.That(skin.LayoutInfos[GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents].AllDrawables.ToArray(), Has.Length.EqualTo(10));
Assert.That(skin.LayoutInfos[GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents].AllDrawables.Select(i => i.Type), Contains.Item(typeof(PlayerName)));
Assert.That(skin.LayoutInfos[GlobalSkinnableContainers.MainHUDComponents].AllDrawables.ToArray(), Has.Length.EqualTo(10));
Assert.That(skin.LayoutInfos[GlobalSkinnableContainers.MainHUDComponents].AllDrawables.Select(i => i.Type), Contains.Item(typeof(PlayerName)));
}
}
@ -134,10 +134,10 @@ namespace osu.Game.Tests.Skins
var skin = new TestSkin(new SkinInfo(), null, storage);
Assert.That(skin.LayoutInfos, Has.Count.EqualTo(2));
Assert.That(skin.LayoutInfos[GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents].AllDrawables.ToArray(), Has.Length.EqualTo(6));
Assert.That(skin.LayoutInfos[GlobalSkinnableContainerLookup.GlobalSkinnableContainers.SongSelect].AllDrawables.ToArray(), Has.Length.EqualTo(1));
Assert.That(skin.LayoutInfos[GlobalSkinnableContainers.MainHUDComponents].AllDrawables.ToArray(), Has.Length.EqualTo(6));
Assert.That(skin.LayoutInfos[GlobalSkinnableContainers.SongSelect].AllDrawables.ToArray(), Has.Length.EqualTo(1));
var skinnableInfo = skin.LayoutInfos[GlobalSkinnableContainerLookup.GlobalSkinnableContainers.SongSelect].AllDrawables.First();
var skinnableInfo = skin.LayoutInfos[GlobalSkinnableContainers.SongSelect].AllDrawables.First();
Assert.That(skinnableInfo.Type, Is.EqualTo(typeof(SkinnableSprite)));
Assert.That(skinnableInfo.Settings.First().Key, Is.EqualTo("sprite_name"));
@ -148,10 +148,10 @@ namespace osu.Game.Tests.Skins
using (var storage = new ZipArchiveReader(stream))
{
var skin = new TestSkin(new SkinInfo(), null, storage);
Assert.That(skin.LayoutInfos[GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents].AllDrawables.ToArray(), Has.Length.EqualTo(8));
Assert.That(skin.LayoutInfos[GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents].AllDrawables.Select(i => i.Type), Contains.Item(typeof(UnstableRateCounter)));
Assert.That(skin.LayoutInfos[GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents].AllDrawables.Select(i => i.Type), Contains.Item(typeof(ColourHitErrorMeter)));
Assert.That(skin.LayoutInfos[GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents].AllDrawables.Select(i => i.Type), Contains.Item(typeof(LegacySongProgress)));
Assert.That(skin.LayoutInfos[GlobalSkinnableContainers.MainHUDComponents].AllDrawables.ToArray(), Has.Length.EqualTo(8));
Assert.That(skin.LayoutInfos[GlobalSkinnableContainers.MainHUDComponents].AllDrawables.Select(i => i.Type), Contains.Item(typeof(UnstableRateCounter)));
Assert.That(skin.LayoutInfos[GlobalSkinnableContainers.MainHUDComponents].AllDrawables.Select(i => i.Type), Contains.Item(typeof(ColourHitErrorMeter)));
Assert.That(skin.LayoutInfos[GlobalSkinnableContainers.MainHUDComponents].AllDrawables.Select(i => i.Type), Contains.Item(typeof(LegacySongProgress)));
}
}

View File

@ -38,7 +38,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
CreateSkinTest(TrianglesSkin.CreateInfo(), () => new LegacyBeatmapSkin(new BeatmapInfo(), null));
AddUntilStep("wait for hud load", () => Player.ChildrenOfType<SkinnableContainer>().All(c => c.ComponentsLoaded));
AddAssert("hud from default skin", () => AssertComponentsFromExpectedSource(GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents, skinManager.CurrentSkin.Value));
AddAssert("hud from default skin", () => AssertComponentsFromExpectedSource(GlobalSkinnableContainers.MainHUDComponents, skinManager.CurrentSkin.Value));
}
protected void CreateSkinTest(SkinInfo gameCurrentSkin, Func<ISkin> getBeatmapSkin)
@ -53,7 +53,7 @@ namespace osu.Game.Tests.Visual.Gameplay
});
}
protected bool AssertComponentsFromExpectedSource(GlobalSkinnableContainerLookup.GlobalSkinnableContainers target, ISkin expectedSource)
protected bool AssertComponentsFromExpectedSource(GlobalSkinnableContainers target, ISkin expectedSource)
{
var targetContainer = Player.ChildrenOfType<SkinnableContainer>().First(s => s.Lookup.Target == target);
var actualComponentsContainer = targetContainer.ChildrenOfType<Container>().SingleOrDefault(c => c.Parent == targetContainer);

View File

@ -378,10 +378,10 @@ namespace osu.Game.Tests.Visual.Gameplay
}
private SkinnableContainer globalHUDTarget => Player.ChildrenOfType<SkinnableContainer>()
.Single(c => c.Lookup.Target == GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents && c.Lookup.Ruleset == null);
.Single(c => c.Lookup.Target == GlobalSkinnableContainers.MainHUDComponents && c.Lookup.Ruleset == null);
private SkinnableContainer rulesetHUDTarget => Player.ChildrenOfType<SkinnableContainer>()
.Single(c => c.Lookup.Target == GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents && c.Lookup.Ruleset != null);
.Single(c => c.Lookup.Target == GlobalSkinnableContainers.MainHUDComponents && c.Lookup.Ruleset != null);
[Test]
public void TestMigrationArgon()

View File

@ -20,7 +20,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestToggleEditor()
{
var skinComponentsContainer = new SkinnableContainer(new GlobalSkinnableContainerLookup(GlobalSkinnableContainerLookup.GlobalSkinnableContainers.SongSelect));
var skinComponentsContainer = new SkinnableContainer(new GlobalSkinnableContainerLookup(GlobalSkinnableContainers.SongSelect));
AddStep("show available components", () => SetContents(_ => new SkinComponentToolbox(skinComponentsContainer, null)
{

View File

@ -109,7 +109,7 @@ namespace osu.Game.Screens.Play
private readonly List<Drawable> hideTargets;
/// <summary>
/// The container for skin components attached to <see cref="GlobalSkinnableContainerLookup.GlobalSkinnableContainers.Playfield"/>
/// The container for skin components attached to <see cref="GlobalSkinnableContainers.Playfield"/>
/// </summary>
internal readonly Drawable PlayfieldSkinLayer;
@ -132,7 +132,7 @@ namespace osu.Game.Screens.Play
? (rulesetComponents = new HUDComponentsContainer(drawableRuleset.Ruleset.RulesetInfo) { AlwaysPresent = true, })
: Empty(),
PlayfieldSkinLayer = drawableRuleset != null
? new SkinnableContainer(new GlobalSkinnableContainerLookup(GlobalSkinnableContainerLookup.GlobalSkinnableContainers.Playfield, drawableRuleset.Ruleset.RulesetInfo)) { AlwaysPresent = true, }
? new SkinnableContainer(new GlobalSkinnableContainerLookup(GlobalSkinnableContainers.Playfield, drawableRuleset.Ruleset.RulesetInfo)) { AlwaysPresent = true, }
: Empty(),
topRightElements = new FillFlowContainer
{
@ -448,7 +448,7 @@ namespace osu.Game.Screens.Play
private OsuConfigManager config { get; set; }
public HUDComponentsContainer([CanBeNull] RulesetInfo ruleset = null)
: base(new GlobalSkinnableContainerLookup(GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents, ruleset))
: base(new GlobalSkinnableContainerLookup(GlobalSkinnableContainers.MainHUDComponents, ruleset))
{
RelativeSizeAxes = Axes.Both;
}

View File

@ -321,7 +321,7 @@ namespace osu.Game.Screens.Select
}
}
},
new SkinnableContainer(new GlobalSkinnableContainerLookup(GlobalSkinnableContainerLookup.GlobalSkinnableContainers.SongSelect))
new SkinnableContainer(new GlobalSkinnableContainerLookup(GlobalSkinnableContainers.SongSelect))
{
RelativeSizeAxes = Axes.Both,
},

View File

@ -103,7 +103,7 @@ namespace osu.Game.Skinning
switch (containerLookup.Target)
{
case GlobalSkinnableContainerLookup.GlobalSkinnableContainers.SongSelect:
case GlobalSkinnableContainers.SongSelect:
var songSelectComponents = new DefaultSkinComponentsContainer(_ =>
{
// do stuff when we need to.
@ -111,7 +111,7 @@ namespace osu.Game.Skinning
return songSelectComponents;
case GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents:
case GlobalSkinnableContainers.MainHUDComponents:
if (containerLookup.Ruleset != null)
{
return new Container

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.ComponentModel;
using osu.Framework.Extensions;
using osu.Game.Rulesets;
@ -58,20 +57,5 @@ namespace osu.Game.Skinning
{
return HashCode.Combine((int)Target, Ruleset);
}
/// <summary>
/// Represents a particular area or part of a game screen whose layout can be customised using the skin editor.
/// </summary>
public enum GlobalSkinnableContainers
{
[Description("HUD")]
MainHUDComponents,
[Description("Song select")]
SongSelect,
[Description("Playfield")]
Playfield
}
}
}

View File

@ -0,0 +1,22 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.ComponentModel;
namespace osu.Game.Skinning
{
/// <summary>
/// Represents a particular area or part of a game screen whose layout can be customised using the skin editor.
/// </summary>
public enum GlobalSkinnableContainers
{
[Description("HUD")]
MainHUDComponents,
[Description("Song select")]
SongSelect,
[Description("Playfield")]
Playfield
}
}

View File

@ -54,7 +54,7 @@ namespace osu.Game.Skinning
{
switch (containerLookup.Target)
{
case GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents:
case GlobalSkinnableContainers.MainHUDComponents:
// this should exist in LegacySkin instead, but there isn't a fallback skin for LegacySkins yet.
// therefore keep the check here until fallback default legacy skin is supported.
if (!this.HasFont(LegacyFont.Score))

View File

@ -364,7 +364,7 @@ namespace osu.Game.Skinning
switch (containerLookup.Target)
{
case GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents:
case GlobalSkinnableContainers.MainHUDComponents:
if (containerLookup.Ruleset != null)
{
return new DefaultSkinComponentsContainer(container =>

View File

@ -43,10 +43,10 @@ namespace osu.Game.Skinning
public SkinConfiguration Configuration { get; set; }
public IDictionary<GlobalSkinnableContainerLookup.GlobalSkinnableContainers, SkinLayoutInfo> LayoutInfos => layoutInfos;
public IDictionary<GlobalSkinnableContainers, SkinLayoutInfo> LayoutInfos => layoutInfos;
private readonly Dictionary<GlobalSkinnableContainerLookup.GlobalSkinnableContainers, SkinLayoutInfo> layoutInfos =
new Dictionary<GlobalSkinnableContainerLookup.GlobalSkinnableContainers, SkinLayoutInfo>();
private readonly Dictionary<GlobalSkinnableContainers, SkinLayoutInfo> layoutInfos =
new Dictionary<GlobalSkinnableContainers, SkinLayoutInfo>();
public abstract ISample? GetSample(ISampleInfo sampleInfo);
@ -123,7 +123,7 @@ namespace osu.Game.Skinning
}
// skininfo files may be null for default skin.
foreach (GlobalSkinnableContainerLookup.GlobalSkinnableContainers skinnableTarget in Enum.GetValues<GlobalSkinnableContainerLookup.GlobalSkinnableContainers>())
foreach (GlobalSkinnableContainers skinnableTarget in Enum.GetValues<GlobalSkinnableContainers>())
{
string filename = $"{skinnableTarget}.json";
@ -206,7 +206,7 @@ namespace osu.Game.Skinning
#region Deserialisation & Migration
private SkinLayoutInfo? parseLayoutInfo(string jsonContent, GlobalSkinnableContainerLookup.GlobalSkinnableContainers target)
private SkinLayoutInfo? parseLayoutInfo(string jsonContent, GlobalSkinnableContainers target)
{
SkinLayoutInfo? layout = null;
@ -245,7 +245,7 @@ namespace osu.Game.Skinning
return layout;
}
private void applyMigration(SkinLayoutInfo layout, GlobalSkinnableContainerLookup.GlobalSkinnableContainers target, int version)
private void applyMigration(SkinLayoutInfo layout, GlobalSkinnableContainers target, int version)
{
switch (version)
{
@ -253,7 +253,7 @@ namespace osu.Game.Skinning
{
// Combo counters were moved out of the global HUD components into per-ruleset.
// This is to allow some rulesets to customise further (ie. mania and catch moving the combo to within their play area).
if (target != GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents ||
if (target != GlobalSkinnableContainers.MainHUDComponents ||
!layout.TryGetDrawableInfo(null, out var globalHUDComponents) ||
resources == null)
break;

View File

@ -76,7 +76,7 @@ namespace osu.Game.Skinning
switch (containerLookup.Target)
{
case GlobalSkinnableContainerLookup.GlobalSkinnableContainers.SongSelect:
case GlobalSkinnableContainers.SongSelect:
var songSelectComponents = new DefaultSkinComponentsContainer(_ =>
{
// do stuff when we need to.
@ -84,7 +84,7 @@ namespace osu.Game.Skinning
return songSelectComponents;
case GlobalSkinnableContainerLookup.GlobalSkinnableContainers.MainHUDComponents:
case GlobalSkinnableContainers.MainHUDComponents:
var skinnableTargetWrapper = new DefaultSkinComponentsContainer(container =>
{
var score = container.OfType<DefaultScoreCounter>().FirstOrDefault();