1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 13:52:54 +08:00
osu-lazer/osu.Game/Screens/Select/Carousel/CarouselBeatmapSet.cs

59 lines
2.4 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-12-12 16:48:38 +08:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
2017-12-14 19:40:58 +08:00
using osu.Framework.Extensions.IEnumerableExtensions;
2017-12-12 16:48:38 +08:00
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 CarouselBeatmapSet : CarouselGroupEagerSelect
{
2017-12-14 19:40:58 +08:00
public IEnumerable<CarouselBeatmap> Beatmaps => InternalChildren.OfType<CarouselBeatmap>();
2017-12-12 16:48:38 +08:00
public BeatmapSetInfo BeatmapSet;
public CarouselBeatmapSet(BeatmapSetInfo beatmapSet)
{
2017-12-14 19:40:58 +08:00
BeatmapSet = beatmapSet ?? throw new ArgumentNullException(nameof(beatmapSet));
2017-12-12 16:48:38 +08:00
2017-12-14 19:40:58 +08:00
beatmapSet.Beatmaps
.Where(b => !b.Hidden)
.Select(b => new CarouselBeatmap(b))
.ForEach(AddChild);
2017-12-12 16:48:38 +08:00
}
protected override DrawableCarouselItem CreateDrawableRepresentation() => new DrawableCarouselBeatmapSet(this);
2017-12-14 19:40:58 +08:00
public override int CompareTo(FilterCriteria criteria, CarouselItem other)
2017-12-12 16:48:38 +08:00
{
2017-12-14 19:40:58 +08:00
if (!(other is CarouselBeatmapSet otherSet))
return base.CompareTo(criteria, other);
2017-12-12 16:48:38 +08:00
2017-12-14 19:40:58 +08:00
switch (criteria.Sort)
2017-12-12 16:48:38 +08:00
{
default:
case SortMode.Artist:
2017-12-14 19:40:58 +08:00
return string.Compare(BeatmapSet.Metadata.Artist, otherSet.BeatmapSet.Metadata.Artist, StringComparison.InvariantCultureIgnoreCase);
2017-12-12 16:48:38 +08:00
case SortMode.Title:
2017-12-14 19:40:58 +08:00
return string.Compare(BeatmapSet.Metadata.Title, otherSet.BeatmapSet.Metadata.Title, StringComparison.InvariantCultureIgnoreCase);
2017-12-12 16:48:38 +08:00
case SortMode.Author:
2017-12-14 19:40:58 +08:00
return string.Compare(BeatmapSet.Metadata.Author.Username, otherSet.BeatmapSet.Metadata.Author.Username, StringComparison.InvariantCultureIgnoreCase);
2017-12-12 16:48:38 +08:00
case SortMode.Difficulty:
2017-12-14 19:40:58 +08:00
return BeatmapSet.MaxStarDifficulty.CompareTo(otherSet.BeatmapSet.MaxStarDifficulty);
}
}
public override void Filter(FilterCriteria criteria)
{
base.Filter(criteria);
Filtered.Value = InternalChildren.All(i => i.Filtered);
2017-12-12 16:48:38 +08:00
}
public override string ToString() => BeatmapSet.ToString();
2017-12-12 16:48:38 +08:00
}
}