Merge pull request #11307 from bdach/fix-account-creation-overlay-after-logout

Fix account creation overlay not showing up the first time after a log-out
This commit is contained in:
Dean Herbert 2020-12-28 11:52:48 +09:00 committed by GitHub
commit 69fab7de77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 8 deletions

View File

@ -1,6 +1,7 @@
// 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 NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -13,13 +14,12 @@ namespace osu.Game.Tests.Visual.Online
public class TestSceneAccountCreationOverlay : OsuTestScene
{
private readonly Container userPanelArea;
private readonly AccountCreationOverlay accountCreation;
private IBindable<User> localUser;
public TestSceneAccountCreationOverlay()
{
AccountCreationOverlay accountCreation;
Children = new Drawable[]
{
accountCreation = new AccountCreationOverlay(),
@ -31,8 +31,6 @@ namespace osu.Game.Tests.Visual.Online
Origin = Anchor.TopRight,
},
};
AddStep("show", () => accountCreation.Show());
}
[BackgroundDependencyLoader]
@ -42,8 +40,19 @@ namespace osu.Game.Tests.Visual.Online
localUser = API.LocalUser.GetBoundCopy();
localUser.BindValueChanged(user => { userPanelArea.Child = new UserGridPanel(user.NewValue) { Width = 200 }; }, true);
}
AddStep("logout", API.Logout);
[Test]
public void TestOverlayVisibility()
{
AddStep("start hidden", () => accountCreation.Hide());
AddStep("log out", API.Logout);
AddStep("show manually", () => accountCreation.Show());
AddUntilStep("overlay is visible", () => accountCreation.State.Value == Visibility.Visible);
AddStep("log back in", () => API.Login("dummy", "password"));
AddUntilStep("overlay is hidden", () => accountCreation.State.Value == Visibility.Hidden);
}
}
}

View File

@ -9,6 +9,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Screens;
using osu.Framework.Threading;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API;
@ -93,6 +94,11 @@ namespace osu.Game.Overlays
if (welcomeScreen.GetChildScreen() != null)
welcomeScreen.MakeCurrent();
// there might be a stale scheduled hide from a previous API state change.
// cancel it here so that the overlay is not hidden again after one frame.
scheduledHide?.Cancel();
scheduledHide = null;
}
protected override void PopOut()
@ -101,7 +107,9 @@ namespace osu.Game.Overlays
this.FadeOut(100);
}
private void apiStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
private ScheduledDelegate scheduledHide;
private void apiStateChanged(ValueChangedEvent<APIState> state)
{
switch (state.NewValue)
{
@ -113,9 +121,10 @@ namespace osu.Game.Overlays
break;
case APIState.Online:
Hide();
scheduledHide?.Cancel();
scheduledHide = Schedule(Hide);
break;
}
});
}
}
}