2019-08-26 11:21:11 +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.
|
|
|
|
|
2020-09-23 12:16:46 +08:00
|
|
|
using System;
|
2019-08-26 11:21:11 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2019-08-28 15:36:20 +08:00
|
|
|
using osu.Game.Audio;
|
2019-08-26 11:21:11 +08:00
|
|
|
using osu.Game.Configuration;
|
2021-12-26 21:25:28 +08:00
|
|
|
using osu.Game.Storyboards;
|
2019-08-26 11:21:11 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A container which overrides existing skin options with beatmap-local values.
|
|
|
|
/// </summary>
|
2020-09-01 00:29:46 +08:00
|
|
|
public partial class BeatmapSkinProvidingContainer : SkinProvidingContainer
|
2019-08-26 11:21:11 +08:00
|
|
|
{
|
2024-07-04 17:04:38 +08:00
|
|
|
private Bindable<bool> beatmapSkins = null!;
|
|
|
|
private Bindable<bool> beatmapColours = null!;
|
|
|
|
private Bindable<bool> beatmapHitsounds = null!;
|
2019-08-26 11:21:11 +08:00
|
|
|
|
2020-09-23 12:16:46 +08:00
|
|
|
protected override bool AllowConfigurationLookup
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (beatmapSkins == null)
|
|
|
|
throw new InvalidOperationException($"{nameof(BeatmapSkinProvidingContainer)} needs to be loaded before being consumed.");
|
2021-01-14 02:07:07 +08:00
|
|
|
|
|
|
|
return beatmapSkins.Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool AllowColourLookup
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (beatmapColours == null)
|
|
|
|
throw new InvalidOperationException($"{nameof(BeatmapSkinProvidingContainer)} needs to be loaded before being consumed.");
|
2020-09-23 12:16:46 +08:00
|
|
|
|
2021-01-13 13:09:22 +08:00
|
|
|
return beatmapColours.Value;
|
2020-09-23 12:16:46 +08:00
|
|
|
}
|
|
|
|
}
|
2021-01-13 13:25:54 +08:00
|
|
|
|
2022-11-09 15:04:56 +08:00
|
|
|
protected override bool AllowDrawableLookup(ISkinComponentLookup lookup)
|
2020-09-23 12:16:46 +08:00
|
|
|
{
|
|
|
|
if (beatmapSkins == null)
|
|
|
|
throw new InvalidOperationException($"{nameof(BeatmapSkinProvidingContainer)} needs to be loaded before being consumed.");
|
|
|
|
|
|
|
|
return beatmapSkins.Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool AllowTextureLookup(string componentName)
|
|
|
|
{
|
|
|
|
if (beatmapSkins == null)
|
|
|
|
throw new InvalidOperationException($"{nameof(BeatmapSkinProvidingContainer)} needs to be loaded before being consumed.");
|
|
|
|
|
|
|
|
return beatmapSkins.Value;
|
|
|
|
}
|
|
|
|
|
2021-12-26 21:29:07 +08:00
|
|
|
protected override bool AllowSampleLookup(ISampleInfo sampleInfo)
|
2020-09-23 12:16:46 +08:00
|
|
|
{
|
|
|
|
if (beatmapSkins == null)
|
|
|
|
throw new InvalidOperationException($"{nameof(BeatmapSkinProvidingContainer)} needs to be loaded before being consumed.");
|
|
|
|
|
2021-12-26 21:29:07 +08:00
|
|
|
return sampleInfo is StoryboardSampleInfo || beatmapHitsounds.Value;
|
2020-09-23 12:16:46 +08:00
|
|
|
}
|
2019-08-26 11:21:11 +08:00
|
|
|
|
2022-10-12 16:47:20 +08:00
|
|
|
private readonly ISkin skin;
|
2024-07-04 17:04:38 +08:00
|
|
|
private readonly ISkin? classicFallback;
|
|
|
|
|
|
|
|
private Bindable<Skin> currentSkin = null!;
|
2022-10-12 16:47:20 +08:00
|
|
|
|
2024-07-04 17:04:38 +08:00
|
|
|
public BeatmapSkinProvidingContainer(ISkin skin, ISkin? classicFallback = null)
|
2019-08-26 11:21:11 +08:00
|
|
|
: base(skin)
|
|
|
|
{
|
2022-10-12 16:47:20 +08:00
|
|
|
this.skin = skin;
|
2024-07-04 17:04:38 +08:00
|
|
|
this.classicFallback = classicFallback;
|
2019-08-26 11:21:11 +08:00
|
|
|
}
|
|
|
|
|
2020-09-23 12:16:46 +08:00
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
2019-08-26 11:21:11 +08:00
|
|
|
{
|
2020-09-23 12:16:46 +08:00
|
|
|
var config = parent.Get<OsuConfigManager>();
|
2019-08-26 11:21:11 +08:00
|
|
|
|
2020-09-23 12:16:46 +08:00
|
|
|
beatmapSkins = config.GetBindable<bool>(OsuSetting.BeatmapSkins);
|
2021-01-13 13:09:22 +08:00
|
|
|
beatmapColours = config.GetBindable<bool>(OsuSetting.BeatmapColours);
|
2020-09-23 12:16:46 +08:00
|
|
|
beatmapHitsounds = config.GetBindable<bool>(OsuSetting.BeatmapHitsounds);
|
|
|
|
|
|
|
|
return base.CreateChildDependencies(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2022-10-12 16:47:20 +08:00
|
|
|
private void load(SkinManager skins)
|
2020-09-23 12:16:46 +08:00
|
|
|
{
|
2021-07-06 16:37:34 +08:00
|
|
|
beatmapSkins.BindValueChanged(_ => TriggerSourceChanged());
|
|
|
|
beatmapColours.BindValueChanged(_ => TriggerSourceChanged());
|
|
|
|
beatmapHitsounds.BindValueChanged(_ => TriggerSourceChanged());
|
2022-10-12 16:47:20 +08:00
|
|
|
|
2024-07-04 17:04:38 +08:00
|
|
|
currentSkin = skins.CurrentSkin.GetBoundCopy();
|
|
|
|
currentSkin.BindValueChanged(_ =>
|
2022-10-12 16:47:20 +08:00
|
|
|
{
|
2024-07-04 17:04:38 +08:00
|
|
|
bool userSkinIsLegacy = skins.CurrentSkin.Value is LegacySkin;
|
|
|
|
bool beatmapProvidingResources = skin is LegacySkinTransformer legacySkin && legacySkin.IsProvidingLegacyResources;
|
|
|
|
|
|
|
|
// If the beatmap skin looks to have skinnable resources and the user's skin choice is not a legacy skin,
|
|
|
|
// add the default classic skin as a fallback opportunity.
|
|
|
|
if (!userSkinIsLegacy && beatmapProvidingResources && classicFallback != null)
|
|
|
|
SetSources(new[] { skin, classicFallback });
|
|
|
|
else
|
|
|
|
SetSources(new[] { skin });
|
|
|
|
}, true);
|
2019-08-26 11:21:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|