Select recommended difficulty

This commit is contained in:
Endrik Tombak 2020-03-26 00:19:54 +02:00
parent 1587d4b26f
commit 2f5dc93d61
3 changed files with 42 additions and 6 deletions

View File

@ -23,6 +23,8 @@ using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor; using osu.Game.Graphics.Cursor;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using osu.Game.Screens.Select.Carousel; using osu.Game.Screens.Select.Carousel;
using osu.Game.Online.API;
using osu.Game.Users;
namespace osu.Game.Screens.Select namespace osu.Game.Screens.Select
{ {
@ -31,6 +33,8 @@ namespace osu.Game.Screens.Select
private const float bleed_top = FilterControl.HEIGHT; private const float bleed_top = FilterControl.HEIGHT;
private const float bleed_bottom = Footer.HEIGHT; private const float bleed_bottom = Footer.HEIGHT;
private readonly Bindable<User> localUser = new Bindable<User>();
/// <summary> /// <summary>
/// Triggered when the <see cref="BeatmapSets"/> loaded change and are completely loaded. /// Triggered when the <see cref="BeatmapSets"/> loaded change and are completely loaded.
/// </summary> /// </summary>
@ -140,7 +144,7 @@ namespace osu.Game.Screens.Select
private BeatmapManager beatmaps { get; set; } private BeatmapManager beatmaps { get; set; }
[BackgroundDependencyLoader(permitNulls: true)] [BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuConfigManager config) private void load(OsuConfigManager config, IAPIProvider api)
{ {
config.BindWith(OsuSetting.RandomSelectAlgorithm, RandomAlgorithm); config.BindWith(OsuSetting.RandomSelectAlgorithm, RandomAlgorithm);
config.BindWith(OsuSetting.SongSelectRightMouseScroll, RightClickScrollingEnabled); config.BindWith(OsuSetting.SongSelectRightMouseScroll, RightClickScrollingEnabled);
@ -154,6 +158,8 @@ namespace osu.Game.Screens.Select
beatmaps.BeatmapRestored += beatmapRestored; beatmaps.BeatmapRestored += beatmapRestored;
loadBeatmapSets(GetLoadableBeatmaps()); loadBeatmapSets(GetLoadableBeatmaps());
localUser.BindTo(api.LocalUser);
} }
protected virtual IEnumerable<BeatmapSetInfo> GetLoadableBeatmaps() => beatmaps.GetAllUsableBeatmapSetsEnumerable(); protected virtual IEnumerable<BeatmapSetInfo> GetLoadableBeatmaps() => beatmaps.GetAllUsableBeatmapSetsEnumerable();
@ -588,7 +594,7 @@ namespace osu.Game.Screens.Select
b.Metadata = beatmapSet.Metadata; b.Metadata = beatmapSet.Metadata;
} }
var set = new CarouselBeatmapSet(beatmapSet); var set = new CarouselBeatmapSet(beatmapSet, localUser);
foreach (var c in set.Beatmaps) foreach (var c in set.Beatmaps)
{ {

View File

@ -4,19 +4,23 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Screens.Select.Filter; using osu.Game.Screens.Select.Filter;
using osu.Game.Users;
namespace osu.Game.Screens.Select.Carousel namespace osu.Game.Screens.Select.Carousel
{ {
public class CarouselBeatmapSet : CarouselGroupEagerSelect public class CarouselBeatmapSet : CarouselGroupEagerSelect
{ {
private readonly Bindable<User> localUser;
public IEnumerable<CarouselBeatmap> Beatmaps => InternalChildren.OfType<CarouselBeatmap>(); public IEnumerable<CarouselBeatmap> Beatmaps => InternalChildren.OfType<CarouselBeatmap>();
public BeatmapSetInfo BeatmapSet; public BeatmapSetInfo BeatmapSet;
public CarouselBeatmapSet(BeatmapSetInfo beatmapSet) public CarouselBeatmapSet(BeatmapSetInfo beatmapSet, Bindable<User> localUser)
{ {
BeatmapSet = beatmapSet ?? throw new ArgumentNullException(nameof(beatmapSet)); BeatmapSet = beatmapSet ?? throw new ArgumentNullException(nameof(beatmapSet));
@ -24,10 +28,32 @@ namespace osu.Game.Screens.Select.Carousel
.Where(b => !b.Hidden) .Where(b => !b.Hidden)
.Select(b => new CarouselBeatmap(b)) .Select(b => new CarouselBeatmap(b))
.ForEach(AddChild); .ForEach(AddChild);
this.localUser = localUser;
} }
protected override DrawableCarouselItem CreateDrawableRepresentation() => new DrawableCarouselBeatmapSet(this); protected override DrawableCarouselItem CreateDrawableRepresentation() => new DrawableCarouselBeatmapSet(this);
protected override CarouselItem GetNextToSelect()
{
if (LastSelected == null)
{
decimal? pp = localUser.Value?.Statistics?.PP ?? 60; // TODO: This needs to get ruleset specific statistics
var recommendedDifficulty = Math.Pow((double)pp, 0.4) * 0.195;
return Children.OfType<CarouselBeatmap>()
.Where(b => !b.Filtered.Value)
.OrderBy(b =>
{
var difference = b.Beatmap.StarDifficulty - recommendedDifficulty;
return difference >= 0 ? difference * 2 : difference * -1; // prefer easier over harder
})
.FirstOrDefault();
}
return base.GetNextToSelect();
}
public override int CompareTo(FilterCriteria criteria, CarouselItem other) public override int CompareTo(FilterCriteria criteria, CarouselItem other)
{ {
if (!(other is CarouselBeatmapSet otherSet)) if (!(other is CarouselBeatmapSet otherSet))

View File

@ -90,11 +90,15 @@ namespace osu.Game.Screens.Select.Carousel
PerformSelection(); PerformSelection();
} }
protected virtual CarouselItem GetNextToSelect()
{
return Children.Skip(lastSelectedIndex).FirstOrDefault(i => !i.Filtered.Value) ??
Children.Reverse().Skip(InternalChildren.Count - lastSelectedIndex).FirstOrDefault(i => !i.Filtered.Value);
}
protected virtual void PerformSelection() protected virtual void PerformSelection()
{ {
CarouselItem nextToSelect = CarouselItem nextToSelect = GetNextToSelect();
Children.Skip(lastSelectedIndex).FirstOrDefault(i => !i.Filtered.Value) ??
Children.Reverse().Skip(InternalChildren.Count - lastSelectedIndex).FirstOrDefault(i => !i.Filtered.Value);
if (nextToSelect != null) if (nextToSelect != null)
nextToSelect.State.Value = CarouselItemState.Selected; nextToSelect.State.Value = CarouselItemState.Selected;