Fix selection not being preserved when IsValidMod changes

This commit is contained in:
smoogipoo
2021-02-02 20:50:54 +09:00
parent 10ceddf3ff
commit 50e92bd0ed
3 changed files with 23 additions and 6 deletions

View File

@ -367,7 +367,7 @@ namespace osu.Game.Overlays.Mods
base.LoadComplete();
availableMods.BindValueChanged(_ => updateAvailableMods(), true);
SelectedMods.BindValueChanged(selectedModsChanged, true);
SelectedMods.BindValueChanged(_ => updateSelectedButtons(), true);
}
protected override void PopOut()
@ -435,6 +435,8 @@ namespace osu.Game.Overlays.Mods
section.Mods = modEnumeration.Select(getValidModOrNull).Where(m => m != null);
}
updateSelectedButtons();
}
/// <summary>
@ -459,10 +461,13 @@ namespace osu.Game.Overlays.Mods
return validSubset.Length == 1 ? validSubset[0] : new MultiMod(validSubset);
}
private void selectedModsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)
private void updateSelectedButtons()
{
// Enumeration below may update the bindable list.
var selectedMods = SelectedMods.Value.ToList();
foreach (var section in ModSectionsContainer.Children)
section.UpdateSelectedMods(mods.NewValue);
section.UpdateSelectedButtons(selectedMods);
updateMods();
}