mirror of
https://github.com/osukey/osukey.git
synced 2025-06-28 22:58:10 +09:00
Select recommended difficulty
This commit is contained in:
parent
1587d4b26f
commit
2f5dc93d61
@ -23,6 +23,8 @@ using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Cursor;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Screens.Select.Carousel;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Users;
|
||||
|
||||
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_bottom = Footer.HEIGHT;
|
||||
|
||||
private readonly Bindable<User> localUser = new Bindable<User>();
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when the <see cref="BeatmapSets"/> loaded change and are completely loaded.
|
||||
/// </summary>
|
||||
@ -140,7 +144,7 @@ namespace osu.Game.Screens.Select
|
||||
private BeatmapManager beatmaps { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader(permitNulls: true)]
|
||||
private void load(OsuConfigManager config)
|
||||
private void load(OsuConfigManager config, IAPIProvider api)
|
||||
{
|
||||
config.BindWith(OsuSetting.RandomSelectAlgorithm, RandomAlgorithm);
|
||||
config.BindWith(OsuSetting.SongSelectRightMouseScroll, RightClickScrollingEnabled);
|
||||
@ -154,6 +158,8 @@ namespace osu.Game.Screens.Select
|
||||
beatmaps.BeatmapRestored += beatmapRestored;
|
||||
|
||||
loadBeatmapSets(GetLoadableBeatmaps());
|
||||
|
||||
localUser.BindTo(api.LocalUser);
|
||||
}
|
||||
|
||||
protected virtual IEnumerable<BeatmapSetInfo> GetLoadableBeatmaps() => beatmaps.GetAllUsableBeatmapSetsEnumerable();
|
||||
@ -588,7 +594,7 @@ namespace osu.Game.Screens.Select
|
||||
b.Metadata = beatmapSet.Metadata;
|
||||
}
|
||||
|
||||
var set = new CarouselBeatmapSet(beatmapSet);
|
||||
var set = new CarouselBeatmapSet(beatmapSet, localUser);
|
||||
|
||||
foreach (var c in set.Beatmaps)
|
||||
{
|
||||
|
@ -4,19 +4,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Screens.Select.Filter;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Screens.Select.Carousel
|
||||
{
|
||||
public class CarouselBeatmapSet : CarouselGroupEagerSelect
|
||||
{
|
||||
private readonly Bindable<User> localUser;
|
||||
|
||||
public IEnumerable<CarouselBeatmap> Beatmaps => InternalChildren.OfType<CarouselBeatmap>();
|
||||
|
||||
public BeatmapSetInfo BeatmapSet;
|
||||
|
||||
public CarouselBeatmapSet(BeatmapSetInfo beatmapSet)
|
||||
public CarouselBeatmapSet(BeatmapSetInfo beatmapSet, Bindable<User> localUser)
|
||||
{
|
||||
BeatmapSet = beatmapSet ?? throw new ArgumentNullException(nameof(beatmapSet));
|
||||
|
||||
@ -24,10 +28,32 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
.Where(b => !b.Hidden)
|
||||
.Select(b => new CarouselBeatmap(b))
|
||||
.ForEach(AddChild);
|
||||
|
||||
this.localUser = localUser;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (!(other is CarouselBeatmapSet otherSet))
|
||||
|
@ -90,11 +90,15 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
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()
|
||||
{
|
||||
CarouselItem nextToSelect =
|
||||
Children.Skip(lastSelectedIndex).FirstOrDefault(i => !i.Filtered.Value) ??
|
||||
Children.Reverse().Skip(InternalChildren.Count - lastSelectedIndex).FirstOrDefault(i => !i.Filtered.Value);
|
||||
CarouselItem nextToSelect = GetNextToSelect();
|
||||
|
||||
if (nextToSelect != null)
|
||||
nextToSelect.State.Value = CarouselItemState.Selected;
|
||||
|
Loading…
x
Reference in New Issue
Block a user