mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 00:02:54 +08:00
Copy selected mods properties into overlay's buttons
This commit is contained in:
parent
b4df2d6d43
commit
2ce9599957
@ -127,18 +127,28 @@ namespace osu.Game.Overlays.Mods
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Select one or more mods in this section and deselects all other ones.
|
||||
/// Updates all buttons with the given list of selected mods.
|
||||
/// </summary>
|
||||
/// <param name="modTypes">The types of <see cref="Mod"/>s which should be selected.</param>
|
||||
public void SelectTypes(IEnumerable<Type> modTypes)
|
||||
/// <param name="newSelectedMods">The types of <see cref="Mod"/>s to select.</param>
|
||||
public void UpdateSelectedMods(IReadOnlyList<Mod> newSelectedMods)
|
||||
{
|
||||
foreach (var button in buttons)
|
||||
{
|
||||
int i = Array.FindIndex(button.Mods, m => modTypes.Any(t => t == m.GetType()));
|
||||
int index = -1;
|
||||
|
||||
if (i >= 0)
|
||||
button.SelectAt(i);
|
||||
else
|
||||
foreach (var mod in newSelectedMods)
|
||||
{
|
||||
index = Array.FindIndex(button.Mods, m1 => mod.GetType() == m1.GetType());
|
||||
if (index < 0)
|
||||
continue;
|
||||
|
||||
var buttonMod = button.Mods[index];
|
||||
buttonMod.CopyFrom(mod);
|
||||
button.SelectAt(index);
|
||||
break;
|
||||
}
|
||||
|
||||
if (index < 0)
|
||||
button.Deselect();
|
||||
}
|
||||
}
|
||||
|
@ -409,7 +409,7 @@ namespace osu.Game.Overlays.Mods
|
||||
private void selectedModsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)
|
||||
{
|
||||
foreach (var section in ModSectionsContainer.Children)
|
||||
section.SelectTypes(mods.NewValue.Select(m => m.GetType()).ToList());
|
||||
section.UpdateSelectedMods(mods.NewValue);
|
||||
|
||||
updateMods();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user