2020-04-16 08:01:36 +00: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 09:05:51 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
2020-04-16 08:01:36 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2020-04-16 09:05:51 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2020-04-16 08:01:36 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-04-16 09:05:51 +00:00
|
|
|
|
using osu.Game.Online.API;
|
2020-04-16 08:01:36 +00:00
|
|
|
|
using osu.Game.Overlays.Dashboard;
|
2020-04-16 09:05:51 +00:00
|
|
|
|
using osu.Game.Overlays.Dashboard.Friends;
|
2020-04-16 08:01:36 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
|
|
|
|
public class DashboardOverlay : FullscreenOverlay
|
|
|
|
|
{
|
2020-04-16 09:05:51 +00:00
|
|
|
|
private CancellationTokenSource cancellationToken;
|
|
|
|
|
|
2020-04-20 06:34:48 +00:00
|
|
|
|
private Box background;
|
|
|
|
|
private Container content;
|
|
|
|
|
private DashboardOverlayHeader header;
|
|
|
|
|
private LoadingLayer loading;
|
|
|
|
|
private OverlayScrollContainer scrollFlow;
|
2020-04-16 08:01:36 +00:00
|
|
|
|
|
|
|
|
|
public DashboardOverlay()
|
|
|
|
|
: base(OverlayColourScheme.Purple)
|
2020-04-20 06:34:48 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
2020-04-16 08:01:36 +00:00
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
background = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
},
|
2020-04-16 09:05:51 +00:00
|
|
|
|
scrollFlow = new OverlayScrollContainer
|
2020-04-16 08:01:36 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
ScrollbarVisible = false,
|
|
|
|
|
Child = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2020-04-16 09:05:51 +00:00
|
|
|
|
header = new DashboardOverlayHeader
|
2020-04-16 08:01:36 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Depth = -float.MaxValue
|
|
|
|
|
},
|
|
|
|
|
content = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-04-16 09:05:51 +00:00
|
|
|
|
loading = new LoadingLayer(content),
|
2020-04-16 08:01:36 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
background.Colour = ColourProvider.Background5;
|
|
|
|
|
}
|
2020-04-16 09:05:51 +00:00
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2020-04-20 06:34:48 +00:00
|
|
|
|
|
2020-04-16 09:05:51 +00:00
|
|
|
|
header.Current.BindValueChanged(onTabChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool displayUpdateRequired = true;
|
|
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
base.PopIn();
|
|
|
|
|
|
2020-04-16 11:10:39 +00:00
|
|
|
|
// We don't want to create a new display on every call, only when exiting from fully closed state.
|
2020-04-16 09:05:51 +00:00
|
|
|
|
if (displayUpdateRequired)
|
|
|
|
|
{
|
|
|
|
|
header.Current.TriggerChange();
|
|
|
|
|
displayUpdateRequired = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOutComplete()
|
|
|
|
|
{
|
|
|
|
|
base.PopOutComplete();
|
|
|
|
|
loadDisplay(Empty());
|
|
|
|
|
displayUpdateRequired = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadDisplay(Drawable display)
|
|
|
|
|
{
|
|
|
|
|
scrollFlow.ScrollToStart();
|
|
|
|
|
|
|
|
|
|
LoadComponentAsync(display, loaded =>
|
|
|
|
|
{
|
2020-04-16 11:10:39 +00:00
|
|
|
|
if (API.IsLoggedIn)
|
|
|
|
|
loading.Hide();
|
|
|
|
|
|
2020-04-16 09:05:51 +00:00
|
|
|
|
content.Child = loaded;
|
|
|
|
|
}, (cancellationToken = new CancellationTokenSource()).Token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onTabChanged(ValueChangedEvent<DashboardOverlayTabs> tab)
|
|
|
|
|
{
|
|
|
|
|
cancellationToken?.Cancel();
|
|
|
|
|
loading.Show();
|
|
|
|
|
|
2020-04-16 11:10:39 +00:00
|
|
|
|
if (!API.IsLoggedIn)
|
|
|
|
|
{
|
|
|
|
|
loadDisplay(Empty());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 09:05:51 +00:00
|
|
|
|
switch (tab.NewValue)
|
|
|
|
|
{
|
|
|
|
|
case DashboardOverlayTabs.Friends:
|
|
|
|
|
loadDisplay(new FriendDisplay());
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new NotImplementedException($"Display for {tab.NewValue} tab is not implemented");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void APIStateChanged(IAPIProvider api, APIState state)
|
|
|
|
|
{
|
2020-04-16 11:10:39 +00:00
|
|
|
|
if (State.Value == Visibility.Hidden)
|
|
|
|
|
return;
|
2020-04-16 09:05:51 +00:00
|
|
|
|
|
2020-04-16 11:10:39 +00:00
|
|
|
|
header.Current.TriggerChange();
|
2020-04-16 09:05:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
cancellationToken?.Cancel();
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
}
|
2020-04-16 08:01:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|