mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 14:42:56 +08:00
Apply review suggestions
This commit is contained in:
parent
d3dc0b63ff
commit
7ca9f4dc20
@ -1,14 +1,13 @@
|
||||
// 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 System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online;
|
||||
using osu.Game.Online.API;
|
||||
using osuTK.Graphics;
|
||||
@ -18,49 +17,75 @@ namespace osu.Game.Tests.Visual.Online
|
||||
[TestFixture]
|
||||
public class TestSceneOnlineViewContainer : OsuTestScene
|
||||
{
|
||||
private readonly OnlineViewContainer onlineView;
|
||||
private readonly TestOnlineViewContainer onlineView;
|
||||
|
||||
public TestSceneOnlineViewContainer()
|
||||
{
|
||||
Child = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = onlineView = new OnlineViewContainer(@"Please sign in to view dummy test content")
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.Blue.Opacity(0.8f),
|
||||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = "dummy online content",
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
}
|
||||
}
|
||||
}
|
||||
Child = onlineView = new TestOnlineViewContainer()
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
private class TestOnlineViewContainer : OnlineViewContainer
|
||||
{
|
||||
public new Container<Drawable> Content => base.Content;
|
||||
|
||||
public new LoadingAnimation LoadingAnimation => base.LoadingAnimation;
|
||||
|
||||
public TestOnlineViewContainer()
|
||||
: base(@"Please sign in to view dummy test content")
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.Blue.Opacity(0.8f),
|
||||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = "dummy online content",
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestOnlineStateVisibility()
|
||||
{
|
||||
AddStep("set status to online", () => ((DummyAPIAccess)API).State = APIState.Online);
|
||||
|
||||
AddAssert("children are visible", () => onlineView.Content.IsPresent);
|
||||
AddAssert("loading animation is not visible", () => !onlineView.LoadingAnimation.IsPresent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestOfflineStateVisibility()
|
||||
{
|
||||
AddStep("set status to offline", () => ((DummyAPIAccess)API).State = APIState.Offline);
|
||||
|
||||
AddAssert("children are hidden", () => !onlineView.Children.First().Parent.IsPresent);
|
||||
|
||||
AddStep("set status to online", () => ((DummyAPIAccess)API).State = APIState.Online);
|
||||
|
||||
AddAssert("children are visible", () => onlineView.Children.First().Parent.IsPresent);
|
||||
AddAssert("children are hidden", () => !onlineView.Content.IsPresent);
|
||||
AddAssert("loading animation is not visible", () => !onlineView.LoadingAnimation.IsPresent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConnectingStateVisibility()
|
||||
{
|
||||
AddStep("set status to connecting", () => ((DummyAPIAccess)API).State = APIState.Connecting);
|
||||
|
||||
AddAssert("children are hidden", () => !onlineView.Children.First().Parent.IsPresent);
|
||||
AddAssert("children are hidden", () => !onlineView.Content.IsPresent);
|
||||
AddAssert("loading animation is visible", () => onlineView.LoadingAnimation.IsPresent);
|
||||
|
||||
AddStep("set status to failing", () => ((DummyAPIAccess)API).State = APIState.Failing);
|
||||
|
||||
AddAssert("children are hidden", () => !onlineView.Content.IsPresent);
|
||||
AddAssert("loading animation is visible", () => onlineView.LoadingAnimation.IsPresent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,16 +14,15 @@ namespace osu.Game.Online
|
||||
/// A <see cref="Container"/> for dislaying online content who require a local user to be logged in.
|
||||
/// Shows its children only when the local user is logged in and supports displaying a placeholder if not.
|
||||
/// </summary>
|
||||
public class OnlineViewContainer : Container, IOnlineComponent
|
||||
public abstract class OnlineViewContainer : Container, IOnlineComponent
|
||||
{
|
||||
private readonly Container placeholderContainer;
|
||||
private readonly Placeholder placeholder;
|
||||
private readonly LoadingAnimation loading;
|
||||
protected readonly LoadingAnimation LoadingAnimation;
|
||||
|
||||
private const int transform_time = 300;
|
||||
|
||||
private readonly Container content;
|
||||
protected override Container<Drawable> Content => content;
|
||||
protected override Container<Drawable> Content { get; }
|
||||
|
||||
[Resolved]
|
||||
protected IAPIProvider API { get; private set; }
|
||||
@ -32,7 +31,7 @@ namespace osu.Game.Online
|
||||
{
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
content = new Container
|
||||
Content = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
@ -42,7 +41,7 @@ namespace osu.Game.Online
|
||||
Alpha = 0,
|
||||
Child = placeholder = new LoginPlaceholder(placeholderMessage)
|
||||
},
|
||||
loading = new LoadingAnimation
|
||||
LoadingAnimation = new LoadingAnimation
|
||||
{
|
||||
Alpha = 0,
|
||||
}
|
||||
@ -53,40 +52,22 @@ namespace osu.Game.Online
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case APIState.Failing:
|
||||
case APIState.Connecting:
|
||||
Schedule(() => UpdatePlaceholderVisibility(PlaceholderStatus.Connecting));
|
||||
break;
|
||||
|
||||
case APIState.Offline:
|
||||
Schedule(() => UpdatePlaceholderVisibility(PlaceholderStatus.Offline));
|
||||
break;
|
||||
|
||||
case APIState.Online:
|
||||
Schedule(() => UpdatePlaceholderVisibility(PlaceholderStatus.Online));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void UpdatePlaceholderVisibility(PlaceholderStatus status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case PlaceholderStatus.Offline:
|
||||
Content.FadeOut(150, Easing.OutQuint);
|
||||
placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * transform_time, Easing.OutQuint);
|
||||
placeholderContainer.FadeInFromZero(2 * transform_time, Easing.OutQuint);
|
||||
loading.Hide();
|
||||
LoadingAnimation.Hide();
|
||||
break;
|
||||
|
||||
case PlaceholderStatus.Online:
|
||||
case APIState.Online:
|
||||
placeholderContainer.FadeOut(150, Easing.OutQuint);
|
||||
Content.FadeIn(transform_time, Easing.OutQuint);
|
||||
loading.Hide();
|
||||
LoadingAnimation.Hide();
|
||||
break;
|
||||
|
||||
case PlaceholderStatus.Connecting:
|
||||
loading.Show();
|
||||
case APIState.Failing:
|
||||
case APIState.Connecting:
|
||||
LoadingAnimation.Show();
|
||||
placeholderContainer.FadeOut(150, Easing.OutQuint);
|
||||
Content.FadeOut(150, Easing.OutQuint);
|
||||
break;
|
||||
@ -104,12 +85,5 @@ namespace osu.Game.Online
|
||||
API?.Unregister(this);
|
||||
base.Dispose(isDisposing);
|
||||
}
|
||||
|
||||
protected enum PlaceholderStatus
|
||||
{
|
||||
Offline,
|
||||
Online,
|
||||
Connecting,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user