diff --git a/osu.Game.Tests/Skins/TestSceneBeatmapSkinLookupDisables.cs b/osu.Game.Tests/Skins/TestSceneBeatmapSkinLookupDisables.cs index 0bbf4406fb..a0f0bd2e77 100644 --- a/osu.Game.Tests/Skins/TestSceneBeatmapSkinLookupDisables.cs +++ b/osu.Game.Tests/Skins/TestSceneBeatmapSkinLookupDisables.cs @@ -26,6 +26,7 @@ namespace osu.Game.Tests.Skins public partial class TestSceneBeatmapSkinLookupDisables : OsuTestScene { private UserSkinSource userSource; + private BeatmapSkinProvidingContainer beatmapSkinProvider; private BeatmapSkinSource beatmapSource; private SkinRequester requester; @@ -36,7 +37,7 @@ namespace osu.Game.Tests.Skins public void SetUp() => Schedule(() => { Add(new SkinProvidingContainer(userSource = new UserSkinSource()) - .WithChild(new BeatmapSkinProvidingContainer(beatmapSource = new BeatmapSkinSource()) + .WithChild(beatmapSkinProvider = new BeatmapSkinProvidingContainer(beatmapSource = new BeatmapSkinSource()) .WithChild(requester = new SkinRequester()))); }); @@ -44,7 +45,7 @@ namespace osu.Game.Tests.Skins [TestCase(true)] public void TestDrawableLookup(bool allowBeatmapLookups) { - AddStep($"Set beatmap skin enabled to {allowBeatmapLookups}", () => config.SetValue(OsuSetting.BeatmapSkins, allowBeatmapLookups)); + AddStep($"Set beatmap skin enabled to {allowBeatmapLookups}", () => beatmapSkinProvider.BeatmapSkins.Value = allowBeatmapLookups); string expected = allowBeatmapLookups ? "beatmap" : "user"; @@ -55,7 +56,7 @@ namespace osu.Game.Tests.Skins [TestCase(true)] public void TestProviderLookup(bool allowBeatmapLookups) { - AddStep($"Set beatmap skin enabled to {allowBeatmapLookups}", () => config.SetValue(OsuSetting.BeatmapSkins, allowBeatmapLookups)); + AddStep($"Set beatmap skin enabled to {allowBeatmapLookups}", () => beatmapSkinProvider.BeatmapSkins.Value = allowBeatmapLookups); ISkin expected() => allowBeatmapLookups ? beatmapSource : userSource; diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 4bde0cbd55..77f4a6a3da 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -287,6 +287,10 @@ namespace osu.Game.Screens.Play dependencies.CacheAs(GameplayState = new GameplayState(playableBeatmap, ruleset, gameplayMods, Score, ScoreProcessor, HealthProcessor, Beatmap.Value.Storyboard, PlayingState)); var rulesetSkinProvider = new RulesetSkinProvidingContainer(ruleset, playableBeatmap, Beatmap.Value.Skin); + config.BindWith(OsuSetting.BeatmapSkins, rulesetSkinProvider.BeatmapSkins); + config.BindWith(OsuSetting.BeatmapColours, rulesetSkinProvider.BeatmapColours); + config.BindWith(OsuSetting.BeatmapHitsounds, rulesetSkinProvider.BeatmapHitsounds); + GameplayClockContainer.Add(new GameplayScrollWheelHandling()); // needs to exist in frame stable content, but is used by underlay layers so make sure assigned early. diff --git a/osu.Game/Screens/Play/ReplayPlayer.cs b/osu.Game/Screens/Play/ReplayPlayer.cs index e2ef847c2b..9ea4c2edc1 100644 --- a/osu.Game/Screens/Play/ReplayPlayer.cs +++ b/osu.Game/Screens/Play/ReplayPlayer.cs @@ -124,7 +124,8 @@ namespace osu.Game.Screens.Play Origin = Anchor.TopCentre, }); - AddInternal(new RulesetSkinProvidingContainer(GameplayState.Ruleset, GameplayState.Beatmap, Beatmap.Value.Skin) + RulesetSkinProvidingContainer rulesetSkinProvider; + AddInternal(rulesetSkinProvider = new RulesetSkinProvidingContainer(GameplayState.Ruleset, GameplayState.Beatmap, Beatmap.Value.Skin) { Child = failIndicator = new ReplayFailIndicator(GameplayClockContainer) { @@ -138,6 +139,9 @@ namespace osu.Game.Screens.Play } } }); + config.BindWith(OsuSetting.BeatmapSkins, rulesetSkinProvider.BeatmapSkins); + config.BindWith(OsuSetting.BeatmapColours, rulesetSkinProvider.BeatmapColours); + config.BindWith(OsuSetting.BeatmapHitsounds, rulesetSkinProvider.BeatmapHitsounds); } protected override void PrepareReplay() diff --git a/osu.Game/Skinning/BeatmapSkinProvidingContainer.cs b/osu.Game/Skinning/BeatmapSkinProvidingContainer.cs index 41fa7fcc66..0348370622 100644 --- a/osu.Game/Skinning/BeatmapSkinProvidingContainer.cs +++ b/osu.Game/Skinning/BeatmapSkinProvidingContainer.cs @@ -1,12 +1,9 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Game.Audio; -using osu.Game.Configuration; -using osu.Game.Storyboards; namespace osu.Game.Skinning { @@ -15,55 +12,19 @@ namespace osu.Game.Skinning /// public partial class BeatmapSkinProvidingContainer : SkinProvidingContainer { - private Bindable beatmapSkins = null!; - private Bindable beatmapColours = null!; - private Bindable beatmapHitsounds = null!; + public BindableWithCurrent BeatmapSkins = new BindableWithCurrent(true); + public BindableWithCurrent BeatmapColours = new BindableWithCurrent(true); + public BindableWithCurrent BeatmapHitsounds = new BindableWithCurrent(true); - protected override bool AllowConfigurationLookup - { - get - { - if (beatmapSkins == null) - throw new InvalidOperationException($"{nameof(BeatmapSkinProvidingContainer)} needs to be loaded before being consumed."); + protected override bool AllowConfigurationLookup => BeatmapSkins.Value; - return beatmapSkins.Value; - } - } + protected override bool AllowColourLookup => BeatmapColours.Value; - protected override bool AllowColourLookup - { - get - { - if (beatmapColours == null) - throw new InvalidOperationException($"{nameof(BeatmapSkinProvidingContainer)} needs to be loaded before being consumed."); + protected override bool AllowDrawableLookup(ISkinComponentLookup lookup) => BeatmapSkins.Value; - return beatmapColours.Value; - } - } + protected override bool AllowTextureLookup(string componentName) => BeatmapSkins.Value; - protected override bool AllowDrawableLookup(ISkinComponentLookup lookup) - { - 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; - } - - protected override bool AllowSampleLookup(ISampleInfo sampleInfo) - { - if (beatmapSkins == null) - throw new InvalidOperationException($"{nameof(BeatmapSkinProvidingContainer)} needs to be loaded before being consumed."); - - return sampleInfo is StoryboardSampleInfo || beatmapHitsounds.Value; - } + protected override bool AllowSampleLookup(ISampleInfo sampleInfo) => BeatmapHitsounds.Value; private readonly ISkin skin; private readonly ISkin? classicFallback; @@ -77,23 +38,12 @@ namespace osu.Game.Skinning this.classicFallback = classicFallback; } - protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) - { - var config = parent.Get(); - - beatmapSkins = config.GetBindable(OsuSetting.BeatmapSkins); - beatmapColours = config.GetBindable(OsuSetting.BeatmapColours); - beatmapHitsounds = config.GetBindable(OsuSetting.BeatmapHitsounds); - - return base.CreateChildDependencies(parent); - } - [BackgroundDependencyLoader] private void load(SkinManager skins) { - beatmapSkins.BindValueChanged(_ => TriggerSourceChanged()); - beatmapColours.BindValueChanged(_ => TriggerSourceChanged()); - beatmapHitsounds.BindValueChanged(_ => TriggerSourceChanged()); + BeatmapSkins.BindValueChanged(_ => TriggerSourceChanged()); + BeatmapColours.BindValueChanged(_ => TriggerSourceChanged()); + BeatmapHitsounds.BindValueChanged(_ => TriggerSourceChanged()); currentSkin = skins.CurrentSkin.GetBoundCopy(); currentSkin.BindValueChanged(_ => diff --git a/osu.Game/Skinning/RulesetSkinProvidingContainer.cs b/osu.Game/Skinning/RulesetSkinProvidingContainer.cs index d736f4cdb5..9c323365d4 100644 --- a/osu.Game/Skinning/RulesetSkinProvidingContainer.cs +++ b/osu.Game/Skinning/RulesetSkinProvidingContainer.cs @@ -9,6 +9,7 @@ using System.Linq; using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Audio; +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.IO.Stores; @@ -25,6 +26,10 @@ namespace osu.Game.Skinning /// public partial class RulesetSkinProvidingContainer : SkinProvidingContainer { + public BindableWithCurrent BeatmapSkins = new BindableWithCurrent(true); + public BindableWithCurrent BeatmapColours = new BindableWithCurrent(true); + public BindableWithCurrent BeatmapHitsounds = new BindableWithCurrent(true); + protected readonly Ruleset Ruleset; protected readonly IBeatmap Beatmap; @@ -55,6 +60,9 @@ namespace osu.Game.Skinning InternalChild = new BeatmapSkinProvidingContainer(GetRulesetTransformedSkin(beatmapSkin), GetRulesetTransformedSkin(skinManager.DefaultClassicSkin)) { Child = Content, + BeatmapSkins = BeatmapSkins, + BeatmapColours = BeatmapColours, + BeatmapHitsounds = BeatmapHitsounds, }; }