mirror of
https://github.com/osukey/osukey.git
synced 2025-05-17 19:47:33 +09: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)));
|
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)
|
private void testSingleMod(Mod mod)
|
||||||
{
|
{
|
||||||
selectNext(mod);
|
selectNext(mod);
|
||||||
|
@ -130,13 +130,13 @@ namespace osu.Game.Overlays.Mods
|
|||||||
/// Updates all buttons with the given list of selected mods.
|
/// Updates all buttons with the given list of selected mods.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="newSelectedMods">The new list of selected mods to select.</param>
|
/// <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)
|
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)
|
foreach (var mod in newSelectedMods)
|
||||||
{
|
{
|
||||||
|
@ -367,7 +367,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
availableMods.BindValueChanged(_ => updateAvailableMods(), true);
|
availableMods.BindValueChanged(_ => updateAvailableMods(), true);
|
||||||
SelectedMods.BindValueChanged(selectedModsChanged, true);
|
SelectedMods.BindValueChanged(_ => updateSelectedButtons(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void PopOut()
|
protected override void PopOut()
|
||||||
@ -435,6 +435,8 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
section.Mods = modEnumeration.Select(getValidModOrNull).Where(m => m != null);
|
section.Mods = modEnumeration.Select(getValidModOrNull).Where(m => m != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateSelectedButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -459,10 +461,13 @@ namespace osu.Game.Overlays.Mods
|
|||||||
return validSubset.Length == 1 ? validSubset[0] : new MultiMod(validSubset);
|
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)
|
foreach (var section in ModSectionsContainer.Children)
|
||||||
section.UpdateSelectedMods(mods.NewValue);
|
section.UpdateSelectedButtons(selectedMods);
|
||||||
|
|
||||||
updateMods();
|
updateMods();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user