1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:07:52 +08:00

Merge pull request #25388 from Joehuu/kudosu-rankings

Add ability to view kudosu rankings
This commit is contained in:
Dean Herbert 2023-11-08 12:46:59 +09:00 committed by GitHub
commit 9df8fc14e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 155 additions and 10 deletions

View File

@ -0,0 +1,28 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.IO.Network;
namespace osu.Game.Online.API.Requests
{
public class GetKudosuRankingsRequest : APIRequest<GetKudosuRankingsResponse>
{
private readonly int page;
public GetKudosuRankingsRequest(int page = 1)
{
this.page = page;
}
protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
req.AddParameter(@"page", page.ToString());
return req;
}
protected override string Target => @"rankings/kudosu";
}
}

View File

@ -0,0 +1,15 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using Newtonsoft.Json;
using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Online.API.Requests
{
public class GetKudosuRankingsResponse
{
[JsonProperty("ranking")]
public List<APIUser> Users = null!;
}
}

View File

@ -34,20 +34,15 @@ namespace osu.Game.Online.API.Requests.Responses
[JsonProperty(@"previous_usernames")]
public string[] PreviousUsernames;
private CountryCode? countryCode;
[JsonProperty(@"country_code")]
private string countryCodeString;
public CountryCode CountryCode
{
get => countryCode ??= (Enum.TryParse(country?.Code, out CountryCode result) ? result : default);
set => countryCode = value;
get => Enum.TryParse(countryCodeString, out CountryCode result) ? result : CountryCode.Unknown;
set => countryCodeString = value.ToString();
}
#pragma warning disable 649
[CanBeNull]
[JsonProperty(@"country")]
private Country country;
#pragma warning restore 649
public readonly Bindable<UserStatus> Status = new Bindable<UserStatus>();
public readonly Bindable<UserActivity> Activity = new Bindable<UserActivity>();

View File

@ -0,0 +1,95 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Rankings.Tables;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Users;
namespace osu.Game.Overlays
{
public partial class KudosuTable : RankingsTable<APIUser>
{
public KudosuTable(int page, List<APIUser> users)
: base(page, users)
{
}
protected override Drawable CreateRowBackground(APIUser item)
{
var background = base.CreateRowBackground(item);
// see: https://github.com/ppy/osu-web/blob/9de00a0b874c56893d98261d558d78d76259d81b/resources/views/multiplayer/rooms/_rankings_table.blade.php#L23
if (!item.Active)
background.Alpha = 0.5f;
return background;
}
protected override Drawable[] CreateRowContent(int index, APIUser item)
{
var content = base.CreateRowContent(index, item);
// see: https://github.com/ppy/osu-web/blob/9de00a0b874c56893d98261d558d78d76259d81b/resources/views/multiplayer/rooms/_rankings_table.blade.php#L23
if (!item.Active)
{
foreach (var d in content)
d.Alpha = 0.5f;
}
return content;
}
protected override RankingsTableColumn[] CreateAdditionalHeaders()
{
const int min_width = 120;
return new[]
{
new RankingsTableColumn(RankingsStrings.KudosuTotal, Anchor.Centre, new Dimension(GridSizeMode.AutoSize, minSize: min_width), true),
new RankingsTableColumn(RankingsStrings.KudosuAvailable, Anchor.Centre, new Dimension(GridSizeMode.AutoSize, minSize: min_width)),
new RankingsTableColumn(RankingsStrings.KudosuUsed, Anchor.Centre, new Dimension(GridSizeMode.AutoSize, minSize: min_width)),
};
}
protected override Drawable[] CreateAdditionalContent(APIUser item)
{
int kudosuTotal = item.Kudosu.Total;
int kudosuAvailable = item.Kudosu.Available;
return new Drawable[]
{
new RowText
{
Text = kudosuTotal.ToLocalisableString(@"N0")
},
new ColouredRowText
{
Text = kudosuAvailable.ToLocalisableString(@"N0")
},
new ColouredRowText
{
Text = (kudosuTotal - kudosuAvailable).ToLocalisableString(@"N0")
},
};
}
protected override CountryCode GetCountryCode(APIUser item) => item.CountryCode;
protected override Drawable CreateFlagContent(APIUser item)
{
var username = new LinkFlowContainer(t => t.Font = OsuFont.GetFont(size: TEXT_SIZE, italics: true))
{
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
TextAnchor = Anchor.CentreLeft
};
username.AddUserLink(item);
return username;
}
}
}

View File

@ -18,6 +18,9 @@ namespace osu.Game.Overlays.Rankings
Score,
[LocalisableDescription(typeof(RankingsStrings), nameof(RankingsStrings.TypeCountry))]
Country
Country,
[LocalisableDescription(typeof(RankingsStrings), nameof(RankingsStrings.TypeKudosu))]
Kudosu,
}
}

View File

@ -135,6 +135,9 @@ namespace osu.Game.Overlays
case RankingsScope.Score:
return new GetUserRankingsRequest(ruleset.Value, UserRankingsType.Score);
case RankingsScope.Kudosu:
return new GetKudosuRankingsRequest();
}
return null;
@ -166,6 +169,12 @@ namespace osu.Game.Overlays
return new CountriesTable(1, countryRequest.Response.Countries);
}
case GetKudosuRankingsRequest kudosuRequest:
if (kudosuRequest.Response == null)
return null;
return new KudosuTable(1, kudosuRequest.Response.Users);
}
return null;