From 023f3fb70e263f6496066a0f399c978dae5e801b Mon Sep 17 00:00:00 2001
From: smoogipoo <smoogipoo@smgi.me>
Date: Thu, 19 Aug 2021 18:19:31 +0900
Subject: [PATCH] Use BackgroundScreen for multiplayer backgrounds

---
 .../OnlinePlay/Lounge/LoungeSubScreen.cs      |  3 +
 .../Screens/OnlinePlay/OnlinePlayScreen.cs    | 61 -------------------
 .../Screens/OnlinePlay/OnlinePlaySubScreen.cs |  9 ++-
 .../OnlinePlay/OnlinePlaySubScreenStack.cs    | 14 +++++
 4 files changed, 25 insertions(+), 62 deletions(-)

diff --git a/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs b/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs
index 677b9c0782..7712e7d734 100644
--- a/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs
+++ b/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs
@@ -23,6 +23,7 @@ using osu.Game.Input;
 using osu.Game.Online.Rooms;
 using osu.Game.Overlays;
 using osu.Game.Rulesets;
+using osu.Game.Screens.Backgrounds;
 using osu.Game.Screens.OnlinePlay.Components;
 using osu.Game.Screens.OnlinePlay.Lounge.Components;
 using osu.Game.Screens.OnlinePlay.Match;
@@ -36,6 +37,8 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
     {
         public override string Title => "Lounge";
 
+        protected override BackgroundScreen CreateBackground() => new BackgroundScreenDefault();
+
         protected override UserActivity InitialActivity => new UserActivity.SearchingForLobby();
 
         protected Container<OsuButton> Buttons { get; } = new Container<OsuButton>
diff --git a/osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs b/osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs
index e5962db608..c057c814ca 100644
--- a/osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs
+++ b/osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs
@@ -78,32 +78,16 @@ namespace osu.Game.Screens.OnlinePlay
         [BackgroundDependencyLoader]
         private void load()
         {
-            var backgroundColour = Color4Extensions.FromHex(@"3e3a44");
-
             InternalChild = waves = new MultiplayerWaveContainer
             {
                 RelativeSizeAxes = Axes.Both,
                 Children = new Drawable[]
                 {
-                    new Box
-                    {
-                        RelativeSizeAxes = Axes.Both,
-                        Colour = backgroundColour,
-                    },
                     new Container
                     {
                         RelativeSizeAxes = Axes.Both,
                         Children = new Drawable[]
                         {
-                            new BeatmapBackgroundSprite
-                            {
-                                RelativeSizeAxes = Axes.Both
-                            },
-                            new Box
-                            {
-                                RelativeSizeAxes = Axes.Both,
-                                Colour = ColourInfo.GradientVertical(Color4.Black.Opacity(0.9f), Color4.Black.Opacity(0.6f))
-                            },
                             screenStack = new OnlinePlaySubScreenStack
                             {
                                 RelativeSizeAxes = Axes.Both
@@ -276,51 +260,6 @@ namespace osu.Game.Screens.OnlinePlay
             }
         }
 
-        private class BeatmapBackgroundSprite : OnlinePlayBackgroundSprite
-        {
-            protected override UpdateableBeatmapBackgroundSprite CreateBackgroundSprite() => new BlurredBackgroundSprite(BeatmapSetCoverType) { RelativeSizeAxes = Axes.Both };
-
-            public class BlurredBackgroundSprite : UpdateableBeatmapBackgroundSprite
-            {
-                public BlurredBackgroundSprite(BeatmapSetCoverType type)
-                    : base(type)
-                {
-                }
-
-                protected override double LoadDelay => 200;
-
-                protected override Drawable CreateDrawable(BeatmapInfo model) =>
-                    new BufferedLoader(base.CreateDrawable(model));
-            }
-
-            // This class is an unfortunate requirement due to `LongRunningLoad` requiring direct async loading.
-            // It means that if the web request fetching the beatmap background takes too long, it will suddenly appear.
-            internal class BufferedLoader : BufferedContainer
-            {
-                private readonly Drawable drawable;
-
-                public BufferedLoader(Drawable drawable)
-                {
-                    this.drawable = drawable;
-
-                    RelativeSizeAxes = Axes.Both;
-                    BlurSigma = new Vector2(10);
-                    FrameBufferScale = new Vector2(0.5f);
-                    CacheDrawnFrameBuffer = true;
-                }
-
-                [BackgroundDependencyLoader]
-                private void load()
-                {
-                    LoadComponentAsync(drawable, d =>
-                    {
-                        Add(d);
-                        ForceRedraw();
-                    });
-                }
-            }
-        }
-
         ScreenStack IHasSubScreenStack.SubScreenStack => screenStack;
     }
 }
diff --git a/osu.Game/Screens/OnlinePlay/OnlinePlaySubScreen.cs b/osu.Game/Screens/OnlinePlay/OnlinePlaySubScreen.cs
index e1bd889088..58531a4b1c 100644
--- a/osu.Game/Screens/OnlinePlay/OnlinePlaySubScreen.cs
+++ b/osu.Game/Screens/OnlinePlay/OnlinePlaySubScreen.cs
@@ -35,13 +35,16 @@ namespace osu.Game.Screens.OnlinePlay
 
         public override void OnEntering(IScreen last)
         {
-            this.FadeInFromZero(APPEAR_DURATION, Easing.OutQuint);
+            base.OnEntering(last);
+
             this.FadeInFromZero(APPEAR_DURATION, Easing.OutQuint);
             this.MoveToX(X_SHIFT).MoveToX(0, X_MOVE_DURATION, Easing.OutQuint);
         }
 
         public override bool OnExiting(IScreen next)
         {
+            base.OnExiting(next);
+
             this.FadeOut(DISAPPEAR_DURATION, Easing.OutQuint);
             this.MoveToX(X_SHIFT, X_MOVE_DURATION, Easing.OutQuint);
 
@@ -50,12 +53,16 @@ namespace osu.Game.Screens.OnlinePlay
 
         public override void OnResuming(IScreen last)
         {
+            base.OnResuming(last);
+
             this.Delay(RESUME_TRANSITION_DELAY).FadeIn(APPEAR_DURATION, Easing.OutQuint);
             this.MoveToX(0, X_MOVE_DURATION, Easing.OutQuint);
         }
 
         public override void OnSuspending(IScreen next)
         {
+            base.OnSuspending(next);
+
             this.FadeOut(DISAPPEAR_DURATION, Easing.OutQuint);
             this.MoveToX(-X_SHIFT, X_MOVE_DURATION, Easing.OutQuint);
         }
diff --git a/osu.Game/Screens/OnlinePlay/OnlinePlaySubScreenStack.cs b/osu.Game/Screens/OnlinePlay/OnlinePlaySubScreenStack.cs
index 7f2a0980c1..69fa3b0916 100644
--- a/osu.Game/Screens/OnlinePlay/OnlinePlaySubScreenStack.cs
+++ b/osu.Game/Screens/OnlinePlay/OnlinePlaySubScreenStack.cs
@@ -1,12 +1,26 @@
 // 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.
 
+using osu.Framework.Extensions.Color4Extensions;
+using osu.Framework.Graphics;
+using osu.Framework.Graphics.Colour;
+using osu.Framework.Graphics.Shapes;
 using osu.Framework.Screens;
+using osuTK.Graphics;
 
 namespace osu.Game.Screens.OnlinePlay
 {
     public class OnlinePlaySubScreenStack : OsuScreenStack
     {
+        public OnlinePlaySubScreenStack()
+        {
+            AddInternal(new Box
+            {
+                RelativeSizeAxes = Axes.Both,
+                Colour = ColourInfo.GradientVertical(Color4.Black.Opacity(0.9f), Color4.Black.Opacity(0.6f))
+            });
+        }
+
         protected override void ScreenChanged(IScreen prev, IScreen next)
         {
             base.ScreenChanged(prev, next);