1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 13:37:25 +08:00

Merge branch 'master' into remove-stupid-weak-reference-bindable-events

This commit is contained in:
Dan Balasescu 2021-11-08 14:41:32 +09:00 committed by GitHub
commit 1c40d5bc08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 35 deletions

View File

@ -71,13 +71,13 @@ namespace osu.Game.Tests.Visual.Online
{ {
base.LoadComplete(); base.LoadComplete();
AddStep("Show offline dummy", () => profile.ShowUser(TEST_USER, false)); AddStep("Show offline dummy", () => profile.ShowUser(TEST_USER));
AddStep("Show null dummy", () => profile.ShowUser(new APIUser AddStep("Show null dummy", () => profile.ShowUser(new APIUser
{ {
Username = @"Null", Username = @"Null",
Id = 1, Id = 1,
}, false)); }));
AddStep("Show ppy", () => profile.ShowUser(new APIUser AddStep("Show ppy", () => profile.ShowUser(new APIUser
{ {
@ -86,7 +86,7 @@ namespace osu.Game.Tests.Visual.Online
IsSupporter = true, IsSupporter = true,
Country = new Country { FullName = @"Australia", FlagName = @"AU" }, Country = new Country { FullName = @"Australia", FlagName = @"AU" },
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg" CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg"
}, api.IsLoggedIn)); }));
AddStep("Show flyte", () => profile.ShowUser(new APIUser AddStep("Show flyte", () => profile.ShowUser(new APIUser
{ {
@ -94,7 +94,7 @@ namespace osu.Game.Tests.Visual.Online
Id = 3103765, Id = 3103765,
Country = new Country { FullName = @"Japan", FlagName = @"JP" }, Country = new Country { FullName = @"Japan", FlagName = @"JP" },
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c6.jpg" CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c6.jpg"
}, api.IsLoggedIn)); }));
AddStep("Show bancho", () => profile.ShowUser(new APIUser AddStep("Show bancho", () => profile.ShowUser(new APIUser
{ {
@ -103,10 +103,10 @@ namespace osu.Game.Tests.Visual.Online
IsBot = true, IsBot = true,
Country = new Country { FullName = @"Saint Helena", FlagName = @"SH" }, Country = new Country { FullName = @"Saint Helena", FlagName = @"SH" },
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c4.jpg" CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c4.jpg"
}, api.IsLoggedIn)); }));
AddStep("Show ppy from username", () => profile.ShowUser(@"peppy")); AddStep("Show ppy from username", () => profile.ShowUser(new APIUser { Username = @"peppy" }));
AddStep("Show flyte from username", () => profile.ShowUser(@"flyte")); AddStep("Show flyte from username", () => profile.ShowUser(new APIUser { Username = @"flyte" }));
AddStep("Hide", profile.Hide); AddStep("Hide", profile.Hide);
AddStep("Show without reload", profile.Show); AddStep("Show without reload", profile.Show);

View File

@ -53,8 +53,10 @@ using osu.Game.Database;
using osu.Game.Extensions; using osu.Game.Extensions;
using osu.Game.IO; using osu.Game.IO;
using osu.Game.Localisation; using osu.Game.Localisation;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Performance; using osu.Game.Performance;
using osu.Game.Skinning.Editor; using osu.Game.Skinning.Editor;
using osu.Game.Users;
namespace osu.Game namespace osu.Game
{ {
@ -323,10 +325,9 @@ namespace osu.Game
break; break;
case LinkAction.OpenUserProfile: case LinkAction.OpenUserProfile:
if (int.TryParse(link.Argument, out int userId)) ShowUser(int.TryParse(link.Argument, out int userId)
ShowUser(userId); ? new APIUser { Id = userId }
else : new APIUser { Username = link.Argument });
ShowUser(link.Argument);
break; break;
@ -383,14 +384,8 @@ namespace osu.Game
/// <summary> /// <summary>
/// Show a user's profile as an overlay. /// Show a user's profile as an overlay.
/// </summary> /// </summary>
/// <param name="userId">The user to display.</param> /// <param name="user">The user to display.</param>
public void ShowUser(int userId) => waitForReady(() => userProfile, _ => userProfile.ShowUser(userId)); public void ShowUser(IUser user) => waitForReady(() => userProfile, _ => userProfile.ShowUser(user));
/// <summary>
/// Show a user's profile as an overlay.
/// </summary>
/// <param name="username">The user to display.</param>
public void ShowUser(string username) => waitForReady(() => userProfile, _ => userProfile.ShowUser(username));
/// <summary> /// <summary>
/// Show a beatmap's set as an overlay, displaying the given beatmap. /// Show a beatmap's set as an overlay, displaying the given beatmap.

View File

@ -14,6 +14,7 @@ using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Profile; using osu.Game.Overlays.Profile;
using osu.Game.Overlays.Profile.Sections; using osu.Game.Overlays.Profile.Sections;
using osu.Game.Users;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -38,18 +39,14 @@ namespace osu.Game.Overlays
protected override Color4 BackgroundColour => ColourProvider.Background6; protected override Color4 BackgroundColour => ColourProvider.Background6;
public void ShowUser(int userId) => ShowUser(new APIUser { Id = userId }); public void ShowUser(IUser user)
public void ShowUser(string username) => ShowUser(new APIUser { Username = username });
public void ShowUser(APIUser user, bool fetchOnline = true)
{ {
if (user == APIUser.SYSTEM_USER) if (user == APIUser.SYSTEM_USER)
return; return;
Show(); Show();
if (user.Id == Header?.User.Value?.Id) if (user.OnlineID == Header?.User.Value?.Id)
return; return;
if (sectionsContainer != null) if (sectionsContainer != null)
@ -116,19 +113,20 @@ namespace osu.Game.Overlays
} }
}; };
if (fetchOnline) sectionsContainer.ScrollToTop();
{
userReq = user.Id > 1 ? new GetUserRequest(user.Id) : new GetUserRequest(user.Username); // Check arbitrarily whether this user has already been populated.
userReq.Success += userLoadComplete; // This is only generally used by tests, but should be quite safe unless we want to force a refresh on loading a previous user in the future.
API.Queue(userReq); if (user is APIUser apiUser && apiUser.JoinDate != default)
}
else
{ {
userReq = null; userReq = null;
userLoadComplete(user); userLoadComplete(apiUser);
return;
} }
sectionsContainer.ScrollToTop(); userReq = user.OnlineID > 1 ? new GetUserRequest(user.OnlineID) : new GetUserRequest(user.Username);
userReq.Success += userLoadComplete;
API.Queue(userReq);
} }
private void userLoadComplete(APIUser user) private void userLoadComplete(APIUser user)

View File

@ -66,7 +66,7 @@ namespace osu.Game.Users.Drawables
private void openProfile() private void openProfile()
{ {
if (user?.Id > 1) if (user?.Id > 1)
game?.ShowUser(user.Id); game?.ShowUser(user);
} }
private class ClickableArea : OsuClickableContainer private class ClickableArea : OsuClickableContainer