Fix selection not occurring when switching from empty ruleset on first load

This commit is contained in:
Dean Herbert 2020-03-20 15:01:26 +09:00
parent 549cec80d6
commit 9b60b535e5
3 changed files with 37 additions and 4 deletions

View File

@ -227,6 +227,32 @@ namespace osu.Game.Tests.Visual.SongSelect
waitForSelection(set_count); waitForSelection(set_count);
} }
[Test]
public void TestSelectionEnteringFromEmptyRuleset()
{
var sets = new List<BeatmapSetInfo>();
AddStep("Create beatmaps for taiko only", () =>
{
var rulesetBeatmapSet = createTestBeatmapSet(1);
var taikoRuleset = rulesets.AvailableRulesets.ElementAt(1);
rulesetBeatmapSet.Beatmaps.ForEach(b =>
{
b.Ruleset = taikoRuleset;
b.RulesetID = 1;
});
sets.Add(rulesetBeatmapSet);
});
loadBeatmaps(sets, () => new FilterCriteria { Ruleset = rulesets.AvailableRulesets.ElementAt(0) });
AddStep("Set non-empty mode filter", () =>
carousel.Filter(new FilterCriteria { Ruleset = rulesets.AvailableRulesets.ElementAt(1) }, false));
AddAssert("Something is selected", () => carousel.SelectedBeatmap != null);
}
/// <summary> /// <summary>
/// Test sorting /// Test sorting
/// </summary> /// </summary>
@ -399,7 +425,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddStep("filter to ruleset 0", () => AddStep("filter to ruleset 0", () =>
carousel.Filter(new FilterCriteria { Ruleset = rulesets.AvailableRulesets.ElementAt(0) }, false)); carousel.Filter(new FilterCriteria { Ruleset = rulesets.AvailableRulesets.ElementAt(0) }, false));
AddStep("select filtered map skipping filtered", () => carousel.SelectBeatmap(testMixed.Beatmaps[1], false)); AddStep("select filtered map skipping filtered", () => carousel.SelectBeatmap(testMixed.Beatmaps[1], false));
AddAssert("unfiltered beatmap not selected", () => carousel.SelectedBeatmap == null); AddAssert("unfiltered beatmap not selected", () => carousel.SelectedBeatmap.RulesetID == 0);
AddStep("remove mixed set", () => AddStep("remove mixed set", () =>
{ {
@ -484,7 +510,7 @@ namespace osu.Game.Tests.Visual.SongSelect
checkVisibleItemCount(true, 15); checkVisibleItemCount(true, 15);
} }
private void loadBeatmaps(List<BeatmapSetInfo> beatmapSets = null) private void loadBeatmaps(List<BeatmapSetInfo> beatmapSets = null, Func<FilterCriteria> initialCriteria = null)
{ {
createCarousel(); createCarousel();
@ -499,7 +525,7 @@ namespace osu.Game.Tests.Visual.SongSelect
bool changed = false; bool changed = false;
AddStep($"Load {(beatmapSets.Count > 0 ? beatmapSets.Count.ToString() : "some")} beatmaps", () => AddStep($"Load {(beatmapSets.Count > 0 ? beatmapSets.Count.ToString() : "some")} beatmaps", () =>
{ {
carousel.Filter(new FilterCriteria()); carousel.Filter(initialCriteria?.Invoke() ?? new FilterCriteria());
carousel.BeatmapSetsChanged = () => changed = true; carousel.BeatmapSetsChanged = () => changed = true;
carousel.BeatmapSets = beatmapSets; carousel.BeatmapSets = beatmapSets;
}); });

View File

@ -751,13 +751,17 @@ namespace osu.Game.Screens.Select
public CarouselRoot(BeatmapCarousel carousel) public CarouselRoot(BeatmapCarousel carousel)
{ {
// root should always remaing selected. if not, PerformSelection will not be called.
State.Value = CarouselItemState.Selected;
State.ValueChanged += state => State.Value = CarouselItemState.Selected;
this.carousel = carousel; this.carousel = carousel;
} }
protected override void PerformSelection() protected override void PerformSelection()
{ {
if (LastSelected == null) if (LastSelected == null)
carousel.SelectNextRandom(); carousel?.SelectNextRandom();
else else
base.PerformSelection(); base.PerformSelection();
} }

View File

@ -150,6 +150,7 @@ namespace osu.Game.Screens.Select
}, },
Child = Carousel = new BeatmapCarousel Child = Carousel = new BeatmapCarousel
{ {
AllowSelection = false, // delay any selection until our bindables are ready to make a good choice.
Anchor = Anchor.CentreRight, Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight, Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
@ -655,6 +656,8 @@ namespace osu.Game.Screens.Select
{ {
bindBindables(); bindBindables();
Carousel.AllowSelection = true;
// If a selection was already obtained, do not attempt to update the selected beatmap. // If a selection was already obtained, do not attempt to update the selected beatmap.
if (Carousel.SelectedBeatmapSet != null) if (Carousel.SelectedBeatmapSet != null)
return; return;