From 03c80d91978988229b338c4056ef3a7f6d282702 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 8 May 2022 01:58:37 +0900 Subject: [PATCH] Reorder methods / properties in `ModSelectScreen` for legibility --- osu.Game/Overlays/Mods/ModSelectScreen.cs | 86 ++++++++++++++--------- 1 file changed, 52 insertions(+), 34 deletions(-) diff --git a/osu.Game/Overlays/Mods/ModSelectScreen.cs b/osu.Game/Overlays/Mods/ModSelectScreen.cs index 8098e8b0f6..ef96811144 100644 --- a/osu.Game/Overlays/Mods/ModSelectScreen.cs +++ b/osu.Game/Overlays/Mods/ModSelectScreen.cs @@ -60,29 +60,20 @@ namespace osu.Game.Overlays.Mods protected virtual ModColumn CreateModColumn(ModType modType, Key[]? toggleKeys = null) => new ModColumn(modType, false, toggleKeys); - protected virtual IEnumerable CreateFooterButtons() => new[] - { - customisationButton = new ShearedToggleButton(BUTTON_WIDTH) - { - Text = ModSelectScreenStrings.ModCustomisation, - Active = { BindTarget = customisationVisible } - }, - new ShearedButton(BUTTON_WIDTH) - { - Text = CommonStrings.DeselectAll, - Action = DeselectAll - } - }; + protected virtual IReadOnlyList ComputeNewModsFromSelection(IReadOnlyList oldSelection, IReadOnlyList newSelection) => newSelection; + + protected virtual IEnumerable CreateFooterButtons() => createDefaultFooterButtons(); private readonly BindableBool customisationVisible = new BindableBool(); - private DifficultyMultiplierDisplay? multiplierDisplay; private ModSettingsArea modSettingsArea = null!; private ColumnScrollContainer columnScroll = null!; private ColumnFlowContainer columnFlow = null!; - private FillFlowContainer footerButtonFlow = null!; private ShearedButton backButton = null!; + + private DifficultyMultiplierDisplay? multiplierDisplay; + private ShearedToggleButton? customisationButton; protected ModSelectScreen(OverlayColourScheme colourScheme = OverlayColourScheme.Green) @@ -193,14 +184,6 @@ namespace osu.Game.Overlays.Mods }; } - private ColumnDimContainer createModColumnContent(ModType modType, Key[]? toggleKeys = null) - => new ColumnDimContainer(CreateModColumn(modType, toggleKeys)) - { - AutoSizeAxes = Axes.X, - RelativeSizeAxes = Axes.Y, - RequestScroll = column => columnScroll.ScrollIntoView(column, extraScroll: 140) - }; - protected override void LoadComplete() { base.LoadComplete(); @@ -224,6 +207,47 @@ namespace osu.Game.Overlays.Mods updateAvailableMods(); } + /// + /// Select all visible mods in all columns. + /// + protected void SelectAll() + { + foreach (var column in columnFlow.Columns) + column.SelectAll(); + } + + /// + /// Deselect all visible mods in all columns. + /// + protected void DeselectAll() + { + foreach (var column in columnFlow.Columns) + column.DeselectAll(); + } + + private ColumnDimContainer createModColumnContent(ModType modType, Key[]? toggleKeys = null) + => new ColumnDimContainer(CreateModColumn(modType, toggleKeys)) + { + AutoSizeAxes = Axes.X, + RelativeSizeAxes = Axes.Y, + RequestScroll = column => columnScroll.ScrollIntoView(column, extraScroll: 140) + }; + + private ShearedButton[] createDefaultFooterButtons() + => new[] + { + customisationButton = new ShearedToggleButton(BUTTON_WIDTH) + { + Text = ModSelectScreenStrings.ModCustomisation, + Active = { BindTarget = customisationVisible } + }, + new ShearedButton(BUTTON_WIDTH) + { + Text = CommonStrings.DeselectAll, + Action = DeselectAll + } + }; + private void updateMultiplier() { if (multiplierDisplay == null) @@ -314,7 +338,7 @@ namespace osu.Game.Overlays.Mods SelectedMods.Value = ComputeNewModsFromSelection(SelectedMods.Value, candidateSelection); } - protected virtual IReadOnlyList ComputeNewModsFromSelection(IReadOnlyList oldSelection, IReadOnlyList newSelection) => newSelection; + #region Transition handling protected override void PopIn() { @@ -360,17 +384,9 @@ namespace osu.Game.Overlays.Mods } } - protected void SelectAll() - { - foreach (var column in columnFlow.Columns) - column.SelectAll(); - } + #endregion - protected void DeselectAll() - { - foreach (var column in columnFlow.Columns) - column.DeselectAll(); - } + #region Input handling public override bool OnPressed(KeyBindingPressEvent e) { @@ -404,6 +420,8 @@ namespace osu.Game.Overlays.Mods } } + #endregion + internal class ColumnScrollContainer : OsuScrollContainer { public ColumnScrollContainer()