2019-01-24 16:43:03 +08:00
|
|
|
// 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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Screens.Select.Filter;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
|
|
|
{
|
|
|
|
public class CarouselBeatmap : CarouselItem
|
|
|
|
{
|
2020-10-12 13:23:18 +08:00
|
|
|
public override float TotalHeight => DrawableCarouselBeatmap.HEIGHT;
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
public readonly BeatmapInfo Beatmap;
|
|
|
|
|
|
|
|
public CarouselBeatmap(BeatmapInfo beatmap)
|
|
|
|
{
|
|
|
|
Beatmap = beatmap;
|
|
|
|
State.Value = CarouselItemState.Collapsed;
|
|
|
|
}
|
|
|
|
|
2020-10-12 11:37:32 +08:00
|
|
|
public override DrawableCarouselItem CreateDrawableRepresentation() => new DrawableCarouselBeatmap(this);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
public override void Filter(FilterCriteria criteria)
|
|
|
|
{
|
|
|
|
base.Filter(criteria);
|
|
|
|
|
2020-03-12 14:01:43 +08:00
|
|
|
bool match =
|
|
|
|
criteria.Ruleset == null ||
|
|
|
|
Beatmap.RulesetID == criteria.Ruleset.ID ||
|
|
|
|
(Beatmap.RulesetID == 0 && criteria.Ruleset.ID > 0 && criteria.AllowConvertedBeatmaps);
|
|
|
|
|
2020-03-05 19:34:24 +08:00
|
|
|
if (Beatmap.BeatmapSet?.Equals(criteria.SelectedBeatmapSet) == true)
|
2020-03-04 19:14:18 +08:00
|
|
|
{
|
2020-03-13 09:01:28 +08:00
|
|
|
// only check ruleset equality or convertability for selected beatmap
|
2020-03-12 14:01:43 +08:00
|
|
|
Filtered.Value = !match;
|
2020-03-04 19:14:18 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-05 00:52:22 +08:00
|
|
|
match &= !criteria.StarDifficulty.HasFilter || criteria.StarDifficulty.IsInRange(Beatmap.StarDifficulty);
|
|
|
|
match &= !criteria.ApproachRate.HasFilter || criteria.ApproachRate.IsInRange(Beatmap.BaseDifficulty.ApproachRate);
|
|
|
|
match &= !criteria.DrainRate.HasFilter || criteria.DrainRate.IsInRange(Beatmap.BaseDifficulty.DrainRate);
|
|
|
|
match &= !criteria.CircleSize.HasFilter || criteria.CircleSize.IsInRange(Beatmap.BaseDifficulty.CircleSize);
|
2021-06-26 22:05:01 +08:00
|
|
|
match &= !criteria.OverallDifficulty.HasFilter || criteria.OverallDifficulty.IsInRange(Beatmap.BaseDifficulty.OverallDifficulty);
|
2019-12-05 00:52:22 +08:00
|
|
|
match &= !criteria.Length.HasFilter || criteria.Length.IsInRange(Beatmap.Length);
|
|
|
|
match &= !criteria.BPM.HasFilter || criteria.BPM.IsInRange(Beatmap.BPM);
|
2019-09-19 01:37:35 +08:00
|
|
|
|
2019-12-05 00:52:22 +08:00
|
|
|
match &= !criteria.BeatDivisor.HasFilter || criteria.BeatDivisor.IsInRange(Beatmap.BeatDivisor);
|
|
|
|
match &= !criteria.OnlineStatus.HasFilter || criteria.OnlineStatus.IsInRange(Beatmap.Status);
|
2019-09-19 01:37:35 +08:00
|
|
|
|
2019-12-05 00:52:22 +08:00
|
|
|
match &= !criteria.Creator.HasFilter || criteria.Creator.Matches(Beatmap.Metadata.AuthorString);
|
|
|
|
match &= !criteria.Artist.HasFilter || criteria.Artist.Matches(Beatmap.Metadata.Artist) ||
|
2019-09-22 05:16:23 +08:00
|
|
|
criteria.Artist.Matches(Beatmap.Metadata.ArtistUnicode);
|
|
|
|
|
2020-01-24 17:57:17 +08:00
|
|
|
match &= !criteria.UserStarDifficulty.HasFilter || criteria.UserStarDifficulty.IsInRange(Beatmap.StarDifficulty);
|
2018-10-10 22:46:02 +08:00
|
|
|
|
2019-09-19 01:37:35 +08:00
|
|
|
if (match)
|
2019-11-11 19:53:22 +08:00
|
|
|
{
|
2020-05-07 12:04:08 +08:00
|
|
|
var terms = Beatmap.SearchableTerms;
|
2019-12-05 00:52:22 +08:00
|
|
|
|
2019-09-19 01:37:35 +08:00
|
|
|
foreach (var criteriaTerm in criteria.SearchTerms)
|
2020-11-02 01:54:44 +08:00
|
|
|
match &= terms.Any(term => term.Contains(criteriaTerm, StringComparison.InvariantCultureIgnoreCase));
|
2020-10-10 20:34:01 +08:00
|
|
|
|
|
|
|
// if a match wasn't found via text matching of terms, do a second catch-all check matching against online IDs.
|
|
|
|
// this should be done after text matching so we can prioritise matching numbers in metadata.
|
|
|
|
if (!match && criteria.SearchNumber.HasValue)
|
|
|
|
{
|
|
|
|
match = (Beatmap.OnlineBeatmapID == criteria.SearchNumber.Value) ||
|
|
|
|
(Beatmap.BeatmapSet?.OnlineBeatmapSetID == criteria.SearchNumber.Value);
|
|
|
|
}
|
2019-11-11 19:53:22 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-09-02 19:25:36 +08:00
|
|
|
if (match)
|
2020-09-09 22:10:21 +08:00
|
|
|
match &= criteria.Collection?.Beatmaps.Contains(Beatmap) ?? true;
|
2020-09-02 19:25:36 +08:00
|
|
|
|
2021-03-03 03:11:21 +08:00
|
|
|
if (match && criteria.RulesetCriteria != null)
|
|
|
|
match &= criteria.RulesetCriteria.Matches(Beatmap);
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
Filtered.Value = !match;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override int CompareTo(FilterCriteria criteria, CarouselItem other)
|
|
|
|
{
|
|
|
|
if (!(other is CarouselBeatmap otherBeatmap))
|
|
|
|
return base.CompareTo(criteria, other);
|
|
|
|
|
|
|
|
switch (criteria.Sort)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case SortMode.Difficulty:
|
|
|
|
var ruleset = Beatmap.RulesetID.CompareTo(otherBeatmap.Beatmap.RulesetID);
|
|
|
|
if (ruleset != 0) return ruleset;
|
|
|
|
|
|
|
|
return Beatmap.StarDifficulty.CompareTo(otherBeatmap.Beatmap.StarDifficulty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string ToString() => Beatmap.ToString();
|
|
|
|
}
|
|
|
|
}
|