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

Merge branch 'master' into fix-checkbox-filterability

This commit is contained in:
Dan Balasescu 2019-06-12 16:43:30 +09:00 committed by GitHub
commit 47dad52091
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 8 deletions

View File

@ -138,7 +138,7 @@ namespace osu.Game.Tests.Visual.SongSelect
{ {
createSongSelect(); createSongSelect();
changeRuleset(2); changeRuleset(2);
importForRuleset(0); addRulesetImportStep(0);
AddUntilStep("no selection", () => songSelect.Carousel.SelectedBeatmap == null); AddUntilStep("no selection", () => songSelect.Carousel.SelectedBeatmap == null);
} }
@ -147,8 +147,8 @@ namespace osu.Game.Tests.Visual.SongSelect
{ {
createSongSelect(); createSongSelect();
changeRuleset(2); changeRuleset(2);
importForRuleset(2); addRulesetImportStep(2);
importForRuleset(1); addRulesetImportStep(1);
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmap.RulesetID == 2); AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmap.RulesetID == 2);
changeRuleset(1); changeRuleset(1);
@ -210,7 +210,52 @@ namespace osu.Game.Tests.Visual.SongSelect
AddAssert("start not requested", () => !startRequested); AddAssert("start not requested", () => !startRequested);
} }
private void importForRuleset(int id) => AddStep($"import test map for ruleset {id}", () => manager.Import(createTestBeatmapSet(getImportId(), rulesets.AvailableRulesets.Where(r => r.ID == id).ToArray()))); [Test]
public void TestAddNewBeatmapWhileSelectingRandom()
{
const int test_count = 10;
int beatmapChangedCount = 0;
int debounceCount = 0;
createSongSelect();
AddStep("Setup counters", () =>
{
beatmapChangedCount = 0;
debounceCount = 0;
songSelect.Carousel.SelectionChanged += _ => beatmapChangedCount++;
});
AddRepeatStep($"Create beatmaps {test_count} times", () =>
{
importForRuleset(0);
Scheduler.AddDelayed(() =>
{
// Wait for debounce
songSelect.Carousel.SelectNextRandom();
++debounceCount;
}, 400);
}, test_count);
AddUntilStep("Debounce limit reached", () => debounceCount == test_count);
// The selected beatmap should have changed an additional 2 times since both initially loading songselect and the first import also triggers selectionChanged
AddAssert($"Beatmap changed {test_count + 2} times", () => beatmapChangedCount == test_count + 2);
}
[Test]
public void TestHideSetSelectsCorrectBeatmap()
{
int? previousID = null;
createSongSelect();
addRulesetImportStep(0);
AddStep("Move to last difficulty", () => songSelect.Carousel.SelectBeatmap(songSelect.Carousel.BeatmapSets.First().Beatmaps.Last()));
AddStep("Store current ID", () => previousID = songSelect.Carousel.SelectedBeatmap.ID);
AddStep("Hide first beatmap", () => manager.Hide(songSelect.Carousel.SelectedBeatmapSet.Beatmaps.First()));
AddAssert("Selected beatmap has not changed", () => songSelect.Carousel.SelectedBeatmap.ID == previousID);
}
private void addRulesetImportStep(int id) => AddStep($"import test map for ruleset {id}", () => importForRuleset(id));
private void importForRuleset(int id) => manager.Import(createTestBeatmapSet(getImportId(), rulesets.AvailableRulesets.Where(r => r.ID == id).ToArray()));
private static int importId; private static int importId;
private int getImportId() => ++importId; private int getImportId() => ++importId;

View File

@ -152,9 +152,12 @@ namespace osu.Game.Screens.Select
{ {
Schedule(() => Schedule(() =>
{ {
int? previouslySelectedID = null;
CarouselBeatmapSet existingSet = beatmapSets.FirstOrDefault(b => b.BeatmapSet.ID == beatmapSet.ID); CarouselBeatmapSet existingSet = beatmapSets.FirstOrDefault(b => b.BeatmapSet.ID == beatmapSet.ID);
bool hadSelection = existingSet?.State?.Value == CarouselItemState.Selected; // If the selected beatmap is about to be removed, store its ID so it can be re-selected if required
if (existingSet?.State?.Value == CarouselItemState.Selected)
previouslySelectedID = selectedBeatmap?.Beatmap.ID;
var newSet = createCarouselSet(beatmapSet); var newSet = createCarouselSet(beatmapSet);
@ -172,8 +175,8 @@ namespace osu.Game.Screens.Select
applyActiveCriteria(false, false); applyActiveCriteria(false, false);
//check if we can/need to maintain our current selection. //check if we can/need to maintain our current selection.
if (hadSelection) if (previouslySelectedID != null)
select((CarouselItem)newSet.Beatmaps.FirstOrDefault(b => b.Beatmap.ID == selectedBeatmap?.Beatmap.ID) ?? newSet); select((CarouselItem)newSet.Beatmaps.FirstOrDefault(b => b.Beatmap.ID == previouslySelectedID) ?? newSet);
itemsCache.Invalidate(); itemsCache.Invalidate();
Schedule(() => BeatmapSetsChanged?.Invoke()); Schedule(() => BeatmapSetsChanged?.Invoke());

View File

@ -594,11 +594,17 @@ namespace osu.Game.Screens.Select
{ {
bindBindables(); bindBindables();
// If a selection was already obtained, do not attempt to update the selected beatmap.
if (Carousel.SelectedBeatmapSet != null)
return;
// Attempt to select the current beatmap on the carousel, if it is valid to be selected.
if (!Beatmap.IsDefault && Beatmap.Value.BeatmapSetInfo?.DeletePending == false && Beatmap.Value.BeatmapSetInfo?.Protected == false if (!Beatmap.IsDefault && Beatmap.Value.BeatmapSetInfo?.DeletePending == false && Beatmap.Value.BeatmapSetInfo?.Protected == false
&& Carousel.SelectBeatmap(Beatmap.Value.BeatmapInfo, false)) && Carousel.SelectBeatmap(Beatmap.Value.BeatmapInfo, false))
return; return;
if (Carousel.SelectedBeatmapSet == null && !Carousel.SelectNextRandom()) // If the current active beatmap could not be selected, select a new random beatmap.
if (!Carousel.SelectNextRandom())
{ {
// in the case random selection failed, we want to trigger selectionChanged // in the case random selection failed, we want to trigger selectionChanged
// to show the dummy beatmap (we have nothing else to display). // to show the dummy beatmap (we have nothing else to display).