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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2021-07-06 15:40:23 +08:00
|
|
|
using System.Collections.Generic;
|
2021-07-06 15:41:48 +08:00
|
|
|
using System.Diagnostics;
|
2021-06-28 17:43:12 +08:00
|
|
|
using System.Linq;
|
2021-06-10 18:41:41 +08:00
|
|
|
using JetBrains.Annotations;
|
2021-06-10 01:41:16 +08:00
|
|
|
using osu.Framework.Allocation;
|
2021-06-11 05:25:19 +08:00
|
|
|
using osu.Framework.Audio;
|
2021-06-10 01:41:16 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-06-24 15:07:38 +08:00
|
|
|
using osu.Framework.IO.Stores;
|
2021-06-11 05:25:19 +08:00
|
|
|
using osu.Framework.Platform;
|
2021-06-10 01:41:16 +08:00
|
|
|
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>
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class RulesetSkinProvidingContainer : SkinProvidingContainer
|
2021-06-10 01:41:16 +08:00
|
|
|
{
|
2021-06-10 20:05:08 +08:00
|
|
|
protected readonly Ruleset Ruleset;
|
|
|
|
protected readonly IBeatmap Beatmap;
|
2021-06-10 01:41:16 +08:00
|
|
|
|
2024-07-04 17:04:38 +08:00
|
|
|
[CanBeNull]
|
|
|
|
private readonly ISkin beatmapSkin;
|
|
|
|
|
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
|
|
|
|
2024-07-04 17:04:38 +08:00
|
|
|
protected override Container<Drawable> Content { get; } = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
};
|
2021-06-10 01:41:16 +08:00
|
|
|
|
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;
|
2024-07-04 17:04:38 +08:00
|
|
|
this.beatmapSkin = beatmapSkin;
|
|
|
|
}
|
2021-06-10 01:41:16 +08:00
|
|
|
|
2024-07-04 17:04:38 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(SkinManager skinManager)
|
|
|
|
{
|
|
|
|
InternalChild = new BeatmapSkinProvidingContainer(GetRulesetTransformedSkin(beatmapSkin), GetRulesetTransformedSkin(skinManager.DefaultClassicSkin))
|
2021-06-10 01:41:16 +08:00
|
|
|
{
|
2024-07-04 17:04:38 +08:00
|
|
|
Child = Content,
|
2021-06-10 01:41:16 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-28 14:18:29 +08:00
|
|
|
private ResourceStoreBackedSkin rulesetResourcesSkin;
|
2021-06-28 14:11:28 +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-28 14:11:28 +08:00
|
|
|
if (Ruleset.CreateResourceStore() is IResourceStore<byte[]> resources)
|
2021-06-28 16:16:26 +08:00
|
|
|
rulesetResourcesSkin = new ResourceStoreBackedSkin(resources, parent.Get<GameHost>(), parent.Get<AudioManager>());
|
|
|
|
|
2021-07-06 16:18:45 +08:00
|
|
|
return base.CreateChildDependencies(parent);
|
2021-06-10 01:41:16 +08:00
|
|
|
}
|
|
|
|
|
2021-10-12 12:04:48 +08:00
|
|
|
protected override void RefreshSources()
|
2021-06-10 01:41:16 +08:00
|
|
|
{
|
2021-07-06 16:18:45 +08:00
|
|
|
// Populate a local list first so we can adjust the returned order as we go.
|
|
|
|
var sources = new List<ISkin>();
|
2021-06-10 18:04:34 +08:00
|
|
|
|
2021-07-06 15:41:48 +08:00
|
|
|
Debug.Assert(ParentSource != null);
|
|
|
|
|
2022-09-15 16:36:14 +08:00
|
|
|
foreach (var source in ParentSource.AllSources)
|
2021-06-21 09:16:58 +08:00
|
|
|
{
|
2022-09-15 16:36:14 +08:00
|
|
|
switch (source)
|
2021-06-22 15:19:55 +08:00
|
|
|
{
|
2022-09-15 16:36:14 +08:00
|
|
|
case Skin skin:
|
|
|
|
sources.Add(GetRulesetTransformedSkin(skin));
|
2021-06-22 15:19:55 +08:00
|
|
|
break;
|
2021-06-21 09:16:58 +08:00
|
|
|
|
2021-06-22 15:19:55 +08:00
|
|
|
default:
|
2022-09-15 16:36:14 +08:00
|
|
|
sources.Add(source);
|
2021-06-22 15:19:55 +08:00
|
|
|
break;
|
|
|
|
}
|
2021-06-21 09:16:58 +08:00
|
|
|
}
|
2021-06-23 01:38:24 +08:00
|
|
|
|
2022-09-15 15:02:57 +08:00
|
|
|
// TODO: check
|
2022-09-17 23:14:49 +08:00
|
|
|
int lastDefaultSkinIndex = sources.IndexOf(sources.OfType<TrianglesSkin>().LastOrDefault());
|
2021-06-24 15:07:38 +08:00
|
|
|
|
2021-06-28 14:38:42 +08:00
|
|
|
// Ruleset resources should be given the ability to override game-wide defaults
|
2021-06-28 17:43:12 +08:00
|
|
|
// This is achieved by placing them before the last instance of DefaultSkin.
|
2021-06-28 14:38:42 +08:00
|
|
|
// Note that DefaultSkin may not be present in some test scenes.
|
2021-06-28 17:43:12 +08:00
|
|
|
if (lastDefaultSkinIndex >= 0)
|
2021-07-06 16:18:45 +08:00
|
|
|
sources.Insert(lastDefaultSkinIndex, rulesetResourcesSkin);
|
2021-06-28 14:11:28 +08:00
|
|
|
else
|
2021-07-06 16:18:45 +08:00
|
|
|
sources.Add(rulesetResourcesSkin);
|
2021-07-06 15:40:23 +08:00
|
|
|
|
2021-10-12 10:55:04 +08:00
|
|
|
SetSources(sources);
|
2021-06-11 21:26:53 +08:00
|
|
|
}
|
|
|
|
|
2022-09-15 16:36:14 +08:00
|
|
|
protected ISkin GetRulesetTransformedSkin(ISkin skin)
|
2021-06-11 21:26:53 +08:00
|
|
|
{
|
2022-09-15 16:36:14 +08:00
|
|
|
if (skin == null)
|
2021-06-21 09:16:58 +08:00
|
|
|
return null;
|
2021-06-11 21:26:53 +08:00
|
|
|
|
2022-09-15 16:36:14 +08:00
|
|
|
var rulesetTransformed = Ruleset.CreateSkinTransformer(skin, Beatmap);
|
2021-06-11 21:26:53 +08:00
|
|
|
if (rulesetTransformed != null)
|
|
|
|
return rulesetTransformed;
|
2021-06-10 18:04:34 +08:00
|
|
|
|
2022-09-15 16:36:14 +08:00
|
|
|
return skin;
|
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-10 18:04:34 +08:00
|
|
|
|
2021-06-28 14:11:28 +08:00
|
|
|
rulesetResourcesSkin?.Dispose();
|
2021-06-10 01:41:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|