Don't re-filter unless mods may change the filter

This commit is contained in:
Dan Balasescu 2024-04-15 21:07:36 +09:00
parent fe7df808b6
commit 343b3ba0e6
No known key found for this signature in database
5 changed files with 47 additions and 6 deletions

View File

@ -1,9 +1,14 @@
// 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.Collections.Generic;
using System.Linq;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Filter;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Mods;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring.Legacy;
using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Filter;
@ -30,5 +35,20 @@ public bool TryParseCustomKeywordCriteria(string key, Operator op, string value)
return false;
}
public bool FilterMayChangeFromMods(ValueChangedEvent<IReadOnlyList<Mod>> mods)
{
if (keys.HasFilter)
{
// Interpreting as the Mod type is required for equality comparison.
HashSet<Mod> oldSet = mods.OldValue.OfType<ManiaKeyMod>().AsEnumerable<Mod>().ToHashSet();
HashSet<Mod> newSet = mods.NewValue.OfType<ManiaKeyMod>().AsEnumerable<Mod>().ToHashSet();
if (!oldSet.SetEquals(newSet))
return true;
}
return false;
}
}
}

View File

@ -1,10 +1,13 @@
// 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.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Filter;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Carousel;
using osu.Game.Screens.Select.Filter;
@ -311,6 +314,8 @@ public CustomCriteria(bool shouldMatch)
public bool Matches(BeatmapInfo beatmapInfo, FilterCriteria criteria) => match;
public bool TryParseCustomKeywordCriteria(string key, Operator op, string value) => false;
public bool FilterMayChangeFromMods(ValueChangedEvent<IReadOnlyList<Mod>> mods) => false;
}
}
}

View File

@ -2,10 +2,13 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Filter;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Carousel;
using osu.Game.Screens.Select.Filter;
@ -514,6 +517,8 @@ public bool TryParseCustomKeywordCriteria(string key, Operator op, string value)
return false;
}
public bool FilterMayChangeFromMods(ValueChangedEvent<IReadOnlyList<Mod>> mods) => false;
}
private static readonly object[] correct_date_query_examples =

View File

@ -1,7 +1,10 @@
// 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.Collections.Generic;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Filter;
@ -52,5 +55,12 @@ public interface IRulesetFilterCriteria
/// while ignored criteria are included in <see cref="FilterCriteria.SearchText"/>.
/// </returns>
bool TryParseCustomKeywordCriteria(string key, Operator op, string value);
/// <summary>
/// Whether to reapply the filter as a result of the given change in applied mods.
/// </summary>
/// <param name="mods">The change in mods.</param>
/// <returns>Whether the filter should be re-applied.</returns>
bool FilterMayChangeFromMods(ValueChangedEvent<IReadOnlyList<Mod>> mods);
}
}

View File

@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -49,15 +50,14 @@ public LocalisableString InformationalText
}
private OsuTabControl<SortMode> sortTabs;
private Bindable<SortMode> sortMode;
private Bindable<GroupMode> groupMode;
private FilterControlTextBox searchTextBox;
private CollectionDropdown collectionDropdown;
[CanBeNull]
private FilterCriteria currentCriteria;
public FilterCriteria CreateCriteria()
{
string query = searchTextBox.Text;
@ -228,7 +228,8 @@ private void load(OsuColour colours, OsuConfigManager config)
if (m.NewValue.SequenceEqual(m.OldValue))
return;
updateCriteria();
if (currentCriteria?.RulesetCriteria?.FilterMayChangeFromMods(m) == true)
updateCriteria();
});
groupMode.BindValueChanged(_ => updateCriteria());
@ -263,7 +264,7 @@ public void Activate()
private readonly Bindable<double> minimumStars = new BindableDouble();
private readonly Bindable<double> maximumStars = new BindableDouble();
private void updateCriteria() => FilterChanged?.Invoke(CreateCriteria());
private void updateCriteria() => FilterChanged?.Invoke(currentCriteria = CreateCriteria());
protected override bool OnClick(ClickEvent e) => true;