2020-04-16 16:01:36 +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.
|
|
|
|
|
|
2020-04-16 17:05:51 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
2020-04-16 16:01:36 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2020-04-16 17:05:51 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2020-04-16 16:01:36 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-04-16 17:05:51 +08:00
|
|
|
|
using osu.Game.Online.API;
|
2020-04-16 16:01:36 +08:00
|
|
|
|
using osu.Game.Overlays.Dashboard;
|
2020-04-16 17:05:51 +08:00
|
|
|
|
using osu.Game.Overlays.Dashboard.Friends;
|
2020-04-16 16:01:36 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
2021-01-18 15:48:12 +08:00
|
|
|
|
public class DashboardOverlay : WebOverlay<DashboardOverlayHeader>
|
2020-04-16 16:01:36 +08:00
|
|
|
|
{
|
2020-04-16 17:05:51 +08:00
|
|
|
|
private CancellationTokenSource cancellationToken;
|
|
|
|
|
|
2020-04-16 16:01:36 +08:00
|
|
|
|
public DashboardOverlay()
|
2021-01-18 15:48:12 +08:00
|
|
|
|
: base(OverlayColourScheme.Purple)
|
2020-04-20 14:34:48 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-22 13:19:12 +08:00
|
|
|
|
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(IAPIProvider api)
|
|
|
|
|
{
|
|
|
|
|
apiState.BindTo(api.State);
|
|
|
|
|
apiState.BindValueChanged(onlineStateChanged, true);
|
2020-04-16 16:01:36 +08:00
|
|
|
|
}
|
2020-04-16 17:05:51 +08:00
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2020-09-03 15:27:31 +08:00
|
|
|
|
Header.Current.BindValueChanged(onTabChanged);
|
2020-04-16 17:05:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 15:48:12 +08:00
|
|
|
|
protected override DashboardOverlayHeader CreateHeader() => new DashboardOverlayHeader();
|
|
|
|
|
|
2020-04-16 17:05:51 +08:00
|
|
|
|
private bool displayUpdateRequired = true;
|
|
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
base.PopIn();
|
|
|
|
|
|
2020-04-16 19:10:39 +08:00
|
|
|
|
// We don't want to create a new display on every call, only when exiting from fully closed state.
|
2020-04-16 17:05:51 +08:00
|
|
|
|
if (displayUpdateRequired)
|
|
|
|
|
{
|
2020-09-03 15:27:31 +08:00
|
|
|
|
Header.Current.TriggerChange();
|
2020-04-16 17:05:51 +08:00
|
|
|
|
displayUpdateRequired = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOutComplete()
|
|
|
|
|
{
|
|
|
|
|
base.PopOutComplete();
|
|
|
|
|
loadDisplay(Empty());
|
|
|
|
|
displayUpdateRequired = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadDisplay(Drawable display)
|
|
|
|
|
{
|
2021-01-18 15:48:12 +08:00
|
|
|
|
ScrollFlow.ScrollToStart();
|
2020-04-16 17:05:51 +08:00
|
|
|
|
|
|
|
|
|
LoadComponentAsync(display, loaded =>
|
|
|
|
|
{
|
2020-04-16 19:10:39 +08:00
|
|
|
|
if (API.IsLoggedIn)
|
2021-01-18 15:48:12 +08:00
|
|
|
|
Loading.Hide();
|
2020-04-16 19:10:39 +08:00
|
|
|
|
|
2021-01-18 15:48:12 +08:00
|
|
|
|
Child = loaded;
|
2020-04-16 17:05:51 +08:00
|
|
|
|
}, (cancellationToken = new CancellationTokenSource()).Token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onTabChanged(ValueChangedEvent<DashboardOverlayTabs> tab)
|
|
|
|
|
{
|
|
|
|
|
cancellationToken?.Cancel();
|
2021-01-18 15:48:12 +08:00
|
|
|
|
Loading.Show();
|
2020-04-16 17:05:51 +08:00
|
|
|
|
|
2020-04-16 19:10:39 +08:00
|
|
|
|
if (!API.IsLoggedIn)
|
|
|
|
|
{
|
|
|
|
|
loadDisplay(Empty());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 17:05:51 +08:00
|
|
|
|
switch (tab.NewValue)
|
|
|
|
|
{
|
|
|
|
|
case DashboardOverlayTabs.Friends:
|
|
|
|
|
loadDisplay(new FriendDisplay());
|
|
|
|
|
break;
|
|
|
|
|
|
2020-10-28 16:19:14 +08:00
|
|
|
|
case DashboardOverlayTabs.CurrentlyPlaying:
|
2020-11-06 11:54:08 +08:00
|
|
|
|
loadDisplay(new CurrentlyPlayingDisplay());
|
2020-10-28 16:19:14 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2020-04-16 17:05:51 +08:00
|
|
|
|
default:
|
|
|
|
|
throw new NotImplementedException($"Display for {tab.NewValue} tab is not implemented");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-22 13:19:12 +08:00
|
|
|
|
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
|
2020-04-16 17:05:51 +08:00
|
|
|
|
{
|
2020-04-16 19:10:39 +08:00
|
|
|
|
if (State.Value == Visibility.Hidden)
|
|
|
|
|
return;
|
2020-04-16 17:05:51 +08:00
|
|
|
|
|
2020-09-03 15:27:31 +08:00
|
|
|
|
Header.Current.TriggerChange();
|
2020-10-22 13:19:12 +08:00
|
|
|
|
});
|
2020-04-16 17:05:51 +08:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
cancellationToken?.Cancel();
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
}
|
2020-04-16 16:01:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|