mirror of
https://github.com/ppy/osu
synced 2024-12-11 01:19:26 +00:00
0bd1964d8e
A perfect implementation of this would probably leave the filter/header content visible, but that requires some re-thinking and restructuring to how the content is displayed in these overlays (ie. the header component shouldn't be inside the `ScrollContainer` as it is fixed). Supersedes and closes #10774. Closes #933. Addresses most pieces of #7417.
101 lines
2.8 KiB
C#
101 lines
2.8 KiB
C#
// 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 System.Threading;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Bindables;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Game.Online.API;
|
|
|
|
namespace osu.Game.Overlays
|
|
{
|
|
public abstract class TabbableOnlineOverlay<THeader, TEnum> : OnlineOverlay<THeader>
|
|
where THeader : TabControlOverlayHeader<TEnum>
|
|
{
|
|
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
|
|
|
|
private CancellationTokenSource cancellationToken;
|
|
private bool displayUpdateRequired = true;
|
|
|
|
protected TabbableOnlineOverlay(OverlayColourScheme colourScheme)
|
|
: base(colourScheme)
|
|
{
|
|
}
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load(IAPIProvider api)
|
|
{
|
|
apiState.BindTo(api.State);
|
|
apiState.BindValueChanged(onlineStateChanged, true);
|
|
}
|
|
|
|
protected override void LoadComplete()
|
|
{
|
|
base.LoadComplete();
|
|
Header.Current.BindValueChanged(tab => OnTabChanged(tab.NewValue));
|
|
}
|
|
|
|
protected override void PopIn()
|
|
{
|
|
base.PopIn();
|
|
|
|
// We don't want to create a new display on every call, only when exiting from fully closed state.
|
|
if (displayUpdateRequired)
|
|
{
|
|
Header.Current.TriggerChange();
|
|
displayUpdateRequired = false;
|
|
}
|
|
}
|
|
|
|
protected override void PopOutComplete()
|
|
{
|
|
base.PopOutComplete();
|
|
LoadDisplay(Empty());
|
|
displayUpdateRequired = true;
|
|
}
|
|
|
|
protected void LoadDisplay(Drawable display)
|
|
{
|
|
ScrollFlow.ScrollToStart();
|
|
|
|
LoadComponentAsync(display, loaded =>
|
|
{
|
|
Loading.Hide();
|
|
|
|
Child = loaded;
|
|
}, (cancellationToken = new CancellationTokenSource()).Token);
|
|
}
|
|
|
|
protected virtual void OnTabChanged(TEnum tab)
|
|
{
|
|
cancellationToken?.Cancel();
|
|
Loading.Show();
|
|
|
|
if (!API.IsLoggedIn)
|
|
{
|
|
LoadDisplay(Empty());
|
|
return;
|
|
}
|
|
|
|
CreateDisplayToLoad(tab);
|
|
}
|
|
|
|
protected abstract void CreateDisplayToLoad(TEnum tab);
|
|
|
|
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
|
|
{
|
|
if (State.Value == Visibility.Hidden)
|
|
return;
|
|
|
|
Header.Current.TriggerChange();
|
|
});
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
{
|
|
cancellationToken?.Cancel();
|
|
base.Dispose(isDisposing);
|
|
}
|
|
}
|
|
}
|