|
4 | 4 | using System;
|
5 | 5 | using osu.Framework.Allocation;
|
6 | 6 | using osu.Framework.Bindables;
|
| 7 | +using osu.Framework.Extensions; |
7 | 8 | using osu.Framework.Graphics.Sprites;
|
8 | 9 | using osu.Framework.Input.Events;
|
| 10 | +using osu.Framework.Localisation; |
| 11 | +using osu.Game.Beatmaps; |
9 | 12 | using osu.Game.Configuration;
|
| 13 | +using osu.Game.Extensions; |
10 | 14 | using osu.Game.Graphics;
|
11 | 15 | using osu.Game.Localisation;
|
| 16 | +using osu.Game.Online.API; |
12 | 17 | using osu.Game.Overlays.Dialog;
|
13 | 18 | using osu.Game.Resources.Localisation.Web;
|
| 19 | +using osu.Game.Rulesets; |
| 20 | +using osu.Game.Utils; |
14 | 21 | using osuTK.Graphics;
|
15 | 22 | using CommonStrings = osu.Game.Resources.Localisation.Web.CommonStrings;
|
16 | 23 |
|
17 | 24 | namespace osu.Game.Overlays.BeatmapListing
|
18 | 25 | {
|
19 | 26 | public partial class BeatmapSearchGeneralFilterRow : BeatmapSearchMultipleSelectionFilterRow<SearchGeneral>
|
20 | 27 | {
|
| 28 | + public readonly IBindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>(); |
| 29 | + |
21 | 30 | public BeatmapSearchGeneralFilterRow()
|
22 | 31 | : base(BeatmapsStrings.ListingSearchFiltersGeneral)
|
23 | 32 | {
|
24 | 33 | }
|
25 | 34 |
|
26 |
| - protected override MultipleSelectionFilter CreateMultipleSelectionFilter() => new GeneralFilter(); |
| 35 | + protected override MultipleSelectionFilter CreateMultipleSelectionFilter() => new GeneralFilter |
| 36 | + { |
| 37 | + Ruleset = { BindTarget = Ruleset } |
| 38 | + }; |
27 | 39 |
|
28 | 40 | private partial class GeneralFilter : MultipleSelectionFilter
|
29 | 41 | {
|
| 42 | + public readonly IBindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>(); |
| 43 | + |
30 | 44 | protected override MultipleSelectionFilterTabItem CreateTabItem(SearchGeneral value)
|
31 | 45 | {
|
32 |
| - if (value == SearchGeneral.FeaturedArtists) |
33 |
| - return new FeaturedArtistsTabItem(); |
| 46 | + switch (value) |
| 47 | + { |
| 48 | + case SearchGeneral.Recommended: |
| 49 | + return new RecommendedDifficultyTabItem |
| 50 | + { |
| 51 | + Ruleset = { BindTarget = Ruleset } |
| 52 | + }; |
| 53 | + |
| 54 | + case SearchGeneral.FeaturedArtists: |
| 55 | + return new FeaturedArtistsTabItem(); |
| 56 | + |
| 57 | + default: |
| 58 | + return new MultipleSelectionFilterTabItem(value); |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + private partial class RecommendedDifficultyTabItem : MultipleSelectionFilterTabItem |
| 64 | + { |
| 65 | + public readonly IBindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>(); |
| 66 | + |
| 67 | + [Resolved] |
| 68 | + private DifficultyRecommender? recommender { get; set; } |
| 69 | + |
| 70 | + [Resolved] |
| 71 | + private IAPIProvider api { get; set; } = null!; |
| 72 | + |
| 73 | + [Resolved] |
| 74 | + private RulesetStore rulesets { get; set; } = null!; |
| 75 | + |
| 76 | + public RecommendedDifficultyTabItem() |
| 77 | + : base(SearchGeneral.Recommended) |
| 78 | + { |
| 79 | + } |
| 80 | + |
| 81 | + protected override void LoadComplete() |
| 82 | + { |
| 83 | + base.LoadComplete(); |
| 84 | + |
| 85 | + if (recommender != null) recommender.StarRatingUpdated += updateText; |
34 | 86 |
|
35 |
| - return new MultipleSelectionFilterTabItem(value); |
| 87 | + Ruleset.BindValueChanged(_ => updateText(), true); |
| 88 | + } |
| 89 | + |
| 90 | + private void updateText() |
| 91 | + { |
| 92 | + // fallback to profile default game mode if beatmap listing mode filter is set to Any |
| 93 | + // TODO: find a way to update `PlayMode` when the profile default game mode has changed |
| 94 | + var ruleset = Ruleset.Value.IsLegacyRuleset() ? Ruleset.Value : rulesets.GetRuleset(api.LocalUser.Value.PlayMode)!; |
| 95 | + Text.Text = LocalisableString.Interpolate($"{Value.GetLocalisableDescription()} ({recommender?.GetRecommendedStarRatingFor(ruleset).FormatStarRating()})"); |
36 | 96 | }
|
37 | 97 | }
|
38 | 98 |
|
|
0 commit comments