From 230b347c1efbfc7baa7da6af8676356e47d7a4d2 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 1 Feb 2021 12:18:11 +0900 Subject: [PATCH] Move ModSelectOverlay.IsValidMod to a property --- osu.Game/Overlays/Mods/ModSelectOverlay.cs | 29 ++++++++++++++----- .../Overlays/Mods/SoloModSelectOverlay.cs | 6 ---- .../Multiplayer/FreeModSelectOverlay.cs | 5 ---- .../Multiplayer/MultiplayerMatchSongSelect.cs | 11 +++++-- osu.Game/Screens/Select/MatchSongSelect.cs | 5 +++- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/osu.Game/Overlays/Mods/ModSelectOverlay.cs b/osu.Game/Overlays/Mods/ModSelectOverlay.cs index 5709ca3b8d..c21b9ba409 100644 --- a/osu.Game/Overlays/Mods/ModSelectOverlay.cs +++ b/osu.Game/Overlays/Mods/ModSelectOverlay.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Audio.Sample; @@ -29,7 +30,6 @@ namespace osu.Game.Overlays.Mods { public abstract class ModSelectOverlay : WaveOverlayContainer { - private readonly Func isValidMod; public const float HEIGHT = 510; protected readonly TriangleButton DeselectAllButton; @@ -46,6 +46,20 @@ public abstract class ModSelectOverlay : WaveOverlayContainer protected readonly ModSettingsContainer ModSettingsContainer; + [NotNull] + private Func isValidMod = m => true; + + [NotNull] + public Func IsValidMod + { + get => isValidMod; + set + { + isValidMod = value ?? throw new ArgumentNullException(nameof(value)); + updateAvailableMods(); + } + } + public readonly Bindable> SelectedMods = new Bindable>(Array.Empty()); private Bindable>> availableMods; @@ -60,10 +74,8 @@ public abstract class ModSelectOverlay : WaveOverlayContainer private SampleChannel sampleOn, sampleOff; - protected ModSelectOverlay(Func isValidMod = null) + protected ModSelectOverlay() { - this.isValidMod = isValidMod ?? (m => true); - Waves.FirstWaveColour = Color4Extensions.FromHex(@"19b0e2"); Waves.SecondWaveColour = Color4Extensions.FromHex(@"2280a2"); Waves.ThirdWaveColour = Color4Extensions.FromHex(@"005774"); @@ -350,7 +362,7 @@ protected override void LoadComplete() { base.LoadComplete(); - availableMods.BindValueChanged(availableModsChanged, true); + availableMods.BindValueChanged(_ => updateAvailableMods(), true); SelectedMods.BindValueChanged(selectedModsChanged, true); } @@ -405,12 +417,13 @@ protected override bool OnKeyDown(KeyDownEvent e) public override bool OnPressed(GlobalAction action) => false; // handled by back button - private void availableModsChanged(ValueChangedEvent>> mods) + private void updateAvailableMods() { - if (mods.NewValue == null) return; + if (availableMods.Value == null) + return; foreach (var section in ModSectionsContainer.Children) - section.Mods = mods.NewValue[section.ModType].Where(isValidMod); + section.Mods = availableMods.Value[section.ModType].Where(IsValidMod); } private void selectedModsChanged(ValueChangedEvent> mods) diff --git a/osu.Game/Overlays/Mods/SoloModSelectOverlay.cs b/osu.Game/Overlays/Mods/SoloModSelectOverlay.cs index 53d0c9fce9..d039ad1f98 100644 --- a/osu.Game/Overlays/Mods/SoloModSelectOverlay.cs +++ b/osu.Game/Overlays/Mods/SoloModSelectOverlay.cs @@ -1,18 +1,12 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using osu.Game.Rulesets.Mods; namespace osu.Game.Overlays.Mods { public class SoloModSelectOverlay : ModSelectOverlay { - public SoloModSelectOverlay(Func isValidMod = null) - : base(isValidMod) - { - } - protected override void OnModSelected(Mod mod) { base.OnModSelected(mod); diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/FreeModSelectOverlay.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/FreeModSelectOverlay.cs index 10b68ec5a6..56e74a8460 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/FreeModSelectOverlay.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/FreeModSelectOverlay.cs @@ -14,11 +14,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer { public class FreeModSelectOverlay : ModSelectOverlay { - public FreeModSelectOverlay(Func isValidMod = null) - : base(isValidMod) - { - } - protected override ModSection CreateModSection(ModType type) => new FreeModSection(type); private class FreeModSection : ModSection diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchSongSelect.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchSongSelect.cs index 86b8f22d34..d36ebeec0f 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchSongSelect.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchSongSelect.cs @@ -54,7 +54,11 @@ public MultiplayerMatchSongSelect() { Padding = new MarginPadding { Horizontal = HORIZONTAL_OVERFLOW_PADDING }; - freeModSelectOverlay = new FreeModSelectOverlay(isValidMod) { SelectedMods = { BindTarget = freeMods } }; + freeModSelectOverlay = new FreeModSelectOverlay + { + SelectedMods = { BindTarget = freeMods }, + IsValidMod = isValidMod, + }; } [BackgroundDependencyLoader] @@ -130,7 +134,10 @@ public override bool OnExiting(IScreen next) protected override BeatmapDetailArea CreateBeatmapDetailArea() => new PlayBeatmapDetailArea(); - protected override ModSelectOverlay CreateModSelectOverlay() => new SoloModSelectOverlay(isValidMod); + protected override ModSelectOverlay CreateModSelectOverlay() => new SoloModSelectOverlay + { + IsValidMod = isValidMod + }; protected override IEnumerable<(FooterButton, OverlayContainer)> CreateFooterButtons() { diff --git a/osu.Game/Screens/Select/MatchSongSelect.cs b/osu.Game/Screens/Select/MatchSongSelect.cs index 280f46f9ab..98e02a9294 100644 --- a/osu.Game/Screens/Select/MatchSongSelect.cs +++ b/osu.Game/Screens/Select/MatchSongSelect.cs @@ -81,7 +81,10 @@ private void populateItemFromCurrent(PlaylistItem item) item.RequiredMods.AddRange(Mods.Value.Select(m => m.CreateCopy())); } - protected override ModSelectOverlay CreateModSelectOverlay() => new SoloModSelectOverlay(isValidMod); + protected override ModSelectOverlay CreateModSelectOverlay() => new SoloModSelectOverlay + { + IsValidMod = isValidMod + }; private bool isValidMod(Mod mod) => !(mod is ModAutoplay) && (mod as MultiMod)?.Mods.Any(mm => mm is ModAutoplay) != true; }