mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 02:02:53 +08:00
Fix selection not being preserved when IsValidMod changes
This commit is contained in:
parent
10ceddf3ff
commit
50e92bd0ed
@ -153,6 +153,18 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
AddAssert("nightcore still visible", () => modSelect.ChildrenOfType<ModButton>().Any(b => b.Mods.Any(m => m is OsuModNightcore)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestChangeIsValidPreservesSelection()
|
||||
{
|
||||
changeRuleset(0);
|
||||
|
||||
AddStep("select DT + HD", () => SelectedMods.Value = new Mod[] { new OsuModDoubleTime(), new OsuModHidden() });
|
||||
AddAssert("DT + HD selected", () => modSelect.ChildrenOfType<ModButton>().Count(b => b.Selected) == 2);
|
||||
|
||||
AddStep("make NF invalid", () => modSelect.IsValidMod = m => !(m is ModNoFail));
|
||||
AddAssert("DT + HD still selected", () => modSelect.ChildrenOfType<ModButton>().Count(b => b.Selected) == 2);
|
||||
}
|
||||
|
||||
private void testSingleMod(Mod mod)
|
||||
{
|
||||
selectNext(mod);
|
||||
|
@ -130,13 +130,13 @@ namespace osu.Game.Overlays.Mods
|
||||
/// Updates all buttons with the given list of selected mods.
|
||||
/// </summary>
|
||||
/// <param name="newSelectedMods">The new list of selected mods to select.</param>
|
||||
public void UpdateSelectedMods(IReadOnlyList<Mod> newSelectedMods)
|
||||
public void UpdateSelectedButtons(IReadOnlyList<Mod> newSelectedMods)
|
||||
{
|
||||
foreach (var button in buttons)
|
||||
updateButtonMods(button, newSelectedMods);
|
||||
updateButtonSelection(button, newSelectedMods);
|
||||
}
|
||||
|
||||
private void updateButtonMods(ModButton button, IReadOnlyList<Mod> newSelectedMods)
|
||||
private void updateButtonSelection(ModButton button, IReadOnlyList<Mod> newSelectedMods)
|
||||
{
|
||||
foreach (var mod in newSelectedMods)
|
||||
{
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user