1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-16 06:43:20 +08:00

Abstractify ModSelectOverlay

This commit is contained in:
smoogipoo 2021-01-27 22:02:23 +09:00
parent 0ff300628e
commit 91d34d86f7
5 changed files with 34 additions and 19 deletions

View File

@ -265,7 +265,7 @@ namespace osu.Game.Tests.Visual.UserInterface
private void checkLabelColor(Func<Color4> getColour) => AddAssert("check label has expected colour", () => modSelect.MultiplierLabel.Colour.AverageColour == getColour());
private class TestModSelectOverlay : ModSelectOverlay
private class TestModSelectOverlay : SoloModSelectOverlay
{
public new Bindable<IReadOnlyList<Mod>> SelectedMods => base.SelectedMods;

View File

@ -27,7 +27,7 @@ using osuTK.Input;
namespace osu.Game.Overlays.Mods
{
public class ModSelectOverlay : WaveOverlayContainer
public abstract class ModSelectOverlay : WaveOverlayContainer
{
private readonly Func<Mod, bool> isValidMod;
public const float HEIGHT = 510;
@ -60,7 +60,7 @@ namespace osu.Game.Overlays.Mods
private SampleChannel sampleOn, sampleOff;
public ModSelectOverlay(Func<Mod, bool> isValidMod = null)
protected ModSelectOverlay(Func<Mod, bool> isValidMod = null)
{
this.isValidMod = isValidMod ?? (m => true);
@ -346,19 +346,6 @@ namespace osu.Game.Overlays.Mods
refreshSelectedMods();
}
/// <summary>
/// Deselect one or more mods.
/// </summary>
/// <param name="modTypes">The types of <see cref="Mod"/>s which should be deselected.</param>
/// <param name="immediate">Set to true to bypass animations and update selections immediately.</param>
private void deselectTypes(Type[] modTypes, bool immediate = false)
{
if (modTypes.Length == 0) return;
foreach (var section in ModSectionsContainer.Children)
section.DeselectTypes(modTypes, immediate);
}
protected override void LoadComplete()
{
base.LoadComplete();
@ -458,7 +445,7 @@ namespace osu.Game.Overlays.Mods
{
if (State.Value == Visibility.Visible) sampleOn?.Play();
deselectTypes(selectedMod.IncompatibleMods, true);
OnModSelected(selectedMod);
if (selectedMod.RequiresConfiguration) ModSettingsContainer.Show();
}
@ -470,6 +457,10 @@ namespace osu.Game.Overlays.Mods
refreshSelectedMods();
}
protected virtual void OnModSelected(Mod mod)
{
}
private void refreshSelectedMods() => SelectedMods.Value = ModSectionsContainer.Children.SelectMany(s => s.SelectedMods).ToArray();
protected virtual ModSection CreateModSection(ModType type) => new ModSection(type);

View File

@ -0,0 +1,24 @@
// 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);
foreach (var section in ModSectionsContainer.Children)
section.DeselectTypes(mod.IncompatibleMods, true);
}
}
}

View File

@ -81,7 +81,7 @@ namespace osu.Game.Screens.Select
item.RequiredMods.AddRange(Mods.Value.Select(m => m.CreateCopy()));
}
protected override ModSelectOverlay CreateModSelectOverlay() => new ModSelectOverlay(isValidMod);
protected override ModSelectOverlay CreateModSelectOverlay() => new SoloModSelectOverlay(isValidMod);
private bool isValidMod(Mod mod) => !(mod is ModAutoplay) && (mod as MultiMod)?.Mods.Any(mm => mm is ModAutoplay) != true;
}

View File

@ -301,7 +301,7 @@ namespace osu.Game.Screens.Select
}
}
protected virtual ModSelectOverlay CreateModSelectOverlay() => new ModSelectOverlay();
protected virtual ModSelectOverlay CreateModSelectOverlay() => new SoloModSelectOverlay();
protected virtual void ApplyFilterToCarousel(FilterCriteria criteria)
{