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.
|
|
|
|
/// Providing access to the <see cref="SkinManager"/> skin sources and the beatmap skin each surrounded with the ruleset legacy skin transformer.
|
|
|
|
/// While also limiting lookups from falling back to any parent <see cref="ISkinSource"/>s out of this container.
|
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>
|
|
|
|
/// This container already re-exposes all <see cref="SkinManager"/> skin sources in a ruleset-usable form.
|
|
|
|
/// Therefore disallow falling back to any parent <see cref="ISkinSource"/> any further.
|
|
|
|
/// </remarks>
|
|
|
|
protected override bool AllowFallingBackToParent => false;
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private SkinManager skinManager { get; set; }
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2021-06-10 20:05:08 +08:00
|
|
|
UpdateSkins();
|
2021-06-22 08:44:32 +08:00
|
|
|
skinManager.SourceChanged += OnSourceChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnSourceChanged()
|
|
|
|
{
|
|
|
|
UpdateSkins();
|
|
|
|
base.OnSourceChanged();
|
2021-06-10 01:41:16 +08:00
|
|
|
}
|
|
|
|
|
2021-06-10 20:05:08 +08:00
|
|
|
protected virtual void UpdateSkins()
|
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-21 09:16:58 +08:00
|
|
|
// TODO: we also want to insert a DefaultLegacySkin here if the current *beatmap* is providing any skinned elements.
|
2021-06-10 18:04:34 +08:00
|
|
|
|
2021-06-21 09:16:58 +08:00
|
|
|
switch (skinManager.CurrentSkin.Value)
|
|
|
|
{
|
|
|
|
case LegacySkin currentLegacySkin:
|
|
|
|
SkinSources.Add(GetLegacyRulesetTransformedSkin(currentLegacySkin));
|
|
|
|
|
|
|
|
if (currentLegacySkin != skinManager.DefaultLegacySkin)
|
|
|
|
SkinSources.Add(GetLegacyRulesetTransformedSkin(skinManager.DefaultLegacySkin));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
SkinSources.Add(skinManager.CurrentSkin.Value);
|
|
|
|
break;
|
|
|
|
}
|
2021-06-22 07:54:34 +08:00
|
|
|
|
2021-06-22 08:45:43 +08:00
|
|
|
if (skinManager.CurrentSkin.Value != skinManager.DefaultSkin)
|
|
|
|
SkinSources.Add(skinManager.DefaultSkin);
|
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);
|
|
|
|
|
|
|
|
if (skinManager != null)
|
2021-06-22 10:05:41 +08:00
|
|
|
skinManager.SourceChanged -= OnSourceChanged;
|
2021-06-22 07:52:37 +08:00
|
|
|
}
|
2021-06-10 01:41:16 +08:00
|
|
|
}
|
|
|
|
}
|