1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 16:22:55 +08:00

Merge branch 'master' into issue-17877

This commit is contained in:
Dean Herbert 2022-04-20 12:52:13 +09:00 committed by GitHub
commit d2f1468b5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 130 additions and 42 deletions

View File

@ -0,0 +1,30 @@
// 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;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Localisation;
namespace osu.Game.Localisation
{
public class DebugLocalisationStore : ILocalisationStore
{
public string Get(string lookup) => $@"[[{lookup.Substring(lookup.LastIndexOf('.') + 1)}]]";
public Task<string> GetAsync(string lookup, CancellationToken cancellationToken = default) => Task.FromResult(Get(lookup));
public Stream GetStream(string name) => throw new NotImplementedException();
public IEnumerable<string> GetAvailableResources() => throw new NotImplementedException();
public CultureInfo EffectiveCulture { get; } = CultureInfo.CurrentCulture;
public void Dispose()
{
}
}
}

View File

@ -110,6 +110,11 @@ namespace osu.Game.Localisation
// zh_hk,
[Description(@"繁體中文(台灣)")]
zh_hant
zh_hant,
#if DEBUG
[Description(@"Debug (show raw keys)")]
debug
#endif
}
}

View File

@ -13,8 +13,8 @@ namespace osu.Game.Online.API.Requests
private readonly BeatmapSetType type;
public GetUserBeatmapsRequest(long userId, BeatmapSetType type, int page = 0, int itemsPerPage = 6)
: base(page, itemsPerPage)
public GetUserBeatmapsRequest(long userId, BeatmapSetType type, PaginationParameters pagination)
: base(pagination)
{
this.userId = userId;
this.type = type;

View File

@ -10,8 +10,8 @@ namespace osu.Game.Online.API.Requests
{
private readonly long userId;
public GetUserKudosuHistoryRequest(long userId, int page = 0, int itemsPerPage = 5)
: base(page, itemsPerPage)
public GetUserKudosuHistoryRequest(long userId, PaginationParameters pagination)
: base(pagination)
{
this.userId = userId;
}

View File

@ -10,8 +10,8 @@ namespace osu.Game.Online.API.Requests
{
private readonly long userId;
public GetUserMostPlayedBeatmapsRequest(long userId, int page = 0, int itemsPerPage = 5)
: base(page, itemsPerPage)
public GetUserMostPlayedBeatmapsRequest(long userId, PaginationParameters pagination)
: base(pagination)
{
this.userId = userId;
}

View File

@ -10,8 +10,8 @@ namespace osu.Game.Online.API.Requests
{
private readonly long userId;
public GetUserRecentActivitiesRequest(long userId, int page = 0, int itemsPerPage = 5)
: base(page, itemsPerPage)
public GetUserRecentActivitiesRequest(long userId, PaginationParameters pagination)
: base(pagination)
{
this.userId = userId;
}

View File

@ -14,8 +14,8 @@ namespace osu.Game.Online.API.Requests
private readonly ScoreType type;
private readonly RulesetInfo ruleset;
public GetUserScoresRequest(long userId, ScoreType type, int page = 0, int itemsPerPage = 5, RulesetInfo ruleset = null)
: base(page, itemsPerPage)
public GetUserScoresRequest(long userId, ScoreType type, PaginationParameters pagination, RulesetInfo ruleset = null)
: base(pagination)
{
this.userId = userId;
this.type = type;

View File

@ -8,21 +8,19 @@ namespace osu.Game.Online.API.Requests
{
public abstract class PaginatedAPIRequest<T> : APIRequest<T> where T : class
{
private readonly int page;
private readonly int itemsPerPage;
private readonly PaginationParameters pagination;
protected PaginatedAPIRequest(int page, int itemsPerPage)
protected PaginatedAPIRequest(PaginationParameters pagination)
{
this.page = page;
this.itemsPerPage = itemsPerPage;
this.pagination = pagination;
}
protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
req.AddParameter("offset", (page * itemsPerPage).ToString(CultureInfo.InvariantCulture));
req.AddParameter("limit", itemsPerPage.ToString(CultureInfo.InvariantCulture));
req.AddParameter("offset", pagination.Offset.ToString(CultureInfo.InvariantCulture));
req.AddParameter("limit", pagination.Limit.ToString(CultureInfo.InvariantCulture));
return req;
}

View File

@ -0,0 +1,38 @@
// 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.
namespace osu.Game.Online.API.Requests
{
/// <summary>
/// Represents a pagination data used for <see cref="PaginatedAPIRequest{T}"/>.
/// </summary>
public readonly struct PaginationParameters
{
/// <summary>
/// The starting point of the request.
/// </summary>
public int Offset { get; }
/// <summary>
/// The maximum number of items to return in this request.
/// </summary>
public int Limit { get; }
public PaginationParameters(int offset, int limit)
{
Offset = offset;
Limit = limit;
}
public PaginationParameters(int limit)
: this(0, limit)
{
}
/// <summary>
/// Returns a <see cref="PaginationParameters"/> of the next number of items defined by <paramref name="limit"/> after this.
/// </summary>
/// <param name="limit">The limit of the next pagination.</param>
public PaginationParameters TakeNext(int limit) => new PaginationParameters(Offset + Limit, limit);
}
}

View File

@ -628,6 +628,14 @@ namespace osu.Game
foreach (var language in Enum.GetValues(typeof(Language)).OfType<Language>())
{
#if DEBUG
if (language == Language.debug)
{
Localisation.AddLanguage(Language.debug.ToString(), new DebugLocalisationStore());
continue;
}
#endif
string cultureCode = language.ToCultureCode();
try

View File

@ -20,11 +20,12 @@ namespace osu.Game.Overlays.Profile.Sections.Beatmaps
private const float panel_padding = 10f;
private readonly BeatmapSetType type;
protected override int InitialItemsCount => type == BeatmapSetType.Graveyard ? 2 : 6;
public PaginatedBeatmapContainer(BeatmapSetType type, Bindable<APIUser> user, LocalisableString headerText)
: base(user, headerText)
{
this.type = type;
ItemsPerPage = 6;
}
[BackgroundDependencyLoader]
@ -57,8 +58,8 @@ namespace osu.Game.Overlays.Profile.Sections.Beatmaps
}
}
protected override APIRequest<List<APIBeatmapSet>> CreateRequest() =>
new GetUserBeatmapsRequest(User.Value.Id, type, VisiblePages++, ItemsPerPage);
protected override APIRequest<List<APIBeatmapSet>> CreateRequest(PaginationParameters pagination) =>
new GetUserBeatmapsRequest(User.Value.Id, type, pagination);
protected override Drawable CreateDrawableItem(APIBeatmapSet model) => model.OnlineID > 0
? new BeatmapCardNormal(model)

View File

@ -19,7 +19,6 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
public PaginatedMostPlayedBeatmapContainer(Bindable<APIUser> user)
: base(user, UsersStrings.ShowExtraHistoricalMostPlayedTitle)
{
ItemsPerPage = 5;
}
[BackgroundDependencyLoader]
@ -30,8 +29,8 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
protected override int GetCount(APIUser user) => user.BeatmapPlayCountsCount;
protected override APIRequest<List<APIUserMostPlayedBeatmap>> CreateRequest() =>
new GetUserMostPlayedBeatmapsRequest(User.Value.Id, VisiblePages++, ItemsPerPage);
protected override APIRequest<List<APIUserMostPlayedBeatmap>> CreateRequest(PaginationParameters pagination) =>
new GetUserMostPlayedBeatmapsRequest(User.Value.Id, pagination);
protected override Drawable CreateDrawableItem(APIUserMostPlayedBeatmap mostPlayed) =>
new DrawableMostPlayedBeatmap(mostPlayed);

View File

@ -17,11 +17,10 @@ namespace osu.Game.Overlays.Profile.Sections.Kudosu
public PaginatedKudosuHistoryContainer(Bindable<APIUser> user)
: base(user, missingText: UsersStrings.ShowExtraKudosuEntryEmpty)
{
ItemsPerPage = 5;
}
protected override APIRequest<List<APIKudosuHistory>> CreateRequest()
=> new GetUserKudosuHistoryRequest(User.Value.Id, VisiblePages++, ItemsPerPage);
protected override APIRequest<List<APIKudosuHistory>> CreateRequest(PaginationParameters pagination)
=> new GetUserKudosuHistoryRequest(User.Value.Id, pagination);
protected override Drawable CreateDrawableItem(APIKudosuHistory item) => new DrawableKudosuHistoryItem(item);
}

View File

@ -14,6 +14,7 @@ using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osuTK;
@ -21,11 +22,20 @@ namespace osu.Game.Overlays.Profile.Sections
{
public abstract class PaginatedProfileSubsection<TModel> : ProfileSubsection
{
/// <summary>
/// The number of items displayed per page.
/// </summary>
protected virtual int ItemsPerPage => 50;
/// <summary>
/// The number of items displayed initially.
/// </summary>
protected virtual int InitialItemsCount => 5;
[Resolved]
private IAPIProvider api { get; set; }
protected int VisiblePages;
protected int ItemsPerPage;
protected PaginationParameters? CurrentPage { get; private set; }
protected ReverseChildIDFillFlowContainer<Drawable> ItemsContainer { get; private set; }
@ -87,7 +97,7 @@ namespace osu.Game.Overlays.Profile.Sections
loadCancellation?.Cancel();
retrievalRequest?.Cancel();
VisiblePages = 0;
CurrentPage = null;
ItemsContainer.Clear();
if (e.NewValue != null)
@ -101,7 +111,9 @@ namespace osu.Game.Overlays.Profile.Sections
{
loadCancellation = new CancellationTokenSource();
retrievalRequest = CreateRequest();
CurrentPage = CurrentPage?.TakeNext(ItemsPerPage) ?? new PaginationParameters(InitialItemsCount);
retrievalRequest = CreateRequest(CurrentPage.Value);
retrievalRequest.Success += UpdateItems;
api.Queue(retrievalRequest);
@ -111,7 +123,7 @@ namespace osu.Game.Overlays.Profile.Sections
{
OnItemsReceived(items);
if (!items.Any() && VisiblePages == 1)
if (!items.Any() && CurrentPage?.Offset == 0)
{
moreButton.Hide();
moreButton.IsLoading = false;
@ -125,7 +137,8 @@ namespace osu.Game.Overlays.Profile.Sections
LoadComponentsAsync(items.Select(CreateDrawableItem).Where(d => d != null), drawables =>
{
missing.Hide();
moreButton.FadeTo(items.Count == ItemsPerPage ? 1 : 0);
moreButton.FadeTo(items.Count == CurrentPage?.Limit ? 1 : 0);
moreButton.IsLoading = false;
ItemsContainer.AddRange(drawables);
@ -138,7 +151,7 @@ namespace osu.Game.Overlays.Profile.Sections
{
}
protected abstract APIRequest<List<TModel>> CreateRequest();
protected abstract APIRequest<List<TModel>> CreateRequest(PaginationParameters pagination);
protected abstract Drawable CreateDrawableItem(TModel model);

View File

@ -23,8 +23,6 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
: base(user, headerText)
{
this.type = type;
ItemsPerPage = 5;
}
[BackgroundDependencyLoader]
@ -56,14 +54,14 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
protected override void OnItemsReceived(List<APIScore> items)
{
if (VisiblePages == 0)
if (CurrentPage == null || CurrentPage?.Offset == 0)
drawableItemIndex = 0;
base.OnItemsReceived(items);
}
protected override APIRequest<List<APIScore>> CreateRequest() =>
new GetUserScoresRequest(User.Value.Id, type, VisiblePages++, ItemsPerPage);
protected override APIRequest<List<APIScore>> CreateRequest(PaginationParameters pagination) =>
new GetUserScoresRequest(User.Value.Id, type, pagination);
private int drawableItemIndex;

View File

@ -19,7 +19,6 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
public PaginatedRecentActivityContainer(Bindable<APIUser> user)
: base(user, missingText: EventsStrings.Empty)
{
ItemsPerPage = 10;
}
[BackgroundDependencyLoader]
@ -28,8 +27,8 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
ItemsContainer.Spacing = new Vector2(0, 8);
}
protected override APIRequest<List<APIRecentActivity>> CreateRequest() =>
new GetUserRecentActivitiesRequest(User.Value.Id, VisiblePages++, ItemsPerPage);
protected override APIRequest<List<APIRecentActivity>> CreateRequest(PaginationParameters pagination) =>
new GetUserRecentActivitiesRequest(User.Value.Id, pagination);
protected override Drawable CreateDrawableItem(APIRecentActivity model) => new DrawableRecentActivity(model);
}