2020-01-14 04:12:19 +08:00
|
|
|
|
// 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 osu.Framework.Allocation;
|
2020-01-09 00:41:44 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-01-20 03:24:46 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-01-09 00:41:44 +08:00
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
|
using osu.Game.Online.Placeholders;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Online
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2020-02-12 01:10:46 +08:00
|
|
|
|
/// A <see cref="Container"/> for displaying online content which require a local user to be logged in.
|
2020-01-09 00:41:44 +08:00
|
|
|
|
/// Shows its children only when the local user is logged in and supports displaying a placeholder if not.
|
|
|
|
|
/// </summary>
|
2020-01-25 04:10:31 +08:00
|
|
|
|
public abstract class OnlineViewContainer : Container, IOnlineComponent
|
2020-01-09 00:41:44 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly Placeholder placeholder;
|
2020-01-25 04:10:31 +08:00
|
|
|
|
protected readonly LoadingAnimation LoadingAnimation;
|
2020-01-09 00:41:44 +08:00
|
|
|
|
|
2020-02-05 22:04:10 +08:00
|
|
|
|
protected const double TRANSFORM_TIME = 300.0;
|
2020-01-09 00:41:44 +08:00
|
|
|
|
|
2020-02-12 01:10:46 +08:00
|
|
|
|
private readonly Container viewTarget;
|
2020-01-25 04:10:31 +08:00
|
|
|
|
protected override Container<Drawable> Content { get; }
|
2020-01-09 00:41:44 +08:00
|
|
|
|
|
2020-01-18 01:53:17 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
protected IAPIProvider API { get; private set; }
|
|
|
|
|
|
2020-02-05 22:04:10 +08:00
|
|
|
|
protected OnlineViewContainer(string placeholderMessage)
|
2020-01-09 00:41:44 +08:00
|
|
|
|
{
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
2020-02-12 01:10:46 +08:00
|
|
|
|
viewTarget = new Container
|
2020-01-09 00:41:44 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-02-05 22:04:10 +08:00
|
|
|
|
Child = Content = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
}
|
2020-01-09 00:41:44 +08:00
|
|
|
|
},
|
2020-02-05 22:04:10 +08:00
|
|
|
|
placeholder = new LoginPlaceholder(placeholderMessage),
|
2020-01-25 04:10:31 +08:00
|
|
|
|
LoadingAnimation = new LoadingAnimation
|
2020-01-20 03:24:46 +08:00
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
}
|
2020-01-09 00:41:44 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-18 01:53:17 +08:00
|
|
|
|
public virtual void APIStateChanged(IAPIProvider api, APIState state)
|
2020-01-09 00:41:44 +08:00
|
|
|
|
{
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
2020-01-20 03:24:46 +08:00
|
|
|
|
case APIState.Offline:
|
2020-02-12 01:10:46 +08:00
|
|
|
|
PopContentOut(viewTarget);
|
2020-02-05 22:04:10 +08:00
|
|
|
|
placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * TRANSFORM_TIME, Easing.OutQuint);
|
|
|
|
|
placeholder.FadeInFromZero(2 * TRANSFORM_TIME, Easing.OutQuint);
|
2020-01-25 04:10:31 +08:00
|
|
|
|
LoadingAnimation.Hide();
|
2020-01-20 03:24:46 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2020-01-25 04:10:31 +08:00
|
|
|
|
case APIState.Online:
|
2020-02-12 01:10:46 +08:00
|
|
|
|
PopContentIn(viewTarget);
|
2020-02-05 22:04:10 +08:00
|
|
|
|
placeholder.FadeOut(TRANSFORM_TIME / 2, Easing.OutQuint);
|
2020-01-25 04:10:31 +08:00
|
|
|
|
LoadingAnimation.Hide();
|
2020-01-20 03:24:46 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2020-01-25 04:10:31 +08:00
|
|
|
|
case APIState.Failing:
|
|
|
|
|
case APIState.Connecting:
|
2020-02-12 01:10:46 +08:00
|
|
|
|
PopContentOut(viewTarget);
|
2020-01-25 04:10:31 +08:00
|
|
|
|
LoadingAnimation.Show();
|
2020-02-05 22:04:10 +08:00
|
|
|
|
placeholder.FadeOut(TRANSFORM_TIME / 2, Easing.OutQuint);
|
2020-01-20 03:24:46 +08:00
|
|
|
|
break;
|
2020-01-09 00:41:44 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-12 01:10:46 +08:00
|
|
|
|
protected abstract void PopContentOut(Drawable content);
|
2020-02-05 22:04:10 +08:00
|
|
|
|
|
2020-02-12 01:10:46 +08:00
|
|
|
|
protected abstract void PopContentIn(Drawable content);
|
2020-02-05 22:04:10 +08:00
|
|
|
|
|
2020-01-18 01:53:17 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
API?.Register(this);
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
2020-01-09 00:41:44 +08:00
|
|
|
|
{
|
2020-01-18 01:53:17 +08:00
|
|
|
|
API?.Unregister(this);
|
|
|
|
|
base.Dispose(isDisposing);
|
2020-01-09 00:41:44 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|