Add support for switching rulesets on profile overlay

This commit is contained in:
Bartłomiej Dach 2022-12-30 19:12:50 +01:00
parent a2e726502f
commit c759b743dc
No known key found for this signature in database
8 changed files with 25 additions and 17 deletions

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Linq; using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
@ -12,6 +13,9 @@ namespace osu.Game.Overlays.Profile.Header.Components
{ {
public partial class ProfileRulesetSelector : OverlayRulesetSelector public partial class ProfileRulesetSelector : OverlayRulesetSelector
{ {
[Resolved]
private UserProfileOverlay? profileOverlay { get; set; }
public readonly Bindable<UserProfile?> UserProfile = new Bindable<UserProfile?>(); public readonly Bindable<UserProfile?> UserProfile = new Bindable<UserProfile?>();
protected override void LoadComplete() protected override void LoadComplete()
@ -19,6 +23,11 @@ namespace osu.Game.Overlays.Profile.Header.Components
base.LoadComplete(); base.LoadComplete();
UserProfile.BindValueChanged(userProfile => updateState(userProfile.NewValue), true); UserProfile.BindValueChanged(userProfile => updateState(userProfile.NewValue), true);
Current.BindValueChanged(ruleset =>
{
if (UserProfile.Value != null && !ruleset.NewValue.Equals(UserProfile.Value.Ruleset))
profileOverlay?.ShowUser(UserProfile.Value.User, ruleset.NewValue);
});
} }
private void updateState(UserProfile? userProfile) private void updateState(UserProfile? userProfile)

View File

@ -64,8 +64,8 @@ namespace osu.Game.Overlays.Profile.Sections.Beatmaps
} }
} }
protected override APIRequest<List<APIBeatmapSet>> CreateRequest(APIUser user, PaginationParameters pagination) => protected override APIRequest<List<APIBeatmapSet>> CreateRequest(UserProfile userProfile, PaginationParameters pagination) =>
new GetUserBeatmapsRequest(user.Id, type, pagination); new GetUserBeatmapsRequest(userProfile.User.Id, type, pagination);
protected override Drawable? CreateDrawableItem(APIBeatmapSet model) => model.OnlineID > 0 protected override Drawable? CreateDrawableItem(APIBeatmapSet model) => model.OnlineID > 0
? new BeatmapCardNormal(model) ? new BeatmapCardNormal(model)

View File

@ -29,8 +29,8 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
protected override int GetCount(APIUser user) => user.BeatmapPlayCountsCount; protected override int GetCount(APIUser user) => user.BeatmapPlayCountsCount;
protected override APIRequest<List<APIUserMostPlayedBeatmap>> CreateRequest(APIUser user, PaginationParameters pagination) => protected override APIRequest<List<APIUserMostPlayedBeatmap>> CreateRequest(UserProfile userProfile, PaginationParameters pagination) =>
new GetUserMostPlayedBeatmapsRequest(user.Id, pagination); new GetUserMostPlayedBeatmapsRequest(userProfile.User.Id, pagination);
protected override Drawable CreateDrawableItem(APIUserMostPlayedBeatmap mostPlayed) => protected override Drawable CreateDrawableItem(APIUserMostPlayedBeatmap mostPlayed) =>
new DrawableMostPlayedBeatmap(mostPlayed); new DrawableMostPlayedBeatmap(mostPlayed);

View File

@ -8,7 +8,6 @@ using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.API; using osu.Game.Online.API;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Game.Resources.Localisation.Web; using osu.Game.Resources.Localisation.Web;
using APIUser = osu.Game.Online.API.Requests.Responses.APIUser;
namespace osu.Game.Overlays.Profile.Sections.Kudosu namespace osu.Game.Overlays.Profile.Sections.Kudosu
{ {
@ -19,8 +18,8 @@ namespace osu.Game.Overlays.Profile.Sections.Kudosu
{ {
} }
protected override APIRequest<List<APIKudosuHistory>> CreateRequest(APIUser user, PaginationParameters pagination) protected override APIRequest<List<APIKudosuHistory>> CreateRequest(UserProfile userProfile, PaginationParameters pagination)
=> new GetUserKudosuHistoryRequest(user.Id, pagination); => new GetUserKudosuHistoryRequest(userProfile.User.Id, pagination);
protected override Drawable CreateDrawableItem(APIKudosuHistory item) => new DrawableKudosuHistoryItem(item); protected override Drawable CreateDrawableItem(APIKudosuHistory item) => new DrawableKudosuHistoryItem(item);
} }

View File

@ -109,14 +109,14 @@ namespace osu.Game.Overlays.Profile.Sections
private void showMore() private void showMore()
{ {
if (UserProfile.Value?.User == null) if (UserProfile.Value == null)
return; return;
loadCancellation = new CancellationTokenSource(); loadCancellation = new CancellationTokenSource();
CurrentPage = CurrentPage?.TakeNext(ItemsPerPage) ?? new PaginationParameters(InitialItemsCount); CurrentPage = CurrentPage?.TakeNext(ItemsPerPage) ?? new PaginationParameters(InitialItemsCount);
retrievalRequest = CreateRequest(UserProfile.Value.User, CurrentPage.Value); retrievalRequest = CreateRequest(UserProfile.Value, CurrentPage.Value);
retrievalRequest.Success += items => UpdateItems(items, loadCancellation); retrievalRequest.Success += items => UpdateItems(items, loadCancellation);
api.Queue(retrievalRequest); api.Queue(retrievalRequest);
@ -154,7 +154,7 @@ namespace osu.Game.Overlays.Profile.Sections
{ {
} }
protected abstract APIRequest<List<TModel>> CreateRequest(APIUser user, PaginationParameters pagination); protected abstract APIRequest<List<TModel>> CreateRequest(UserProfile userProfile, PaginationParameters pagination);
protected abstract Drawable? CreateDrawableItem(TModel model); protected abstract Drawable? CreateDrawableItem(TModel model);

View File

@ -60,8 +60,8 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
base.OnItemsReceived(items); base.OnItemsReceived(items);
} }
protected override APIRequest<List<SoloScoreInfo>> CreateRequest(APIUser user, PaginationParameters pagination) => protected override APIRequest<List<SoloScoreInfo>> CreateRequest(UserProfile userProfile, PaginationParameters pagination) =>
new GetUserScoresRequest(user.Id, type, pagination); new GetUserScoresRequest(userProfile.User.Id, type, pagination, userProfile.Ruleset);
private int drawableItemIndex; private int drawableItemIndex;

View File

@ -10,7 +10,6 @@ using System.Collections.Generic;
using osuTK; using osuTK;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Game.Resources.Localisation.Web; using osu.Game.Resources.Localisation.Web;
using APIUser = osu.Game.Online.API.Requests.Responses.APIUser;
namespace osu.Game.Overlays.Profile.Sections.Recent namespace osu.Game.Overlays.Profile.Sections.Recent
{ {
@ -27,8 +26,8 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
ItemsContainer.Spacing = new Vector2(0, 8); ItemsContainer.Spacing = new Vector2(0, 8);
} }
protected override APIRequest<List<APIRecentActivity>> CreateRequest(APIUser user, PaginationParameters pagination) => protected override APIRequest<List<APIRecentActivity>> CreateRequest(UserProfile userProfile, PaginationParameters pagination) =>
new GetUserRecentActivitiesRequest(user.Id, pagination); new GetUserRecentActivitiesRequest(userProfile.User.Id, pagination);
protected override Drawable CreateDrawableItem(APIRecentActivity model) => new DrawableRecentActivity(model); protected override Drawable CreateDrawableItem(APIRecentActivity model) => new DrawableRecentActivity(model);
} }

View File

@ -11,6 +11,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Extensions;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
@ -52,7 +53,7 @@ namespace osu.Game.Overlays
Show(); Show();
if (user.OnlineID == Header?.UserProfile.Value?.User.Id) if (user.OnlineID == Header.UserProfile.Value?.User.Id && ruleset?.MatchesOnlineID(Header.UserProfile.Value?.Ruleset) == true)
return; return;
if (sectionsContainer != null) if (sectionsContainer != null)
@ -121,7 +122,7 @@ namespace osu.Game.Overlays
sectionsContainer.ScrollToTop(); sectionsContainer.ScrollToTop();
userReq = user.OnlineID > 1 ? new GetUserRequest(user.OnlineID) : new GetUserRequest(user.Username); userReq = user.OnlineID > 1 ? new GetUserRequest(user.OnlineID, ruleset) : new GetUserRequest(user.Username, ruleset);
userReq.Success += u => userLoadComplete(u, ruleset); userReq.Success += u => userLoadComplete(u, ruleset);
API.Queue(userReq); API.Queue(userReq);
} }