mirror of
https://github.com/osukey/osukey.git
synced 2025-05-07 22:57:31 +09:00
Reorder and tidy up bindable flows
This commit is contained in:
parent
aee93934d5
commit
b9dac6c3b2
@ -46,6 +46,18 @@ namespace osu.Game.Online.Leaderboards
|
|||||||
|
|
||||||
private bool scoresLoadedOnce;
|
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;
|
private readonly Container content;
|
||||||
|
|
||||||
protected override Container<Drawable> Content => content;
|
protected override Container<Drawable> Content => content;
|
||||||
@ -239,33 +251,19 @@ namespace osu.Game.Online.Leaderboards
|
|||||||
|
|
||||||
protected virtual void Reset()
|
protected virtual void Reset()
|
||||||
{
|
{
|
||||||
getScoresRequest?.Cancel();
|
cancelPendingWork();
|
||||||
getScoresRequest = null;
|
|
||||||
Scores = null;
|
Scores = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Resolved(CanBeNull = true)]
|
protected override void LoadComplete()
|
||||||
private IAPIProvider api { get; set; }
|
|
||||||
|
|
||||||
private ScheduledDelegate pendingUpdateScores;
|
|
||||||
|
|
||||||
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load()
|
|
||||||
{
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
if (api != null)
|
if (api != null)
|
||||||
|
{
|
||||||
apiState.BindTo(api.State);
|
apiState.BindTo(api.State);
|
||||||
|
apiState.BindValueChanged(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)
|
switch (state.NewValue)
|
||||||
{
|
{
|
||||||
@ -277,6 +275,10 @@ namespace osu.Game.Online.Leaderboards
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
RefetchScores();
|
||||||
|
}
|
||||||
|
|
||||||
public void RefetchScores() => Scheduler.AddOnce(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.
|
// this avoids scope changes flickering a "no scores" placeholder before initialisation of song select is finished.
|
||||||
if (!scoresLoadedOnce) return;
|
if (!scoresLoadedOnce) return;
|
||||||
|
|
||||||
getScoresRequest?.Cancel();
|
cancelPendingWork();
|
||||||
getScoresRequest = null;
|
|
||||||
|
|
||||||
getScoresRequestCallback?.Cancel();
|
|
||||||
getScoresRequestCallback = null;
|
|
||||||
|
|
||||||
pendingUpdateScores?.Cancel();
|
|
||||||
pendingUpdateScores = Schedule(() =>
|
pendingUpdateScores = Schedule(() =>
|
||||||
{
|
{
|
||||||
PlaceholderState = PlaceholderState.Retrieving;
|
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>
|
/// <summary>
|
||||||
/// Performs a fetch/refresh of scores to be displayed.
|
/// Performs a fetch/refresh of scores to be displayed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user