1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 08:12:56 +08:00

Refactor populateStatistics to avoid disposing

This commit is contained in:
Henry Lin 2022-02-03 11:52:37 +08:00
parent 19eb9ad8a7
commit aff36d4e16

View File

@ -85,9 +85,36 @@ namespace osu.Game.Screens.Ranking.Statistics
{
playableBeatmap = beatmapManager.GetWorkingBeatmap(newScore.BeatmapInfo).GetPlayableBeatmap(newScore.Ruleset, newScore.Mods);
}, loadCancellation.Token).ContinueWith(t => Schedule(() =>
{
bool hitEventsAvailable = newScore.HitEvents.Count != 0;
Container<Drawable> container;
var statisticRows = newScore.Ruleset.CreateInstance().CreateStatisticsForScore(newScore, playableBeatmap);
if (!hitEventsAvailable && statisticRows.SelectMany(r => r.Columns).All(c => c.RequiresHitEvents))
{
container = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new MessagePlaceholder("Extended statistics are only available after watching a replay!"),
new ReplayDownloadButton(newScore)
{
Scale = new Vector2(1.5f),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
}
};
}
else
{
FillFlowContainer rows;
Container<Drawable> container = new OsuScrollContainer(Direction.Vertical)
container = new OsuScrollContainer(Direction.Vertical)
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
@ -104,11 +131,9 @@ namespace osu.Game.Screens.Ranking.Statistics
}
};
bool panelIsEmpty = true;
bool panelIsComplete = true;
bool hitEventsAvailable = newScore.HitEvents.Count != 0;
foreach (var row in newScore.Ruleset.CreateInstance().CreateStatisticsForScore(newScore, playableBeatmap))
foreach (var row in statisticRows)
{
var columnsToDisplay = hitEventsAvailable
? row.Columns
@ -117,9 +142,7 @@ namespace osu.Game.Screens.Ranking.Statistics
if (columnsToDisplay.Length < row.Columns.Length)
panelIsComplete = false;
if (columnsToDisplay.Any())
panelIsEmpty = false;
else
if (columnsToDisplay.Length == 0)
continue;
rows.Add(new GridContainer
@ -142,32 +165,7 @@ namespace osu.Game.Screens.Ranking.Statistics
});
}
if (!hitEventsAvailable)
{
if (panelIsEmpty)
{
// Replace the scroll container with fill flow container to get the message centered.
rows.Dispose();
container.Dispose();
container = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new MessagePlaceholder("Extended statistics are only available after watching a replay!"),
new ReplayDownloadButton(newScore)
{
Scale = new Vector2(1.5f),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
}
};
}
else if (!panelIsComplete)
if (!hitEventsAvailable && !panelIsComplete)
{
rows.Add(new FillFlowContainer
{