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

Merge pull request #1137 from smoogipooo/fix-bargraph-crash

Fix selecting unranked beatmaps in song select crashing the game.
This commit is contained in:
Dean Herbert 2017-08-19 13:43:30 +09:00 committed by GitHub
commit 3eb5267651

View File

@ -44,19 +44,31 @@ namespace osu.Game.Graphics.UserInterface
{
List<Bar> bars = Children.ToList();
foreach (var bar in value.Select((length, index) => new { Value = length, Bar = bars.Count > index ? bars[index] : null }))
{
float length = MaxValue ?? value.Max();
if (length != 0)
length = bar.Value / length;
float size = value.Count();
if (size != 0)
size = 1.0f / size;
if (bar.Bar != null)
{
bar.Bar.Length = bar.Value / (MaxValue ?? value.Max());
bar.Bar.Size = (direction & BarDirection.Horizontal) > 0 ? new Vector2(1, 1.0f / value.Count()) : new Vector2(1.0f / value.Count(), 1);
bar.Bar.Length = length;
bar.Bar.Size = (direction & BarDirection.Horizontal) > 0 ? new Vector2(1, size) : new Vector2(size, 1);
}
else
{
Add(new Bar
{
RelativeSizeAxes = Axes.Both,
Size = (direction & BarDirection.Horizontal) > 0 ? new Vector2(1, 1.0f / value.Count()) : new Vector2(1.0f / value.Count(), 1),
Length = bar.Value / (MaxValue ?? value.Max()),
Size = (direction & BarDirection.Horizontal) > 0 ? new Vector2(1, size) : new Vector2(size, 1),
Length = length,
Direction = Direction,
});
}
}
//I'm using ToList() here because Where() returns an Enumerable which can change it's elements afterwards
RemoveRange(Children.Where((bar, index) => index >= value.Count()).ToList());
}