From e1eda89ea69234164ae055d1f129626d8fc970f7 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Wed, 8 Jan 2020 17:41:44 +0100 Subject: [PATCH 01/22] Implement OnlineContainer --- osu.Game/Online/OnlineContainer.cs | 76 ++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 osu.Game/Online/OnlineContainer.cs diff --git a/osu.Game/Online/OnlineContainer.cs b/osu.Game/Online/OnlineContainer.cs new file mode 100644 index 0000000000..6ab5203fe6 --- /dev/null +++ b/osu.Game/Online/OnlineContainer.cs @@ -0,0 +1,76 @@ +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Online.API; +using osu.Game.Online.Placeholders; + +namespace osu.Game.Online +{ + /// + /// A 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. + /// + public class OnlineViewContainer : Container, IOnlineComponent + { + private readonly Container content; + private readonly Container placeholderContainer; + private readonly Placeholder placeholder; + + private const int transform_time = 300; + + protected override Container Content => content; + + public OnlineViewContainer(string placeholder_message) + { + InternalChildren = new Drawable[] + { + content = new Container + { + RelativeSizeAxes = Axes.Both, + }, + placeholderContainer = new Container + { + RelativeSizeAxes = Axes.Both, + Alpha = 0, + Child = placeholder = new LoginPlaceholder() + }, + }; + } + + public void APIStateChanged(IAPIProvider api, APIState state) + { + switch (state) + { + case APIState.Offline: + case APIState.Connecting: + Schedule(() =>updatePlaceholderVisibility(true)); + break; + + default: + Schedule(() => updatePlaceholderVisibility(false)); + break; + } + } + + private void updatePlaceholderVisibility(bool show_placeholder) + { + if (show_placeholder) + { + content.FadeOut(transform_time / 2, Easing.OutQuint); + placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * transform_time, Easing.OutQuint); + placeholderContainer.FadeInFromZero(2 * transform_time, Easing.OutQuint); + } + else + { + placeholderContainer.FadeOut(transform_time / 2, Easing.OutQuint); + content.FadeIn(transform_time, Easing.OutQuint); + } + } + + [BackgroundDependencyLoader] + private void load(IAPIProvider api) + { + api.Register(this); + } + } +} From e9a52984845e9a39cab5a5dd09081aa7045d6436 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Sun, 12 Jan 2020 15:50:35 +0100 Subject: [PATCH 02/22] Allow setting the displayed text on LoginPlaceholder --- osu.Game/Online/Leaderboards/Leaderboard.cs | 2 +- osu.Game/Online/OnlineContainer.cs | 2 +- osu.Game/Online/Placeholders/LoginPlaceholder.cs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game/Online/Leaderboards/Leaderboard.cs b/osu.Game/Online/Leaderboards/Leaderboard.cs index 55233bef6e..095e552ddd 100644 --- a/osu.Game/Online/Leaderboards/Leaderboard.cs +++ b/osu.Game/Online/Leaderboards/Leaderboard.cs @@ -151,7 +151,7 @@ namespace osu.Game.Online.Leaderboards break; case PlaceholderState.NotLoggedIn: - replacePlaceholder(new LoginPlaceholder()); + replacePlaceholder(new LoginPlaceholder(@"Please sign in to view online leaderboards!")); break; case PlaceholderState.NotSupporter: diff --git a/osu.Game/Online/OnlineContainer.cs b/osu.Game/Online/OnlineContainer.cs index 6ab5203fe6..6a8963599f 100644 --- a/osu.Game/Online/OnlineContainer.cs +++ b/osu.Game/Online/OnlineContainer.cs @@ -32,7 +32,7 @@ namespace osu.Game.Online { RelativeSizeAxes = Axes.Both, Alpha = 0, - Child = placeholder = new LoginPlaceholder() + Child = placeholder = new LoginPlaceholder(placeholder_message) }, }; } diff --git a/osu.Game/Online/Placeholders/LoginPlaceholder.cs b/osu.Game/Online/Placeholders/LoginPlaceholder.cs index ffc6623229..f3b5a86785 100644 --- a/osu.Game/Online/Placeholders/LoginPlaceholder.cs +++ b/osu.Game/Online/Placeholders/LoginPlaceholder.cs @@ -14,7 +14,7 @@ namespace osu.Game.Online.Placeholders [Resolved(CanBeNull = true)] private LoginOverlay login { get; set; } - public LoginPlaceholder() + public LoginPlaceholder(string actionMessage) { AddIcon(FontAwesome.Solid.UserLock, cp => { @@ -22,7 +22,7 @@ namespace osu.Game.Online.Placeholders cp.Padding = new MarginPadding { Right = 10 }; }); - AddText(@"Please sign in to view online leaderboards!"); + AddText(actionMessage); } protected override bool OnMouseDown(MouseDownEvent e) From 8f6c6ad77a6198c8954195e656099b6fc4450732 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Sun, 12 Jan 2020 17:43:44 +0100 Subject: [PATCH 03/22] Fix class name not corresponding to filename --- osu.Game/Online/{OnlineContainer.cs => OnlineViewContainer.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename osu.Game/Online/{OnlineContainer.cs => OnlineViewContainer.cs} (100%) diff --git a/osu.Game/Online/OnlineContainer.cs b/osu.Game/Online/OnlineViewContainer.cs similarity index 100% rename from osu.Game/Online/OnlineContainer.cs rename to osu.Game/Online/OnlineViewContainer.cs From 0422b326ad3faa719ba34852a4d80e3b22ce273d Mon Sep 17 00:00:00 2001 From: Lucas A Date: Mon, 13 Jan 2020 21:12:19 +0100 Subject: [PATCH 04/22] Add visual tests --- .../Online/TestSceneOnlineViewContainer.cs | 75 +++++++++++++++++++ osu.Game/Online/API/DummyAPIAccess.cs | 2 +- osu.Game/Online/OnlineViewContainer.cs | 25 ++++--- 3 files changed, 90 insertions(+), 12 deletions(-) create mode 100644 osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs diff --git a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs new file mode 100644 index 0000000000..a8c50a37e7 --- /dev/null +++ b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs @@ -0,0 +1,75 @@ +// Copyright (c) ppy Pty Ltd . 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.Online; +using osu.Game.Online.API; +using osuTK.Graphics; + +namespace osu.Game.Tests.Visual.Online +{ + [TestFixture] + public class TestSceneOnlineViewContainer : OsuTestScene + { + private OnlineViewContainer onlineView; + private Box box; + + public TestSceneOnlineViewContainer() + { + Child = new Container + { + RelativeSizeAxes = Axes.Both, + Child = onlineView = new OnlineViewContainer(@"Please login to view dummy test content") + { + RelativeSizeAxes = Axes.Both, + Children = new Drawable[] + { + box = 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, + } + } + } + }; + } + + [BackgroundDependencyLoader] + private void load() + { + AddStep("set status to offline", () => + { + (API as DummyAPIAccess).State = APIState.Offline; + }); + + AddAssert("children are hidden", () => + { + return !onlineView.Children.First().Parent.IsPresent; + }); + + AddStep("set status to online", () => + { + (API as DummyAPIAccess).State = APIState.Online; + }); + + AddAssert("children are visible", () => + { + return onlineView.Children.First().Parent.IsPresent; + }); + } + } +} diff --git a/osu.Game/Online/API/DummyAPIAccess.cs b/osu.Game/Online/API/DummyAPIAccess.cs index 7f23f9b5d5..a1c3475fd9 100644 --- a/osu.Game/Online/API/DummyAPIAccess.cs +++ b/osu.Game/Online/API/DummyAPIAccess.cs @@ -33,7 +33,7 @@ namespace osu.Game.Online.API public APIState State { get => state; - private set + set { if (state == value) return; diff --git a/osu.Game/Online/OnlineViewContainer.cs b/osu.Game/Online/OnlineViewContainer.cs index 6a8963599f..a7f81b4776 100644 --- a/osu.Game/Online/OnlineViewContainer.cs +++ b/osu.Game/Online/OnlineViewContainer.cs @@ -1,4 +1,7 @@ -using osu.Framework.Allocation; +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Online.API; @@ -20,7 +23,7 @@ namespace osu.Game.Online protected override Container Content => content; - public OnlineViewContainer(string placeholder_message) + public OnlineViewContainer(string placeholderMessage) { InternalChildren = new Drawable[] { @@ -32,7 +35,7 @@ namespace osu.Game.Online { RelativeSizeAxes = Axes.Both, Alpha = 0, - Child = placeholder = new LoginPlaceholder(placeholder_message) + Child = placeholder = new LoginPlaceholder(placeholderMessage) }, }; } @@ -43,7 +46,7 @@ namespace osu.Game.Online { case APIState.Offline: case APIState.Connecting: - Schedule(() =>updatePlaceholderVisibility(true)); + Schedule(() => updatePlaceholderVisibility(true)); break; default: @@ -52,18 +55,18 @@ namespace osu.Game.Online } } - private void updatePlaceholderVisibility(bool show_placeholder) + private void updatePlaceholderVisibility(bool showPlaceholder) { - if (show_placeholder) + if (showPlaceholder) { - content.FadeOut(transform_time / 2, Easing.OutQuint); - placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * transform_time, Easing.OutQuint); - placeholderContainer.FadeInFromZero(2 * transform_time, Easing.OutQuint); + content.FadeOut(transform_time / 2, Easing.OutQuint); + placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * transform_time, Easing.OutQuint); + placeholderContainer.FadeInFromZero(2 * transform_time, Easing.OutQuint); } else { - placeholderContainer.FadeOut(transform_time / 2, Easing.OutQuint); - content.FadeIn(transform_time, Easing.OutQuint); + placeholderContainer.FadeOut(transform_time / 2, Easing.OutQuint); + content.FadeIn(transform_time, Easing.OutQuint); } } From f00938971eda2ba95c451792a6ce56234f073532 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Fri, 17 Jan 2020 18:53:17 +0100 Subject: [PATCH 05/22] Apply review suggestions --- .../Online/TestSceneOnlineViewContainer.cs | 2 +- osu.Game/Online/OnlineViewContainer.cs | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs index a8c50a37e7..9b7de2b7f4 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs @@ -26,7 +26,7 @@ namespace osu.Game.Tests.Visual.Online Child = new Container { RelativeSizeAxes = Axes.Both, - Child = onlineView = new OnlineViewContainer(@"Please login to view dummy test content") + Child = onlineView = new OnlineViewContainer(@"view dummy test content") { RelativeSizeAxes = Axes.Both, Children = new Drawable[] diff --git a/osu.Game/Online/OnlineViewContainer.cs b/osu.Game/Online/OnlineViewContainer.cs index a7f81b4776..ac3a3edd67 100644 --- a/osu.Game/Online/OnlineViewContainer.cs +++ b/osu.Game/Online/OnlineViewContainer.cs @@ -23,6 +23,9 @@ namespace osu.Game.Online protected override Container Content => content; + [Resolved] + protected IAPIProvider API { get; private set; } + public OnlineViewContainer(string placeholderMessage) { InternalChildren = new Drawable[] @@ -35,12 +38,12 @@ namespace osu.Game.Online { RelativeSizeAxes = Axes.Both, Alpha = 0, - Child = placeholder = new LoginPlaceholder(placeholderMessage) + Child = placeholder = new LoginPlaceholder($@"Please sign in to {placeholderMessage}") }, }; } - public void APIStateChanged(IAPIProvider api, APIState state) + public virtual void APIStateChanged(IAPIProvider api, APIState state) { switch (state) { @@ -70,10 +73,16 @@ namespace osu.Game.Online } } - [BackgroundDependencyLoader] - private void load(IAPIProvider api) + protected override void LoadComplete() { - api.Register(this); + API?.Register(this); + base.LoadComplete(); + } + + protected override void Dispose(bool isDisposing) + { + API?.Unregister(this); + base.Dispose(isDisposing); } } } From e1f172e3f820c88b481f546b49752a71a1b754bc Mon Sep 17 00:00:00 2001 From: Lucas A Date: Fri, 17 Jan 2020 19:29:42 +0100 Subject: [PATCH 06/22] Fix CI issues --- .../Online/TestSceneOnlineViewContainer.cs | 25 +++++-------------- osu.Game/Online/OnlineViewContainer.cs | 4 +-- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs index 9b7de2b7f4..4579e4f428 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs @@ -18,8 +18,7 @@ namespace osu.Game.Tests.Visual.Online [TestFixture] public class TestSceneOnlineViewContainer : OsuTestScene { - private OnlineViewContainer onlineView; - private Box box; + private readonly OnlineViewContainer onlineView; public TestSceneOnlineViewContainer() { @@ -31,7 +30,7 @@ namespace osu.Game.Tests.Visual.Online RelativeSizeAxes = Axes.Both, Children = new Drawable[] { - box = new Box + new Box { RelativeSizeAxes = Axes.Both, Colour = Color4.Blue.Opacity(0.8f), @@ -51,25 +50,13 @@ namespace osu.Game.Tests.Visual.Online [BackgroundDependencyLoader] private void load() { - AddStep("set status to offline", () => - { - (API as DummyAPIAccess).State = APIState.Offline; - }); + AddStep("set status to offline", () => ((DummyAPIAccess)API).State = APIState.Offline); - AddAssert("children are hidden", () => - { - return !onlineView.Children.First().Parent.IsPresent; - }); + AddAssert("children are hidden", () => !onlineView.Children.First().Parent.IsPresent); - AddStep("set status to online", () => - { - (API as DummyAPIAccess).State = APIState.Online; - }); + AddStep("set status to online", () => ((DummyAPIAccess)API).State = APIState.Online); - AddAssert("children are visible", () => - { - return onlineView.Children.First().Parent.IsPresent; - }); + AddAssert("children are visible", () => onlineView.Children.First().Parent.IsPresent); } } } diff --git a/osu.Game/Online/OnlineViewContainer.cs b/osu.Game/Online/OnlineViewContainer.cs index ac3a3edd67..0a8432ee12 100644 --- a/osu.Game/Online/OnlineViewContainer.cs +++ b/osu.Game/Online/OnlineViewContainer.cs @@ -62,13 +62,13 @@ namespace osu.Game.Online { if (showPlaceholder) { - content.FadeOut(transform_time / 2, Easing.OutQuint); + content.FadeOut(150, Easing.OutQuint); placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * transform_time, Easing.OutQuint); placeholderContainer.FadeInFromZero(2 * transform_time, Easing.OutQuint); } else { - placeholderContainer.FadeOut(transform_time / 2, Easing.OutQuint); + placeholderContainer.FadeOut(150, Easing.OutQuint); content.FadeIn(transform_time, Easing.OutQuint); } } From 6d51b344abfc6929f5029044dc01b10f8e9dc28d Mon Sep 17 00:00:00 2001 From: Lucas A Date: Sun, 19 Jan 2020 20:24:46 +0100 Subject: [PATCH 07/22] Display a loading animation when the user is connecting --- .../Online/TestSceneOnlineViewContainer.cs | 4 ++ osu.Game/Online/OnlineViewContainer.cs | 57 ++++++++++++++----- 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs index 4579e4f428..ddb672dbf4 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs @@ -57,6 +57,10 @@ namespace osu.Game.Tests.Visual.Online AddStep("set status to online", () => ((DummyAPIAccess)API).State = APIState.Online); 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); } } } diff --git a/osu.Game/Online/OnlineViewContainer.cs b/osu.Game/Online/OnlineViewContainer.cs index 0a8432ee12..35296409e5 100644 --- a/osu.Game/Online/OnlineViewContainer.cs +++ b/osu.Game/Online/OnlineViewContainer.cs @@ -4,6 +4,7 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Game.Graphics.UserInterface; using osu.Game.Online.API; using osu.Game.Online.Placeholders; @@ -15,12 +16,13 @@ namespace osu.Game.Online /// public class OnlineViewContainer : Container, IOnlineComponent { - private readonly Container content; private readonly Container placeholderContainer; private readonly Placeholder placeholder; + private readonly LoadingAnimation loading; private const int transform_time = 300; + private readonly Container content; protected override Container Content => content; [Resolved] @@ -40,6 +42,10 @@ namespace osu.Game.Online Alpha = 0, Child = placeholder = new LoginPlaceholder($@"Please sign in to {placeholderMessage}") }, + loading = new LoadingAnimation + { + Alpha = 0, + } }; } @@ -47,29 +53,43 @@ namespace osu.Game.Online { switch (state) { - case APIState.Offline: + case APIState.Failing: case APIState.Connecting: - Schedule(() => updatePlaceholderVisibility(true)); + Schedule(() => UpdatePlaceholderVisibility(PlaceholderStatus.Connecting)); break; - default: - Schedule(() => updatePlaceholderVisibility(false)); + case APIState.Offline: + Schedule(() => UpdatePlaceholderVisibility(PlaceholderStatus.Offline)); + break; + + case APIState.Online: + Schedule(() => UpdatePlaceholderVisibility(PlaceholderStatus.Online)); break; } } - private void updatePlaceholderVisibility(bool showPlaceholder) + protected void UpdatePlaceholderVisibility(PlaceholderStatus status) { - if (showPlaceholder) + switch (status) { - content.FadeOut(150, Easing.OutQuint); - placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * transform_time, Easing.OutQuint); - placeholderContainer.FadeInFromZero(2 * transform_time, Easing.OutQuint); - } - else - { - placeholderContainer.FadeOut(150, Easing.OutQuint); - content.FadeIn(transform_time, Easing.OutQuint); + 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(); + break; + + 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); base.Dispose(isDisposing); } + + protected enum PlaceholderStatus + { + Offline, + Online, + Connecting, + } } } From d3dc0b63ff9cc9715b5e46909e39ef76435d5007 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Thu, 23 Jan 2020 19:09:34 +0100 Subject: [PATCH 08/22] Remove string concatenation from ctor --- osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs | 2 +- osu.Game/Online/OnlineViewContainer.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs index ddb672dbf4..fddb82d400 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs @@ -25,7 +25,7 @@ namespace osu.Game.Tests.Visual.Online Child = new Container { RelativeSizeAxes = Axes.Both, - Child = onlineView = new OnlineViewContainer(@"view dummy test content") + Child = onlineView = new OnlineViewContainer(@"Please sign in to view dummy test content") { RelativeSizeAxes = Axes.Both, Children = new Drawable[] diff --git a/osu.Game/Online/OnlineViewContainer.cs b/osu.Game/Online/OnlineViewContainer.cs index 35296409e5..49174320d3 100644 --- a/osu.Game/Online/OnlineViewContainer.cs +++ b/osu.Game/Online/OnlineViewContainer.cs @@ -40,7 +40,7 @@ namespace osu.Game.Online { RelativeSizeAxes = Axes.Both, Alpha = 0, - Child = placeholder = new LoginPlaceholder($@"Please sign in to {placeholderMessage}") + Child = placeholder = new LoginPlaceholder(placeholderMessage) }, loading = new LoadingAnimation { From 7ca9f4dc2091c56bd66b11365cbc2dfaa403e4df Mon Sep 17 00:00:00 2001 From: Lucas A Date: Fri, 24 Jan 2020 21:10:31 +0100 Subject: [PATCH 09/22] Apply review suggestions --- .../Online/TestSceneOnlineViewContainer.cs | 85 ++++++++++++------- osu.Game/Online/OnlineViewContainer.cs | 48 +++-------- 2 files changed, 66 insertions(+), 67 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs index fddb82d400..277146e4be 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs @@ -1,14 +1,13 @@ // Copyright (c) ppy Pty Ltd . 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 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); } } } diff --git a/osu.Game/Online/OnlineViewContainer.cs b/osu.Game/Online/OnlineViewContainer.cs index 49174320d3..7874a9fcaf 100644 --- a/osu.Game/Online/OnlineViewContainer.cs +++ b/osu.Game/Online/OnlineViewContainer.cs @@ -14,16 +14,15 @@ namespace osu.Game.Online /// A 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. /// - 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 Content => content; + protected override Container 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, - } } } From 30e0a34e50d083af8726aaaff54fde5c3133f4b0 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Wed, 5 Feb 2020 15:04:10 +0100 Subject: [PATCH 10/22] Wrap Content into a container for animating visibility. --- .../Online/TestSceneOnlineViewContainer.cs | 14 ++++--- osu.Game/Online/OnlineViewContainer.cs | 39 ++++++++++--------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs index 277146e4be..5427db5af3 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs @@ -30,8 +30,6 @@ namespace osu.Game.Tests.Visual.Online private class TestOnlineViewContainer : OnlineViewContainer { - public new Container Content => base.Content; - public new LoadingAnimation LoadingAnimation => base.LoadingAnimation; public TestOnlineViewContainer() @@ -54,6 +52,10 @@ namespace osu.Game.Tests.Visual.Online } }; } + + protected override void FadeContentOut(Drawable content) => content.Hide(); + + protected override void FadeContentIn(Drawable content) => content.Show(); } [Test] @@ -61,7 +63,7 @@ namespace osu.Game.Tests.Visual.Online { AddStep("set status to online", () => ((DummyAPIAccess)API).State = APIState.Online); - AddAssert("children are visible", () => onlineView.Content.IsPresent); + AddAssert("children are visible", () => onlineView.TransformationTarget.IsPresent); AddAssert("loading animation is not visible", () => !onlineView.LoadingAnimation.IsPresent); } @@ -70,7 +72,7 @@ namespace osu.Game.Tests.Visual.Online { AddStep("set status to offline", () => ((DummyAPIAccess)API).State = APIState.Offline); - AddAssert("children are hidden", () => !onlineView.Content.IsPresent); + AddAssert("children are hidden", () => !onlineView.TransformationTarget.IsPresent); AddAssert("loading animation is not visible", () => !onlineView.LoadingAnimation.IsPresent); } @@ -79,12 +81,12 @@ namespace osu.Game.Tests.Visual.Online { AddStep("set status to connecting", () => ((DummyAPIAccess)API).State = APIState.Connecting); - AddAssert("children are hidden", () => !onlineView.Content.IsPresent); + AddAssert("children are hidden", () => !onlineView.TransformationTarget.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("children are hidden", () => !onlineView.TransformationTarget.IsPresent); AddAssert("loading animation is visible", () => onlineView.LoadingAnimation.IsPresent); } } diff --git a/osu.Game/Online/OnlineViewContainer.cs b/osu.Game/Online/OnlineViewContainer.cs index 7874a9fcaf..ac5a7941ea 100644 --- a/osu.Game/Online/OnlineViewContainer.cs +++ b/osu.Game/Online/OnlineViewContainer.cs @@ -11,36 +11,35 @@ using osu.Game.Online.Placeholders; namespace osu.Game.Online { /// - /// A for dislaying online content who require a local user to be logged in. + /// A for dislaying online content which 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. /// public abstract class OnlineViewContainer : Container, IOnlineComponent { - private readonly Container placeholderContainer; private readonly Placeholder placeholder; protected readonly LoadingAnimation LoadingAnimation; - private const int transform_time = 300; + protected const double TRANSFORM_TIME = 300.0; + internal readonly Container TransformationTarget; protected override Container Content { get; } [Resolved] protected IAPIProvider API { get; private set; } - public OnlineViewContainer(string placeholderMessage) + protected OnlineViewContainer(string placeholderMessage) { InternalChildren = new Drawable[] { - Content = new Container + TransformationTarget = new Container { RelativeSizeAxes = Axes.Both, + Child = Content = new Container + { + RelativeSizeAxes = Axes.Both, + } }, - placeholderContainer = new Container - { - RelativeSizeAxes = Axes.Both, - Alpha = 0, - Child = placeholder = new LoginPlaceholder(placeholderMessage) - }, + placeholder = new LoginPlaceholder(placeholderMessage), LoadingAnimation = new LoadingAnimation { Alpha = 0, @@ -53,27 +52,31 @@ namespace osu.Game.Online switch (state) { case APIState.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); + FadeContentOut(TransformationTarget); + placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * TRANSFORM_TIME, Easing.OutQuint); + placeholder.FadeInFromZero(2 * TRANSFORM_TIME, Easing.OutQuint); LoadingAnimation.Hide(); break; case APIState.Online: - placeholderContainer.FadeOut(150, Easing.OutQuint); - Content.FadeIn(transform_time, Easing.OutQuint); + FadeContentIn(TransformationTarget); + placeholder.FadeOut(TRANSFORM_TIME / 2, Easing.OutQuint); LoadingAnimation.Hide(); break; case APIState.Failing: case APIState.Connecting: + FadeContentOut(TransformationTarget); LoadingAnimation.Show(); - placeholderContainer.FadeOut(150, Easing.OutQuint); - Content.FadeOut(150, Easing.OutQuint); + placeholder.FadeOut(TRANSFORM_TIME / 2, Easing.OutQuint); break; } } + protected abstract void FadeContentOut(Drawable content); + + protected abstract void FadeContentIn(Drawable content); + protected override void LoadComplete() { API?.Register(this); From b9e10cb49872c4eb0253a6498050e5cca49a96e0 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Tue, 11 Feb 2020 18:10:46 +0100 Subject: [PATCH 11/22] Privatize ViewTarget --- .../Online/TestSceneOnlineViewContainer.cs | 18 ++++++++++++------ osu.Game/Online/OnlineViewContainer.cs | 16 ++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs index 5427db5af3..2b9609f6e0 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs @@ -32,6 +32,8 @@ namespace osu.Game.Tests.Visual.Online { public new LoadingAnimation LoadingAnimation => base.LoadingAnimation; + public CompositeDrawable ViewTarget => base.Content.Parent; + public TestOnlineViewContainer() : base(@"Please sign in to view dummy test content") { @@ -53,9 +55,9 @@ namespace osu.Game.Tests.Visual.Online }; } - protected override void FadeContentOut(Drawable content) => content.Hide(); + protected override void PopContentOut(Drawable content) => content.Hide(); - protected override void FadeContentIn(Drawable content) => content.Show(); + protected override void PopContentIn(Drawable content) => content.Show(); } [Test] @@ -63,7 +65,7 @@ namespace osu.Game.Tests.Visual.Online { AddStep("set status to online", () => ((DummyAPIAccess)API).State = APIState.Online); - AddAssert("children are visible", () => onlineView.TransformationTarget.IsPresent); + AddAssert("children are visible", () => onlineView.ViewTarget.IsPresent); AddAssert("loading animation is not visible", () => !onlineView.LoadingAnimation.IsPresent); } @@ -72,7 +74,7 @@ namespace osu.Game.Tests.Visual.Online { AddStep("set status to offline", () => ((DummyAPIAccess)API).State = APIState.Offline); - AddAssert("children are hidden", () => !onlineView.TransformationTarget.IsPresent); + AddAssert("children are hidden", () => !onlineView.ViewTarget.IsPresent); AddAssert("loading animation is not visible", () => !onlineView.LoadingAnimation.IsPresent); } @@ -81,12 +83,16 @@ namespace osu.Game.Tests.Visual.Online { AddStep("set status to connecting", () => ((DummyAPIAccess)API).State = APIState.Connecting); - AddAssert("children are hidden", () => !onlineView.TransformationTarget.IsPresent); + AddAssert("children are hidden", () => !onlineView.ViewTarget.IsPresent); AddAssert("loading animation is visible", () => onlineView.LoadingAnimation.IsPresent); + } + [Test] + public void TestFailingStateVisibility() + { AddStep("set status to failing", () => ((DummyAPIAccess)API).State = APIState.Failing); - AddAssert("children are hidden", () => !onlineView.TransformationTarget.IsPresent); + AddAssert("children are hidden", () => !onlineView.ViewTarget.IsPresent); AddAssert("loading animation is visible", () => onlineView.LoadingAnimation.IsPresent); } } diff --git a/osu.Game/Online/OnlineViewContainer.cs b/osu.Game/Online/OnlineViewContainer.cs index ac5a7941ea..c512ca531a 100644 --- a/osu.Game/Online/OnlineViewContainer.cs +++ b/osu.Game/Online/OnlineViewContainer.cs @@ -11,7 +11,7 @@ using osu.Game.Online.Placeholders; namespace osu.Game.Online { /// - /// A for dislaying online content which require a local user to be logged in. + /// A for displaying online content which 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. /// public abstract class OnlineViewContainer : Container, IOnlineComponent @@ -21,7 +21,7 @@ namespace osu.Game.Online protected const double TRANSFORM_TIME = 300.0; - internal readonly Container TransformationTarget; + private readonly Container viewTarget; protected override Container Content { get; } [Resolved] @@ -31,7 +31,7 @@ namespace osu.Game.Online { InternalChildren = new Drawable[] { - TransformationTarget = new Container + viewTarget = new Container { RelativeSizeAxes = Axes.Both, Child = Content = new Container @@ -52,30 +52,30 @@ namespace osu.Game.Online switch (state) { case APIState.Offline: - FadeContentOut(TransformationTarget); + PopContentOut(viewTarget); placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * TRANSFORM_TIME, Easing.OutQuint); placeholder.FadeInFromZero(2 * TRANSFORM_TIME, Easing.OutQuint); LoadingAnimation.Hide(); break; case APIState.Online: - FadeContentIn(TransformationTarget); + PopContentIn(viewTarget); placeholder.FadeOut(TRANSFORM_TIME / 2, Easing.OutQuint); LoadingAnimation.Hide(); break; case APIState.Failing: case APIState.Connecting: - FadeContentOut(TransformationTarget); + PopContentOut(viewTarget); LoadingAnimation.Show(); placeholder.FadeOut(TRANSFORM_TIME / 2, Easing.OutQuint); break; } } - protected abstract void FadeContentOut(Drawable content); + protected abstract void PopContentOut(Drawable content); - protected abstract void FadeContentIn(Drawable content); + protected abstract void PopContentIn(Drawable content); protected override void LoadComplete() { From dac0148c94076026b579a8bc31fbba93bdd134c3 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Thu, 13 Feb 2020 20:08:14 +0100 Subject: [PATCH 12/22] Apply review suggestions. --- .../Online/TestSceneOnlineViewContainer.cs | 2 +- osu.Game/Online/OnlineViewContainer.cs | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs index 2b9609f6e0..9dac28d347 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs @@ -32,7 +32,7 @@ namespace osu.Game.Tests.Visual.Online { public new LoadingAnimation LoadingAnimation => base.LoadingAnimation; - public CompositeDrawable ViewTarget => base.Content.Parent; + public CompositeDrawable ViewTarget => base.Content; public TestOnlineViewContainer() : base(@"Please sign in to view dummy test content") diff --git a/osu.Game/Online/OnlineViewContainer.cs b/osu.Game/Online/OnlineViewContainer.cs index c512ca531a..4b59f6ae80 100644 --- a/osu.Game/Online/OnlineViewContainer.cs +++ b/osu.Game/Online/OnlineViewContainer.cs @@ -21,8 +21,8 @@ namespace osu.Game.Online protected const double TRANSFORM_TIME = 300.0; - private readonly Container viewTarget; - protected override Container Content { get; } + private Container viewContent; + protected override Container Content => viewContent; [Resolved] protected IAPIProvider API { get; private set; } @@ -31,13 +31,9 @@ namespace osu.Game.Online { InternalChildren = new Drawable[] { - viewTarget = new Container + viewContent = new Container { RelativeSizeAxes = Axes.Both, - Child = Content = new Container - { - RelativeSizeAxes = Axes.Both, - } }, placeholder = new LoginPlaceholder(placeholderMessage), LoadingAnimation = new LoadingAnimation @@ -52,21 +48,21 @@ namespace osu.Game.Online switch (state) { case APIState.Offline: - PopContentOut(viewTarget); + PopContentOut(viewContent); placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * TRANSFORM_TIME, Easing.OutQuint); placeholder.FadeInFromZero(2 * TRANSFORM_TIME, Easing.OutQuint); LoadingAnimation.Hide(); break; case APIState.Online: - PopContentIn(viewTarget); + PopContentIn(viewContent); placeholder.FadeOut(TRANSFORM_TIME / 2, Easing.OutQuint); LoadingAnimation.Hide(); break; case APIState.Failing: case APIState.Connecting: - PopContentOut(viewTarget); + PopContentOut(viewContent); LoadingAnimation.Show(); placeholder.FadeOut(TRANSFORM_TIME / 2, Easing.OutQuint); break; From 049b0d93d13530c090612a20a27124ee79fcaf38 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Thu, 13 Feb 2020 21:40:08 +0100 Subject: [PATCH 13/22] Add back default content fade transitions --- .../Visual/Online/TestSceneOnlineViewContainer.cs | 4 ---- osu.Game/Online/OnlineViewContainer.cs | 6 +++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs index 9dac28d347..39b9fd71d0 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs @@ -54,10 +54,6 @@ namespace osu.Game.Tests.Visual.Online } }; } - - protected override void PopContentOut(Drawable content) => content.Hide(); - - protected override void PopContentIn(Drawable content) => content.Show(); } [Test] diff --git a/osu.Game/Online/OnlineViewContainer.cs b/osu.Game/Online/OnlineViewContainer.cs index 4b59f6ae80..2a9aa60e2d 100644 --- a/osu.Game/Online/OnlineViewContainer.cs +++ b/osu.Game/Online/OnlineViewContainer.cs @@ -21,7 +21,7 @@ namespace osu.Game.Online protected const double TRANSFORM_TIME = 300.0; - private Container viewContent; + private readonly Container viewContent; protected override Container Content => viewContent; [Resolved] @@ -69,9 +69,9 @@ namespace osu.Game.Online } } - protected abstract void PopContentOut(Drawable content); + protected virtual void PopContentOut(Drawable content) => content.FadeOut(TRANSFORM_TIME / 2, Easing.OutQuint); - protected abstract void PopContentIn(Drawable content); + protected virtual void PopContentIn(Drawable content) => content.FadeIn(TRANSFORM_TIME, Easing.OutQuint); protected override void LoadComplete() { From aa7efe6141e0ca80c3a908e3902b1dba5c95d4e9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Feb 2020 15:26:55 +0900 Subject: [PATCH 14/22] Fix tests potentially failing due to timing issues --- .../Online/TestSceneOnlineViewContainer.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs index 39b9fd71d0..d656600a18 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs @@ -61,8 +61,8 @@ namespace osu.Game.Tests.Visual.Online { AddStep("set status to online", () => ((DummyAPIAccess)API).State = APIState.Online); - AddAssert("children are visible", () => onlineView.ViewTarget.IsPresent); - AddAssert("loading animation is not visible", () => !onlineView.LoadingAnimation.IsPresent); + AddUntilStep("children are visible", () => onlineView.ViewTarget.IsPresent); + AddUntilStep("loading animation is not visible", () => !onlineView.LoadingAnimation.IsPresent); } [Test] @@ -70,8 +70,8 @@ namespace osu.Game.Tests.Visual.Online { AddStep("set status to offline", () => ((DummyAPIAccess)API).State = APIState.Offline); - AddAssert("children are hidden", () => !onlineView.ViewTarget.IsPresent); - AddAssert("loading animation is not visible", () => !onlineView.LoadingAnimation.IsPresent); + AddUntilStep("children are not visible", () => !onlineView.ViewTarget.IsPresent); + AddUntilStep("loading animation is not visible", () => !onlineView.LoadingAnimation.IsPresent); } [Test] @@ -79,8 +79,8 @@ namespace osu.Game.Tests.Visual.Online { AddStep("set status to connecting", () => ((DummyAPIAccess)API).State = APIState.Connecting); - AddAssert("children are hidden", () => !onlineView.ViewTarget.IsPresent); - AddAssert("loading animation is visible", () => onlineView.LoadingAnimation.IsPresent); + AddUntilStep("children are not visible", () => !onlineView.ViewTarget.IsPresent); + AddUntilStep("loading animation is visible", () => onlineView.LoadingAnimation.IsPresent); } [Test] @@ -88,8 +88,8 @@ namespace osu.Game.Tests.Visual.Online { AddStep("set status to failing", () => ((DummyAPIAccess)API).State = APIState.Failing); - AddAssert("children are hidden", () => !onlineView.ViewTarget.IsPresent); - AddAssert("loading animation is visible", () => onlineView.LoadingAnimation.IsPresent); + AddUntilStep("children are not visible", () => !onlineView.ViewTarget.IsPresent); + AddUntilStep("loading animation is visible", () => onlineView.LoadingAnimation.IsPresent); } } } From c34f1f40eafd8e06f6a7009fc4661105e40664cc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Feb 2020 15:27:09 +0900 Subject: [PATCH 15/22] Fix test text not being centered --- osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs index d656600a18..2bd0d59632 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs @@ -6,6 +6,7 @@ using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; using osu.Game.Online; @@ -38,6 +39,7 @@ namespace osu.Game.Tests.Visual.Online : base(@"Please sign in to view dummy test content") { RelativeSizeAxes = Axes.Both; + Children = new Drawable[] { new Box @@ -48,7 +50,7 @@ namespace osu.Game.Tests.Visual.Online new OsuSpriteText { Text = "dummy online content", - RelativeSizeAxes = Axes.Both, + Font = OsuFont.Default.With(size: 40), Anchor = Anchor.Centre, Origin = Anchor.Centre, } From b86b5e9adb3369f675346d0ef2b22429d87c7a61 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Feb 2020 15:27:39 +0900 Subject: [PATCH 16/22] Move nested class to bottom of file --- .../Online/TestSceneOnlineViewContainer.cs | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs index 2bd0d59632..3c2735ca56 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneOnlineViewContainer.cs @@ -29,35 +29,6 @@ namespace osu.Game.Tests.Visual.Online }; } - private class TestOnlineViewContainer : OnlineViewContainer - { - public new LoadingAnimation LoadingAnimation => base.LoadingAnimation; - - public CompositeDrawable ViewTarget => base.Content; - - 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", - Font = OsuFont.Default.With(size: 40), - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - } - }; - } - } - [Test] public void TestOnlineStateVisibility() { @@ -93,5 +64,34 @@ namespace osu.Game.Tests.Visual.Online AddUntilStep("children are not visible", () => !onlineView.ViewTarget.IsPresent); AddUntilStep("loading animation is visible", () => onlineView.LoadingAnimation.IsPresent); } + + private class TestOnlineViewContainer : OnlineViewContainer + { + public new LoadingAnimation LoadingAnimation => base.LoadingAnimation; + + public CompositeDrawable ViewTarget => base.Content; + + 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", + Font = OsuFont.Default.With(size: 40), + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + } + }; + } + } } } From 4d5abab2ee0b39704f0e5b91bf41e01e7b50f83b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Feb 2020 15:29:50 +0900 Subject: [PATCH 17/22] Remove unnecessary content private storage --- osu.Game/Online/OnlineViewContainer.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/osu.Game/Online/OnlineViewContainer.cs b/osu.Game/Online/OnlineViewContainer.cs index 2a9aa60e2d..0ffb342bfc 100644 --- a/osu.Game/Online/OnlineViewContainer.cs +++ b/osu.Game/Online/OnlineViewContainer.cs @@ -21,8 +21,7 @@ namespace osu.Game.Online protected const double TRANSFORM_TIME = 300.0; - private readonly Container viewContent; - protected override Container Content => viewContent; + protected override Container Content { get; } [Resolved] protected IAPIProvider API { get; private set; } @@ -31,7 +30,7 @@ namespace osu.Game.Online { InternalChildren = new Drawable[] { - viewContent = new Container + Content = new Container { RelativeSizeAxes = Axes.Both, }, @@ -48,21 +47,21 @@ namespace osu.Game.Online switch (state) { case APIState.Offline: - PopContentOut(viewContent); + PopContentOut(Content); placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * TRANSFORM_TIME, Easing.OutQuint); placeholder.FadeInFromZero(2 * TRANSFORM_TIME, Easing.OutQuint); LoadingAnimation.Hide(); break; case APIState.Online: - PopContentIn(viewContent); + PopContentIn(Content); placeholder.FadeOut(TRANSFORM_TIME / 2, Easing.OutQuint); LoadingAnimation.Hide(); break; case APIState.Failing: case APIState.Connecting: - PopContentOut(viewContent); + PopContentOut(Content); LoadingAnimation.Show(); placeholder.FadeOut(TRANSFORM_TIME / 2, Easing.OutQuint); break; From 7e6c194d4a9c9f04712db293bc39f5f6baf201f5 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Feb 2020 15:34:46 +0900 Subject: [PATCH 18/22] Add missing xmldoc --- osu.Game/Online/OnlineViewContainer.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/osu.Game/Online/OnlineViewContainer.cs b/osu.Game/Online/OnlineViewContainer.cs index 0ffb342bfc..50b4820d15 100644 --- a/osu.Game/Online/OnlineViewContainer.cs +++ b/osu.Game/Online/OnlineViewContainer.cs @@ -68,8 +68,14 @@ namespace osu.Game.Online } } + /// + /// Applies a transform to the online content to make it hidden. + /// protected virtual void PopContentOut(Drawable content) => content.FadeOut(TRANSFORM_TIME / 2, Easing.OutQuint); + /// + /// Applies a transform to the online content to make it visible. + /// protected virtual void PopContentIn(Drawable content) => content.FadeIn(TRANSFORM_TIME, Easing.OutQuint); protected override void LoadComplete() From 6f1cecd86f7fc4efa6e00c0da8e44972f332f880 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Feb 2020 15:35:39 +0900 Subject: [PATCH 19/22] Move LoadComplete up in method --- osu.Game/Online/OnlineViewContainer.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game/Online/OnlineViewContainer.cs b/osu.Game/Online/OnlineViewContainer.cs index 50b4820d15..3b2243c97a 100644 --- a/osu.Game/Online/OnlineViewContainer.cs +++ b/osu.Game/Online/OnlineViewContainer.cs @@ -42,6 +42,12 @@ namespace osu.Game.Online }; } + protected override void LoadComplete() + { + API?.Register(this); + base.LoadComplete(); + } + public virtual void APIStateChanged(IAPIProvider api, APIState state) { switch (state) @@ -78,12 +84,6 @@ namespace osu.Game.Online /// protected virtual void PopContentIn(Drawable content) => content.FadeIn(TRANSFORM_TIME, Easing.OutQuint); - protected override void LoadComplete() - { - API?.Register(this); - base.LoadComplete(); - } - protected override void Dispose(bool isDisposing) { API?.Unregister(this); From edf9cfc8635580d7e40c188828a2533ec5b824ab Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Feb 2020 15:36:06 +0900 Subject: [PATCH 20/22] API can't be null on load --- osu.Game/Online/OnlineViewContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Online/OnlineViewContainer.cs b/osu.Game/Online/OnlineViewContainer.cs index 3b2243c97a..b16fbb7aed 100644 --- a/osu.Game/Online/OnlineViewContainer.cs +++ b/osu.Game/Online/OnlineViewContainer.cs @@ -44,7 +44,7 @@ namespace osu.Game.Online protected override void LoadComplete() { - API?.Register(this); + API.Register(this); base.LoadComplete(); } From 720ceca78a3cdd5c90acf75684c8a0d65af2f67b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Feb 2020 15:38:47 +0900 Subject: [PATCH 21/22] Final tidy-up pass --- osu.Game/Online/OnlineViewContainer.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/osu.Game/Online/OnlineViewContainer.cs b/osu.Game/Online/OnlineViewContainer.cs index b16fbb7aed..83fbff733f 100644 --- a/osu.Game/Online/OnlineViewContainer.cs +++ b/osu.Game/Online/OnlineViewContainer.cs @@ -19,7 +19,7 @@ namespace osu.Game.Online private readonly Placeholder placeholder; protected readonly LoadingAnimation LoadingAnimation; - protected const double TRANSFORM_TIME = 300.0; + private const double transform_duration = 300; protected override Container Content { get; } @@ -44,8 +44,9 @@ namespace osu.Game.Online protected override void LoadComplete() { - API.Register(this); base.LoadComplete(); + + API.Register(this); } public virtual void APIStateChanged(IAPIProvider api, APIState state) @@ -54,14 +55,14 @@ namespace osu.Game.Online { case APIState.Offline: PopContentOut(Content); - placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * TRANSFORM_TIME, Easing.OutQuint); - placeholder.FadeInFromZero(2 * TRANSFORM_TIME, Easing.OutQuint); + placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * transform_duration, Easing.OutQuint); + placeholder.FadeInFromZero(2 * transform_duration, Easing.OutQuint); LoadingAnimation.Hide(); break; case APIState.Online: PopContentIn(Content); - placeholder.FadeOut(TRANSFORM_TIME / 2, Easing.OutQuint); + placeholder.FadeOut(transform_duration / 2, Easing.OutQuint); LoadingAnimation.Hide(); break; @@ -69,7 +70,7 @@ namespace osu.Game.Online case APIState.Connecting: PopContentOut(Content); LoadingAnimation.Show(); - placeholder.FadeOut(TRANSFORM_TIME / 2, Easing.OutQuint); + placeholder.FadeOut(transform_duration / 2, Easing.OutQuint); break; } } @@ -77,12 +78,12 @@ namespace osu.Game.Online /// /// Applies a transform to the online content to make it hidden. /// - protected virtual void PopContentOut(Drawable content) => content.FadeOut(TRANSFORM_TIME / 2, Easing.OutQuint); + protected virtual void PopContentOut(Drawable content) => content.FadeOut(transform_duration / 2, Easing.OutQuint); /// /// Applies a transform to the online content to make it visible. /// - protected virtual void PopContentIn(Drawable content) => content.FadeIn(TRANSFORM_TIME, Easing.OutQuint); + protected virtual void PopContentIn(Drawable content) => content.FadeIn(transform_duration, Easing.OutQuint); protected override void Dispose(bool isDisposing) { From a75715607b3882c14ccab7984cc9ee4a97534522 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Feb 2020 15:41:46 +0900 Subject: [PATCH 22/22] Move drawable load to asynchronous context --- osu.Game/Online/OnlineViewContainer.cs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/osu.Game/Online/OnlineViewContainer.cs b/osu.Game/Online/OnlineViewContainer.cs index 83fbff733f..689c1c0afb 100644 --- a/osu.Game/Online/OnlineViewContainer.cs +++ b/osu.Game/Online/OnlineViewContainer.cs @@ -16,24 +16,30 @@ namespace osu.Game.Online /// public abstract class OnlineViewContainer : Container, IOnlineComponent { - private readonly Placeholder placeholder; - protected readonly LoadingAnimation LoadingAnimation; + protected LoadingAnimation LoadingAnimation { get; private set; } + + protected override Container Content { get; } = new Container { RelativeSizeAxes = Axes.Both }; + + private readonly string placeholderMessage; + + private Placeholder placeholder; private const double transform_duration = 300; - protected override Container Content { get; } - [Resolved] protected IAPIProvider API { get; private set; } protected OnlineViewContainer(string placeholderMessage) + { + this.placeholderMessage = placeholderMessage; + } + + [BackgroundDependencyLoader] + private void load() { InternalChildren = new Drawable[] { - Content = new Container - { - RelativeSizeAxes = Axes.Both, - }, + Content, placeholder = new LoginPlaceholder(placeholderMessage), LoadingAnimation = new LoadingAnimation {