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

Rename SkinnableTarget to GlobalSkinLookup

This commit is contained in:
Dean Herbert 2022-11-09 16:03:29 +09:00
parent c908969d9b
commit e75c3b3f94
17 changed files with 68 additions and 68 deletions

View File

@ -27,11 +27,11 @@ namespace osu.Game.Rulesets.Catch.Skinning.Legacy
public override Drawable? GetDrawableComponent(ISkinLookup lookup)
{
if (lookup is SkinnableTargetLookup targetComponent)
if (lookup is GlobalSkinLookup targetComponent)
{
switch (targetComponent.Target)
switch (targetComponent.Lookup)
{
case SkinnableTarget.MainHUDComponents:
case GlobalSkinLookup.LookupType.MainHUDComponents:
var components = base.GetDrawableComponent(lookup) as SkinnableTargetComponentsContainer;
if (providesComboCounter && components != null)

View File

@ -80,7 +80,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[SkinnableTarget.MainHUDComponents], Has.Length.EqualTo(9));
Assert.That(skin.DrawableComponentInfo[GlobalSkinLookup.LookupType.MainHUDComponents], Has.Length.EqualTo(9));
}
}
@ -93,10 +93,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[SkinnableTarget.MainHUDComponents], Has.Length.EqualTo(6));
Assert.That(skin.DrawableComponentInfo[SkinnableTarget.SongSelect], Has.Length.EqualTo(1));
Assert.That(skin.DrawableComponentInfo[GlobalSkinLookup.LookupType.MainHUDComponents], Has.Length.EqualTo(6));
Assert.That(skin.DrawableComponentInfo[GlobalSkinLookup.LookupType.SongSelect], Has.Length.EqualTo(1));
var skinnableInfo = skin.DrawableComponentInfo[SkinnableTarget.SongSelect].First();
var skinnableInfo = skin.DrawableComponentInfo[GlobalSkinLookup.LookupType.SongSelect].First();
Assert.That(skinnableInfo.Type, Is.EqualTo(typeof(SkinnableSprite)));
Assert.That(skinnableInfo.Settings.First().Key, Is.EqualTo("sprite_name"));
@ -107,10 +107,10 @@ namespace osu.Game.Tests.Skins
using (var storage = new ZipArchiveReader(stream))
{
var skin = new TestSkin(new SkinInfo(), null, storage);
Assert.That(skin.DrawableComponentInfo[SkinnableTarget.MainHUDComponents], Has.Length.EqualTo(8));
Assert.That(skin.DrawableComponentInfo[SkinnableTarget.MainHUDComponents].Select(i => i.Type), Contains.Item(typeof(UnstableRateCounter)));
Assert.That(skin.DrawableComponentInfo[SkinnableTarget.MainHUDComponents].Select(i => i.Type), Contains.Item(typeof(ColourHitErrorMeter)));
Assert.That(skin.DrawableComponentInfo[SkinnableTarget.MainHUDComponents].Select(i => i.Type), Contains.Item(typeof(LegacySongProgress)));
Assert.That(skin.DrawableComponentInfo[GlobalSkinLookup.LookupType.MainHUDComponents], Has.Length.EqualTo(8));
Assert.That(skin.DrawableComponentInfo[GlobalSkinLookup.LookupType.MainHUDComponents].Select(i => i.Type), Contains.Item(typeof(UnstableRateCounter)));
Assert.That(skin.DrawableComponentInfo[GlobalSkinLookup.LookupType.MainHUDComponents].Select(i => i.Type), Contains.Item(typeof(ColourHitErrorMeter)));
Assert.That(skin.DrawableComponentInfo[GlobalSkinLookup.LookupType.MainHUDComponents].Select(i => i.Type), Contains.Item(typeof(LegacySongProgress)));
}
}

View File

@ -40,7 +40,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
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(SkinnableTarget.MainHUDComponents, skinManager.CurrentSkin.Value));
AddAssert("hud from default skin", () => AssertComponentsFromExpectedSource(GlobalSkinLookup.LookupType.MainHUDComponents, skinManager.CurrentSkin.Value));
}
protected void CreateSkinTest(SkinInfo gameCurrentSkin, Func<ISkin> getBeatmapSkin)
@ -55,7 +55,7 @@ namespace osu.Game.Tests.Visual.Gameplay
});
}
protected bool AssertComponentsFromExpectedSource(SkinnableTarget target, ISkin expectedSource)
protected bool AssertComponentsFromExpectedSource(GlobalSkinLookup.LookupType target, ISkin expectedSource)
{
var actualComponentsContainer = Player.ChildrenOfType<SkinnableTargetContainer>().First(s => s.Target == target)
.ChildrenOfType<SkinnableTargetComponentsContainer>().SingleOrDefault();
@ -65,7 +65,7 @@ namespace osu.Game.Tests.Visual.Gameplay
var actualInfo = actualComponentsContainer.CreateSkinnableInfo();
var expectedComponentsContainer = (SkinnableTargetComponentsContainer)expectedSource.GetDrawableComponent(new SkinnableTargetLookup(target));
var expectedComponentsContainer = (SkinnableTargetComponentsContainer)expectedSource.GetDrawableComponent(new GlobalSkinLookup(target));
if (expectedComponentsContainer == null)
return false;

View File

@ -391,7 +391,7 @@ namespace osu.Game.Screens.Play
private OsuConfigManager config { get; set; }
public MainComponentsContainer()
: base(SkinnableTarget.MainHUDComponents)
: base(GlobalSkinLookup.LookupType.MainHUDComponents)
{
RelativeSizeAxes = Axes.Both;
}

View File

@ -250,7 +250,7 @@ namespace osu.Game.Screens.Select
}
}
},
new SkinnableTargetContainer(SkinnableTarget.SongSelect)
new SkinnableTargetContainer(GlobalSkinLookup.LookupType.SongSelect)
{
RelativeSizeAxes = Axes.Both,
},

View File

@ -88,10 +88,10 @@ namespace osu.Game.Skinning
switch (lookup)
{
case SkinnableTargetLookup target:
switch (target.Target)
case GlobalSkinLookup globalLookup:
switch (globalLookup.Lookup)
{
case SkinnableTarget.SongSelect:
case GlobalSkinLookup.LookupType.SongSelect:
var songSelectComponents = new SkinnableTargetComponentsContainer(_ =>
{
// do stuff when we need to.
@ -99,7 +99,7 @@ namespace osu.Game.Skinning
return songSelectComponents;
case SkinnableTarget.MainHUDComponents:
case GlobalSkinLookup.LookupType.MainHUDComponents:
var skinnableTargetWrapper = new SkinnableTargetComponentsContainer(container =>
{
var score = container.OfType<DefaultScoreCounter>().FirstOrDefault();

View File

@ -314,7 +314,7 @@ namespace osu.Game.Skinning.Editor
private ISkinnableTarget getFirstTarget() => availableTargets.FirstOrDefault();
private ISkinnableTarget getTarget(SkinnableTarget target)
private ISkinnableTarget getTarget(GlobalSkinLookup.LookupType target)
{
return availableTargets.FirstOrDefault(c => c.Target == target);
}

View File

@ -0,0 +1,23 @@
// 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.
namespace osu.Game.Skinning
{
public class GlobalSkinLookup : ISkinLookup
{
public readonly LookupType Lookup;
public string LookupName => Lookup.ToString();
public GlobalSkinLookup(LookupType lookup)
{
Lookup = lookup;
}
public enum LookupType
{
MainHUDComponents,
SongSelect
}
}
}

View File

@ -5,12 +5,17 @@ using System;
using osu.Framework.Bindables;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics;
using osu.Game.Configuration;
namespace osu.Game.Skinning
{
/// <summary>
/// Denotes a drawable which, as a drawable, can be adjusted via skinning specifications.
/// </summary>
/// <remarks>
/// Attaching this interface to any <see cref="IDrawable"/> will make it serialisable to skin settings.
/// Adding <see cref="SettingSourceAttribute"/> annotated bindables will also serialise these settings alongside each instance.
/// </remarks>
public interface ISkinnableDrawable : IDrawable
{
/// <summary>

View File

@ -18,7 +18,7 @@ namespace osu.Game.Skinning
/// <summary>
/// The definition of this target.
/// </summary>
SkinnableTarget Target { get; }
GlobalSkinLookup.LookupType Target { get; }
/// <summary>
/// A bindable list of components which are being tracked by this skinnable target.

View File

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

@ -329,10 +329,10 @@ namespace osu.Game.Skinning
switch (lookup)
{
case SkinnableTargetLookup target:
switch (target.Target)
case GlobalSkinLookup target:
switch (target.Lookup)
{
case SkinnableTarget.MainHUDComponents:
case GlobalSkinLookup.LookupType.MainHUDComponents:
var skinnableTargetWrapper = new SkinnableTargetComponentsContainer(container =>
{
var score = container.OfType<LegacyScoreCounter>().FirstOrDefault();

View File

@ -37,9 +37,9 @@ namespace osu.Game.Skinning
public SkinConfiguration Configuration { get; set; }
public IDictionary<SkinnableTarget, SkinnableInfo[]> DrawableComponentInfo => drawableComponentInfo;
public IDictionary<GlobalSkinLookup.LookupType, SkinnableInfo[]> DrawableComponentInfo => drawableComponentInfo;
private readonly Dictionary<SkinnableTarget, SkinnableInfo[]> drawableComponentInfo = new Dictionary<SkinnableTarget, SkinnableInfo[]>();
private readonly Dictionary<GlobalSkinLookup.LookupType, SkinnableInfo[]> drawableComponentInfo = new Dictionary<GlobalSkinLookup.LookupType, SkinnableInfo[]>();
public abstract ISample? GetSample(ISampleInfo sampleInfo);
@ -97,7 +97,7 @@ namespace osu.Game.Skinning
Configuration = new SkinConfiguration();
// skininfo files may be null for default skin.
foreach (SkinnableTarget skinnableTarget in Enum.GetValues(typeof(SkinnableTarget)))
foreach (GlobalSkinLookup.LookupType skinnableTarget in Enum.GetValues(typeof(GlobalSkinLookup.LookupType)))
{
string filename = $"{skinnableTarget}.json";
@ -158,8 +158,8 @@ namespace osu.Game.Skinning
{
switch (lookup)
{
case SkinnableTargetLookup target:
if (!DrawableComponentInfo.TryGetValue(target.Target, out var skinnableInfo))
case GlobalSkinLookup target:
if (!DrawableComponentInfo.TryGetValue(target.Lookup, out var skinnableInfo))
return null;
var components = new List<Drawable>();

View File

@ -1,11 +0,0 @@
// 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.
namespace osu.Game.Skinning
{
public enum SkinnableTarget
{
MainHUDComponents,
SongSelect
}
}

View File

@ -13,7 +13,7 @@ namespace osu.Game.Skinning
{
private SkinnableTargetComponentsContainer? content;
public SkinnableTarget Target { get; }
public GlobalSkinLookup.LookupType Target { get; }
public IBindableList<ISkinnableDrawable> Components => components;
@ -25,7 +25,7 @@ namespace osu.Game.Skinning
private CancellationTokenSource? cancellationSource;
public SkinnableTargetContainer(SkinnableTarget target)
public SkinnableTargetContainer(GlobalSkinLookup.LookupType target)
{
Target = target;
}
@ -39,7 +39,7 @@ namespace osu.Game.Skinning
components.Clear();
ComponentsLoaded = false;
content = CurrentSkin.GetDrawableComponent(new SkinnableTargetLookup(Target)) as SkinnableTargetComponentsContainer;
content = CurrentSkin.GetDrawableComponent(new GlobalSkinLookup(Target)) as SkinnableTargetComponentsContainer;
cancellationSource?.Cancel();
cancellationSource = null;

View File

@ -1,17 +0,0 @@
// 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.
namespace osu.Game.Skinning
{
public class SkinnableTargetLookup : ISkinLookup
{
public readonly SkinnableTarget Target;
public string LookupName => Target.ToString();
public SkinnableTargetLookup(SkinnableTarget target)
{
Target = target;
}
}
}

View File

@ -66,10 +66,10 @@ namespace osu.Game.Skinning
switch (lookup)
{
case SkinnableTargetLookup target:
switch (target.Target)
case GlobalSkinLookup target:
switch (target.Lookup)
{
case SkinnableTarget.SongSelect:
case GlobalSkinLookup.LookupType.SongSelect:
var songSelectComponents = new SkinnableTargetComponentsContainer(_ =>
{
// do stuff when we need to.
@ -77,7 +77,7 @@ namespace osu.Game.Skinning
return songSelectComponents;
case SkinnableTarget.MainHUDComponents:
case GlobalSkinLookup.LookupType.MainHUDComponents:
var skinnableTargetWrapper = new SkinnableTargetComponentsContainer(container =>
{
var score = container.OfType<DefaultScoreCounter>().FirstOrDefault();