diff --git a/osu.Game/Overlays/Mods/ModSection.cs b/osu.Game/Overlays/Mods/ModSection.cs index 03c1f0468c..4765787caf 100644 --- a/osu.Game/Overlays/Mods/ModSection.cs +++ b/osu.Game/Overlays/Mods/ModSection.cs @@ -27,14 +27,8 @@ namespace osu.Game.Overlays.Mods public string Header { - get - { - return headerLabel.Text; - } - set - { - headerLabel.Text = value; - } + get => headerLabel.Text; + set => headerLabel.Text = value; } public IEnumerable SelectedMods => buttons.Select(b => b.SelectedMod).Where(m => m != null); @@ -47,12 +41,12 @@ namespace osu.Game.Overlays.Mods { if (m == null) return new ModButtonEmpty(); - else - return new ModButton(m) - { - SelectedColour = selectedColour, - SelectionChanged = Action, - }; + + return new ModButton(m) + { + SelectedColour = selectedColour, + SelectionChanged = Action, + }; }).ToArray(); ButtonsContainer.Children = modContainers; @@ -65,10 +59,7 @@ namespace osu.Game.Overlays.Mods private Color4 selectedColour = Color4.White; public Color4 SelectedColour { - get - { - return selectedColour; - } + get => selectedColour; set { if (value == selectedColour) return; @@ -102,31 +93,31 @@ namespace osu.Game.Overlays.Mods { Mod selected = button.SelectedMod; if (selected == null) continue; - foreach (Type type in modTypes) + foreach (var type in modTypes) if (type.IsInstanceOfType(selected)) { if (immediate) button.Deselect(); else - Scheduler.AddDelayed(() => button.Deselect(), delay += 50); + Scheduler.AddDelayed(button.Deselect, delay += 50); } } } /// - /// Select one or more mods in this section. + /// Select one or more mods in this section and deselects all other ones. /// - /// The types of s which should be deselected. - public void SelectTypes(IEnumerable mods) + /// The types of s which should be selected. + public void SelectTypes(IEnumerable modTypes) { foreach (var button in buttons) { - for (int i = 0; i < button.Mods.Length; i++) - { - foreach (var mod in mods) - if (mod.GetType().IsInstanceOfType(button.Mods[i])) - button.SelectAt(i); - } + int i = Array.FindIndex(button.Mods, m => modTypes.Any(t => t.IsInstanceOfType(m))); + + if (i >= 0) + button.SelectAt(i); + else + button.Deselect(); } } diff --git a/osu.Game/Overlays/Mods/ModSelectOverlay.cs b/osu.Game/Overlays/Mods/ModSelectOverlay.cs index 1ad1adadcf..fe7b7bae99 100644 --- a/osu.Game/Overlays/Mods/ModSelectOverlay.cs +++ b/osu.Game/Overlays/Mods/ModSelectOverlay.cs @@ -76,7 +76,7 @@ namespace osu.Game.Overlays.Mods private void selectedModsChanged(IEnumerable obj) { foreach (ModSection section in ModSectionsContainer.Children) - section.SelectTypes(obj); + section.SelectTypes(obj.Select(m => m.GetType()).ToList()); updateMods(); } diff --git a/osu.Game/Screens/Select/PlaySongSelect.cs b/osu.Game/Screens/Select/PlaySongSelect.cs index c347bfe70f..09524d2eac 100644 --- a/osu.Game/Screens/Select/PlaySongSelect.cs +++ b/osu.Game/Screens/Select/PlaySongSelect.cs @@ -99,7 +99,7 @@ namespace osu.Game.Screens.Select if (removeAutoModOnResume) { var autoType = Ruleset.Value.CreateInstance().GetAutoplayMod().GetType(); - SelectedMods.Value = SelectedMods.Value.Where(m => m.GetType() != autoType).ToArray(); + modSelect.DeselectTypes(new[] { autoType }, true); removeAutoModOnResume = false; }