mirror of
https://github.com/ppy/osu
synced 2025-01-19 04:20:59 +00:00
Fix wrong filtering in testing
This commit is contained in:
parent
ab94b4dce1
commit
7422b5285c
@ -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
|
||||
|
@ -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]
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user