2017-12-12 16:48:38 +08:00
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Game.Beatmaps;
|
2017-12-14 19:40:58 +08:00
|
|
|
using osu.Game.Screens.Select.Filter;
|
2017-12-12 16:48:38 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
|
|
|
{
|
|
|
|
public class CarouselBeatmap : CarouselItem
|
|
|
|
{
|
|
|
|
public readonly BeatmapInfo Beatmap;
|
|
|
|
|
|
|
|
public CarouselBeatmap(BeatmapInfo beatmap)
|
|
|
|
{
|
|
|
|
Beatmap = beatmap;
|
2017-12-16 22:56:14 +08:00
|
|
|
State.Value = CarouselItemState.Collapsed;
|
2017-12-12 16:48:38 +08:00
|
|
|
}
|
|
|
|
|
2017-12-13 11:46:02 +08:00
|
|
|
protected override DrawableCarouselItem CreateDrawableRepresentation() => new DrawableCarouselBeatmap(this);
|
2017-12-12 16:48:38 +08:00
|
|
|
|
|
|
|
public override void Filter(FilterCriteria criteria)
|
|
|
|
{
|
|
|
|
base.Filter(criteria);
|
|
|
|
|
2017-12-13 11:46:02 +08:00
|
|
|
bool match = criteria.Ruleset == null || Beatmap.RulesetID == criteria.Ruleset.ID || Beatmap.RulesetID == 0 && criteria.Ruleset.ID > 0 && criteria.AllowConvertedBeatmaps;
|
2017-12-12 16:48:38 +08:00
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(criteria.SearchText))
|
|
|
|
match &=
|
|
|
|
Beatmap.Metadata.SearchableTerms.Any(term => term.IndexOf(criteria.SearchText, StringComparison.InvariantCultureIgnoreCase) >= 0) ||
|
|
|
|
Beatmap.Version.IndexOf(criteria.SearchText, StringComparison.InvariantCultureIgnoreCase) >= 0;
|
|
|
|
|
|
|
|
Filtered.Value = !match;
|
|
|
|
}
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2017-12-16 15:14:37 +08:00
|
|
|
|
|
|
|
public override string ToString() => Beatmap.ToString();
|
2017-12-12 16:48:38 +08:00
|
|
|
}
|
|
|
|
}
|