diff --git a/osu.Game/Overlays/SkinEditor/ExternalEditOverlay.cs b/osu.Game/Overlays/SkinEditor/ExternalEditOverlay.cs index d8dc01362c..cbf85c6f2b 100644 --- a/osu.Game/Overlays/SkinEditor/ExternalEditOverlay.cs +++ b/osu.Game/Overlays/SkinEditor/ExternalEditOverlay.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Diagnostics; using System.IO; using System.Threading.Tasks; using osu.Framework.Allocation; @@ -45,6 +46,7 @@ namespace osu.Game.Overlays.SkinEditor private SkinManager skinManager { get; set; } = null!; private ExternalEditOperation? editOperation; + private TaskCompletionSource? taskCompletionSource; protected override bool DimMainContent => false; @@ -95,8 +97,11 @@ namespace osu.Game.Overlays.SkinEditor }; } - public async Task Begin(SkinInfo skinInfo) + public async Task Begin(SkinInfo skinInfo) { + if (taskCompletionSource != null) + throw new InvalidOperationException("Cannot start multiple concurrent external edits!"); + Show(); showSpinner("Mounting external skin..."); setGlobalSkinDisabled(true); @@ -114,6 +119,7 @@ namespace osu.Game.Overlays.SkinEditor await Task.Delay(1000).ConfigureAwait(true); setGlobalSkinDisabled(false); Hide(); + return Task.FromException(ex); } Schedule(() => @@ -163,6 +169,7 @@ namespace osu.Game.Overlays.SkinEditor b.Enabled.Value = true; openDirectory(); }, 1000); + return (taskCompletionSource = new TaskCompletionSource()).Task; } private void openDirectory() @@ -175,6 +182,8 @@ namespace osu.Game.Overlays.SkinEditor private async Task finish() { + Debug.Assert(taskCompletionSource != null); + showSpinner("Cleaning up..."); await Task.Delay(500).ConfigureAwait(true); @@ -189,6 +198,9 @@ namespace osu.Game.Overlays.SkinEditor await Task.Delay(1000).ConfigureAwait(true); Hide(); setGlobalSkinDisabled(false); + taskCompletionSource.SetException(ex); + taskCompletionSource = null; + return; } Schedule(() => @@ -205,6 +217,8 @@ namespace osu.Game.Overlays.SkinEditor Hide(); }); + taskCompletionSource.SetResult(); + taskCompletionSource = null; } private void setGlobalSkinDisabled(bool disabled) diff --git a/osu.Game/Overlays/SkinEditor/SkinEditor.cs b/osu.Game/Overlays/SkinEditor/SkinEditor.cs index 140c011e3c..f4a1bb7562 100644 --- a/osu.Game/Overlays/SkinEditor/SkinEditor.cs +++ b/osu.Game/Overlays/SkinEditor/SkinEditor.cs @@ -48,6 +48,8 @@ namespace osu.Game.Overlays.SkinEditor public readonly BindableList SelectedComponents = new BindableList(); + public bool ExternalEditInProgress => externalEditOperation != null && !externalEditOperation.IsCompleted; + protected override bool StartHidden => true; private Drawable? targetScreen; @@ -107,6 +109,8 @@ namespace osu.Game.Overlays.SkinEditor [Resolved] private ExternalEditOverlay? externalEditOverlay { get; set; } + private Task? externalEditOperation; + public SkinEditor() { } @@ -286,7 +290,7 @@ namespace osu.Game.Overlays.SkinEditor var skin = currentSkin.Value.SkinInfo.PerformRead(s => s.Detach()); - await externalEditOverlay!.Begin(skin).ConfigureAwait(false); + externalEditOperation = await externalEditOverlay!.Begin(skin).ConfigureAwait(false); } public bool OnPressed(KeyBindingPressEvent e) diff --git a/osu.Game/Overlays/SkinEditor/SkinEditorOverlay.cs b/osu.Game/Overlays/SkinEditor/SkinEditorOverlay.cs index 571f99bd08..344dcc0d66 100644 --- a/osu.Game/Overlays/SkinEditor/SkinEditorOverlay.cs +++ b/osu.Game/Overlays/SkinEditor/SkinEditorOverlay.cs @@ -334,6 +334,14 @@ namespace osu.Game.Overlays.SkinEditor leasedBeatmapSkins = null; } + public new void ToggleVisibility() + { + if (skinEditor?.ExternalEditInProgress == true) + return; + + base.ToggleVisibility(); + } + private partial class EndlessPlayer : ReplayPlayer { protected override UserActivity? InitialActivity => null;