Fix wrong filtering in testing

This commit is contained in:
Cootz 2023-05-05 22:41:30 +03:00
parent ab94b4dce1
commit 7422b5285c
6 changed files with 43 additions and 11 deletions

View File

@ -291,7 +291,7 @@ namespace osu.Game.Tests.Visual.UserInterface
private void setFilter(Func<Mod, bool>? filter)
{
foreach (var modState in this.ChildrenOfType<ModColumn>().Single().AvailableMods)
modState.MatchingFilter.Value = filter?.Invoke(modState.Mod) == false;
modState.MatchingFilter.Value = filter?.Invoke(modState.Mod) ?? true;
}
private partial class TestModColumn : ModColumn

View File

@ -431,15 +431,15 @@ namespace osu.Game.Tests.Visual.UserInterface
createScreen();
changeRuleset(0);
AddAssert("double time visible", () => modSelectOverlay.ChildrenOfType<ModPanel>().Where(panel => panel.Mod is OsuModDoubleTime).Any(panel => panel.MatchingFilter));
AddAssert("double time visible", () => modSelectOverlay.ChildrenOfType<ModPanel>().Where(panel => panel.Mod is OsuModDoubleTime).Any(panel => panel.IsValid));
AddStep("make double time invalid", () => modSelectOverlay.IsValidMod = m => !(m is OsuModDoubleTime));
AddUntilStep("double time not visible", () => modSelectOverlay.ChildrenOfType<ModPanel>().Where(panel => panel.Mod is OsuModDoubleTime).All(panel => !panel.MatchingFilter));
AddAssert("nightcore still visible", () => modSelectOverlay.ChildrenOfType<ModPanel>().Where(panel => panel.Mod is OsuModNightcore).Any(panel => panel.MatchingFilter));
AddUntilStep("double time not visible", () => modSelectOverlay.ChildrenOfType<ModPanel>().Where(panel => panel.Mod is OsuModDoubleTime).All(panel => !panel.IsValid));
AddAssert("nightcore still visible", () => modSelectOverlay.ChildrenOfType<ModPanel>().Where(panel => panel.Mod is OsuModNightcore).Any(panel => panel.IsValid));
AddStep("make double time valid again", () => modSelectOverlay.IsValidMod = _ => true);
AddUntilStep("double time visible", () => modSelectOverlay.ChildrenOfType<ModPanel>().Where(panel => panel.Mod is OsuModDoubleTime).Any(panel => panel.MatchingFilter));
AddAssert("nightcore still visible", () => modSelectOverlay.ChildrenOfType<ModPanel>().Where(b => b.Mod is OsuModNightcore).Any(panel => panel.MatchingFilter));
AddUntilStep("double time visible", () => modSelectOverlay.ChildrenOfType<ModPanel>().Where(panel => panel.Mod is OsuModDoubleTime).Any(panel => panel.IsValid));
AddAssert("nightcore still visible", () => modSelectOverlay.ChildrenOfType<ModPanel>().Where(b => b.Mod is OsuModNightcore).Any(panel => panel.IsValid));
}
[Test]
@ -465,7 +465,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("set ruleset", () => Ruleset.Value = testRuleset.RulesetInfo);
waitForColumnLoad();
AddAssert("unimplemented mod panel is filtered", () => !getPanelForMod(typeof(TestUnimplementedMod)).MatchingFilter);
AddAssert("unimplemented mod panel is filtered", () => !getPanelForMod(typeof(TestUnimplementedMod)).IsValid);
}
[Test]

View File

@ -47,6 +47,7 @@ namespace osu.Game.Overlays.Mods
{
mod.Active.BindValueChanged(_ => updateState());
mod.MatchingFilter.BindValueChanged(_ => updateState());
mod.ValidForSelection.BindValueChanged(_ => updateState());
}
updateState();
@ -145,7 +146,7 @@ namespace osu.Game.Overlays.Mods
private void updateState()
{
Alpha = availableMods.All(mod => !mod.MatchingFilter.Value) ? 0 : 1;
Alpha = availableMods.All(mod => !mod.MatchingFilter.Value || !mod.ValidForSelection.Value) ? 0 : 1;
if (toggleAllCheckbox != null && !SelectionAnimationRunning)
{

View File

@ -56,7 +56,8 @@ namespace osu.Game.Overlays.Mods
{
base.LoadComplete();
canBeShown.BindTo(modState.ValidForSelection);
modState.ValidForSelection.BindValueChanged(_ => updateFilterState());
modState.MatchingFilter.BindValueChanged(_ => updateFilterState(), true);
}
protected override void Select()
@ -71,6 +72,23 @@ namespace osu.Game.Overlays.Mods
Active.Value = false;
}
/// <summary>
/// Determine if <see cref="ModPanel"/> is valid and can be shown
/// </summary>
public bool IsValid => modState.IsValid;
public bool ValidForSelection
{
get => modState.ValidForSelection.Value;
set
{
if (modState.ValidForSelection.Value == value)
return;
modState.ValidForSelection.Value = value;
}
}
#region Filtering support
public override IEnumerable<LocalisableString> FilterTerms => new[]
@ -89,13 +107,21 @@ namespace osu.Game.Overlays.Mods
return;
modState.MatchingFilter.Value = value;
this.FadeTo(value ? 1 : 0);
}
}
/// <summary>
/// This property is always <see langword="true"/> because it affects search result
/// </summary>
private readonly BindableBool canBeShown = new BindableBool(true);
IBindable<bool> IConditionalFilterable.CanBeShown => canBeShown;
private void updateFilterState()
{
this.FadeTo(IsValid ? 1 : 0);
}
#endregion
}
}

View File

@ -38,6 +38,11 @@ namespace osu.Game.Overlays.Mods
/// </summary>
public BindableBool ValidForSelection { get; } = new BindableBool(true);
/// <summary>
/// Determine if <see cref="Mod"/> is valid and can be shown
/// </summary>
public bool IsValid => MatchingFilter.Value && ValidForSelection.Value;
/// <summary>
/// Whether the mod is matching the current filter, i.e. it is available for user selection.
/// </summary>

View File

@ -44,7 +44,7 @@ namespace osu.Game.Overlays.Mods
{
Enabled.Value = availableMods.Value
.SelectMany(pair => pair.Value)
.Any(modState => !modState.Active.Value && !modState.MatchingFilter.Value);
.Any(modState => !modState.Active.Value && modState.IsValid);
}
public bool OnPressed(KeyBindingPressEvent<PlatformAction> e)