From 5157a78ae6f7fbb2c94482aeae8ac0b0e556bd2a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 8 Jun 2022 16:53:06 +0900 Subject: [PATCH] Isolate nested sample screens from main game to avoid toolbar interactions --- .../Overlays/FirstRunSetup/ScreenUIScale.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/osu.Game/Overlays/FirstRunSetup/ScreenUIScale.cs b/osu.Game/Overlays/FirstRunSetup/ScreenUIScale.cs index 8452691bb5..f09a26a527 100644 --- a/osu.Game/Overlays/FirstRunSetup/ScreenUIScale.cs +++ b/osu.Game/Overlays/FirstRunSetup/ScreenUIScale.cs @@ -126,6 +126,7 @@ namespace osu.Game.Overlays.FirstRunSetup private class SampleScreenContainer : CompositeDrawable { private readonly OsuScreen screen; + // Minimal isolation from main game. [Cached] @@ -151,6 +152,9 @@ namespace osu.Game.Overlays.FirstRunSetup RelativeSizeAxes = Axes.Both; } + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) => + new DependencyContainer(new DependencyIsolationContainer(base.CreateChildDependencies(parent))); + [BackgroundDependencyLoader] private void load(AudioManager audio, TextureStore textures, RulesetStore rulesets) { @@ -197,5 +201,41 @@ namespace osu.Game.Overlays.FirstRunSetup stack.PushSynchronously(screen); } } + + private class DependencyIsolationContainer : IReadOnlyDependencyContainer + { + private readonly IReadOnlyDependencyContainer parentDependencies; + + private readonly Type[] isolatedTypes = + { + typeof(OsuGame) + }; + + public DependencyIsolationContainer(IReadOnlyDependencyContainer parentDependencies) + { + this.parentDependencies = parentDependencies; + } + + public object Get(Type type) + { + if (isolatedTypes.Contains(type)) + return null; + + return parentDependencies.Get(type); + } + + public object Get(Type type, CacheInfo info) + { + if (isolatedTypes.Contains(type)) + return null; + + return parentDependencies.Get(type, info); + } + + public void Inject(T instance) where T : class + { + parentDependencies.Inject(instance); + } + } } }