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
|
|
|
|
{
|
|
|
|
public readonly BeatmapInfo Beatmap;
|
|
|
|
|
|
|
|
public CarouselBeatmap(BeatmapInfo beatmap)
|
|
|
|
{
|
|
|
|
Beatmap = beatmap;
|
|
|
|
State.Value = CarouselItemState.Collapsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override DrawableCarouselItem CreateDrawableRepresentation() => new DrawableCarouselBeatmap(this);
|
|
|
|
|
|
|
|
public override void Filter(FilterCriteria criteria)
|
|
|
|
{
|
|
|
|
base.Filter(criteria);
|
|
|
|
|
2019-09-19 01:37:35 +08:00
|
|
|
bool match =
|
|
|
|
criteria.Ruleset == null ||
|
|
|
|
Beatmap.RulesetID == criteria.Ruleset.ID ||
|
|
|
|
(Beatmap.RulesetID == 0 && criteria.Ruleset.ID > 0 && criteria.AllowConvertedBeatmaps);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-09-19 01:37:35 +08:00
|
|
|
match &= criteria.StarDifficulty.IsInRange(Beatmap.StarDifficulty);
|
|
|
|
match &= criteria.ApproachRate.IsInRange(Beatmap.BaseDifficulty.ApproachRate);
|
|
|
|
match &= criteria.DrainRate.IsInRange(Beatmap.BaseDifficulty.DrainRate);
|
|
|
|
match &= criteria.CircleSize.IsInRange(Beatmap.BaseDifficulty.CircleSize);
|
|
|
|
match &= criteria.Length.IsInRange(Beatmap.Length);
|
|
|
|
match &= criteria.BPM.IsInRange(Beatmap.BPM);
|
|
|
|
|
2019-09-19 15:53:27 +08:00
|
|
|
match &= criteria.BeatDivisor.IsInRange(Beatmap.BeatDivisor);
|
2019-09-19 16:12:07 +08:00
|
|
|
match &= criteria.OnlineStatus.IsInRange(Beatmap.Status);
|
2019-09-19 01:37:35 +08:00
|
|
|
|
2019-09-22 05:16:23 +08:00
|
|
|
match &= criteria.Creator.Matches(Beatmap.Metadata.AuthorString);
|
|
|
|
match &= criteria.Artist.Matches(Beatmap.Metadata.Artist) ||
|
|
|
|
criteria.Artist.Matches(Beatmap.Metadata.ArtistUnicode);
|
|
|
|
|
2019-09-19 01:37:35 +08:00
|
|
|
if (match)
|
|
|
|
foreach (var criteriaTerm in criteria.SearchTerms)
|
|
|
|
match &=
|
|
|
|
Beatmap.Metadata.SearchableTerms.Any(term => term.IndexOf(criteriaTerm, StringComparison.InvariantCultureIgnoreCase) >= 0) ||
|
|
|
|
Beatmap.Version.IndexOf(criteriaTerm, StringComparison.InvariantCultureIgnoreCase) >= 0;
|
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();
|
|
|
|
}
|
|
|
|
}
|