1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Add ability to view kudosu rankings

This commit is contained in:
Joseph Madamba 2023-11-07 15:53:41 -08:00
parent 34219c1103
commit 387de7ec24
5 changed files with 151 additions and 1 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

@ -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;