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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2021-07-06 07:40:23 +00:00
|
|
|
using System.Collections.Generic;
|
2021-07-06 07:41:48 +00:00
|
|
|
using System.Diagnostics;
|
2021-06-28 09:43:12 +00:00
|
|
|
using System.Linq;
|
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-24 07:07:38 +00:00
|
|
|
using osu.Framework.IO.Stores;
|
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-28 06:18:29 +00:00
|
|
|
private ResourceStoreBackedSkin rulesetResourcesSkin;
|
2021-06-28 06:11:28 +00:00
|
|
|
|
2021-06-25 06:55:29 +00:00
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
2021-06-09 17:41:16 +00:00
|
|
|
{
|
2021-06-28 06:11:28 +00:00
|
|
|
if (Ruleset.CreateResourceStore() is IResourceStore<byte[]> resources)
|
2021-06-28 08:16:26 +00:00
|
|
|
rulesetResourcesSkin = new ResourceStoreBackedSkin(resources, parent.Get<GameHost>(), parent.Get<AudioManager>());
|
|
|
|
|
2021-07-06 08:18:45 +00:00
|
|
|
return base.CreateChildDependencies(parent);
|
2021-06-09 17:41:16 +00:00
|
|
|
}
|
|
|
|
|
2021-10-12 04:04:48 +00:00
|
|
|
protected override void RefreshSources()
|
2021-06-09 17:41:16 +00:00
|
|
|
{
|
2021-07-06 08:18:45 +00:00
|
|
|
// Populate a local list first so we can adjust the returned order as we go.
|
|
|
|
var sources = new List<ISkin>();
|
2021-06-10 10:04:34 +00:00
|
|
|
|
2021-07-06 07:41:48 +00:00
|
|
|
Debug.Assert(ParentSource != null);
|
|
|
|
|
|
|
|
foreach (var skin in ParentSource.AllSources)
|
2021-06-21 01:16:58 +00:00
|
|
|
{
|
2021-06-22 07:19:55 +00:00
|
|
|
switch (skin)
|
|
|
|
{
|
|
|
|
case LegacySkin legacySkin:
|
2021-07-06 08:18:45 +00:00
|
|
|
sources.Add(GetLegacyRulesetTransformedSkin(legacySkin));
|
2021-06-22 07:19:55 +00:00
|
|
|
break;
|
2021-06-21 01:16:58 +00:00
|
|
|
|
2021-06-22 07:19:55 +00:00
|
|
|
default:
|
2021-07-06 08:18:45 +00:00
|
|
|
sources.Add(skin);
|
2021-06-22 07:19:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-06-21 01:16:58 +00:00
|
|
|
}
|
2021-06-22 17:38:24 +00:00
|
|
|
|
2021-07-06 08:18:45 +00:00
|
|
|
int lastDefaultSkinIndex = sources.IndexOf(sources.OfType<DefaultSkin>().LastOrDefault());
|
2021-06-24 07:07:38 +00:00
|
|
|
|
2021-06-28 06:38:42 +00:00
|
|
|
// Ruleset resources should be given the ability to override game-wide defaults
|
2021-06-28 09:43:12 +00:00
|
|
|
// This is achieved by placing them before the last instance of DefaultSkin.
|
2021-06-28 06:38:42 +00:00
|
|
|
// Note that DefaultSkin may not be present in some test scenes.
|
2021-06-28 09:43:12 +00:00
|
|
|
if (lastDefaultSkinIndex >= 0)
|
2021-07-06 08:18:45 +00:00
|
|
|
sources.Insert(lastDefaultSkinIndex, rulesetResourcesSkin);
|
2021-06-28 06:11:28 +00:00
|
|
|
else
|
2021-07-06 08:18:45 +00:00
|
|
|
sources.Add(rulesetResourcesSkin);
|
2021-07-06 07:40:23 +00:00
|
|
|
|
2021-10-12 02:55:04 +00:00
|
|
|
SetSources(sources);
|
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-28 06:11:28 +00:00
|
|
|
rulesetResourcesSkin?.Dispose();
|
2021-06-09 17:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|