osukey/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs
2022-04-19 02:48:34 +03:00

81 lines
2.4 KiB
C#

// 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.Graphics.Containers;
using osu.Game.Online.API.Requests;
using System;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Online.API.Requests.Responses;
using System.Collections.Generic;
using osu.Game.Online.API;
using osu.Framework.Allocation;
using osu.Framework.Localisation;
using APIUser = osu.Game.Online.API.Requests.Responses.APIUser;
namespace osu.Game.Overlays.Profile.Sections.Ranks
{
public class PaginatedScoreContainer : PaginatedProfileSubsection<APIScore>
{
private readonly ScoreType type;
public PaginatedScoreContainer(ScoreType type, Bindable<APIUser> user, LocalisableString headerText)
: base(user, headerText)
{
this.type = type;
}
[BackgroundDependencyLoader]
private void load()
{
ItemsContainer.Direction = FillDirection.Vertical;
}
protected override int GetCount(APIUser user)
{
switch (type)
{
case ScoreType.Best:
return user.ScoresBestCount;
case ScoreType.Firsts:
return user.ScoresFirstCount;
case ScoreType.Recent:
return user.ScoresRecentCount;
case ScoreType.Pinned:
return user.ScoresPinnedCount;
default:
return 0;
}
}
protected override void OnItemsReceived(List<APIScore> items)
{
if (CurrentPage == null || CurrentPage?.Offset == 0)
drawableItemIndex = 0;
base.OnItemsReceived(items);
}
protected override APIRequest<List<APIScore>> CreateRequest(PaginationParameters pagination) =>
new GetUserScoresRequest(User.Value.Id, type, pagination);
private int drawableItemIndex;
protected override Drawable CreateDrawableItem(APIScore model)
{
switch (type)
{
default:
return new DrawableProfileScore(model);
case ScoreType.Best:
return new DrawableProfileWeightedScore(model, Math.Pow(0.95, drawableItemIndex++));
}
}
}
}