1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 04:12:53 +08:00
osu-lazer/osu.Game/Overlays/Rankings/Tables/UserBasedTable.cs

82 lines
3.2 KiB
C#
Raw Normal View History

2020-02-28 05:26:21 +08:00
// 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.
2019-11-29 01:09:05 +08:00
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Users;
2020-02-05 02:02:10 +08:00
using osu.Game.Scoring;
namespace osu.Game.Overlays.Rankings.Tables
{
public abstract class UserBasedTable : RankingsTable<UserStatistics>
{
2019-11-29 01:09:05 +08:00
protected UserBasedTable(int page, IReadOnlyList<UserStatistics> rankings)
: base(page, rankings)
{
}
protected virtual IEnumerable<string> GradeColumns => new List<string> { "SS", "S", "A" };
2020-02-28 05:23:50 +08:00
protected override TableColumn[] CreateAdditionalHeaders() => new[]
2020-02-28 05:23:50 +08:00
{
2020-02-28 05:26:21 +08:00
new TableColumn("Accuracy", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
new TableColumn("Play Count", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
}.Concat(CreateUniqueHeaders())
.Concat(GradeColumns.Select(grade => new TableColumn(grade, Anchor.Centre, new Dimension(GridSizeMode.AutoSize))))
.ToArray();
protected override Drawable CreateHeader(int index, TableColumn column)
{
var title = column?.Header ?? string.Empty;
return new UserTableHeaderText(title, HighlightedColumn == title, GradeColumns.Contains(title));
2020-02-28 05:23:50 +08:00
}
2019-11-28 18:07:43 +08:00
protected sealed override Country GetCountry(UserStatistics item) => item.User.Country;
2019-11-28 18:07:43 +08:00
protected sealed override Drawable CreateFlagContent(UserStatistics item)
{
2020-02-28 05:26:21 +08:00
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.User);
return username;
}
2019-11-28 18:07:43 +08:00
protected sealed override Drawable[] CreateAdditionalContent(UserStatistics item) => new[]
{
new ColoredRowText { Text = item.DisplayAccuracy, },
2019-11-28 18:07:43 +08:00
new ColoredRowText { Text = $@"{item.PlayCount:N0}", },
}.Concat(CreateUniqueContent(item)).Concat(new[]
{
2020-02-05 02:02:10 +08:00
new ColoredRowText { Text = $@"{item.GradesCount[ScoreRank.XH] + item.GradesCount[ScoreRank.X]:N0}", },
new ColoredRowText { Text = $@"{item.GradesCount[ScoreRank.SH] + item.GradesCount[ScoreRank.S]:N0}", },
new ColoredRowText { Text = $@"{item.GradesCount[ScoreRank.A]:N0}", }
}).ToArray();
protected abstract TableColumn[] CreateUniqueHeaders();
protected abstract Drawable[] CreateUniqueContent(UserStatistics item);
private class UserTableHeaderText : HeaderText
{
public UserTableHeaderText(string text, bool isHighlighted, bool isGrade)
: base(text, isHighlighted)
{
Margin = new MarginPadding
{
// Grade columns have extra horizontal padding for readibility
Horizontal = isGrade ? 20 : 10,
Vertical = 5
};
}
}
}
}