mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 11:20:04 +08:00
Wrap Content into a container for animating visibility.
This commit is contained in:
parent
7ca9f4dc20
commit
30e0a34e50
@ -30,8 +30,6 @@ namespace osu.Game.Tests.Visual.Online
|
||||
|
||||
private class TestOnlineViewContainer : OnlineViewContainer
|
||||
{
|
||||
public new Container<Drawable> 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);
|
||||
}
|
||||
}
|
||||
|
@ -11,36 +11,35 @@ using osu.Game.Online.Placeholders;
|
||||
namespace osu.Game.Online
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="Container"/> for dislaying online content who require a local user to be logged in.
|
||||
/// A <see cref="Container"/> 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.
|
||||
/// </summary>
|
||||
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<Drawable> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user