From 32c7a023f8206ec6cde60e4d1d2dc9641eb06a66 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 11 Mar 2022 19:54:13 +0900 Subject: [PATCH 1/4] Make `OsuGame.ScreenChanged` `private` and non-`virtual` Just reducing complexity scope here. --- osu.Game/OsuGame.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index fb81e4fd14..7cd043083a 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -1140,7 +1140,7 @@ namespace osu.Game MenuCursorContainer.CanShowCursor = (ScreenStack.CurrentScreen as IOsuScreen)?.CursorVisible ?? false; } - protected virtual void ScreenChanged(IScreen current, IScreen newScreen) + private void screenChanged(IScreen current, IScreen newScreen) { skinEditor.Reset(); @@ -1187,11 +1187,11 @@ namespace osu.Game } } - private void screenPushed(IScreen lastScreen, IScreen newScreen) => ScreenChanged(lastScreen, newScreen); + private void screenPushed(IScreen lastScreen, IScreen newScreen) => screenChanged(lastScreen, newScreen); private void screenExited(IScreen lastScreen, IScreen newScreen) { - ScreenChanged(lastScreen, newScreen); + screenChanged(lastScreen, newScreen); if (newScreen == null) Exit(); From 9a1ade4f7907b695aeaa0d5ca19d18e63c4fa554 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 11 Mar 2022 23:08:40 +0900 Subject: [PATCH 2/4] Refactor `SkinEditor` to support switching target screens without full reload --- osu.Game/OsuGame.cs | 4 +-- osu.Game/Skinning/Editor/SkinEditor.cs | 29 ++++++++++----- osu.Game/Skinning/Editor/SkinEditorOverlay.cs | 35 +++++++++++++++---- 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 7cd043083a..ae117d03d2 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -1142,8 +1142,6 @@ namespace osu.Game private void screenChanged(IScreen current, IScreen newScreen) { - skinEditor.Reset(); - switch (newScreen) { case IntroScreen intro: @@ -1185,6 +1183,8 @@ namespace osu.Game else BackButton.Hide(); } + + skinEditor.SetTarget((Screen)newScreen); } private void screenPushed(IScreen lastScreen, IScreen newScreen) => screenChanged(lastScreen, newScreen); diff --git a/osu.Game/Skinning/Editor/SkinEditor.cs b/osu.Game/Skinning/Editor/SkinEditor.cs index ae5cbc95f0..cd21507128 100644 --- a/osu.Game/Skinning/Editor/SkinEditor.cs +++ b/osu.Game/Skinning/Editor/SkinEditor.cs @@ -28,7 +28,7 @@ namespace osu.Game.Skinning.Editor protected override bool StartHidden => true; - private readonly Drawable targetScreen; + private Drawable targetScreen; private OsuTextFlowContainer headerText; @@ -42,11 +42,13 @@ namespace osu.Game.Skinning.Editor private bool hasBegunMutating; + private Container blueprintContainerContainer; + public SkinEditor(Drawable targetScreen) { - this.targetScreen = targetScreen; - RelativeSizeAxes = Axes.Both; + + UpdateTargetScreen(targetScreen); } [BackgroundDependencyLoader] @@ -113,13 +115,9 @@ namespace osu.Game.Skinning.Editor Origin = Anchor.CentreLeft, RequestPlacement = placeComponent }, - new Container + blueprintContainerContainer = new Container { RelativeSizeAxes = Axes.Both, - Children = new Drawable[] - { - new SkinBlueprintContainer(targetScreen), - } }, } } @@ -147,6 +145,21 @@ namespace osu.Game.Skinning.Editor }, true); } + public void UpdateTargetScreen(Drawable targetScreen) + { + this.targetScreen = targetScreen; + + Scheduler.AddOnce(loadBlueprintContainer); + + void loadBlueprintContainer() + { + blueprintContainerContainer.Children = new Drawable[] + { + new SkinBlueprintContainer(targetScreen), + }; + } + } + private void skinChanged() { headerText.Clear(); diff --git a/osu.Game/Skinning/Editor/SkinEditorOverlay.cs b/osu.Game/Skinning/Editor/SkinEditorOverlay.cs index 61c363b019..08dad2a146 100644 --- a/osu.Game/Skinning/Editor/SkinEditorOverlay.cs +++ b/osu.Game/Skinning/Editor/SkinEditorOverlay.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Diagnostics; using JetBrains.Annotations; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -8,6 +9,7 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; +using osu.Framework.Screens; using osu.Game.Graphics.Containers; using osu.Game.Input.Bindings; @@ -114,15 +116,36 @@ namespace osu.Game.Skinning.Editor } /// - /// Exit any existing skin editor due to the game state changing. + /// Set a new target screen which will be used to find skinnable components. /// - public void Reset() + public void SetTarget(Screen screen) { - skinEditor?.Save(); - skinEditor?.Hide(); - skinEditor?.Expire(); + if (skinEditor == null) return; - skinEditor = null; + skinEditor.Save(); + + // AddOnce with paramter will ensure the newest target is loaded if there is any overlap. + Scheduler.AddOnce(setTarget, screen); + } + + private void setTarget(Screen target) + { + Debug.Assert(skinEditor != null); + + if (!target.IsLoaded) + { + Scheduler.AddOnce(setTarget, target); + return; + } + + if (skinEditor.State.Value == Visibility.Visible) + skinEditor.UpdateTargetScreen(target); + else + { + skinEditor.Hide(); + skinEditor.Expire(); + skinEditor = null; + } } } } From d1a9b88fe7756e6925b26511459840009b3180c5 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 13 Mar 2022 16:05:45 +0900 Subject: [PATCH 3/4] Fix typo in comment Co-authored-by: Salman Ahmed --- osu.Game/Skinning/Editor/SkinEditorOverlay.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Skinning/Editor/SkinEditorOverlay.cs b/osu.Game/Skinning/Editor/SkinEditorOverlay.cs index 08dad2a146..abd8272633 100644 --- a/osu.Game/Skinning/Editor/SkinEditorOverlay.cs +++ b/osu.Game/Skinning/Editor/SkinEditorOverlay.cs @@ -124,7 +124,7 @@ namespace osu.Game.Skinning.Editor skinEditor.Save(); - // AddOnce with paramter will ensure the newest target is loaded if there is any overlap. + // AddOnce with parameter will ensure the newest target is loaded if there is any overlap. Scheduler.AddOnce(setTarget, screen); } From f95e753adbfb170317c68ba19155f16e1b3a10a1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 13 Mar 2022 16:10:06 +0900 Subject: [PATCH 4/4] Rename double-container variable name --- osu.Game/Skinning/Editor/SkinEditor.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Skinning/Editor/SkinEditor.cs b/osu.Game/Skinning/Editor/SkinEditor.cs index cd21507128..829faab116 100644 --- a/osu.Game/Skinning/Editor/SkinEditor.cs +++ b/osu.Game/Skinning/Editor/SkinEditor.cs @@ -42,7 +42,7 @@ namespace osu.Game.Skinning.Editor private bool hasBegunMutating; - private Container blueprintContainerContainer; + private Container content; public SkinEditor(Drawable targetScreen) { @@ -115,7 +115,7 @@ namespace osu.Game.Skinning.Editor Origin = Anchor.CentreLeft, RequestPlacement = placeComponent }, - blueprintContainerContainer = new Container + content = new Container { RelativeSizeAxes = Axes.Both, }, @@ -153,7 +153,7 @@ namespace osu.Game.Skinning.Editor void loadBlueprintContainer() { - blueprintContainerContainer.Children = new Drawable[] + content.Children = new Drawable[] { new SkinBlueprintContainer(targetScreen), };