mirror of https://github.com/ppy/osu
Move ModSelectOverlay.IsValidMod to a property
This commit is contained in:
parent
ab9a3e6dd0
commit
230b347c1e
|
@ -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<Mod, bool> 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<Mod, bool> isValidMod = m => true;
|
||||
|
||||
[NotNull]
|
||||
public Func<Mod, bool> IsValidMod
|
||||
{
|
||||
get => isValidMod;
|
||||
set
|
||||
{
|
||||
isValidMod = value ?? throw new ArgumentNullException(nameof(value));
|
||||
updateAvailableMods();
|
||||
}
|
||||
}
|
||||
|
||||
public readonly Bindable<IReadOnlyList<Mod>> SelectedMods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
||||
|
||||
private Bindable<Dictionary<ModType, IReadOnlyList<Mod>>> availableMods;
|
||||
|
@ -60,10 +74,8 @@ public abstract class ModSelectOverlay : WaveOverlayContainer
|
|||
|
||||
private SampleChannel sampleOn, sampleOff;
|
||||
|
||||
protected ModSelectOverlay(Func<Mod, bool> 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<Dictionary<ModType, IReadOnlyList<Mod>>> 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<IReadOnlyList<Mod>> mods)
|
||||
|
|
|
@ -1,18 +1,12 @@
|
|||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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<Mod, bool> isValidMod = null)
|
||||
: base(isValidMod)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModSelected(Mod mod)
|
||||
{
|
||||
base.OnModSelected(mod);
|
||||
|
|
|
@ -14,11 +14,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||
{
|
||||
public class FreeModSelectOverlay : ModSelectOverlay
|
||||
{
|
||||
public FreeModSelectOverlay(Func<Mod, bool> isValidMod = null)
|
||||
: base(isValidMod)
|
||||
{
|
||||
}
|
||||
|
||||
protected override ModSection CreateModSection(ModType type) => new FreeModSection(type);
|
||||
|
||||
private class FreeModSection : ModSection
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue