2019-08-26 03:21:11 +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.
|
|
|
|
|
2020-09-23 04:16:46 +00:00
|
|
|
using System;
|
2019-08-26 03:21:11 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2019-08-28 07:36:20 +00:00
|
|
|
using osu.Game.Audio;
|
2019-08-26 03:21:11 +00:00
|
|
|
using osu.Game.Configuration;
|
2021-12-26 13:25:28 +00:00
|
|
|
using osu.Game.Storyboards;
|
2019-08-26 03:21:11 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A container which overrides existing skin options with beatmap-local values.
|
|
|
|
/// </summary>
|
2020-08-31 16:29:46 +00:00
|
|
|
public partial class BeatmapSkinProvidingContainer : SkinProvidingContainer
|
2019-08-26 03:21:11 +00:00
|
|
|
{
|
2024-07-04 09:04:38 +00:00
|
|
|
private Bindable<bool> beatmapSkins = null!;
|
|
|
|
private Bindable<bool> beatmapColours = null!;
|
|
|
|
private Bindable<bool> beatmapHitsounds = null!;
|
2019-08-26 03:21:11 +00:00
|
|
|
|
2020-09-23 04:16:46 +00:00
|
|
|
protected override bool AllowConfigurationLookup
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (beatmapSkins == null)
|
|
|
|
throw new InvalidOperationException($"{nameof(BeatmapSkinProvidingContainer)} needs to be loaded before being consumed.");
|
2021-01-13 18:07:07 +00: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 04:16:46 +00:00
|
|
|
|
2021-01-13 05:09:22 +00:00
|
|
|
return beatmapColours.Value;
|
2020-09-23 04:16:46 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-13 05:25:54 +00:00
|
|
|
|
2022-11-09 07:04:56 +00:00
|
|
|
protected override bool AllowDrawableLookup(ISkinComponentLookup lookup)
|
2020-09-23 04:16:46 +00: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 13:29:07 +00:00
|
|
|
protected override bool AllowSampleLookup(ISampleInfo sampleInfo)
|
2020-09-23 04:16:46 +00:00
|
|
|
{
|
|
|
|
if (beatmapSkins == null)
|
|
|
|
throw new InvalidOperationException($"{nameof(BeatmapSkinProvidingContainer)} needs to be loaded before being consumed.");
|
|
|
|
|
2021-12-26 13:29:07 +00:00
|
|
|
return sampleInfo is StoryboardSampleInfo || beatmapHitsounds.Value;
|
2020-09-23 04:16:46 +00:00
|
|
|
}
|
2019-08-26 03:21:11 +00:00
|
|
|
|
2022-10-12 08:47:20 +00:00
|
|
|
private readonly ISkin skin;
|
2024-07-04 09:04:38 +00:00
|
|
|
private readonly ISkin? classicFallback;
|
|
|
|
|
|
|
|
private Bindable<Skin> currentSkin = null!;
|
2022-10-12 08:47:20 +00:00
|
|
|
|
2024-07-04 09:04:38 +00:00
|
|
|
public BeatmapSkinProvidingContainer(ISkin skin, ISkin? classicFallback = null)
|
2019-08-26 03:21:11 +00:00
|
|
|
: base(skin)
|
|
|
|
{
|
2022-10-12 08:47:20 +00:00
|
|
|
this.skin = skin;
|
2024-07-04 09:04:38 +00:00
|
|
|
this.classicFallback = classicFallback;
|
2019-08-26 03:21:11 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 04:16:46 +00:00
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
2019-08-26 03:21:11 +00:00
|
|
|
{
|
2020-09-23 04:16:46 +00:00
|
|
|
var config = parent.Get<OsuConfigManager>();
|
2019-08-26 03:21:11 +00:00
|
|
|
|
2020-09-23 04:16:46 +00:00
|
|
|
beatmapSkins = config.GetBindable<bool>(OsuSetting.BeatmapSkins);
|
2021-01-13 05:09:22 +00:00
|
|
|
beatmapColours = config.GetBindable<bool>(OsuSetting.BeatmapColours);
|
2020-09-23 04:16:46 +00:00
|
|
|
beatmapHitsounds = config.GetBindable<bool>(OsuSetting.BeatmapHitsounds);
|
|
|
|
|
|
|
|
return base.CreateChildDependencies(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2022-10-12 08:47:20 +00:00
|
|
|
private void load(SkinManager skins)
|
2020-09-23 04:16:46 +00:00
|
|
|
{
|
2021-07-06 08:37:34 +00:00
|
|
|
beatmapSkins.BindValueChanged(_ => TriggerSourceChanged());
|
|
|
|
beatmapColours.BindValueChanged(_ => TriggerSourceChanged());
|
|
|
|
beatmapHitsounds.BindValueChanged(_ => TriggerSourceChanged());
|
2022-10-12 08:47:20 +00:00
|
|
|
|
2024-07-04 09:04:38 +00:00
|
|
|
currentSkin = skins.CurrentSkin.GetBoundCopy();
|
|
|
|
currentSkin.BindValueChanged(_ =>
|
2022-10-12 08:47:20 +00:00
|
|
|
{
|
2024-07-04 09:04:38 +00:00
|
|
|
bool userSkinIsLegacy = skins.CurrentSkin.Value is LegacySkin;
|
|
|
|
bool beatmapProvidingResources = skin is LegacySkinTransformer legacySkin && legacySkin.IsProvidingLegacyResources;
|
|
|
|
|
2024-07-05 01:09:06 +00:00
|
|
|
// Some beatmaps provide a limited selection of skin elements to add some visual flair.
|
|
|
|
// In stable, these elements will take lookup priority over the selected skin (whether that be a user skin or default).
|
|
|
|
//
|
|
|
|
// To replicate this we need to pay special attention to the fallback order.
|
|
|
|
// If a user has a non-legacy skin (argon, triangles) selected, the game won't normally fall back to a legacy skin.
|
|
|
|
// In turn this can create an unexpected visual experience.
|
|
|
|
//
|
|
|
|
// So here, check what skin the user has selected. If it's already a legacy skin then we don't need to do anything special.
|
|
|
|
// If it isn't, we insert the classic default. Note that this is only done if the beatmap seems to be providing skin elements,
|
|
|
|
// as we only want to override the user's (non-legacy) skin choice when required for beatmap skin visuals.
|
2024-07-04 09:04:38 +00:00
|
|
|
if (!userSkinIsLegacy && beatmapProvidingResources && classicFallback != null)
|
|
|
|
SetSources(new[] { skin, classicFallback });
|
|
|
|
else
|
|
|
|
SetSources(new[] { skin });
|
|
|
|
}, true);
|
2019-08-26 03:21:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|