diff --git a/osu.Game/Overlays/Mods/SelectAllModsButton.cs b/osu.Game/Overlays/Mods/SelectAllModsButton.cs index b9d6bf9633..f7078b2fa5 100644 --- a/osu.Game/Overlays/Mods/SelectAllModsButton.cs +++ b/osu.Game/Overlays/Mods/SelectAllModsButton.cs @@ -1,22 +1,48 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Collections.Generic; +using System.Linq; +using osu.Framework.Bindables; using osu.Framework.Input; using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; using osu.Game.Graphics.UserInterface; using osu.Game.Localisation; +using osu.Game.Rulesets.Mods; using osu.Game.Screens.OnlinePlay; namespace osu.Game.Overlays.Mods { public class SelectAllModsButton : ShearedButton, IKeyBindingHandler { + private readonly Bindable> selectedMods = new Bindable>(); + private readonly Bindable>> availableMods = new Bindable>>(); + public SelectAllModsButton(FreeModSelectOverlay modSelectOverlay) : base(ModSelectOverlay.BUTTON_WIDTH) { Text = CommonStrings.SelectAll; Action = modSelectOverlay.SelectAll; + + selectedMods.BindTo(modSelectOverlay.SelectedMods); + availableMods.BindTo(modSelectOverlay.AvailableMods); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + selectedMods.BindValueChanged(_ => Scheduler.AddOnce(updateEnabledState)); + availableMods.BindValueChanged(_ => Scheduler.AddOnce(updateEnabledState)); + updateEnabledState(); + } + + private void updateEnabledState() + { + Enabled.Value = availableMods.Value + .SelectMany(pair => pair.Value) + .Any(modState => !modState.Active.Value && !modState.Filtered.Value); } public bool OnPressed(KeyBindingPressEvent e)