1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 16:07:24 +08:00

Add mods to FilterCriteria, pass to ruleset method

This commit is contained in:
Dan Balasescu 2024-03-28 23:02:25 +09:00
parent c08a4898b2
commit 9fd6449fd8
No known key found for this signature in database
8 changed files with 22 additions and 13 deletions

View File

@ -4,7 +4,6 @@
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Filter;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Scoring.Legacy;
using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Filter;
@ -14,9 +13,9 @@ namespace osu.Game.Rulesets.Mania
{
private FilterCriteria.OptionalRange<float> keys;
public bool Matches(BeatmapInfo beatmapInfo)
public bool Matches(BeatmapInfo beatmapInfo, FilterCriteria criteria)
{
return !keys.HasFilter || keys.IsInRange(ManiaBeatmapConverter.GetColumnCount(LegacyBeatmapConversionDifficultyInfo.FromBeatmapInfo(beatmapInfo)));
return !keys.HasFilter || keys.IsInRange(ManiaBeatmapConverter.GetColumnCount(beatmapInfo, criteria.Mods));
}
public bool TryParseCustomKeywordCriteria(string key, Operator op, string value)

View File

@ -309,7 +309,7 @@ namespace osu.Game.Tests.NonVisual.Filtering
match = shouldMatch;
}
public bool Matches(BeatmapInfo beatmapInfo) => match;
public bool Matches(BeatmapInfo beatmapInfo, FilterCriteria criteria) => match;
public bool TryParseCustomKeywordCriteria(string key, Operator op, string value) => false;
}
}

View File

@ -502,7 +502,7 @@ namespace osu.Game.Tests.NonVisual.Filtering
{
public string? CustomValue { get; set; }
public bool Matches(BeatmapInfo beatmapInfo) => true;
public bool Matches(BeatmapInfo beatmapInfo, FilterCriteria criteria) => true;
public bool TryParseCustomKeywordCriteria(string key, Operator op, string value)
{

View File

@ -18,11 +18,12 @@ namespace osu.Game.Rulesets.Filter
/// in addition to the ones mandated by song select.
/// </summary>
/// <param name="beatmapInfo">The beatmap to test the criteria against.</param>
/// <param name="criteria">The filter criteria.</param>
/// <returns>
/// <c>true</c> if the beatmap matches the ruleset-specific custom filtering criteria,
/// <c>false</c> otherwise.
/// </returns>
bool Matches(BeatmapInfo beatmapInfo);
bool Matches(BeatmapInfo beatmapInfo, FilterCriteria criteria);
/// <summary>
/// Attempts to parse a single custom keyword criterion, given by the user via the song select search box.

View File

@ -85,7 +85,7 @@ namespace osu.Game.Screens.Select.Carousel
match &= criteria.CollectionBeatmapMD5Hashes?.Contains(BeatmapInfo.MD5Hash) ?? true;
if (match && criteria.RulesetCriteria != null)
match &= criteria.RulesetCriteria.Matches(BeatmapInfo);
match &= criteria.RulesetCriteria.Matches(BeatmapInfo, criteria);
return match;
}

View File

@ -77,7 +77,7 @@ namespace osu.Game.Screens.Select.Carousel
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
[Resolved]
private IBindable<IReadOnlyList<Mod>>? mods { get; set; } = null!;
private IBindable<IReadOnlyList<Mod>> mods { get; set; } = null!;
private IBindable<StarDifficulty?> starDifficultyBindable = null!;
private CancellationTokenSource? starDifficultyCancellationSource;
@ -189,7 +189,7 @@ namespace osu.Game.Screens.Select.Carousel
base.LoadComplete();
ruleset.BindValueChanged(_ => updateKeyCount());
mods?.BindValueChanged(_ => updateKeyCount());
mods.BindValueChanged(_ => updateKeyCount());
}
protected override void Selected()
@ -260,7 +260,7 @@ namespace osu.Game.Screens.Select.Carousel
ILegacyRuleset legacyRuleset = (ILegacyRuleset)ruleset.Value.CreateInstance();
keyCountText.Alpha = 1;
keyCountText.Text = $"[{legacyRuleset.GetKeyCount(beatmapInfo, mods?.Value)}K]";
keyCountText.Text = $"[{legacyRuleset.GetKeyCount(beatmapInfo, mods.Value)}K]";
}
else
keyCountText.Alpha = 0;

View File

@ -4,6 +4,7 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -22,6 +23,7 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Select.Filter;
using osuTK;
using osuTK.Graphics;
@ -65,6 +67,7 @@ namespace osu.Game.Screens.Select
Sort = sortMode.Value,
AllowConvertedBeatmaps = showConverted.Value,
Ruleset = ruleset.Value,
Mods = mods.Value,
CollectionBeatmapMD5Hashes = collectionDropdown.Current.Value?.Collection?.PerformRead(c => c.BeatmapMD5Hashes).ToImmutableHashSet()
};
@ -84,7 +87,7 @@ namespace osu.Game.Screens.Select
base.ReceivePositionalInputAt(screenSpacePos) || sortTabs.ReceivePositionalInputAt(screenSpacePos);
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuColour colours, IBindable<RulesetInfo> parentRuleset, OsuConfigManager config)
private void load(OsuColour colours, OsuConfigManager config)
{
sortMode = config.GetBindable<SortMode>(OsuSetting.SongSelectSortingMode);
groupMode = config.GetBindable<GroupMode>(OsuSetting.SongSelectGroupingMode);
@ -214,8 +217,8 @@ namespace osu.Game.Screens.Select
config.BindWith(OsuSetting.DisplayStarsMaximum, maximumStars);
maximumStars.ValueChanged += _ => updateCriteria();
ruleset.BindTo(parentRuleset);
ruleset.BindValueChanged(_ => updateCriteria());
mods.BindValueChanged(_ => updateCriteria());
groupMode.BindValueChanged(_ => updateCriteria());
sortMode.BindValueChanged(_ => updateCriteria());
@ -239,7 +242,11 @@ namespace osu.Game.Screens.Select
searchTextBox.HoldFocus = true;
}
private readonly IBindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
[Resolved]
private IBindable<IReadOnlyList<Mod>> mods { get; set; } = null!;
private readonly Bindable<bool> showConverted = new Bindable<bool>();
private readonly Bindable<double> minimumStars = new BindableDouble();

View File

@ -10,6 +10,7 @@ using osu.Game.Beatmaps;
using osu.Game.Collections;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Filter;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Select.Filter;
namespace osu.Game.Screens.Select
@ -50,6 +51,7 @@ namespace osu.Game.Screens.Select
public OptionalTextFilter[] SearchTerms = Array.Empty<OptionalTextFilter>();
public RulesetInfo? Ruleset;
public IReadOnlyList<Mod>? Mods;
public bool AllowConvertedBeatmaps;
private string searchText = string.Empty;