1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-18 17:30:00 +08:00

Add "My Maps" grouping mode

This commit is contained in:
Salman Alshamrani
2025-08-06 13:07:59 +03:00
Unverified
parent 8b2e394509
commit e0706dd700
4 changed files with 42 additions and 6 deletions
+2 -2
View File
@@ -41,8 +41,8 @@ namespace osu.Game.Screens.Select.Filter
[LocalisableDescription(typeof(SongSelectStrings), nameof(SongSelectStrings.Length))]
Length,
// [LocalisableDescription(typeof(SongSelectStrings), nameof(SongSelectStrings.MyMaps))]
// MyMaps,
[LocalisableDescription(typeof(SongSelectStrings), nameof(SongSelectStrings.MyMaps))]
MyMaps,
// [LocalisableDescription(typeof(SongSelectStrings), nameof(SongSelectStrings.RankAchieved))]
// RankAchieved,
+12
View File
@@ -118,6 +118,18 @@ namespace osu.Game.Screens.Select
public IRulesetFilterCriteria? RulesetCriteria { get; set; }
/// <summary>
/// The user ID of the current local user, used to filter to own maps when <see cref="GroupMode.MyMaps"/> is selected.
/// Or null if the user is not logged in.
/// </summary>
public int? LocalUserId { get; set; }
/// <summary>
/// The username of the current local user, used to filter to own maps when <see cref="GroupMode.MyMaps"/> is selected.
/// Or null if the user is not logged in.
/// </summary>
public string? LocalUserUsername { get; set; }
public readonly struct OptionalSet<T> : IEquatable<OptionalSet<T>>
where T : struct, Enum
{
@@ -220,13 +220,13 @@ namespace osu.Game.Screens.SelectV2
var collections = getCollections?.Invoke() ?? Enumerable.Empty<BeatmapCollection>();
return getGroupsBy(b => defineGroupByCollection(b, collections), items);
case GroupMode.MyMaps:
return getGroupsBy(b => defineGroupByOwnMaps(b, criteria.LocalUserId, criteria.LocalUserUsername), items);
// TODO: need implementation
// case GroupMode.Favourites:
// goto case GroupMode.None;
//
// case GroupMode.MyMaps:
// goto case GroupMode.None;
//
// case GroupMode.RankAchieved:
// goto case GroupMode.None;
@@ -395,6 +395,16 @@ namespace osu.Game.Screens.SelectV2
return new GroupDefinition(1, "Not in collection");
}
private GroupDefinition defineGroupByOwnMaps(BeatmapInfo beatmap, int? localUserId, string? localUserUsername)
{
var author = beatmap.BeatmapSet!.Metadata.Author;
if (author.OnlineID == localUserId || author.Username == localUserUsername)
return new GroupDefinition(0, "My maps");
return new GroupDefinition(1, "Not my maps");
}
private static T? aggregateMax<T>(BeatmapInfo b, Func<BeatmapInfo, T> func)
{
var beatmaps = b.BeatmapSet!.Beatmaps.Where(bb => !bb.Hidden);
+15 -1
View File
@@ -19,6 +19,8 @@ using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Localisation;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Select;
@@ -54,6 +56,11 @@ namespace osu.Game.Screens.SelectV2
[Resolved]
private RealmAccess realm { get; set; } = null!;
[Resolved]
private IAPIProvider api { get; set; } = null!;
private IBindable<APIUser>? localUser;
public LocalisableString StatusText
{
get => searchTextBox.StatusText;
@@ -229,6 +236,10 @@ namespace osu.Game.Screens.SelectV2
if (changeSet != null && groupDropdown.Current.Value == GroupMode.Collections)
updateCriteria();
});
localUser = api.LocalUser.GetBoundCopy();
localUser.BindValueChanged(_ => updateCriteria());
updateCriteria();
}
@@ -244,6 +255,7 @@ namespace osu.Game.Screens.SelectV2
public FilterCriteria CreateCriteria()
{
string query = searchTextBox.Current.Value;
bool isValidUser = api.LocalUser.Value.Id > 1;
var criteria = new FilterCriteria
{
@@ -252,7 +264,9 @@ namespace osu.Game.Screens.SelectV2
AllowConvertedBeatmaps = showConvertedBeatmapsButton.Active.Value,
Ruleset = ruleset.Value,
Mods = mods.Value,
CollectionBeatmapMD5Hashes = collectionDropdown.Current.Value?.Collection?.PerformRead(c => c.BeatmapMD5Hashes).ToImmutableHashSet()
CollectionBeatmapMD5Hashes = collectionDropdown.Current.Value?.Collection?.PerformRead(c => c.BeatmapMD5Hashes).ToImmutableHashSet(),
LocalUserId = isValidUser ? api.LocalUser.Value.Id : null,
LocalUserUsername = isValidUser ? api.LocalUser.Value.Username : null,
};
if (!difficultyRangeSlider.LowerBound.IsDefault)