mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 23:12:56 +08:00
Add ruleset to UserProfile
This commit is contained in:
parent
4dd7727f71
commit
1722f3a125
@ -11,6 +11,7 @@ using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Profile;
|
||||
using osu.Game.Overlays.Profile.Sections;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
@ -38,8 +39,8 @@ namespace osu.Game.Tests.Visual.Online
|
||||
Child = section = new HistoricalSection(),
|
||||
});
|
||||
|
||||
AddStep("Show peppy", () => section.UserProfile.Value = new UserProfile(new APIUser { Id = 2 }));
|
||||
AddStep("Show WubWoofWolf", () => section.UserProfile.Value = new UserProfile(new APIUser { Id = 39828 }));
|
||||
AddStep("Show peppy", () => section.UserProfile.Value = new UserProfile(new APIUser { Id = 2 }, new OsuRuleset().RulesetInfo));
|
||||
AddStep("Show WubWoofWolf", () => section.UserProfile.Value = new UserProfile(new APIUser { Id = 39828 }, new OsuRuleset().RulesetInfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ using osu.Framework.Testing;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Overlays.Profile;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
@ -44,49 +45,49 @@ namespace osu.Game.Tests.Visual.Online
|
||||
[Test]
|
||||
public void TestNullValues()
|
||||
{
|
||||
AddStep("Load user", () => user.Value = new UserProfile(user_with_null_values));
|
||||
AddStep("Load user", () => user.Value = new UserProfile(user_with_null_values, new OsuRuleset().RulesetInfo));
|
||||
AddAssert("Section is hidden", () => section.Alpha == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEmptyValues()
|
||||
{
|
||||
AddStep("Load user", () => user.Value = new UserProfile(user_with_empty_values));
|
||||
AddStep("Load user", () => user.Value = new UserProfile(user_with_empty_values, new OsuRuleset().RulesetInfo));
|
||||
AddAssert("Section is hidden", () => section.Alpha == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestOneValue()
|
||||
{
|
||||
AddStep("Load user", () => user.Value = new UserProfile(user_with_one_value));
|
||||
AddStep("Load user", () => user.Value = new UserProfile(user_with_one_value, new OsuRuleset().RulesetInfo));
|
||||
AddAssert("Section is hidden", () => section.Alpha == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestTwoValues()
|
||||
{
|
||||
AddStep("Load user", () => user.Value = new UserProfile(user_with_two_values));
|
||||
AddStep("Load user", () => user.Value = new UserProfile(user_with_two_values, new OsuRuleset().RulesetInfo));
|
||||
AddAssert("Section is visible", () => section.Alpha == 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstantValues()
|
||||
{
|
||||
AddStep("Load user", () => user.Value = new UserProfile(user_with_constant_values));
|
||||
AddStep("Load user", () => user.Value = new UserProfile(user_with_constant_values, new OsuRuleset().RulesetInfo));
|
||||
AddAssert("Section is visible", () => section.Alpha == 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstantZeroValues()
|
||||
{
|
||||
AddStep("Load user", () => user.Value = new UserProfile(user_with_zero_values));
|
||||
AddStep("Load user", () => user.Value = new UserProfile(user_with_zero_values, new OsuRuleset().RulesetInfo));
|
||||
AddAssert("Section is visible", () => section.Alpha == 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFilledValues()
|
||||
{
|
||||
AddStep("Load user", () => user.Value = new UserProfile(user_with_filled_values));
|
||||
AddStep("Load user", () => user.Value = new UserProfile(user_with_filled_values, new OsuRuleset().RulesetInfo));
|
||||
AddAssert("Section is visible", () => section.Alpha == 1);
|
||||
AddAssert("Array length is the same", () => user_with_filled_values.MonthlyPlayCounts.Length == getChartValuesLength());
|
||||
}
|
||||
@ -94,7 +95,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
[Test]
|
||||
public void TestMissingValues()
|
||||
{
|
||||
AddStep("Load user", () => user.Value = new UserProfile(user_with_missing_values));
|
||||
AddStep("Load user", () => user.Value = new UserProfile(user_with_missing_values, new OsuRuleset().RulesetInfo));
|
||||
AddAssert("Section is visible", () => section.Alpha == 1);
|
||||
AddAssert("Array length is 7", () => getChartValuesLength() == 7);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ using osu.Framework.Testing;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Profile;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Online
|
||||
@ -29,7 +30,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
[Test]
|
||||
public void TestBasic()
|
||||
{
|
||||
AddStep("Show example user", () => header.UserProfile.Value = new UserProfile(TestSceneUserProfileOverlay.TEST_USER));
|
||||
AddStep("Show example user", () => header.UserProfile.Value = new UserProfile(TestSceneUserProfileOverlay.TEST_USER, new OsuRuleset().RulesetInfo));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -41,7 +42,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
Username = "IAmOnline",
|
||||
LastVisit = DateTimeOffset.Now,
|
||||
IsOnline = true,
|
||||
}));
|
||||
}, new OsuRuleset().RulesetInfo));
|
||||
|
||||
AddStep("Show offline user", () => header.UserProfile.Value = new UserProfile(new APIUser
|
||||
{
|
||||
@ -49,7 +50,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
Username = "IAmOffline",
|
||||
LastVisit = DateTimeOffset.Now.AddDays(-10),
|
||||
IsOnline = false,
|
||||
}));
|
||||
}, new OsuRuleset().RulesetInfo));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -70,7 +71,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
Data = Enumerable.Range(2345, 45).Concat(Enumerable.Range(2109, 40)).ToArray()
|
||||
},
|
||||
}
|
||||
}));
|
||||
}, new OsuRuleset().RulesetInfo));
|
||||
|
||||
AddStep("Show unranked user", () => header.UserProfile.Value = new UserProfile(new APIUser
|
||||
{
|
||||
@ -86,7 +87,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
Data = Enumerable.Range(2345, 85).ToArray()
|
||||
},
|
||||
}
|
||||
}));
|
||||
}, new OsuRuleset().RulesetInfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Profile;
|
||||
using osu.Game.Overlays.Profile.Sections;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
@ -45,7 +46,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
}
|
||||
});
|
||||
|
||||
AddStep("Show cookiezi", () => ranks.UserProfile.Value = new UserProfile(new APIUser { Id = 124493 }));
|
||||
AddStep("Show cookiezi", () => ranks.UserProfile.Value = new UserProfile(new APIUser { Id = 124493 }, new OsuRuleset().RulesetInfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Rulesets;
|
||||
|
||||
namespace osu.Game.Overlays.Profile
|
||||
{
|
||||
@ -15,11 +16,15 @@ namespace osu.Game.Overlays.Profile
|
||||
/// </summary>
|
||||
public APIUser User { get; }
|
||||
|
||||
// TODO: add ruleset
|
||||
/// <summary>
|
||||
/// The ruleset that the user profile is being shown with.
|
||||
/// </summary>
|
||||
public RulesetInfo Ruleset { get; }
|
||||
|
||||
public UserProfile(APIUser user)
|
||||
public UserProfile(APIUser user, RulesetInfo ruleset)
|
||||
{
|
||||
User = user;
|
||||
Ruleset = ruleset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.ObjectExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
@ -15,6 +16,7 @@ using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Overlays.Profile;
|
||||
using osu.Game.Overlays.Profile.Sections;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Users;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
@ -29,6 +31,9 @@ namespace osu.Game.Overlays
|
||||
private ProfileSectionsContainer? sectionsContainer;
|
||||
private ProfileSectionTabControl? tabs;
|
||||
|
||||
[Resolved]
|
||||
private RulesetStore rulesets { get; set; } = null!;
|
||||
|
||||
public const float CONTENT_X_MARGIN = 70;
|
||||
|
||||
public UserProfileOverlay()
|
||||
@ -40,7 +45,7 @@ namespace osu.Game.Overlays
|
||||
|
||||
protected override Color4 BackgroundColour => ColourProvider.Background6;
|
||||
|
||||
public void ShowUser(IUser user)
|
||||
public void ShowUser(IUser user, IRulesetInfo? ruleset = null)
|
||||
{
|
||||
if (user.OnlineID == APIUser.SYSTEM_USER_ID)
|
||||
return;
|
||||
@ -117,15 +122,17 @@ namespace osu.Game.Overlays
|
||||
sectionsContainer.ScrollToTop();
|
||||
|
||||
userReq = user.OnlineID > 1 ? new GetUserRequest(user.OnlineID) : new GetUserRequest(user.Username);
|
||||
userReq.Success += userLoadComplete;
|
||||
userReq.Success += u => userLoadComplete(u, ruleset);
|
||||
API.Queue(userReq);
|
||||
}
|
||||
|
||||
private void userLoadComplete(APIUser user)
|
||||
private void userLoadComplete(APIUser user, IRulesetInfo? ruleset)
|
||||
{
|
||||
Debug.Assert(sections != null && sectionsContainer != null && tabs != null);
|
||||
|
||||
var userProfile = new UserProfile(user);
|
||||
var actualRuleset = rulesets.GetRuleset(ruleset?.ShortName ?? user.PlayMode).AsNonNull();
|
||||
|
||||
var userProfile = new UserProfile(user, actualRuleset);
|
||||
Header.UserProfile.Value = userProfile;
|
||||
|
||||
if (user.ProfileOrder != null)
|
||||
|
Loading…
Reference in New Issue
Block a user