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
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
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;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
|
|
|
{
|
|
|
|
public class CarouselBeatmapSet : CarouselGroupEagerSelect
|
|
|
|
{
|
2020-10-12 13:23:18 +08:00
|
|
|
public override float TotalHeight
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
switch (State.Value)
|
|
|
|
{
|
|
|
|
case CarouselItemState.Selected:
|
2020-10-13 17:13:36 +08:00
|
|
|
return DrawableCarouselBeatmapSet.HEIGHT + Children.Count(c => c.Visible) * DrawableCarouselBeatmap.HEIGHT;
|
2020-10-12 13:23:18 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
return DrawableCarouselBeatmapSet.HEIGHT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-12 11:37:41 +08:00
|
|
|
|
2017-12-14 19:40:58 +08:00
|
|
|
public IEnumerable<CarouselBeatmap> Beatmaps => InternalChildren.OfType<CarouselBeatmap>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
public BeatmapSetInfo BeatmapSet;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-04-11 15:58:13 +08:00
|
|
|
public Func<IEnumerable<BeatmapInfo>, BeatmapInfo> GetRecommendedBeatmap;
|
|
|
|
|
|
|
|
public CarouselBeatmapSet(BeatmapSetInfo beatmapSet)
|
2017-12-12 16:48:38 +08:00
|
|
|
{
|
2017-12-14 19:40:58 +08:00
|
|
|
BeatmapSet = beatmapSet ?? throw new ArgumentNullException(nameof(beatmapSet));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-12-14 19:40:58 +08:00
|
|
|
beatmapSet.Beatmaps
|
|
|
|
.Where(b => !b.Hidden)
|
2022-01-27 14:59:20 +08:00
|
|
|
.OrderBy(b => b.Ruleset)
|
2022-01-07 21:57:22 +08:00
|
|
|
.ThenBy(b => b.StarRating)
|
2017-12-14 19:40:58 +08:00
|
|
|
.Select(b => new CarouselBeatmap(b))
|
|
|
|
.ForEach(AddChild);
|
2017-12-12 16:48:38 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-03-26 06:19:54 +08:00
|
|
|
protected override CarouselItem GetNextToSelect()
|
|
|
|
{
|
2020-12-04 05:13:14 +08:00
|
|
|
if (LastSelected == null || LastSelected.Filtered.Value)
|
2020-03-26 06:19:54 +08:00
|
|
|
{
|
2021-10-02 11:44:22 +08:00
|
|
|
if (GetRecommendedBeatmap?.Invoke(Children.OfType<CarouselBeatmap>().Where(b => !b.Filtered.Value).Select(b => b.BeatmapInfo)) is BeatmapInfo recommended)
|
2021-11-24 11:16:08 +08:00
|
|
|
return Children.OfType<CarouselBeatmap>().First(b => b.BeatmapInfo.Equals(recommended));
|
2020-03-26 06:19:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return base.GetNextToSelect();
|
|
|
|
}
|
|
|
|
|
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);
|
2018-04-13 17:19:50 +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:
|
2022-01-04 13:35:18 +08:00
|
|
|
return string.Compare(BeatmapSet.Metadata.Artist, otherSet.BeatmapSet.Metadata.Artist, StringComparison.OrdinalIgnoreCase);
|
2019-04-01 11:44:46 +08:00
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
case SortMode.Title:
|
2022-01-04 13:35:18 +08:00
|
|
|
return string.Compare(BeatmapSet.Metadata.Title, otherSet.BeatmapSet.Metadata.Title, StringComparison.OrdinalIgnoreCase);
|
2019-04-01 11:44:46 +08:00
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
case SortMode.Author:
|
2022-01-04 13:35:18 +08:00
|
|
|
return string.Compare(BeatmapSet.Metadata.Author.Username, otherSet.BeatmapSet.Metadata.Author.Username, StringComparison.OrdinalIgnoreCase);
|
2019-04-01 11:44:46 +08:00
|
|
|
|
2021-05-10 05:26:45 +08:00
|
|
|
case SortMode.Source:
|
2022-01-04 13:35:18 +08:00
|
|
|
return string.Compare(BeatmapSet.Metadata.Source, otherSet.BeatmapSet.Metadata.Source, StringComparison.OrdinalIgnoreCase);
|
2021-05-10 05:26:45 +08:00
|
|
|
|
2019-06-05 17:17:43 +08:00
|
|
|
case SortMode.DateAdded:
|
|
|
|
return otherSet.BeatmapSet.DateAdded.CompareTo(BeatmapSet.DateAdded);
|
|
|
|
|
2019-07-07 23:14:23 +08:00
|
|
|
case SortMode.BPM:
|
2019-10-07 14:16:26 +08:00
|
|
|
return compareUsingAggregateMax(otherSet, b => b.BPM);
|
2019-07-07 23:14:23 +08:00
|
|
|
|
2019-07-07 23:26:56 +08:00
|
|
|
case SortMode.Length:
|
2019-10-07 14:16:26 +08:00
|
|
|
return compareUsingAggregateMax(otherSet, b => b.Length);
|
2019-07-07 23:26:56 +08:00
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
case SortMode.Difficulty:
|
2021-11-11 16:18:51 +08:00
|
|
|
return compareUsingAggregateMax(otherSet, b => b.StarRating);
|
2017-12-14 19:40:58 +08:00
|
|
|
}
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-10-07 14:16:26 +08:00
|
|
|
/// <summary>
|
|
|
|
/// All beatmaps which are not filtered and valid for display.
|
|
|
|
/// </summary>
|
2021-10-02 11:44:22 +08:00
|
|
|
protected IEnumerable<BeatmapInfo> ValidBeatmaps => Beatmaps.Where(b => !b.Filtered.Value || b.State.Value == CarouselItemState.Selected).Select(b => b.BeatmapInfo);
|
2019-10-07 14:16:26 +08:00
|
|
|
|
|
|
|
private int compareUsingAggregateMax(CarouselBeatmapSet other, Func<BeatmapInfo, double> func)
|
|
|
|
{
|
2021-10-27 12:04:41 +08:00
|
|
|
bool ourBeatmaps = ValidBeatmaps.Any();
|
|
|
|
bool otherBeatmaps = other.ValidBeatmaps.Any();
|
2019-10-07 14:16:26 +08:00
|
|
|
|
|
|
|
if (!ourBeatmaps && !otherBeatmaps) return 0;
|
|
|
|
if (!ourBeatmaps) return -1;
|
|
|
|
if (!otherBeatmaps) return 1;
|
|
|
|
|
|
|
|
return ValidBeatmaps.Max(func).CompareTo(other.ValidBeatmaps.Max(func));
|
|
|
|
}
|
|
|
|
|
2017-12-14 19:40:58 +08:00
|
|
|
public override void Filter(FilterCriteria criteria)
|
|
|
|
{
|
|
|
|
base.Filter(criteria);
|
2019-02-21 17:56:34 +08:00
|
|
|
Filtered.Value = InternalChildren.All(i => i.Filtered.Value);
|
2017-12-12 16:48:38 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-12-16 15:14:37 +08:00
|
|
|
public override string ToString() => BeatmapSet.ToString();
|
2017-12-12 16:48:38 +08:00
|
|
|
}
|
|
|
|
}
|