From 8a01050168038c41c6f8fc33d77848b91b85ccbb Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 15 May 2022 03:16:33 +0900 Subject: [PATCH] Refactor mod select button initialisation to allow shared usage of deselect button --- osu.Game/Overlays/Mods/ModSelectOverlay.cs | 43 +++++++++++-------- .../OnlinePlay/FreeModSelectOverlay.cs | 16 +++---- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/osu.Game/Overlays/Mods/ModSelectOverlay.cs b/osu.Game/Overlays/Mods/ModSelectOverlay.cs index fb988b5bfe..1dad185b78 100644 --- a/osu.Game/Overlays/Mods/ModSelectOverlay.cs +++ b/osu.Game/Overlays/Mods/ModSelectOverlay.cs @@ -56,11 +56,32 @@ namespace osu.Game.Overlays.Mods /// protected virtual bool ShowTotalMultiplier => true; + /// + /// Whether per-mod customisation controls are visible. + /// + protected virtual bool AllowCustomisation => true; + protected virtual ModColumn CreateModColumn(ModType modType, Key[]? toggleKeys = null) => new ModColumn(modType, false, toggleKeys); protected virtual IReadOnlyList ComputeNewModsFromSelection(IReadOnlyList oldSelection, IReadOnlyList newSelection) => newSelection; - protected virtual IEnumerable CreateFooterButtons() => createDefaultFooterButtons(); + protected virtual IEnumerable CreateFooterButtons() + { + if (AllowCustomisation) + { + yield return customisationButton = new ShearedToggleButton(BUTTON_WIDTH) + { + Text = ModSelectOverlayStrings.ModCustomisation, + Active = { BindTarget = customisationVisible } + }; + } + + yield return deselectAllButton = new ShearedButton(BUTTON_WIDTH) + { + Text = CommonStrings.DeselectAll, + Action = DeselectAll + }; + } private readonly Bindable>> availableMods = new Bindable>>(); private readonly Dictionary> localAvailableMods = new Dictionary>(); @@ -77,6 +98,7 @@ namespace osu.Game.Overlays.Mods private DifficultyMultiplierDisplay? multiplierDisplay; private ShearedToggleButton? customisationButton; + private ShearedButton? deselectAllButton; protected ModSelectOverlay(OverlayColourScheme colourScheme = OverlayColourScheme.Green) : base(colourScheme) @@ -201,7 +223,7 @@ namespace osu.Game.Overlays.Mods // This is an optimisation to prevent refreshing the available settings controls when it can be // reasonably assumed that the settings panel is never to be displayed (e.g. FreeModSelectOverlay). - if (customisationButton != null) + if (AllowCustomisation) ((IBindable>)modSettingsArea.SelectedMods).BindTo(SelectedMods); SelectedMods.BindValueChanged(val => @@ -256,21 +278,6 @@ namespace osu.Game.Overlays.Mods }; } - private ShearedButton[] createDefaultFooterButtons() - => new[] - { - customisationButton = new ShearedToggleButton(BUTTON_WIDTH) - { - Text = ModSelectOverlayStrings.ModCustomisation, - Active = { BindTarget = customisationVisible } - }, - new ShearedButton(BUTTON_WIDTH) - { - Text = CommonStrings.DeselectAll, - Action = DeselectAll - } - }; - private void createLocalMods() { localAvailableMods.Clear(); @@ -510,7 +517,7 @@ namespace osu.Game.Overlays.Mods } case GlobalAction.DeselectAllMods: - DeselectAll(); + deselectAllButton?.TriggerClick(); return true; } diff --git a/osu.Game/Screens/OnlinePlay/FreeModSelectOverlay.cs b/osu.Game/Screens/OnlinePlay/FreeModSelectOverlay.cs index 6e1c9b7a59..790333ea5b 100644 --- a/osu.Game/Screens/OnlinePlay/FreeModSelectOverlay.cs +++ b/osu.Game/Screens/OnlinePlay/FreeModSelectOverlay.cs @@ -4,6 +4,7 @@ using System; using osu.Game.Overlays; using System.Collections.Generic; +using System.Linq; using osu.Framework.Graphics; using osu.Game.Graphics.UserInterface; using osu.Game.Overlays.Mods; @@ -17,6 +18,8 @@ namespace osu.Game.Screens.OnlinePlay { protected override bool ShowTotalMultiplier => false; + protected override bool AllowCustomisation => false; + public new Func IsValidMod { get => base.IsValidMod; @@ -31,22 +34,13 @@ namespace osu.Game.Screens.OnlinePlay protected override ModColumn CreateModColumn(ModType modType, Key[] toggleKeys = null) => new ModColumn(modType, true, toggleKeys); - protected override IEnumerable CreateFooterButtons() => new[] - { + protected override IEnumerable CreateFooterButtons() => base.CreateFooterButtons().Prepend( new ShearedButton(BUTTON_WIDTH) { Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, Text = CommonStrings.SelectAll, Action = SelectAll - }, - new ShearedButton(BUTTON_WIDTH) - { - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - Text = CommonStrings.DeselectAll, - Action = DeselectAll - } - }; + }); } }