2021-06-10 01:41:16 +08:00
|
|
|
// 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.
|
|
|
|
|
2021-06-10 18:41:41 +08:00
|
|
|
using JetBrains.Annotations;
|
2021-06-10 01:41:16 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Rulesets;
|
2021-06-22 07:52:37 +08:00
|
|
|
using osu.Game.Rulesets.UI;
|
2021-06-10 01:41:16 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
{
|
|
|
|
/// <summary>
|
2021-06-22 07:52:37 +08:00
|
|
|
/// A type of <see cref="SkinProvidingContainer"/> specialized for <see cref="DrawableRuleset"/> and other gameplay-related components.
|
2021-06-22 17:05:17 +08:00
|
|
|
/// Providing access to parent skin sources and the beatmap skin each surrounded with the ruleset legacy skin transformer.
|
2021-06-10 01:41:16 +08:00
|
|
|
/// </summary>
|
|
|
|
public class RulesetSkinProvidingContainer : SkinProvidingContainer
|
|
|
|
{
|
2021-06-10 20:05:08 +08:00
|
|
|
protected readonly Ruleset Ruleset;
|
|
|
|
protected readonly IBeatmap Beatmap;
|
2021-06-10 01:41:16 +08:00
|
|
|
|
2021-06-22 07:52:37 +08:00
|
|
|
/// <remarks>
|
2021-06-22 17:05:17 +08:00
|
|
|
/// This container already re-exposes all parent <see cref="ISkinSource"/> sources in a ruleset-usable form.
|
2021-06-22 07:52:37 +08:00
|
|
|
/// Therefore disallow falling back to any parent <see cref="ISkinSource"/> any further.
|
|
|
|
/// </remarks>
|
|
|
|
protected override bool AllowFallingBackToParent => false;
|
2021-06-22 15:20:09 +08:00
|
|
|
|
2021-06-10 01:41:16 +08:00
|
|
|
protected override Container<Drawable> Content { get; }
|
|
|
|
|
2021-06-10 18:41:41 +08:00
|
|
|
public RulesetSkinProvidingContainer(Ruleset ruleset, IBeatmap beatmap, [CanBeNull] ISkin beatmapSkin)
|
2021-06-10 01:41:16 +08:00
|
|
|
{
|
2021-06-10 20:05:08 +08:00
|
|
|
Ruleset = ruleset;
|
|
|
|
Beatmap = beatmap;
|
2021-06-10 01:41:16 +08:00
|
|
|
|
2021-06-21 09:16:58 +08:00
|
|
|
InternalChild = new BeatmapSkinProvidingContainer(beatmapSkin is LegacySkin ? GetLegacyRulesetTransformedSkin(beatmapSkin) : beatmapSkin)
|
2021-06-10 01:41:16 +08:00
|
|
|
{
|
|
|
|
Child = Content = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-25 14:55:29 +08:00
|
|
|
private ISkinSource parentSource;
|
2021-06-10 01:41:16 +08:00
|
|
|
|
2021-06-25 14:55:29 +08:00
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
2021-06-10 01:41:16 +08:00
|
|
|
{
|
2021-06-25 14:55:29 +08:00
|
|
|
parentSource = parent.Get<ISkinSource>();
|
2021-06-28 13:39:55 +08:00
|
|
|
parentSource.SourceChanged += OnSourceChanged;
|
2021-06-25 14:55:29 +08:00
|
|
|
|
2021-06-28 13:39:55 +08:00
|
|
|
// ensure sources are populated and ready for use before childrens' asynchronous load flow.
|
2021-06-25 14:55:29 +08:00
|
|
|
UpdateSkinSources();
|
|
|
|
|
|
|
|
return base.CreateChildDependencies(parent);
|
2021-06-22 08:44:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnSourceChanged()
|
|
|
|
{
|
2021-06-25 14:55:29 +08:00
|
|
|
UpdateSkinSources();
|
2021-06-22 08:44:32 +08:00
|
|
|
base.OnSourceChanged();
|
2021-06-10 01:41:16 +08:00
|
|
|
}
|
|
|
|
|
2021-06-25 14:55:29 +08:00
|
|
|
protected virtual void UpdateSkinSources()
|
2021-06-10 01:41:16 +08:00
|
|
|
{
|
2021-06-10 16:55:22 +08:00
|
|
|
SkinSources.Clear();
|
2021-06-10 18:04:34 +08:00
|
|
|
|
2021-06-25 14:55:29 +08:00
|
|
|
foreach (var skin in parentSource.AllSources)
|
2021-06-21 09:16:58 +08:00
|
|
|
{
|
2021-06-22 15:19:55 +08:00
|
|
|
switch (skin)
|
|
|
|
{
|
|
|
|
case LegacySkin legacySkin:
|
|
|
|
SkinSources.Add(GetLegacyRulesetTransformedSkin(legacySkin));
|
|
|
|
break;
|
2021-06-21 09:16:58 +08:00
|
|
|
|
2021-06-22 15:19:55 +08:00
|
|
|
default:
|
|
|
|
SkinSources.Add(skin);
|
|
|
|
break;
|
|
|
|
}
|
2021-06-21 09:16:58 +08:00
|
|
|
}
|
2021-06-11 21:26:53 +08:00
|
|
|
}
|
|
|
|
|
2021-06-21 09:16:58 +08:00
|
|
|
protected ISkin GetLegacyRulesetTransformedSkin(ISkin legacySkin)
|
2021-06-11 21:26:53 +08:00
|
|
|
{
|
2021-06-21 09:16:58 +08:00
|
|
|
if (legacySkin == null)
|
|
|
|
return null;
|
2021-06-11 21:26:53 +08:00
|
|
|
|
2021-06-21 09:16:58 +08:00
|
|
|
var rulesetTransformed = Ruleset.CreateLegacySkinProvider(legacySkin, Beatmap);
|
2021-06-11 21:26:53 +08:00
|
|
|
if (rulesetTransformed != null)
|
|
|
|
return rulesetTransformed;
|
|
|
|
|
2021-06-21 09:16:58 +08:00
|
|
|
return legacySkin;
|
2021-06-10 01:41:16 +08:00
|
|
|
}
|
2021-06-22 07:52:37 +08:00
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
2021-06-25 14:55:29 +08:00
|
|
|
if (parentSource != null)
|
|
|
|
parentSource.SourceChanged -= OnSourceChanged;
|
2021-06-22 07:52:37 +08:00
|
|
|
}
|
2021-06-10 01:41:16 +08:00
|
|
|
}
|
|
|
|
}
|