mirror of
https://github.com/ppy/osu
synced 2025-03-24 11:56:58 +00:00
Move score update code into own method
This commit is contained in:
parent
c48e9f2bbd
commit
13f445ddd5
@ -33,6 +33,8 @@ namespace osu.Game.Online.Leaderboards
|
|||||||
/// <typeparam name="TScoreInfo">The score model class.</typeparam>
|
/// <typeparam name="TScoreInfo">The score model class.</typeparam>
|
||||||
public abstract class Leaderboard<TScope, TScoreInfo> : CompositeDrawable
|
public abstract class Leaderboard<TScope, TScoreInfo> : CompositeDrawable
|
||||||
{
|
{
|
||||||
|
protected abstract bool IsOnlineScope { get; }
|
||||||
|
|
||||||
private const double fade_duration = 300;
|
private const double fade_duration = 300;
|
||||||
|
|
||||||
private readonly OsuScrollContainer scrollContainer;
|
private readonly OsuScrollContainer scrollContainer;
|
||||||
@ -48,8 +50,6 @@ namespace osu.Game.Online.Leaderboards
|
|||||||
private APIRequest getScoresRequest;
|
private APIRequest getScoresRequest;
|
||||||
private ScheduledDelegate getScoresRequestCallback;
|
private ScheduledDelegate getScoresRequestCallback;
|
||||||
|
|
||||||
protected abstract bool IsOnlineScope { get; }
|
|
||||||
|
|
||||||
[Resolved(CanBeNull = true)]
|
[Resolved(CanBeNull = true)]
|
||||||
private IAPIProvider api { get; set; }
|
private IAPIProvider api { get; set; }
|
||||||
|
|
||||||
@ -62,49 +62,9 @@ namespace osu.Game.Online.Leaderboards
|
|||||||
get => scores;
|
get => scores;
|
||||||
protected set
|
protected set
|
||||||
{
|
{
|
||||||
Debug.Assert(ThreadSafety.IsUpdateThread);
|
|
||||||
|
|
||||||
scores = value;
|
scores = value;
|
||||||
|
|
||||||
scrollFlow?.FadeOut(fade_duration, Easing.OutQuint).Expire();
|
updateScoresDrawables();
|
||||||
scrollFlow = null;
|
|
||||||
|
|
||||||
showScoresCancellationSource?.Cancel();
|
|
||||||
|
|
||||||
if (scores?.Any() != true)
|
|
||||||
{
|
|
||||||
loading.Hide();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ensure placeholder is hidden when displaying scores
|
|
||||||
PlaceholderState = PlaceholderState.Successful;
|
|
||||||
|
|
||||||
var scoreFlow = new FillFlowContainer<LeaderboardScore>
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
AutoSizeAxes = Axes.Y,
|
|
||||||
Spacing = new Vector2(0f, 5f),
|
|
||||||
Padding = new MarginPadding { Top = 10, Bottom = 5 },
|
|
||||||
ChildrenEnumerable = scores.Select((s, index) => CreateDrawableScore(s, index + 1))
|
|
||||||
};
|
|
||||||
|
|
||||||
// schedule because we may not be loaded yet (LoadComponentAsync complains).
|
|
||||||
LoadComponentAsync(scoreFlow, _ =>
|
|
||||||
{
|
|
||||||
scrollContainer.Add(scrollFlow = scoreFlow);
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
foreach (var s in scrollFlow.Children)
|
|
||||||
{
|
|
||||||
using (s.BeginDelayedSequence(i++ * 50))
|
|
||||||
s.Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
scrollContainer.ScrollToStart(false);
|
|
||||||
loading.Hide();
|
|
||||||
}, (showScoresCancellationSource = new CancellationTokenSource()).Token);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,6 +284,51 @@ namespace osu.Game.Online.Leaderboards
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateScoresDrawables()
|
||||||
|
{
|
||||||
|
Debug.Assert(ThreadSafety.IsUpdateThread);
|
||||||
|
|
||||||
|
scrollFlow?.FadeOut(fade_duration, Easing.OutQuint).Expire();
|
||||||
|
scrollFlow = null;
|
||||||
|
|
||||||
|
showScoresCancellationSource?.Cancel();
|
||||||
|
|
||||||
|
if (scores?.Any() != true)
|
||||||
|
{
|
||||||
|
loading.Hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure placeholder is hidden when displaying scores
|
||||||
|
PlaceholderState = PlaceholderState.Successful;
|
||||||
|
|
||||||
|
var scoreFlow = new FillFlowContainer<LeaderboardScore>
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
Spacing = new Vector2(0f, 5f),
|
||||||
|
Padding = new MarginPadding { Top = 10, Bottom = 5 },
|
||||||
|
ChildrenEnumerable = scores.Select((s, index) => CreateDrawableScore(s, index + 1))
|
||||||
|
};
|
||||||
|
|
||||||
|
// schedule because we may not be loaded yet (LoadComponentAsync complains).
|
||||||
|
LoadComponentAsync(scoreFlow, _ =>
|
||||||
|
{
|
||||||
|
scrollContainer.Add(scrollFlow = scoreFlow);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
foreach (var s in scrollFlow.Children)
|
||||||
|
{
|
||||||
|
using (s.BeginDelayedSequence(i++ * 50))
|
||||||
|
s.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollContainer.ScrollToStart(false);
|
||||||
|
loading.Hide();
|
||||||
|
}, (showScoresCancellationSource = new CancellationTokenSource()).Token);
|
||||||
|
}
|
||||||
|
|
||||||
private void replacePlaceholder(Placeholder placeholder)
|
private void replacePlaceholder(Placeholder placeholder)
|
||||||
{
|
{
|
||||||
if (placeholder != null && placeholder.Equals(currentPlaceholder))
|
if (placeholder != null && placeholder.Equals(currentPlaceholder))
|
||||||
|
Loading…
Reference in New Issue
Block a user