Simplify and rename `SkinnableTargetComponentsContainer`

This commit is contained in:
Dean Herbert 2023-02-15 17:24:34 +09:00
parent 24961d1ac0
commit 8bbd00822c
8 changed files with 24 additions and 30 deletions

View File

@ -4,6 +4,7 @@
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Skinning;
using osuTK.Graphics;
@ -32,7 +33,7 @@ public CatchLegacySkinTransformer(ISkin skin)
switch (targetComponent.Lookup)
{
case GlobalSkinComponentLookup.LookupType.MainHUDComponents:
var components = base.GetDrawableComponent(lookup) as SkinnableTargetComponentsContainer;
var components = base.GetDrawableComponent(lookup) as Container;
if (providesComboCounter && components != null)
{

View File

@ -58,14 +58,14 @@ protected void CreateSkinTest(SkinInfo gameCurrentSkin, Func<ISkin> getBeatmapSk
protected bool AssertComponentsFromExpectedSource(GlobalSkinComponentLookup.LookupType target, ISkin expectedSource)
{
var actualComponentsContainer = Player.ChildrenOfType<SkinnableTargetContainer>().First(s => s.Target == target)
.ChildrenOfType<SkinnableTargetComponentsContainer>().SingleOrDefault();
.ChildrenOfType<Container>().SingleOrDefault();
if (actualComponentsContainer == null)
return false;
var actualInfo = actualComponentsContainer.CreateSkinnableInfo();
var expectedComponentsContainer = (SkinnableTargetComponentsContainer)expectedSource.GetDrawableComponent(new GlobalSkinComponentLookup(target));
var expectedComponentsContainer = (DefaultSkinComponentsContainer)expectedSource.GetDrawableComponent(new GlobalSkinComponentLookup(target));
if (expectedComponentsContainer == null)
return false;

View File

@ -94,7 +94,7 @@ public ArgonSkin(SkinInfo skin, IStorageResourceProvider resources)
switch (globalLookup.Lookup)
{
case GlobalSkinComponentLookup.LookupType.SongSelect:
var songSelectComponents = new SkinnableTargetComponentsContainer(_ =>
var songSelectComponents = new DefaultSkinComponentsContainer(_ =>
{
// do stuff when we need to.
});
@ -102,7 +102,7 @@ public ArgonSkin(SkinInfo skin, IStorageResourceProvider resources)
return songSelectComponents;
case GlobalSkinComponentLookup.LookupType.MainHUDComponents:
var skinnableTargetWrapper = new SkinnableTargetComponentsContainer(container =>
var skinnableTargetWrapper = new DefaultSkinComponentsContainer(container =>
{
var score = container.OfType<DefaultScoreCounter>().FirstOrDefault();
var accuracy = container.OfType<DefaultAccuracyCounter>().FirstOrDefault();

View File

@ -2,39 +2,28 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using Newtonsoft.Json;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Skinning
{
/// <summary>
/// A container which groups the components of a <see cref="SkinnableTargetContainer"/> into a single object.
/// Optionally also applies a default layout to the components.
/// A container which can be used to specify default skin components layouts.
/// Handles applying a default layout to the components.
/// </summary>
[Serializable]
public partial class SkinnableTargetComponentsContainer : Container, ISkinnableDrawable
public partial class DefaultSkinComponentsContainer : Container
{
public bool IsEditable => false;
public bool UsesFixedAnchor { get; set; }
private readonly Action<Container>? applyDefaults;
/// <summary>
/// Construct a wrapper with defaults that should be applied once.
/// </summary>
/// <param name="applyDefaults">A function to apply the default layout.</param>
public SkinnableTargetComponentsContainer(Action<Container> applyDefaults)
: this()
{
this.applyDefaults = applyDefaults;
}
[JsonConstructor]
public SkinnableTargetComponentsContainer()
public DefaultSkinComponentsContainer(Action<Container> applyDefaults)
{
RelativeSizeAxes = Axes.Both;
this.applyDefaults = applyDefaults;
}
protected override void LoadComplete()

View File

@ -347,7 +347,7 @@ protected override void ParseConfigurationStream(Stream stream)
switch (target.Lookup)
{
case GlobalSkinComponentLookup.LookupType.MainHUDComponents:
var skinnableTargetWrapper = new SkinnableTargetComponentsContainer(container =>
var skinnableTargetWrapper = new DefaultSkinComponentsContainer(container =>
{
var score = container.OfType<LegacyScoreCounter>().FirstOrDefault();
var accuracy = container.OfType<GameplayAccuracyCounter>().FirstOrDefault();

View File

@ -11,6 +11,7 @@
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores;
using osu.Framework.Logging;
@ -174,8 +175,9 @@ public void UpdateDrawableTarget(ISkinnableTarget targetContainer)
foreach (var i in skinnableInfo)
components.Add(i.CreateInstance());
return new SkinnableTargetComponentsContainer
return new Container
{
RelativeSizeAxes = Axes.Both,
Children = components,
};
}

View File

@ -7,13 +7,14 @@
using System.Threading;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Screens.Play.HUD;
namespace osu.Game.Skinning
{
public partial class SkinnableTargetContainer : SkinReloadableDrawable, ISkinnableTarget
{
private SkinnableTargetComponentsContainer? content;
private Container? content;
public GlobalSkinComponentLookup.LookupType Target { get; }
@ -39,15 +40,16 @@ public void Reload(SkinnableInfo[] skinnableInfo)
foreach (var i in skinnableInfo)
drawables.Add(i.CreateInstance());
Reload(new SkinnableTargetComponentsContainer
Reload(new Container
{
RelativeSizeAxes = Axes.Both,
Children = drawables,
});
}
public void Reload() => Reload(CurrentSkin.GetDrawableComponent(new GlobalSkinComponentLookup(Target)) as SkinnableTargetComponentsContainer);
public void Reload() => Reload(CurrentSkin.GetDrawableComponent(new GlobalSkinComponentLookup(Target)) as Container);
public void Reload(SkinnableTargetComponentsContainer? componentsContainer)
public void Reload(Container? componentsContainer)
{
ClearInternal();
components.Clear();

View File

@ -72,7 +72,7 @@ public TrianglesSkin(SkinInfo skin, IStorageResourceProvider resources)
switch (target.Lookup)
{
case GlobalSkinComponentLookup.LookupType.SongSelect:
var songSelectComponents = new SkinnableTargetComponentsContainer(_ =>
var songSelectComponents = new DefaultSkinComponentsContainer(_ =>
{
// do stuff when we need to.
});
@ -80,7 +80,7 @@ public TrianglesSkin(SkinInfo skin, IStorageResourceProvider resources)
return songSelectComponents;
case GlobalSkinComponentLookup.LookupType.MainHUDComponents:
var skinnableTargetWrapper = new SkinnableTargetComponentsContainer(container =>
var skinnableTargetWrapper = new DefaultSkinComponentsContainer(container =>
{
var score = container.OfType<DefaultScoreCounter>().FirstOrDefault();
var accuracy = container.OfType<DefaultAccuracyCounter>().FirstOrDefault();