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
|
|
|
|
|
|
|
using System;
|
2019-12-04 16:52:22 +00:00
|
|
|
using System.Collections.Generic;
|
2018-04-13 09:19:50 +00:00
|
|
|
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);
|
|
|
|
|
2020-03-12 06:01:43 +00:00
|
|
|
bool match =
|
|
|
|
criteria.Ruleset == null ||
|
|
|
|
Beatmap.RulesetID == criteria.Ruleset.ID ||
|
|
|
|
(Beatmap.RulesetID == 0 && criteria.Ruleset.ID > 0 && criteria.AllowConvertedBeatmaps);
|
|
|
|
|
2020-03-05 11:34:24 +00:00
|
|
|
if (Beatmap.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;
|
|
|
|
}
|
|
|
|
|
2019-12-04 16:52:22 +00: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);
|
|
|
|
match &= !criteria.Length.HasFilter || criteria.Length.IsInRange(Beatmap.Length);
|
|
|
|
match &= !criteria.BPM.HasFilter || criteria.BPM.IsInRange(Beatmap.BPM);
|
2019-09-18 17:37:35 +00:00
|
|
|
|
2019-12-04 16:52:22 +00:00
|
|
|
match &= !criteria.BeatDivisor.HasFilter || criteria.BeatDivisor.IsInRange(Beatmap.BeatDivisor);
|
|
|
|
match &= !criteria.OnlineStatus.HasFilter || criteria.OnlineStatus.IsInRange(Beatmap.Status);
|
2019-09-18 17:37:35 +00:00
|
|
|
|
2019-12-04 16:52:22 +00:00
|
|
|
match &= !criteria.Creator.HasFilter || criteria.Creator.Matches(Beatmap.Metadata.AuthorString);
|
|
|
|
match &= !criteria.Artist.HasFilter || criteria.Artist.Matches(Beatmap.Metadata.Artist) ||
|
2019-09-21 21:16:23 +00:00
|
|
|
criteria.Artist.Matches(Beatmap.Metadata.ArtistUnicode);
|
|
|
|
|
2020-01-24 09:57:17 +00:00
|
|
|
match &= !criteria.UserStarDifficulty.HasFilter || criteria.UserStarDifficulty.IsInRange(Beatmap.StarDifficulty);
|
2018-10-10 14:46:02 +00:00
|
|
|
|
2019-09-18 17:37:35 +00:00
|
|
|
if (match)
|
2019-11-11 11:53:22 +00:00
|
|
|
{
|
2019-12-04 16:52:22 +00:00
|
|
|
var terms = new List<string>();
|
|
|
|
|
|
|
|
terms.AddRange(Beatmap.Metadata.SearchableTerms);
|
|
|
|
terms.Add(Beatmap.Version);
|
|
|
|
|
2019-09-18 17:37:35 +00:00
|
|
|
foreach (var criteriaTerm in criteria.SearchTerms)
|
2019-12-04 16:52:22 +00:00
|
|
|
match &= terms.Any(term => term.IndexOf(criteriaTerm, StringComparison.InvariantCultureIgnoreCase) >= 0);
|
2019-11-11 11:53:22 +00:00
|
|
|
}
|
2018-04-13 09:19:50 +00: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();
|
|
|
|
}
|
|
|
|
}
|