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