From 30e0a34e50d083af8726aaaff54fde5c3133f4b0 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Wed, 5 Feb 2020 15:04:10 +0100 Subject: [PATCH] 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);