Merge pull request #13915 from bdach/fix-tourney-seeding-crash

Fix seeding screen crashing on seedings with null mod
This commit is contained in:
Dean Herbert 2021-07-18 17:47:29 +09:00 committed by GitHub
commit 353ff5c6ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 36 deletions

View File

@ -1,9 +1,13 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.Ladder.Components;
using osu.Game.Tournament.Screens.TeamIntro;
namespace osu.Game.Tournament.Tests.Screens
@ -11,16 +15,41 @@ namespace osu.Game.Tournament.Tests.Screens
public class TestSceneSeedingScreen : TournamentTestScene
{
[Cached]
private readonly LadderInfo ladder = new LadderInfo();
[BackgroundDependencyLoader]
private void load()
private readonly LadderInfo ladder = new LadderInfo
{
Add(new SeedingScreen
Teams =
{
new TournamentTeam
{
FullName = { Value = @"Japan" },
Acronym = { Value = "JPN" },
SeedingResults =
{
new SeedingResult
{
// Mod intentionally left blank.
Seed = { Value = 4 }
},
new SeedingResult
{
Mod = { Value = "DT" },
Seed = { Value = 8 }
}
}
}
}
};
[Test]
public void TestBasic()
{
AddStep("create seeding screen", () => Add(new SeedingScreen
{
FillMode = FillMode.Fit,
FillAspectRatio = 16 / 9f
});
}));
AddStep("set team to Japan", () => this.ChildrenOfType<SettingsTeamDropdown>().Single().Current.Value = ladder.Teams.Single());
}
}
}

View File

@ -181,44 +181,48 @@ public ModRow(string mods, int seeding)
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
FillFlowContainer row;
InternalChildren = new Drawable[]
{
new FillFlowContainer
row = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5),
Children = new Drawable[]
{
new Sprite
{
Texture = textures.Get($"mods/{mods.ToLower()}"),
Scale = new Vector2(0.5f)
},
new Container
{
Size = new Vector2(50, 16),
CornerRadius = 10,
Masking = true,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = TournamentGame.ELEMENT_BACKGROUND_COLOUR,
},
new TournamentSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = seeding.ToString("#,0"),
Colour = TournamentGame.ELEMENT_FOREGROUND_COLOUR
},
}
},
}
},
};
if (!string.IsNullOrEmpty(mods))
{
row.Add(new Sprite
{
Texture = textures.Get($"mods/{mods.ToLower()}"),
Scale = new Vector2(0.5f)
});
}
row.Add(new Container
{
Size = new Vector2(50, 16),
CornerRadius = 10,
Masking = true,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = TournamentGame.ELEMENT_BACKGROUND_COLOUR,
},
new TournamentSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = seeding.ToString("#,0"),
Colour = TournamentGame.ELEMENT_FOREGROUND_COLOUR
},
}
});
}
}
}