Fix classic fallback not having a transformer (and only add if required)

This commit is contained in:
Dean Herbert 2024-07-04 18:04:38 +09:00
parent a4c575f77a
commit b2af49c102
No known key found for this signature in database
2 changed files with 34 additions and 20 deletions

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -17,9 +15,9 @@ namespace osu.Game.Skinning
/// </summary> /// </summary>
public partial class BeatmapSkinProvidingContainer : SkinProvidingContainer public partial class BeatmapSkinProvidingContainer : SkinProvidingContainer
{ {
private Bindable<bool> beatmapSkins; private Bindable<bool> beatmapSkins = null!;
private Bindable<bool> beatmapColours; private Bindable<bool> beatmapColours = null!;
private Bindable<bool> beatmapHitsounds; private Bindable<bool> beatmapHitsounds = null!;
protected override bool AllowConfigurationLookup protected override bool AllowConfigurationLookup
{ {
@ -68,11 +66,15 @@ namespace osu.Game.Skinning
} }
private readonly ISkin skin; private readonly ISkin skin;
private readonly ISkin? classicFallback;
public BeatmapSkinProvidingContainer(ISkin skin) private Bindable<Skin> currentSkin = null!;
public BeatmapSkinProvidingContainer(ISkin skin, ISkin? classicFallback = null)
: base(skin) : base(skin)
{ {
this.skin = skin; this.skin = skin;
this.classicFallback = classicFallback;
} }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
@ -93,15 +95,19 @@ namespace osu.Game.Skinning
beatmapColours.BindValueChanged(_ => TriggerSourceChanged()); beatmapColours.BindValueChanged(_ => TriggerSourceChanged());
beatmapHitsounds.BindValueChanged(_ => TriggerSourceChanged()); beatmapHitsounds.BindValueChanged(_ => TriggerSourceChanged());
// If the beatmap skin looks to have skinnable resources, add the default classic skin as a fallback opportunity. currentSkin = skins.CurrentSkin.GetBoundCopy();
if (skin is LegacySkinTransformer legacySkin && legacySkin.IsProvidingLegacyResources) currentSkin.BindValueChanged(_ =>
{ {
SetSources(new[] bool userSkinIsLegacy = skins.CurrentSkin.Value is LegacySkin;
{ bool beatmapProvidingResources = skin is LegacySkinTransformer legacySkin && legacySkin.IsProvidingLegacyResources;
skin,
skins.DefaultClassicSkin // If the beatmap skin looks to have skinnable resources and the user's skin choice is not a legacy skin,
}); // add the default classic skin as a fallback opportunity.
} if (!userSkinIsLegacy && beatmapProvidingResources && classicFallback != null)
SetSources(new[] { skin, classicFallback });
else
SetSources(new[] { skin });
}, true);
} }
} }
} }

View File

@ -28,25 +28,33 @@ namespace osu.Game.Skinning
protected readonly Ruleset Ruleset; protected readonly Ruleset Ruleset;
protected readonly IBeatmap Beatmap; protected readonly IBeatmap Beatmap;
[CanBeNull]
private readonly ISkin beatmapSkin;
/// <remarks> /// <remarks>
/// This container already re-exposes all parent <see cref="ISkinSource"/> sources in a ruleset-usable form. /// This container already re-exposes all parent <see cref="ISkinSource"/> sources in a ruleset-usable form.
/// Therefore disallow falling back to any parent <see cref="ISkinSource"/> any further. /// Therefore disallow falling back to any parent <see cref="ISkinSource"/> any further.
/// </remarks> /// </remarks>
protected override bool AllowFallingBackToParent => false; protected override bool AllowFallingBackToParent => false;
protected override Container<Drawable> Content { get; } protected override Container<Drawable> Content { get; } = new Container
{
RelativeSizeAxes = Axes.Both,
};
public RulesetSkinProvidingContainer(Ruleset ruleset, IBeatmap beatmap, [CanBeNull] ISkin beatmapSkin) public RulesetSkinProvidingContainer(Ruleset ruleset, IBeatmap beatmap, [CanBeNull] ISkin beatmapSkin)
{ {
Ruleset = ruleset; Ruleset = ruleset;
Beatmap = beatmap; Beatmap = beatmap;
this.beatmapSkin = beatmapSkin;
}
InternalChild = new BeatmapSkinProvidingContainer(GetRulesetTransformedSkin(beatmapSkin)) [BackgroundDependencyLoader]
private void load(SkinManager skinManager)
{
InternalChild = new BeatmapSkinProvidingContainer(GetRulesetTransformedSkin(beatmapSkin), GetRulesetTransformedSkin(skinManager.DefaultClassicSkin))
{ {
Child = Content = new Container Child = Content,
{
RelativeSizeAxes = Axes.Both,
}
}; };
} }