From e01f342ab0b01799792310fa3679a15ca590d0e2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 2 Feb 2019 17:11:25 +0900 Subject: [PATCH] wip --- osu.Game/Screens/Multi/Multiplayer.cs | 16 +++-- .../Screens/Multi/MultiplayerSubScreen.cs | 16 +++-- osu.Game/Screens/OsuScreen.cs | 67 +++---------------- osu.Game/Screens/OsuScreenDependencies.cs | 41 ++++++++++++ 4 files changed, 71 insertions(+), 69 deletions(-) create mode 100644 osu.Game/Screens/OsuScreenDependencies.cs diff --git a/osu.Game/Screens/Multi/Multiplayer.cs b/osu.Game/Screens/Multi/Multiplayer.cs index d9a2fb7507..6bd47ff810 100644 --- a/osu.Game/Screens/Multi/Multiplayer.cs +++ b/osu.Game/Screens/Multi/Multiplayer.cs @@ -61,13 +61,19 @@ namespace osu.Game.Screens.Multi [Resolved(CanBeNull = true)] private OsuLogo logo { get; set; } - public Bindable Beatmap => screenDependencies.Beatmap; + public Bindable Beatmap { get; set; } - public Bindable Ruleset => screenDependencies.Ruleset; + public Bindable Ruleset { get; set; } - private OsuScreenDependencies screenDependencies; + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) + { + var deps = new OsuScreenDependencies(DisallowExternalBeatmapRulesetChanges, base.CreateChildDependencies(parent)); - protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) => screenDependencies = new OsuScreenDependencies(DisallowExternalBeatmapRulesetChanges, base.CreateChildDependencies(parent)); + Beatmap = deps.Beatmap; + Ruleset = deps.Ruleset; + + return deps; + } public Multiplayer() { @@ -188,8 +194,6 @@ namespace osu.Game.Screens.Multi { waves.Hide(); - screenDependencies.Dispose(); - this.Delay(WaveContainer.DISAPPEAR_DURATION).FadeOut(); cancelLooping(); diff --git a/osu.Game/Screens/Multi/MultiplayerSubScreen.cs b/osu.Game/Screens/Multi/MultiplayerSubScreen.cs index 1d6561622a..b0d89c9bba 100644 --- a/osu.Game/Screens/Multi/MultiplayerSubScreen.cs +++ b/osu.Game/Screens/Multi/MultiplayerSubScreen.cs @@ -34,13 +34,19 @@ namespace osu.Game.Screens.Multi public abstract string Title { get; } public virtual string ShortTitle => Title; - public Bindable Beatmap => screenDependencies.Beatmap; + public Bindable Beatmap { get; set; } - public Bindable Ruleset => screenDependencies.Ruleset; + public Bindable Ruleset { get; set; } - private OsuScreenDependencies screenDependencies; + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) + { + var deps = new OsuScreenDependencies(DisallowExternalBeatmapRulesetChanges, base.CreateChildDependencies(parent)); - protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) => screenDependencies = new OsuScreenDependencies(DisallowExternalBeatmapRulesetChanges, base.CreateChildDependencies(parent)); + Beatmap = deps.Beatmap; + Ruleset = deps.Ruleset; + + return deps; + } [Resolved(CanBeNull = true)] protected OsuGame Game { get; private set; } @@ -67,8 +73,6 @@ namespace osu.Game.Screens.Multi this.FadeOut(WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint); this.MoveToX(200, WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint); - screenDependencies.Dispose(); - return false; } diff --git a/osu.Game/Screens/OsuScreen.cs b/osu.Game/Screens/OsuScreen.cs index bfed4345f1..86f1f3a9d9 100644 --- a/osu.Game/Screens/OsuScreen.cs +++ b/osu.Game/Screens/OsuScreen.cs @@ -1,7 +1,6 @@ // 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 Microsoft.EntityFrameworkCore.Internal; using osu.Framework.Allocation; using osu.Framework.Audio; @@ -51,7 +50,6 @@ namespace osu.Game.Screens protected new OsuGameBase Game => base.Game as OsuGameBase; - /// /// Disallow changes to game-wise Beatmap/Ruleset bindables for this screen (and all children). /// @@ -61,13 +59,19 @@ namespace osu.Game.Screens public virtual float BackgroundParallaxAmount => 1; - public Bindable Beatmap => screenDependencies.Beatmap; + public Bindable Beatmap { get; set; } - public Bindable Ruleset => screenDependencies.Ruleset; + public Bindable Ruleset { get; set; } - private OsuScreenDependencies screenDependencies; + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) + { + var deps = new OsuScreenDependencies(DisallowExternalBeatmapRulesetChanges, base.CreateChildDependencies(parent)); - protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) => screenDependencies = new OsuScreenDependencies(DisallowExternalBeatmapRulesetChanges, base.CreateChildDependencies(parent)); + Beatmap = deps.Beatmap; + Ruleset = deps.Ruleset; + + return deps; + } protected BackgroundScreen Background => backgroundStack?.CurrentScreen as BackgroundScreen; @@ -140,8 +144,6 @@ namespace osu.Game.Screens if (localBackground != null && backgroundStack?.CurrentScreen == localBackground) backgroundStack?.Exit(); - screenDependencies.Dispose(); - return false; } @@ -208,53 +210,4 @@ namespace osu.Game.Screens /// protected virtual BackgroundScreen CreateBackground() => null; } - - public class OsuScreenDependencies : DependencyContainer, IDisposable - { - private readonly bool leaseOwner; - - public Bindable Beatmap { get; private set; } - - public Bindable Ruleset { get; private set; } - - public OsuScreenDependencies(bool requireLease, IReadOnlyDependencyContainer parent) - : base(parent) - { - if (requireLease) - { - Beatmap = parent.Get>()?.GetBoundCopy(); - if (Beatmap == null) - { - leaseOwner = true; - Cache(Beatmap = parent.Get>().BeginLease(true)); - } - - Ruleset = parent.Get>()?.GetBoundCopy(); - if (Ruleset == null) - { - leaseOwner = true; - Cache(Ruleset = parent.Get>().BeginLease(true)); - } - } - else - { - Beatmap = (parent.Get>() ?? parent.Get>()).GetBoundCopy(); - Ruleset = (parent.Get>() ?? parent.Get>()).GetBoundCopy(); - } - } - - public void Dispose() - { - if (leaseOwner) - { - ((LeasedBindable)Beatmap).Return(); - ((LeasedBindable)Ruleset).Return(); - } - else - { - Beatmap.UnbindAll(); - Ruleset.UnbindAll(); - } - } - } } diff --git a/osu.Game/Screens/OsuScreenDependencies.cs b/osu.Game/Screens/OsuScreenDependencies.cs new file mode 100644 index 0000000000..1c355d6320 --- /dev/null +++ b/osu.Game/Screens/OsuScreenDependencies.cs @@ -0,0 +1,41 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Configuration; +using osu.Game.Beatmaps; +using osu.Game.Rulesets; + +namespace osu.Game.Screens +{ + public class OsuScreenDependencies : DependencyContainer + { + public Bindable Beatmap { get; } + + public Bindable Ruleset { get; } + + public OsuScreenDependencies(bool requireLease, IReadOnlyDependencyContainer parent) + : base(parent) + { + if (requireLease) + { + Beatmap = parent.Get>()?.GetBoundCopy(); + if (Beatmap == null) + { + Cache(Beatmap = parent.Get>().BeginLease(true)); + } + + Ruleset = parent.Get>()?.GetBoundCopy(); + if (Ruleset == null) + { + Cache(Ruleset = parent.Get>().BeginLease(true)); + } + } + else + { + Beatmap = (parent.Get>() ?? parent.Get>()).GetBoundCopy(); + Ruleset = (parent.Get>() ?? parent.Get>()).GetBoundCopy(); + } + } + } +} \ No newline at end of file