mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 21:02:55 +08:00
Merge pull request #21299 from frenzibyte/perform-from-runner-load-state
Fix "perform from screen" invoking action on non-loaded screens
This commit is contained in:
commit
4648e7bee0
@ -4,6 +4,7 @@
|
|||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
@ -85,6 +86,19 @@ namespace osu.Game.Tests.Visual.Navigation
|
|||||||
AddAssert("did perform", () => actionPerformed);
|
AddAssert("did perform", () => actionPerformed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestPerformEnsuresScreenIsLoaded()
|
||||||
|
{
|
||||||
|
TestLoadBlockingScreen screen = null;
|
||||||
|
|
||||||
|
AddStep("push blocking screen", () => Game.ScreenStack.Push(screen = new TestLoadBlockingScreen()));
|
||||||
|
AddStep("perform", () => Game.PerformFromScreen(_ => actionPerformed = true, new[] { typeof(TestLoadBlockingScreen) }));
|
||||||
|
AddAssert("action not performed", () => !actionPerformed);
|
||||||
|
|
||||||
|
AddStep("allow load", () => screen.LoadEvent.Set());
|
||||||
|
AddUntilStep("action performed", () => actionPerformed);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestOverlaysAlwaysClosed()
|
public void TestOverlaysAlwaysClosed()
|
||||||
{
|
{
|
||||||
@ -270,5 +284,16 @@ namespace osu.Game.Tests.Visual.Navigation
|
|||||||
return base.OnExiting(e);
|
return base.OnExiting(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class TestLoadBlockingScreen : OsuScreen
|
||||||
|
{
|
||||||
|
public readonly ManualResetEventSlim LoadEvent = new ManualResetEventSlim();
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
LoadEvent.Wait(10000);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,10 @@ namespace osu.Game
|
|||||||
// check if we are already at a valid target screen.
|
// check if we are already at a valid target screen.
|
||||||
if (validScreens.Any(t => t.IsAssignableFrom(type)))
|
if (validScreens.Any(t => t.IsAssignableFrom(type)))
|
||||||
{
|
{
|
||||||
|
if (!((Drawable)current).IsLoaded)
|
||||||
|
// wait until screen is loaded before invoking action.
|
||||||
|
return true;
|
||||||
|
|
||||||
finalAction(current);
|
finalAction(current);
|
||||||
Cancel();
|
Cancel();
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user