1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:57:36 +08:00

Reorder and tidy up bindable flows

This commit is contained in:
Dean Herbert 2022-01-28 21:33:22 +09:00
parent aee93934d5
commit b9dac6c3b2

View File

@ -46,6 +46,18 @@ namespace osu.Game.Online.Leaderboards
private bool scoresLoadedOnce;
private APIRequest getScoresRequest;
private ScheduledDelegate getScoresRequestCallback;
protected abstract bool IsOnlineScope { get; }
[Resolved(CanBeNull = true)]
private IAPIProvider api { get; set; }
private ScheduledDelegate pendingUpdateScores;
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
private readonly Container content;
protected override Container<Drawable> Content => content;
@ -239,44 +251,34 @@ namespace osu.Game.Online.Leaderboards
protected virtual void Reset()
{
getScoresRequest?.Cancel();
getScoresRequest = null;
cancelPendingWork();
Scores = null;
}
[Resolved(CanBeNull = true)]
private IAPIProvider api { get; set; }
private ScheduledDelegate pendingUpdateScores;
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
[BackgroundDependencyLoader]
private void load()
protected override void LoadComplete()
{
base.LoadComplete();
if (api != null)
apiState.BindTo(api.State);
apiState.BindValueChanged(onlineStateChanged, true);
}
private APIRequest getScoresRequest;
private ScheduledDelegate getScoresRequestCallback;
protected abstract bool IsOnlineScope { get; }
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{
switch (state.NewValue)
{
case APIState.Online:
case APIState.Offline:
if (IsOnlineScope)
RefetchScores();
apiState.BindTo(api.State);
apiState.BindValueChanged(state =>
{
switch (state.NewValue)
{
case APIState.Online:
case APIState.Offline:
if (IsOnlineScope)
RefetchScores();
break;
break;
}
});
}
});
RefetchScores();
}
public void RefetchScores() => Scheduler.AddOnce(refetchScores);
@ -286,13 +288,8 @@ namespace osu.Game.Online.Leaderboards
// this avoids scope changes flickering a "no scores" placeholder before initialisation of song select is finished.
if (!scoresLoadedOnce) return;
getScoresRequest?.Cancel();
getScoresRequest = null;
cancelPendingWork();
getScoresRequestCallback?.Cancel();
getScoresRequestCallback = null;
pendingUpdateScores?.Cancel();
pendingUpdateScores = Schedule(() =>
{
PlaceholderState = PlaceholderState.Retrieving;
@ -319,6 +316,18 @@ namespace osu.Game.Online.Leaderboards
});
}
private void cancelPendingWork()
{
getScoresRequest?.Cancel();
getScoresRequest = null;
getScoresRequestCallback?.Cancel();
getScoresRequestCallback = null;
pendingUpdateScores?.Cancel();
pendingUpdateScores = null;
}
/// <summary>
/// Performs a fetch/refresh of scores to be displayed.
/// </summary>