mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 19:22:56 +08:00
Fix ScorePanelList nullref when scores are added too soon
This commit is contained in:
parent
ab538dc3dd
commit
f7c1177cc9
@ -182,6 +182,22 @@ namespace osu.Game.Tests.Visual.Ranking
|
||||
assertExpandedPanelCentred();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAddScoreImmediately()
|
||||
{
|
||||
var score = new TestScoreInfo(new OsuRuleset().RulesetInfo);
|
||||
|
||||
createListStep(() =>
|
||||
{
|
||||
var newList = new ScorePanelList { SelectedScore = { Value = score } };
|
||||
newList.AddScore(score);
|
||||
return newList;
|
||||
});
|
||||
|
||||
assertScoreState(score, true);
|
||||
assertExpandedPanelCentred();
|
||||
}
|
||||
|
||||
private void createListStep(Func<ScorePanelList> creationFunc)
|
||||
{
|
||||
AddStep("create list", () => Child = list = creationFunc().With(d =>
|
||||
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
@ -100,6 +101,9 @@ namespace osu.Game.Screens.Ranking
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
foreach (var d in flow)
|
||||
displayScore(d);
|
||||
|
||||
SelectedScore.BindValueChanged(selectedScoreChanged, true);
|
||||
}
|
||||
|
||||
@ -124,14 +128,35 @@ namespace osu.Game.Screens.Ranking
|
||||
};
|
||||
});
|
||||
|
||||
difficultyCache.GetDifficultyAsync(score.Beatmap, score.Ruleset, score.Mods)
|
||||
.ContinueWith(_ => Schedule(() =>
|
||||
{
|
||||
flow.Add(panel.CreateTrackingContainer().With(d =>
|
||||
var trackingContainer = panel.CreateTrackingContainer().With(d =>
|
||||
{
|
||||
d.Anchor = Anchor.Centre;
|
||||
d.Origin = Anchor.Centre;
|
||||
}));
|
||||
d.Hide();
|
||||
});
|
||||
|
||||
flow.Add(trackingContainer);
|
||||
|
||||
if (IsLoaded)
|
||||
displayScore(trackingContainer);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
private void displayScore(ScorePanelTrackingContainer trackingContainer)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
return;
|
||||
|
||||
var score = trackingContainer.Panel.Score;
|
||||
|
||||
// Calculating score can take a while in extreme scenarios, so only display scores after the process completes.
|
||||
scoreManager.GetTotalScoreAsync(score)
|
||||
.ContinueWith(totalScore => Schedule(() =>
|
||||
{
|
||||
flow.SetLayoutPosition(trackingContainer, totalScore.Result);
|
||||
|
||||
trackingContainer.Show();
|
||||
|
||||
if (SelectedScore.Value == score)
|
||||
{
|
||||
@ -150,9 +175,7 @@ namespace osu.Game.Screens.Ranking
|
||||
scroll.InstantScrollTarget = (scroll.InstantScrollTarget ?? scroll.Target) + ScorePanel.CONTRACTED_WIDTH + panel_spacing;
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
return panel;
|
||||
}), TaskContinuationOptions.OnlyOnRanToCompletion);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -306,28 +329,8 @@ namespace osu.Game.Screens.Ranking
|
||||
{
|
||||
public override IEnumerable<Drawable> FlowingChildren => applySorting(AliveInternalChildren);
|
||||
|
||||
[Resolved]
|
||||
private ScoreManager scoreManager { get; set; }
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
foreach (var c in Children)
|
||||
SetLayoutPosition(c, scoreManager.GetTotalScore(c.Panel.Score));
|
||||
}
|
||||
|
||||
public int GetPanelIndex(ScoreInfo score) => applySorting(Children).TakeWhile(s => s.Panel.Score != score).Count();
|
||||
|
||||
public override void Add(ScorePanelTrackingContainer drawable)
|
||||
{
|
||||
Debug.Assert(drawable != null);
|
||||
|
||||
base.Add(drawable);
|
||||
|
||||
SetLayoutPosition(drawable, scoreManager?.GetTotalScore(drawable.Panel.Score) ?? 0);
|
||||
}
|
||||
|
||||
private IEnumerable<ScorePanelTrackingContainer> applySorting(IEnumerable<Drawable> drawables) => drawables.OfType<ScorePanelTrackingContainer>()
|
||||
.OrderByDescending(GetLayoutPosition)
|
||||
.ThenBy(s => s.Panel.Score.OnlineScoreID);
|
||||
|
Loading…
Reference in New Issue
Block a user