1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 14:17:26 +08:00
osu-lazer/osu.Game/Online/OnlineViewContainer.cs

80 lines
2.6 KiB
C#
Raw Normal View History

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;
using osu.Game.Online.API;
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.
/// Shows its children only when the local user is logged in and supports displaying a placeholder if not.
/// </summary>
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<Drawable> Content => content;
2020-01-14 04:12:19 +08:00
public OnlineViewContainer(string placeholderMessage)
2020-01-09 00:41:44 +08:00
{
InternalChildren = new Drawable[]
{
content = new Container
{
RelativeSizeAxes = Axes.Both,
},
placeholderContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
2020-01-14 04:12:19 +08:00
Child = placeholder = new LoginPlaceholder(placeholderMessage)
2020-01-09 00:41:44 +08:00
},
};
}
public void APIStateChanged(IAPIProvider api, APIState state)
{
switch (state)
{
case APIState.Offline:
case APIState.Connecting:
2020-01-14 04:12:19 +08:00
Schedule(() => updatePlaceholderVisibility(true));
2020-01-09 00:41:44 +08:00
break;
default:
Schedule(() => updatePlaceholderVisibility(false));
break;
}
}
2020-01-14 04:12:19 +08:00
private void updatePlaceholderVisibility(bool showPlaceholder)
2020-01-09 00:41:44 +08:00
{
2020-01-14 04:12:19 +08:00
if (showPlaceholder)
2020-01-09 00:41:44 +08:00
{
2020-01-14 04:12:19 +08:00
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);
2020-01-09 00:41:44 +08:00
}
else
{
2020-01-14 04:12:19 +08:00
placeholderContainer.FadeOut(transform_time / 2, Easing.OutQuint);
content.FadeIn(transform_time, Easing.OutQuint);
2020-01-09 00:41:44 +08:00
}
}
[BackgroundDependencyLoader]
private void load(IAPIProvider api)
{
api.Register(this);
}
}
}