2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
2017-12-12 08:48:38 +00:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Game.Beatmaps;
|
2017-12-14 11:40:58 +00:00
|
|
|
using osu.Game.Screens.Select.Filter;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2017-12-12 08:48:38 +00:00
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
|
|
|
{
|
|
|
|
public class CarouselBeatmap : CarouselItem
|
|
|
|
{
|
2020-10-12 05:23:18 +00:00
|
|
|
public override float TotalHeight => DrawableCarouselBeatmap.HEIGHT;
|
|
|
|
|
2021-10-02 03:44:22 +00:00
|
|
|
public readonly BeatmapInfo BeatmapInfo;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2021-10-02 03:44:22 +00:00
|
|
|
public CarouselBeatmap(BeatmapInfo beatmapInfo)
|
2017-12-12 08:48:38 +00:00
|
|
|
{
|
2021-10-02 03:44:22 +00:00
|
|
|
BeatmapInfo = beatmapInfo;
|
2017-12-16 14:56:14 +00:00
|
|
|
State.Value = CarouselItemState.Collapsed;
|
2017-12-12 08:48:38 +00:00
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-10-12 03:37:32 +00:00
|
|
|
public override DrawableCarouselItem CreateDrawableRepresentation() => new DrawableCarouselBeatmap(this);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2017-12-12 08:48:38 +00:00
|
|
|
public override void Filter(FilterCriteria criteria)
|
|
|
|
{
|
|
|
|
base.Filter(criteria);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-03-12 06:01:43 +00:00
|
|
|
bool match =
|
|
|
|
criteria.Ruleset == null ||
|
2022-01-26 16:25:40 +00:00
|
|
|
BeatmapInfo.Ruleset.ShortName == criteria.Ruleset.ShortName ||
|
2022-01-27 06:19:48 +00:00
|
|
|
(BeatmapInfo.Ruleset.OnlineID == 0 && criteria.Ruleset.OnlineID != 0 && criteria.AllowConvertedBeatmaps);
|
2020-03-12 06:01:43 +00:00
|
|
|
|
2021-10-02 03:44:22 +00:00
|
|
|
if (BeatmapInfo.BeatmapSet?.Equals(criteria.SelectedBeatmapSet) == true)
|
2020-03-04 11:14:18 +00:00
|
|
|
{
|
2020-03-13 01:01:28 +00:00
|
|
|
// only check ruleset equality or convertability for selected beatmap
|
2020-03-12 06:01:43 +00:00
|
|
|
Filtered.Value = !match;
|
2020-03-04 11:14:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-11 08:18:51 +00:00
|
|
|
match &= !criteria.StarDifficulty.HasFilter || criteria.StarDifficulty.IsInRange(BeatmapInfo.StarRating);
|
2022-01-18 13:57:39 +00:00
|
|
|
match &= !criteria.ApproachRate.HasFilter || criteria.ApproachRate.IsInRange(BeatmapInfo.Difficulty.ApproachRate);
|
|
|
|
match &= !criteria.DrainRate.HasFilter || criteria.DrainRate.IsInRange(BeatmapInfo.Difficulty.DrainRate);
|
|
|
|
match &= !criteria.CircleSize.HasFilter || criteria.CircleSize.IsInRange(BeatmapInfo.Difficulty.CircleSize);
|
|
|
|
match &= !criteria.OverallDifficulty.HasFilter || criteria.OverallDifficulty.IsInRange(BeatmapInfo.Difficulty.OverallDifficulty);
|
2021-10-02 03:44:22 +00:00
|
|
|
match &= !criteria.Length.HasFilter || criteria.Length.IsInRange(BeatmapInfo.Length);
|
|
|
|
match &= !criteria.BPM.HasFilter || criteria.BPM.IsInRange(BeatmapInfo.BPM);
|
2019-09-18 17:37:35 +00:00
|
|
|
|
2021-10-02 03:44:22 +00:00
|
|
|
match &= !criteria.BeatDivisor.HasFilter || criteria.BeatDivisor.IsInRange(BeatmapInfo.BeatDivisor);
|
|
|
|
match &= !criteria.OnlineStatus.HasFilter || criteria.OnlineStatus.IsInRange(BeatmapInfo.Status);
|
2019-09-18 17:37:35 +00:00
|
|
|
|
2021-11-04 09:46:26 +00:00
|
|
|
match &= !criteria.Creator.HasFilter || criteria.Creator.Matches(BeatmapInfo.Metadata.Author.Username);
|
2021-10-02 03:44:22 +00:00
|
|
|
match &= !criteria.Artist.HasFilter || criteria.Artist.Matches(BeatmapInfo.Metadata.Artist) ||
|
|
|
|
criteria.Artist.Matches(BeatmapInfo.Metadata.ArtistUnicode);
|
2019-09-21 21:16:23 +00:00
|
|
|
|
2021-11-11 08:18:51 +00:00
|
|
|
match &= !criteria.UserStarDifficulty.HasFilter || criteria.UserStarDifficulty.IsInRange(BeatmapInfo.StarRating);
|
2018-10-10 14:46:02 +00:00
|
|
|
|
2022-01-21 03:26:24 +00:00
|
|
|
if (match && criteria.SearchTerms.Length > 0)
|
2019-11-11 11:53:22 +00:00
|
|
|
{
|
2021-10-27 04:04:41 +00:00
|
|
|
string[] terms = BeatmapInfo.GetSearchableTerms();
|
2019-12-04 16:52:22 +00:00
|
|
|
|
2021-10-27 04:04:41 +00:00
|
|
|
foreach (string criteriaTerm in criteria.SearchTerms)
|
2020-11-01 17:54:44 +00:00
|
|
|
match &= terms.Any(term => term.Contains(criteriaTerm, StringComparison.InvariantCultureIgnoreCase));
|
2020-10-10 12:34:01 +00: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)
|
|
|
|
{
|
2021-11-12 08:45:05 +00:00
|
|
|
match = (BeatmapInfo.OnlineID == criteria.SearchNumber.Value) ||
|
2021-11-12 08:50:31 +00:00
|
|
|
(BeatmapInfo.BeatmapSet?.OnlineID == criteria.SearchNumber.Value);
|
2020-10-10 12:34:01 +00:00
|
|
|
}
|
2019-11-11 11:53:22 +00:00
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-09-02 11:25:36 +00:00
|
|
|
if (match)
|
2021-10-02 03:44:22 +00:00
|
|
|
match &= criteria.Collection?.Beatmaps.Contains(BeatmapInfo) ?? true;
|
2020-09-02 11:25:36 +00:00
|
|
|
|
2021-03-02 19:11:21 +00:00
|
|
|
if (match && criteria.RulesetCriteria != null)
|
2021-10-02 03:44:22 +00:00
|
|
|
match &= criteria.RulesetCriteria.Matches(BeatmapInfo);
|
2021-03-02 19:11:21 +00:00
|
|
|
|
2017-12-12 08:48:38 +00:00
|
|
|
Filtered.Value = !match;
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2017-12-14 11:40:58 +00:00
|
|
|
public override int CompareTo(FilterCriteria criteria, CarouselItem other)
|
|
|
|
{
|
|
|
|
if (!(other is CarouselBeatmap otherBeatmap))
|
|
|
|
return base.CompareTo(criteria, other);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2017-12-14 11:40:58 +00:00
|
|
|
switch (criteria.Sort)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case SortMode.Difficulty:
|
2022-01-27 06:59:20 +00:00
|
|
|
int ruleset = BeatmapInfo.Ruleset.CompareTo(otherBeatmap.BeatmapInfo.Ruleset);
|
2022-01-27 12:46:03 +00:00
|
|
|
|
2017-12-14 11:40:58 +00:00
|
|
|
if (ruleset != 0) return ruleset;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2021-11-11 08:18:51 +00:00
|
|
|
return BeatmapInfo.StarRating.CompareTo(otherBeatmap.BeatmapInfo.StarRating);
|
2017-12-14 11:40:58 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2021-10-02 03:44:22 +00:00
|
|
|
public override string ToString() => BeatmapInfo.ToString();
|
2017-12-12 08:48:38 +00:00
|
|
|
}
|
|
|
|
}
|