Display a loading animation when the user is connecting

This commit is contained in:
Lucas A 2020-01-19 20:24:46 +01:00
parent e1f172e3f8
commit 6d51b344ab
2 changed files with 46 additions and 15 deletions

View File

@ -57,6 +57,10 @@ namespace osu.Game.Tests.Visual.Online
AddStep("set status to online", () => ((DummyAPIAccess)API).State = APIState.Online); AddStep("set status to online", () => ((DummyAPIAccess)API).State = APIState.Online);
AddAssert("children are visible", () => onlineView.Children.First().Parent.IsPresent); AddAssert("children are visible", () => onlineView.Children.First().Parent.IsPresent);
AddStep("set status to connecting", () => ((DummyAPIAccess)API).State = APIState.Connecting);
AddAssert("children are hidden", () => !onlineView.Children.First().Parent.IsPresent);
} }
} }
} }

View File

@ -4,6 +4,7 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.Placeholders; using osu.Game.Online.Placeholders;
@ -15,12 +16,13 @@ namespace osu.Game.Online
/// </summary> /// </summary>
public class OnlineViewContainer : Container, IOnlineComponent public class OnlineViewContainer : Container, IOnlineComponent
{ {
private readonly Container content;
private readonly Container placeholderContainer; private readonly Container placeholderContainer;
private readonly Placeholder placeholder; private readonly Placeholder placeholder;
private readonly LoadingAnimation loading;
private const int transform_time = 300; private const int transform_time = 300;
private readonly Container content;
protected override Container<Drawable> Content => content; protected override Container<Drawable> Content => content;
[Resolved] [Resolved]
@ -40,6 +42,10 @@ namespace osu.Game.Online
Alpha = 0, Alpha = 0,
Child = placeholder = new LoginPlaceholder($@"Please sign in to {placeholderMessage}") Child = placeholder = new LoginPlaceholder($@"Please sign in to {placeholderMessage}")
}, },
loading = new LoadingAnimation
{
Alpha = 0,
}
}; };
} }
@ -47,29 +53,43 @@ namespace osu.Game.Online
{ {
switch (state) switch (state)
{ {
case APIState.Offline: case APIState.Failing:
case APIState.Connecting: case APIState.Connecting:
Schedule(() => updatePlaceholderVisibility(true)); Schedule(() => UpdatePlaceholderVisibility(PlaceholderStatus.Connecting));
break; break;
default: case APIState.Offline:
Schedule(() => updatePlaceholderVisibility(false)); Schedule(() => UpdatePlaceholderVisibility(PlaceholderStatus.Offline));
break;
case APIState.Online:
Schedule(() => UpdatePlaceholderVisibility(PlaceholderStatus.Online));
break; break;
} }
} }
private void updatePlaceholderVisibility(bool showPlaceholder) protected void UpdatePlaceholderVisibility(PlaceholderStatus status)
{ {
if (showPlaceholder) switch (status)
{ {
content.FadeOut(150, Easing.OutQuint); case PlaceholderStatus.Offline:
placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * transform_time, Easing.OutQuint); Content.FadeOut(150, Easing.OutQuint);
placeholderContainer.FadeInFromZero(2 * transform_time, Easing.OutQuint); placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * transform_time, Easing.OutQuint);
} placeholderContainer.FadeInFromZero(2 * transform_time, Easing.OutQuint);
else loading.Hide();
{ break;
placeholderContainer.FadeOut(150, Easing.OutQuint);
content.FadeIn(transform_time, Easing.OutQuint); case PlaceholderStatus.Online:
placeholderContainer.FadeOut(150, Easing.OutQuint);
Content.FadeIn(transform_time, Easing.OutQuint);
loading.Hide();
break;
case PlaceholderStatus.Connecting:
loading.Show();
placeholderContainer.FadeOut(150, Easing.OutQuint);
Content.FadeOut(150, Easing.OutQuint);
break;
} }
} }
@ -84,5 +104,12 @@ namespace osu.Game.Online
API?.Unregister(this); API?.Unregister(this);
base.Dispose(isDisposing); base.Dispose(isDisposing);
} }
protected enum PlaceholderStatus
{
Offline,
Online,
Connecting,
}
} }
} }