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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
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 class BeatmapSkinProvidingContainer : SkinProvidingContainer
|
2019-08-26 03:21:11 +00:00
|
|
|
{
|
2020-09-23 04:16:46 +00:00
|
|
|
private Bindable<bool> beatmapSkins;
|
2021-01-13 05:09:22 +00:00
|
|
|
private Bindable<bool> beatmapColours;
|
2020-09-23 04:16:46 +00:00
|
|
|
private Bindable<bool> beatmapHitsounds;
|
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
|
|
|
|
2020-09-23 04:16:46 +00:00
|
|
|
protected override bool AllowDrawableLookup(ISkinComponent component)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2020-08-31 16:29:46 +00:00
|
|
|
public BeatmapSkinProvidingContainer(ISkin skin)
|
2019-08-26 03:21:11 +00:00
|
|
|
: base(skin)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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]
|
|
|
|
private void load()
|
|
|
|
{
|
2021-07-06 08:37:34 +00:00
|
|
|
beatmapSkins.BindValueChanged(_ => TriggerSourceChanged());
|
|
|
|
beatmapColours.BindValueChanged(_ => TriggerSourceChanged());
|
|
|
|
beatmapHitsounds.BindValueChanged(_ => TriggerSourceChanged());
|
2019-08-26 03:21:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|