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
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Game.Beatmaps;
|
2017-12-14 19:40:58 +08:00
|
|
|
using osu.Game.Screens.Select.Filter;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
|
|
|
{
|
|
|
|
public class CarouselBeatmap : CarouselItem
|
|
|
|
{
|
2020-10-12 13:23:18 +08:00
|
|
|
public override float TotalHeight => DrawableCarouselBeatmap.HEIGHT;
|
|
|
|
|
2021-10-02 11:44:22 +08:00
|
|
|
public readonly BeatmapInfo BeatmapInfo;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-10-02 11:44:22 +08:00
|
|
|
public CarouselBeatmap(BeatmapInfo beatmapInfo)
|
2017-12-12 16:48:38 +08:00
|
|
|
{
|
2021-10-02 11:44:22 +08:00
|
|
|
BeatmapInfo = beatmapInfo;
|
2017-12-16 22:56:14 +08:00
|
|
|
State.Value = CarouselItemState.Collapsed;
|
2017-12-12 16:48:38 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-10-12 11:37:32 +08:00
|
|
|
public override DrawableCarouselItem CreateDrawableRepresentation() => new DrawableCarouselBeatmap(this);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
public override void Filter(FilterCriteria criteria)
|
|
|
|
{
|
|
|
|
base.Filter(criteria);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2023-03-07 16:24:17 +08:00
|
|
|
Filtered.Value = !checkMatch(criteria);
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool checkMatch(FilterCriteria criteria)
|
|
|
|
{
|
2020-03-12 14:01:43 +08:00
|
|
|
bool match =
|
|
|
|
criteria.Ruleset == null ||
|
2022-01-27 00:25:40 +08:00
|
|
|
BeatmapInfo.Ruleset.ShortName == criteria.Ruleset.ShortName ||
|
2022-01-27 14:19:48 +08:00
|
|
|
(BeatmapInfo.Ruleset.OnlineID == 0 && criteria.Ruleset.OnlineID != 0 && criteria.AllowConvertedBeatmaps);
|
2020-03-12 14:01:43 +08:00
|
|
|
|
2021-10-02 11:44:22 +08:00
|
|
|
if (BeatmapInfo.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
|
2023-03-07 16:24:17 +08:00
|
|
|
return match;
|
2020-03-04 19:14:18 +08:00
|
|
|
}
|
|
|
|
|
2023-12-06 10:17:32 +08:00
|
|
|
if (!match) return false;
|
|
|
|
|
2023-12-05 14:28:56 +08:00
|
|
|
if (criteria.SearchTerms.Length > 0)
|
|
|
|
{
|
|
|
|
match = BeatmapInfo.Match(criteria.SearchTerms);
|
|
|
|
|
|
|
|
// 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 = (BeatmapInfo.OnlineID == criteria.SearchNumber.Value) ||
|
|
|
|
(BeatmapInfo.BeatmapSet?.OnlineID == criteria.SearchNumber.Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!match) return false;
|
|
|
|
|
2021-11-11 16:18:51 +08:00
|
|
|
match &= !criteria.StarDifficulty.HasFilter || criteria.StarDifficulty.IsInRange(BeatmapInfo.StarRating);
|
2022-01-18 21:57:39 +08: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 11:44:22 +08:00
|
|
|
match &= !criteria.Length.HasFilter || criteria.Length.IsInRange(BeatmapInfo.Length);
|
2023-03-19 04:35:10 +08:00
|
|
|
match &= !criteria.LastPlayed.HasFilter || criteria.LastPlayed.IsInRange(BeatmapInfo.LastPlayed ?? DateTimeOffset.MinValue);
|
2021-10-02 11:44:22 +08:00
|
|
|
match &= !criteria.BPM.HasFilter || criteria.BPM.IsInRange(BeatmapInfo.BPM);
|
2019-09-19 01:37:35 +08:00
|
|
|
|
2021-10-02 11:44:22 +08:00
|
|
|
match &= !criteria.BeatDivisor.HasFilter || criteria.BeatDivisor.IsInRange(BeatmapInfo.BeatDivisor);
|
|
|
|
match &= !criteria.OnlineStatus.HasFilter || criteria.OnlineStatus.IsInRange(BeatmapInfo.Status);
|
2019-09-19 01:37:35 +08:00
|
|
|
|
2023-03-07 16:24:17 +08:00
|
|
|
if (!match) return false;
|
2023-03-04 23:49:33 +08:00
|
|
|
|
2021-11-04 17:46:26 +08:00
|
|
|
match &= !criteria.Creator.HasFilter || criteria.Creator.Matches(BeatmapInfo.Metadata.Author.Username);
|
2021-10-02 11:44:22 +08:00
|
|
|
match &= !criteria.Artist.HasFilter || criteria.Artist.Matches(BeatmapInfo.Metadata.Artist) ||
|
|
|
|
criteria.Artist.Matches(BeatmapInfo.Metadata.ArtistUnicode);
|
2023-06-27 14:21:13 +08:00
|
|
|
match &= !criteria.Title.HasFilter || criteria.Title.Matches(BeatmapInfo.Metadata.Title) ||
|
|
|
|
criteria.Title.Matches(BeatmapInfo.Metadata.TitleUnicode);
|
2023-10-24 16:32:01 +08:00
|
|
|
match &= !criteria.DifficultyName.HasFilter || criteria.DifficultyName.Matches(BeatmapInfo.DifficultyName);
|
2021-11-11 16:18:51 +08:00
|
|
|
match &= !criteria.UserStarDifficulty.HasFilter || criteria.UserStarDifficulty.IsInRange(BeatmapInfo.StarRating);
|
2018-10-10 22:46:02 +08:00
|
|
|
|
2023-03-07 16:24:17 +08:00
|
|
|
if (!match) return false;
|
2023-03-04 02:21:50 +08:00
|
|
|
|
|
|
|
match &= criteria.CollectionBeatmapMD5Hashes?.Contains(BeatmapInfo.MD5Hash) ?? true;
|
2021-03-03 03:11:21 +08:00
|
|
|
if (match && criteria.RulesetCriteria != null)
|
2024-03-28 22:02:25 +08:00
|
|
|
match &= criteria.RulesetCriteria.Matches(BeatmapInfo, criteria);
|
2021-03-03 03:11:21 +08:00
|
|
|
|
2023-03-07 16:24:17 +08:00
|
|
|
return match;
|
2017-12-12 16:48:38 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-12-14 19:40:58 +08:00
|
|
|
public override int CompareTo(FilterCriteria criteria, CarouselItem other)
|
|
|
|
{
|
|
|
|
if (!(other is CarouselBeatmap otherBeatmap))
|
|
|
|
return base.CompareTo(criteria, other);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-12-14 19:40:58 +08:00
|
|
|
switch (criteria.Sort)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case SortMode.Difficulty:
|
2022-01-27 14:59:20 +08:00
|
|
|
int ruleset = BeatmapInfo.Ruleset.CompareTo(otherBeatmap.BeatmapInfo.Ruleset);
|
2022-01-27 20:46:03 +08:00
|
|
|
|
2017-12-14 19:40:58 +08:00
|
|
|
if (ruleset != 0) return ruleset;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-11-11 16:18:51 +08:00
|
|
|
return BeatmapInfo.StarRating.CompareTo(otherBeatmap.BeatmapInfo.StarRating);
|
2017-12-14 19:40:58 +08:00
|
|
|
}
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-10-02 11:44:22 +08:00
|
|
|
public override string ToString() => BeatmapInfo.ToString();
|
2017-12-12 16:48:38 +08:00
|
|
|
}
|
|
|
|
}
|