From 85c780ae5be25c3b89ea414a2b03d688cefdd452 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Jul 2023 19:19:14 +0900 Subject: [PATCH] Allow the osu! logo to be proxied locally into scenes --- osu.Game/OsuGame.cs | 4 +-- osu.Game/Screens/Menu/MainMenu.cs | 7 ++++++ osu.Game/Screens/Menu/OsuLogo.cs | 41 +++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 5b654e0c16..1a40bb8e3d 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -950,9 +950,9 @@ namespace osu.Game if (!args?.Any(a => a == @"--no-version-overlay") ?? true) loadComponentSingleFile(versionManager = new VersionManager { Depth = int.MinValue }, ScreenContainer.Add); - loadComponentSingleFile(osuLogo, logo => + loadComponentSingleFile(osuLogo, _ => { - logoContainer.Add(logo); + osuLogo.SetupDefaultContainer(logoContainer); // Loader has to be created after the logo has finished loading as Loader performs logo transformations on entering. ScreenStack.Push(CreateLoader().With(l => l.RelativeSizeAxes = Axes.Both)); diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index baa34d4914..510c9a5373 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -8,6 +8,7 @@ using System.Diagnostics; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; using osu.Framework.Logging; @@ -85,6 +86,7 @@ namespace osu.Game.Screens.Menu private ParallaxContainer buttonsContainer; private SongTicker songTicker; + private Container logoTarget; [BackgroundDependencyLoader(true)] private void load(BeatmapListingOverlay beatmapListing, SettingsOverlay settings, OsuConfigManager config, SessionStatics statics) @@ -129,6 +131,7 @@ namespace osu.Game.Screens.Menu } } }, + logoTarget = new Container { RelativeSizeAxes = Axes.Both, }, sideFlashes = new MenuSideFlashes(), songTicker = new SongTicker { @@ -208,6 +211,8 @@ namespace osu.Game.Screens.Menu logo.FadeColour(Color4.White, 100, Easing.OutQuint); logo.FadeIn(100, Easing.OutQuint); + logo.ProxyToContainer(logoTarget); + if (resuming) { Buttons.State = ButtonSystemState.TopLevel; @@ -245,6 +250,8 @@ namespace osu.Game.Screens.Menu var seq = logo.FadeOut(300, Easing.InSine) .ScaleTo(0.2f, 300, Easing.InSine); + logo.ReturnProxy(); + seq.OnComplete(_ => Buttons.SetOsuLogo(null)); seq.OnAbort(_ => Buttons.SetOsuLogo(null)); } diff --git a/osu.Game/Screens/Menu/OsuLogo.cs b/osu.Game/Screens/Menu/OsuLogo.cs index 277b8bf888..8867ecfb2a 100644 --- a/osu.Game/Screens/Menu/OsuLogo.cs +++ b/osu.Game/Screens/Menu/OsuLogo.cs @@ -435,5 +435,46 @@ namespace osu.Game.Screens.Menu logoBounceContainer.MoveTo(Vector2.Zero, 800, Easing.OutElastic); base.OnDragEnd(e); } + + private Container defaultProxyTarget; + private Container currentProxyTarget; + private Drawable proxy; + + public Drawable ProxyToContainer(Container c) + { + if (currentProxyTarget != null) + throw new InvalidOperationException("Previous proxy usage was not returned"); + + if (defaultProxyTarget == null) + throw new InvalidOperationException($"{nameof(SetupDefaultContainer)} must be called first"); + + currentProxyTarget = c; + + defaultProxyTarget.Remove(proxy, false); + currentProxyTarget.Add(proxy); + return proxy; + } + + public void ReturnProxy() + { + if (currentProxyTarget == null) + throw new InvalidOperationException("No usage to return"); + + if (defaultProxyTarget == null) + throw new InvalidOperationException($"{nameof(SetupDefaultContainer)} must be called first"); + + currentProxyTarget.Remove(proxy, false); + currentProxyTarget = null; + + defaultProxyTarget.Add(proxy); + } + + public void SetupDefaultContainer(Container container) + { + defaultProxyTarget = container; + + defaultProxyTarget.Add(this); + defaultProxyTarget.Add(proxy = CreateProxy()); + } } }