1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:07:52 +08:00

Rename SkinnableTargetContainer to SkinComponentsContainer

Also use full `SkinComponentsContainerLookup` instead of the sub-type.
This will potentially be useful once we bring in per-ruleset targets.
This commit is contained in:
Dean Herbert 2023-02-15 18:31:55 +09:00
parent b1cf6d83d8
commit a92e42bb84
17 changed files with 77 additions and 68 deletions

View File

@ -26,7 +26,7 @@ namespace osu.Game.Rulesets.Catch.Tests
if (withModifiedSkin)
{
AddStep("change component scale", () => Player.ChildrenOfType<LegacyScoreCounter>().First().Scale = new Vector2(2f));
AddStep("update target", () => Player.ChildrenOfType<SkinnableTargetContainer>().ForEach(LegacySkin.UpdateDrawableTarget));
AddStep("update target", () => Player.ChildrenOfType<SkinComponentsContainer>().ForEach(LegacySkin.UpdateDrawableTarget));
AddStep("exit player", () => Player.Exit());
CreateTest();
}

View File

@ -28,11 +28,11 @@ namespace osu.Game.Rulesets.Catch.Skinning.Legacy
public override Drawable? GetDrawableComponent(ISkinComponentLookup lookup)
{
if (lookup is GlobalSkinComponentLookup targetComponent)
if (lookup is SkinComponentsContainerLookup componentLookup)
{
switch (targetComponent.Lookup)
switch (componentLookup.Target)
{
case GlobalSkinComponentLookup.LookupType.MainHUDComponents:
case SkinComponentsContainerLookup.TargetArea.MainHUDComponents:
var components = base.GetDrawableComponent(lookup) as Container;
if (providesComboCounter && components != null)

View File

@ -88,7 +88,7 @@ namespace osu.Game.Tests.Skins
var skin = new TestSkin(new SkinInfo(), null, storage);
Assert.That(skin.DrawableComponentInfo, Has.Count.EqualTo(2));
Assert.That(skin.DrawableComponentInfo[GlobalSkinComponentLookup.LookupType.MainHUDComponents], Has.Length.EqualTo(9));
Assert.That(skin.DrawableComponentInfo[SkinComponentsContainerLookup.TargetArea.MainHUDComponents], Has.Length.EqualTo(9));
}
}
@ -101,10 +101,10 @@ namespace osu.Game.Tests.Skins
var skin = new TestSkin(new SkinInfo(), null, storage);
Assert.That(skin.DrawableComponentInfo, Has.Count.EqualTo(2));
Assert.That(skin.DrawableComponentInfo[GlobalSkinComponentLookup.LookupType.MainHUDComponents], Has.Length.EqualTo(6));
Assert.That(skin.DrawableComponentInfo[GlobalSkinComponentLookup.LookupType.SongSelect], Has.Length.EqualTo(1));
Assert.That(skin.DrawableComponentInfo[SkinComponentsContainerLookup.TargetArea.MainHUDComponents], Has.Length.EqualTo(6));
Assert.That(skin.DrawableComponentInfo[SkinComponentsContainerLookup.TargetArea.SongSelect], Has.Length.EqualTo(1));
var skinnableInfo = skin.DrawableComponentInfo[GlobalSkinComponentLookup.LookupType.SongSelect].First();
var skinnableInfo = skin.DrawableComponentInfo[SkinComponentsContainerLookup.TargetArea.SongSelect].First();
Assert.That(skinnableInfo.Type, Is.EqualTo(typeof(SkinnableSprite)));
Assert.That(skinnableInfo.Settings.First().Key, Is.EqualTo("sprite_name"));
@ -115,10 +115,10 @@ namespace osu.Game.Tests.Skins
using (var storage = new ZipArchiveReader(stream))
{
var skin = new TestSkin(new SkinInfo(), null, storage);
Assert.That(skin.DrawableComponentInfo[GlobalSkinComponentLookup.LookupType.MainHUDComponents], Has.Length.EqualTo(8));
Assert.That(skin.DrawableComponentInfo[GlobalSkinComponentLookup.LookupType.MainHUDComponents].Select(i => i.Type), Contains.Item(typeof(UnstableRateCounter)));
Assert.That(skin.DrawableComponentInfo[GlobalSkinComponentLookup.LookupType.MainHUDComponents].Select(i => i.Type), Contains.Item(typeof(ColourHitErrorMeter)));
Assert.That(skin.DrawableComponentInfo[GlobalSkinComponentLookup.LookupType.MainHUDComponents].Select(i => i.Type), Contains.Item(typeof(LegacySongProgress)));
Assert.That(skin.DrawableComponentInfo[SkinComponentsContainerLookup.TargetArea.MainHUDComponents], Has.Length.EqualTo(8));
Assert.That(skin.DrawableComponentInfo[SkinComponentsContainerLookup.TargetArea.MainHUDComponents].Select(i => i.Type), Contains.Item(typeof(UnstableRateCounter)));
Assert.That(skin.DrawableComponentInfo[SkinComponentsContainerLookup.TargetArea.MainHUDComponents].Select(i => i.Type), Contains.Item(typeof(ColourHitErrorMeter)));
Assert.That(skin.DrawableComponentInfo[SkinComponentsContainerLookup.TargetArea.MainHUDComponents].Select(i => i.Type), Contains.Item(typeof(LegacySongProgress)));
}
}

View File

@ -36,8 +36,8 @@ namespace osu.Game.Tests.Visual.Gameplay
public void TestEmptyLegacyBeatmapSkinFallsBack()
{
CreateSkinTest(TrianglesSkin.CreateInfo(), () => new LegacyBeatmapSkin(new BeatmapInfo(), null));
AddUntilStep("wait for hud load", () => Player.ChildrenOfType<SkinnableTargetContainer>().All(c => c.ComponentsLoaded));
AddAssert("hud from default skin", () => AssertComponentsFromExpectedSource(GlobalSkinComponentLookup.LookupType.MainHUDComponents, skinManager.CurrentSkin.Value));
AddUntilStep("wait for hud load", () => Player.ChildrenOfType<SkinComponentsContainer>().All(c => c.ComponentsLoaded));
AddAssert("hud from default skin", () => AssertComponentsFromExpectedSource(SkinComponentsContainerLookup.TargetArea.MainHUDComponents, skinManager.CurrentSkin.Value));
}
protected void CreateSkinTest(SkinInfo gameCurrentSkin, Func<ISkin> getBeatmapSkin)
@ -52,9 +52,9 @@ namespace osu.Game.Tests.Visual.Gameplay
});
}
protected bool AssertComponentsFromExpectedSource(GlobalSkinComponentLookup.LookupType target, ISkin expectedSource)
protected bool AssertComponentsFromExpectedSource(SkinComponentsContainerLookup.TargetArea target, ISkin expectedSource)
{
var targetContainer = Player.ChildrenOfType<SkinnableTargetContainer>().First(s => s.Target == target);
var targetContainer = Player.ChildrenOfType<SkinComponentsContainer>().First(s => s.Lookup.Target == target);
var actualComponentsContainer = targetContainer.ChildrenOfType<Container>().SingleOrDefault(c => c.Parent == targetContainer);
if (actualComponentsContainer == null)
@ -62,7 +62,7 @@ namespace osu.Game.Tests.Visual.Gameplay
var actualInfo = actualComponentsContainer.CreateSerialisedInfo();
var expectedComponentsContainer = expectedSource.GetDrawableComponent(new GlobalSkinComponentLookup(target)) as Container;
var expectedComponentsContainer = expectedSource.GetDrawableComponent(new SkinComponentsContainerLookup(target)) as Container;
if (expectedComponentsContainer == null)
return false;

View File

@ -235,8 +235,8 @@ namespace osu.Game.Tests.Visual.Gameplay
createNew();
AddUntilStep("wait for hud load", () => hudOverlay.IsLoaded);
AddUntilStep("wait for components to be hidden", () => hudOverlay.ChildrenOfType<SkinnableTargetContainer>().Single().Alpha == 0);
AddUntilStep("wait for hud load", () => hudOverlay.ChildrenOfType<SkinnableTargetContainer>().All(c => c.ComponentsLoaded));
AddUntilStep("wait for components to be hidden", () => hudOverlay.ChildrenOfType<SkinComponentsContainer>().Single().Alpha == 0);
AddUntilStep("wait for hud load", () => hudOverlay.ChildrenOfType<SkinComponentsContainer>().All(c => c.ComponentsLoaded));
AddStep("bind on update", () =>
{
@ -254,10 +254,10 @@ namespace osu.Game.Tests.Visual.Gameplay
createNew();
AddUntilStep("wait for hud load", () => hudOverlay.IsLoaded);
AddUntilStep("wait for components to be hidden", () => hudOverlay.ChildrenOfType<SkinnableTargetContainer>().Single().Alpha == 0);
AddUntilStep("wait for components to be hidden", () => hudOverlay.ChildrenOfType<SkinComponentsContainer>().Single().Alpha == 0);
AddStep("reload components", () => hudOverlay.ChildrenOfType<SkinnableTargetContainer>().Single().Reload());
AddUntilStep("skinnable components loaded", () => hudOverlay.ChildrenOfType<SkinnableTargetContainer>().Single().ComponentsLoaded);
AddStep("reload components", () => hudOverlay.ChildrenOfType<SkinComponentsContainer>().Single().Reload());
AddUntilStep("skinnable components loaded", () => hudOverlay.ChildrenOfType<SkinComponentsContainer>().Single().ComponentsLoaded);
}
private void createNew(Action<HUDOverlay>? action = null)

View File

@ -32,7 +32,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
base.SetUpSteps();
AddUntilStep("wait for hud load", () => Player.ChildrenOfType<SkinnableTargetContainer>().All(c => c.ComponentsLoaded));
AddUntilStep("wait for hud load", () => Player.ChildrenOfType<SkinComponentsContainer>().All(c => c.ComponentsLoaded));
AddStep("reload skin editor", () =>
{

View File

@ -339,25 +339,25 @@ namespace osu.Game.Overlays.SkinEditor
settingsSidebar.Add(new SkinSettingsToolbox(component));
}
private IEnumerable<SkinnableTargetContainer> availableTargets => targetScreen.ChildrenOfType<SkinnableTargetContainer>();
private IEnumerable<SkinComponentsContainer> availableTargets => targetScreen.ChildrenOfType<SkinComponentsContainer>();
private ISerialisableDrawableContainer? getFirstTarget() => availableTargets.FirstOrDefault();
private ISerialisableDrawableContainer? getTarget(GlobalSkinComponentLookup.LookupType target)
private ISerialisableDrawableContainer? getTarget(SkinComponentsContainerLookup.TargetArea target)
{
return availableTargets.FirstOrDefault(c => c.Target == target);
return availableTargets.FirstOrDefault(c => c.Lookup.Target == target);
}
private void revert()
{
SkinnableTargetContainer[] targetContainers = availableTargets.ToArray();
SkinComponentsContainer[] targetContainers = availableTargets.ToArray();
foreach (var t in targetContainers)
{
currentSkin.Value.ResetDrawableTarget(t);
// add back default components
getTarget(t.Target)?.Reload();
getTarget(t.Lookup.Target)?.Reload();
}
}
@ -370,7 +370,7 @@ namespace osu.Game.Overlays.SkinEditor
if (!hasBegunMutating)
return;
SkinnableTargetContainer[] targetContainers = availableTargets.ToArray();
SkinComponentsContainer[] targetContainers = availableTargets.ToArray();
foreach (var t in targetContainers)
currentSkin.Value.UpdateDrawableTarget(t);

View File

@ -88,7 +88,7 @@ namespace osu.Game.Screens.Play
private readonly BindableBool holdingForHUD = new BindableBool();
private readonly SkinnableTargetContainer mainComponents;
private readonly SkinComponentsContainer mainComponents;
/// <summary>
/// A flow which sits at the left side of the screen to house leaderboard (and related) components.
@ -390,7 +390,7 @@ namespace osu.Game.Screens.Play
}
}
private partial class MainComponentsContainer : SkinnableTargetContainer
private partial class MainComponentsContainer : SkinComponentsContainer
{
private Bindable<ScoringMode> scoringMode;
@ -398,7 +398,7 @@ namespace osu.Game.Screens.Play
private OsuConfigManager config { get; set; }
public MainComponentsContainer()
: base(GlobalSkinComponentLookup.LookupType.MainHUDComponents)
: base(new SkinComponentsContainerLookup(SkinComponentsContainerLookup.TargetArea.MainHUDComponents))
{
RelativeSizeAxes = Axes.Both;
}

View File

@ -273,7 +273,7 @@ namespace osu.Game.Screens.Select
}
}
},
new SkinnableTargetContainer(GlobalSkinComponentLookup.LookupType.SongSelect)
new SkinComponentsContainer(new SkinComponentsContainerLookup(SkinComponentsContainerLookup.TargetArea.SongSelect))
{
RelativeSizeAxes = Axes.Both,
},

View File

@ -90,10 +90,10 @@ namespace osu.Game.Skinning
switch (lookup)
{
case GlobalSkinComponentLookup globalLookup:
switch (globalLookup.Lookup)
case SkinComponentsContainerLookup componentLookup:
switch (componentLookup.Target)
{
case GlobalSkinComponentLookup.LookupType.SongSelect:
case SkinComponentsContainerLookup.TargetArea.SongSelect:
var songSelectComponents = new DefaultSkinComponentsContainer(_ =>
{
// do stuff when we need to.
@ -101,7 +101,7 @@ namespace osu.Game.Skinning
return songSelectComponents;
case GlobalSkinComponentLookup.LookupType.MainHUDComponents:
case SkinComponentsContainerLookup.TargetArea.MainHUDComponents:
var skinnableTargetWrapper = new DefaultSkinComponentsContainer(container =>
{
var score = container.OfType<DefaultScoreCounter>().FirstOrDefault();

View File

@ -45,11 +45,11 @@ namespace osu.Game.Skinning
public override Drawable? GetDrawableComponent(ISkinComponentLookup lookup)
{
if (lookup is GlobalSkinComponentLookup targetComponent)
if (lookup is SkinComponentsContainerLookup targetComponent)
{
switch (targetComponent.Lookup)
switch (targetComponent.Target)
{
case GlobalSkinComponentLookup.LookupType.MainHUDComponents:
case SkinComponentsContainerLookup.TargetArea.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

@ -343,10 +343,10 @@ namespace osu.Game.Skinning
switch (lookup)
{
case GlobalSkinComponentLookup target:
switch (target.Lookup)
case SkinComponentsContainerLookup componentLookup:
switch (componentLookup.Target)
{
case GlobalSkinComponentLookup.LookupType.MainHUDComponents:
case SkinComponentsContainerLookup.TargetArea.MainHUDComponents:
var skinnableTargetWrapper = new DefaultSkinComponentsContainer(container =>
{
var score = container.OfType<LegacyScoreCounter>().FirstOrDefault();

View File

@ -37,9 +37,9 @@ namespace osu.Game.Skinning
public SkinConfiguration Configuration { get; set; }
public IDictionary<GlobalSkinComponentLookup.LookupType, SerialisedDrawableInfo[]> DrawableComponentInfo => drawableComponentInfo;
public IDictionary<SkinComponentsContainerLookup.TargetArea, SerialisedDrawableInfo[]> DrawableComponentInfo => drawableComponentInfo;
private readonly Dictionary<GlobalSkinComponentLookup.LookupType, SerialisedDrawableInfo[]> drawableComponentInfo = new Dictionary<GlobalSkinComponentLookup.LookupType, SerialisedDrawableInfo[]>();
private readonly Dictionary<SkinComponentsContainerLookup.TargetArea, SerialisedDrawableInfo[]> drawableComponentInfo = new Dictionary<SkinComponentsContainerLookup.TargetArea, SerialisedDrawableInfo[]>();
public abstract ISample? GetSample(ISampleInfo sampleInfo);
@ -100,7 +100,7 @@ namespace osu.Game.Skinning
Configuration = new SkinConfiguration();
// skininfo files may be null for default skin.
foreach (GlobalSkinComponentLookup.LookupType skinnableTarget in Enum.GetValues<GlobalSkinComponentLookup.LookupType>())
foreach (SkinComponentsContainerLookup.TargetArea skinnableTarget in Enum.GetValues<SkinComponentsContainerLookup.TargetArea>())
{
string filename = $"{skinnableTarget}.json";
@ -143,18 +143,18 @@ namespace osu.Game.Skinning
/// Remove all stored customisations for the provided target.
/// </summary>
/// <param name="targetContainer">The target container to reset.</param>
public void ResetDrawableTarget(SkinnableTargetContainer targetContainer)
public void ResetDrawableTarget(SkinComponentsContainer targetContainer)
{
DrawableComponentInfo.Remove(targetContainer.Target);
DrawableComponentInfo.Remove(targetContainer.Lookup.Target);
}
/// <summary>
/// Update serialised information for the provided target.
/// </summary>
/// <param name="targetContainer">The target container to serialise to this skin.</param>
public void UpdateDrawableTarget(SkinnableTargetContainer targetContainer)
public void UpdateDrawableTarget(SkinComponentsContainer targetContainer)
{
DrawableComponentInfo[targetContainer.Target] = ((ISerialisableDrawableContainer)targetContainer).CreateSerialisedInfo().ToArray();
DrawableComponentInfo[targetContainer.Lookup.Target] = ((ISerialisableDrawableContainer)targetContainer).CreateSerialisedInfo().ToArray();
}
public virtual Drawable? GetDrawableComponent(ISkinComponentLookup lookup)
@ -165,8 +165,8 @@ namespace osu.Game.Skinning
case SkinnableSprite.SpriteComponentLookup sprite:
return this.GetAnimation(sprite.LookupName, false, false);
case GlobalSkinComponentLookup target:
if (!DrawableComponentInfo.TryGetValue(target.Lookup, out var skinnableInfo))
case SkinComponentsContainerLookup componentLookup:
if (!DrawableComponentInfo.TryGetValue(componentLookup.Target, out var skinnableInfo))
return null;
var components = new List<Drawable>();

View File

@ -11,11 +11,20 @@ using osu.Framework.Graphics.Containers;
namespace osu.Game.Skinning
{
public partial class SkinnableTargetContainer : SkinReloadableDrawable, ISerialisableDrawableContainer
/// <summary>
/// A container which holds many skinnable components, with functionality to add, remove and reload layouts.
/// Used to allow user customisation of skin layouts.
/// </summary>
/// <remarks>
/// This is currently used as a means of serialising skin layouts to files.
/// Currently, one json file in a skin will represent one <see cref="SkinComponentsContainer"/>, containing
/// the output of <see cref="ISerialisableDrawableContainer.CreateSerialisedInfo"/>.
/// </remarks>
public partial class SkinComponentsContainer : SkinReloadableDrawable, ISerialisableDrawableContainer
{
private Container? content;
public GlobalSkinComponentLookup.LookupType Target { get; }
public SkinComponentsContainerLookup Lookup { get; }
public IBindableList<ISerialisableDrawable> Components => components;
@ -27,9 +36,9 @@ namespace osu.Game.Skinning
private CancellationTokenSource? cancellationSource;
public SkinnableTargetContainer(GlobalSkinComponentLookup.LookupType target)
public SkinComponentsContainer(SkinComponentsContainerLookup lookup)
{
Target = target;
Lookup = lookup;
}
public void Reload(SerialisedDrawableInfo[] skinnableInfo)
@ -46,7 +55,7 @@ namespace osu.Game.Skinning
});
}
public void Reload() => Reload(CurrentSkin.GetDrawableComponent(new GlobalSkinComponentLookup(Target)) as Container);
public void Reload() => Reload(CurrentSkin.GetDrawableComponent(Lookup) as Container);
public void Reload(Container? componentsContainer)
{

View File

@ -3,16 +3,16 @@
namespace osu.Game.Skinning
{
public class GlobalSkinComponentLookup : ISkinComponentLookup
public class SkinComponentsContainerLookup : ISkinComponentLookup
{
public readonly LookupType Lookup;
public readonly TargetArea Target;
public GlobalSkinComponentLookup(LookupType lookup)
public SkinComponentsContainerLookup(TargetArea target)
{
Lookup = lookup;
Target = target;
}
public enum LookupType
public enum TargetArea
{
MainHUDComponents,
SongSelect

View File

@ -68,10 +68,10 @@ namespace osu.Game.Skinning
switch (lookup)
{
case GlobalSkinComponentLookup target:
switch (target.Lookup)
case SkinComponentsContainerLookup componentLookup:
switch (componentLookup.Target)
{
case GlobalSkinComponentLookup.LookupType.SongSelect:
case SkinComponentsContainerLookup.TargetArea.SongSelect:
var songSelectComponents = new DefaultSkinComponentsContainer(_ =>
{
// do stuff when we need to.
@ -79,7 +79,7 @@ namespace osu.Game.Skinning
return songSelectComponents;
case GlobalSkinComponentLookup.LookupType.MainHUDComponents:
case SkinComponentsContainerLookup.TargetArea.MainHUDComponents:
var skinnableTargetWrapper = new DefaultSkinComponentsContainer(container =>
{
var score = container.OfType<DefaultScoreCounter>().FirstOrDefault();

View File

@ -45,13 +45,13 @@ namespace osu.Game.Tests.Visual
private void addResetTargetsStep()
{
AddStep("reset targets", () => this.ChildrenOfType<SkinnableTargetContainer>().ForEach(t =>
AddStep("reset targets", () => this.ChildrenOfType<SkinComponentsContainer>().ForEach(t =>
{
LegacySkin.ResetDrawableTarget(t);
t.Reload();
}));
AddUntilStep("wait for components to load", () => this.ChildrenOfType<SkinnableTargetContainer>().All(t => t.ComponentsLoaded));
AddUntilStep("wait for components to load", () => this.ChildrenOfType<SkinComponentsContainer>().All(t => t.ComponentsLoaded));
}
public partial class SkinProvidingPlayer : TestPlayer