1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-24 19:17:20 +08:00

Add recommended difficulty numerical value near filter in beatmap listing

This commit is contained in:
Joseph Madamba 2024-12-10 15:09:11 -08:00
parent e95dc2b308
commit 92e07b4f99
No known key found for this signature in database
GPG Key ID: 8B746C7BDDF0BD76
3 changed files with 78 additions and 5 deletions

View File

@ -20,6 +20,8 @@ namespace osu.Game.Beatmaps
/// </summary>
public partial class DifficultyRecommender : Component
{
public event Action? StarRatingUpdated;
private readonly LocalUserStatisticsProvider statisticsProvider;
[Resolved]
@ -77,8 +79,12 @@ namespace osu.Game.Beatmaps
{
// algorithm taken from https://github.com/ppy/osu-web/blob/e6e2825516449e3d0f3f5e1852c6bdd3428c3437/app/Models/User.php#L1505
recommendedDifficultyMapping[ruleset.ShortName] = Math.Pow((double)(statistics.PP ?? 0), 0.4) * 0.195;
StarRatingUpdated?.Invoke();
}
public double GetRecommendedStarRatingFor(RulesetInfo ruleset) => recommendedDifficultyMapping[ruleset.ShortName];
/// <summary>
/// Find the recommended difficulty from a selection of available difficulties for the current local user.
/// </summary>

View File

@ -65,7 +65,7 @@ namespace osu.Game.Overlays.BeatmapListing
}
private readonly BeatmapSearchTextBox textBox;
private readonly BeatmapSearchMultipleSelectionFilterRow<SearchGeneral> generalFilter;
private readonly BeatmapSearchGeneralFilterRow generalFilter;
private readonly BeatmapSearchRulesetFilterRow modeFilter;
private readonly BeatmapSearchFilterRow<SearchCategory> categoryFilter;
private readonly BeatmapSearchFilterRow<SearchGenre> genreFilter;
@ -163,6 +163,13 @@ namespace osu.Game.Overlays.BeatmapListing
}, true);
}
protected override void LoadComplete()
{
base.LoadComplete();
generalFilter.Ruleset.BindTo(Ruleset);
}
public void TakeFocus() => textBox.TakeFocus();
private partial class BeatmapSearchTextBox : BasicSearchTextBox

View File

@ -4,13 +4,20 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Extensions;
using osu.Game.Graphics;
using osu.Game.Localisation;
using osu.Game.Online.API;
using osu.Game.Overlays.Dialog;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets;
using osu.Game.Utils;
using osuTK.Graphics;
using CommonStrings = osu.Game.Resources.Localisation.Web.CommonStrings;
@ -18,21 +25,74 @@ namespace osu.Game.Overlays.BeatmapListing
{
public partial class BeatmapSearchGeneralFilterRow : BeatmapSearchMultipleSelectionFilterRow<SearchGeneral>
{
public readonly IBindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
public BeatmapSearchGeneralFilterRow()
: base(BeatmapsStrings.ListingSearchFiltersGeneral)
{
}
protected override MultipleSelectionFilter CreateMultipleSelectionFilter() => new GeneralFilter();
protected override MultipleSelectionFilter CreateMultipleSelectionFilter() => new GeneralFilter
{
Ruleset = { BindTarget = Ruleset }
};
private partial class GeneralFilter : MultipleSelectionFilter
{
public readonly IBindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
protected override MultipleSelectionFilterTabItem CreateTabItem(SearchGeneral value)
{
if (value == SearchGeneral.FeaturedArtists)
return new FeaturedArtistsTabItem();
switch (value)
{
case SearchGeneral.Recommended:
return new RecommendedDifficultyTabItem
{
Ruleset = { BindTarget = Ruleset }
};
return new MultipleSelectionFilterTabItem(value);
case SearchGeneral.FeaturedArtists:
return new FeaturedArtistsTabItem();
default:
return new MultipleSelectionFilterTabItem(value);
}
}
}
private partial class RecommendedDifficultyTabItem : MultipleSelectionFilterTabItem
{
public readonly IBindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
[Resolved]
private DifficultyRecommender? recommender { get; set; }
[Resolved]
private IAPIProvider api { get; set; } = null!;
[Resolved]
private RulesetStore rulesets { get; set; } = null!;
public RecommendedDifficultyTabItem()
: base(SearchGeneral.Recommended)
{
}
protected override void LoadComplete()
{
base.LoadComplete();
if (recommender != null) recommender.StarRatingUpdated += updateText;
Ruleset.BindValueChanged(_ => updateText(), true);
}
private void updateText()
{
// fallback to profile default game mode if beatmap listing mode filter is set to Any
// TODO: find a way to update `PlayMode` when the profile default game mode has changed
var ruleset = Ruleset.Value.IsLegacyRuleset() ? Ruleset.Value : rulesets.GetRuleset(api.LocalUser.Value.PlayMode)!;
Text.Text = LocalisableString.Interpolate($"{Value.GetLocalisableDescription()} ({recommender?.GetRecommendedStarRatingFor(ruleset).FormatStarRating()})");
}
}