mirror of
https://github.com/ppy/osu
synced 2025-01-25 15:23:02 +00: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
|
private class TestOnlineViewContainer : OnlineViewContainer
|
||||||
{
|
{
|
||||||
public new Container<Drawable> Content => base.Content;
|
|
||||||
|
|
||||||
public new LoadingAnimation LoadingAnimation => base.LoadingAnimation;
|
public new LoadingAnimation LoadingAnimation => base.LoadingAnimation;
|
||||||
|
|
||||||
public TestOnlineViewContainer()
|
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]
|
[Test]
|
||||||
@ -61,7 +63,7 @@ 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.Content.IsPresent);
|
AddAssert("children are visible", () => onlineView.TransformationTarget.IsPresent);
|
||||||
AddAssert("loading animation is not visible", () => !onlineView.LoadingAnimation.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);
|
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);
|
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);
|
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);
|
AddAssert("loading animation is visible", () => onlineView.LoadingAnimation.IsPresent);
|
||||||
|
|
||||||
AddStep("set status to failing", () => ((DummyAPIAccess)API).State = APIState.Failing);
|
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);
|
AddAssert("loading animation is visible", () => onlineView.LoadingAnimation.IsPresent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,36 +11,35 @@ using osu.Game.Online.Placeholders;
|
|||||||
namespace osu.Game.Online
|
namespace osu.Game.Online
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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.
|
/// Shows its children only when the local user is logged in and supports displaying a placeholder if not.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class OnlineViewContainer : Container, IOnlineComponent
|
public abstract class OnlineViewContainer : Container, IOnlineComponent
|
||||||
{
|
{
|
||||||
private readonly Container placeholderContainer;
|
|
||||||
private readonly Placeholder placeholder;
|
private readonly Placeholder placeholder;
|
||||||
protected readonly LoadingAnimation LoadingAnimation;
|
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; }
|
protected override Container<Drawable> Content { get; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
protected IAPIProvider API { get; private set; }
|
protected IAPIProvider API { get; private set; }
|
||||||
|
|
||||||
public OnlineViewContainer(string placeholderMessage)
|
protected OnlineViewContainer(string placeholderMessage)
|
||||||
{
|
{
|
||||||
InternalChildren = new Drawable[]
|
InternalChildren = new Drawable[]
|
||||||
{
|
{
|
||||||
Content = new Container
|
TransformationTarget = new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Child = Content = new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
placeholderContainer = new Container
|
placeholder = new LoginPlaceholder(placeholderMessage),
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Alpha = 0,
|
|
||||||
Child = placeholder = new LoginPlaceholder(placeholderMessage)
|
|
||||||
},
|
|
||||||
LoadingAnimation = new LoadingAnimation
|
LoadingAnimation = new LoadingAnimation
|
||||||
{
|
{
|
||||||
Alpha = 0,
|
Alpha = 0,
|
||||||
@ -53,27 +52,31 @@ namespace osu.Game.Online
|
|||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case APIState.Offline:
|
case APIState.Offline:
|
||||||
Content.FadeOut(150, Easing.OutQuint);
|
FadeContentOut(TransformationTarget);
|
||||||
placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * transform_time, Easing.OutQuint);
|
placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * TRANSFORM_TIME, Easing.OutQuint);
|
||||||
placeholderContainer.FadeInFromZero(2 * transform_time, Easing.OutQuint);
|
placeholder.FadeInFromZero(2 * TRANSFORM_TIME, Easing.OutQuint);
|
||||||
LoadingAnimation.Hide();
|
LoadingAnimation.Hide();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case APIState.Online:
|
case APIState.Online:
|
||||||
placeholderContainer.FadeOut(150, Easing.OutQuint);
|
FadeContentIn(TransformationTarget);
|
||||||
Content.FadeIn(transform_time, Easing.OutQuint);
|
placeholder.FadeOut(TRANSFORM_TIME / 2, Easing.OutQuint);
|
||||||
LoadingAnimation.Hide();
|
LoadingAnimation.Hide();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case APIState.Failing:
|
case APIState.Failing:
|
||||||
case APIState.Connecting:
|
case APIState.Connecting:
|
||||||
|
FadeContentOut(TransformationTarget);
|
||||||
LoadingAnimation.Show();
|
LoadingAnimation.Show();
|
||||||
placeholderContainer.FadeOut(150, Easing.OutQuint);
|
placeholder.FadeOut(TRANSFORM_TIME / 2, Easing.OutQuint);
|
||||||
Content.FadeOut(150, Easing.OutQuint);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract void FadeContentOut(Drawable content);
|
||||||
|
|
||||||
|
protected abstract void FadeContentIn(Drawable content);
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
API?.Register(this);
|
API?.Register(this);
|
||||||
|
Loading…
Reference in New Issue
Block a user