2020-03-05 01:19:28 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-09-28 00:33:52 +08:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2019-09-28 00:33:52 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Extensions;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2021-08-29 20:00:28 +08:00
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
2019-11-28 04:35:02 +08:00
|
|
|
using osu.Game.Users;
|
|
|
|
using osu.Game.Users.Drawables;
|
|
|
|
using osuTK;
|
2021-07-28 00:22:47 +08:00
|
|
|
using osu.Framework.Localisation;
|
2019-09-28 00:33:52 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Rankings.Tables
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public abstract partial class RankingsTable<TModel> : TableContainer
|
2019-09-28 00:33:52 +08:00
|
|
|
{
|
2020-02-04 02:22:37 +08:00
|
|
|
protected const int TEXT_SIZE = 12;
|
2019-09-28 00:33:52 +08:00
|
|
|
private const float horizontal_inset = 20;
|
2020-02-28 05:25:49 +08:00
|
|
|
private const float row_height = 32;
|
|
|
|
private const float row_spacing = 3;
|
2019-09-28 00:33:52 +08:00
|
|
|
private const int items_per_page = 50;
|
|
|
|
|
2019-11-29 14:35:33 +08:00
|
|
|
private readonly int page;
|
|
|
|
private readonly IReadOnlyList<TModel> rankings;
|
|
|
|
|
2019-11-29 01:09:05 +08:00
|
|
|
protected RankingsTable(int page, IReadOnlyList<TModel> rankings)
|
2019-09-28 00:33:52 +08:00
|
|
|
{
|
2019-11-29 14:35:33 +08:00
|
|
|
this.page = page;
|
|
|
|
this.rankings = rankings;
|
2019-09-28 00:33:52 +08:00
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
Padding = new MarginPadding { Horizontal = horizontal_inset };
|
2020-02-28 05:25:49 +08:00
|
|
|
RowSize = new Dimension(GridSizeMode.Absolute, row_height + row_spacing);
|
2019-11-29 14:35:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
FillFlowContainer backgroundFlow;
|
2019-09-28 00:33:52 +08:00
|
|
|
|
|
|
|
AddInternal(backgroundFlow = new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Depth = 1f,
|
2020-02-28 05:25:49 +08:00
|
|
|
Margin = new MarginPadding { Top = row_height + row_spacing },
|
|
|
|
Spacing = new Vector2(0, row_spacing),
|
2019-09-28 00:33:52 +08:00
|
|
|
});
|
2019-11-28 02:37:34 +08:00
|
|
|
|
2022-01-09 21:32:33 +08:00
|
|
|
rankings.ForEach(s => backgroundFlow.Add(CreateRowBackground(s)));
|
2019-11-28 02:37:34 +08:00
|
|
|
|
2021-07-28 00:46:49 +08:00
|
|
|
Columns = mainHeaders.Concat(CreateAdditionalHeaders()).Cast<TableColumn>().ToArray();
|
2022-01-09 21:32:33 +08:00
|
|
|
Content = rankings.Select((s, i) => CreateRowContent((page - 1) * items_per_page + i, s)).ToArray().ToRectangular();
|
2019-11-28 02:37:34 +08:00
|
|
|
}
|
|
|
|
|
2022-01-09 21:32:33 +08:00
|
|
|
protected virtual Drawable CreateRowBackground(TModel item) => new TableRowBackground { Height = row_height };
|
|
|
|
|
|
|
|
protected virtual Drawable[] CreateRowContent(int index, TModel item) => new Drawable[] { createIndexDrawable(index), createMainContent(item) }.Concat(CreateAdditionalContent(item)).ToArray();
|
2019-11-28 04:35:02 +08:00
|
|
|
|
2021-07-28 00:46:49 +08:00
|
|
|
private static RankingsTableColumn[] mainHeaders => new[]
|
2019-11-28 02:46:41 +08:00
|
|
|
{
|
2021-07-28 00:46:49 +08:00
|
|
|
new RankingsTableColumn(string.Empty, Anchor.Centre, new Dimension(GridSizeMode.Absolute, 40)), // place
|
|
|
|
new RankingsTableColumn(string.Empty, Anchor.CentreLeft, new Dimension()), // flag and username (country name)
|
2019-11-28 02:46:41 +08:00
|
|
|
};
|
|
|
|
|
2021-07-28 00:46:49 +08:00
|
|
|
protected abstract RankingsTableColumn[] CreateAdditionalHeaders();
|
2019-09-28 00:33:52 +08:00
|
|
|
|
2019-11-28 04:35:02 +08:00
|
|
|
protected abstract Drawable[] CreateAdditionalContent(TModel item);
|
2019-09-28 00:33:52 +08:00
|
|
|
|
2021-07-28 00:46:49 +08:00
|
|
|
protected sealed override Drawable CreateHeader(int index, TableColumn column)
|
|
|
|
=> (column as RankingsTableColumn)?.CreateHeaderText() ?? new HeaderText(column?.Header ?? default, false);
|
2019-09-28 00:33:52 +08:00
|
|
|
|
2022-07-18 13:40:34 +08:00
|
|
|
protected abstract CountryCode GetCountryCode(TModel item);
|
2019-11-28 04:35:02 +08:00
|
|
|
|
|
|
|
protected abstract Drawable CreateFlagContent(TModel item);
|
|
|
|
|
2020-02-28 05:25:49 +08:00
|
|
|
private OsuSpriteText createIndexDrawable(int index) => new RowText
|
2019-11-28 04:35:02 +08:00
|
|
|
{
|
2021-07-31 13:27:20 +08:00
|
|
|
Text = (index + 1).ToLocalisableString(@"\##"),
|
2020-02-04 02:22:37 +08:00
|
|
|
Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.SemiBold)
|
2019-11-28 04:35:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
private FillFlowContainer createMainContent(TModel item) => new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
2020-02-28 05:25:49 +08:00
|
|
|
Spacing = new Vector2(10, 0),
|
|
|
|
Margin = new MarginPadding { Bottom = row_spacing },
|
2019-11-28 04:58:31 +08:00
|
|
|
Children = new[]
|
2019-11-28 04:35:02 +08:00
|
|
|
{
|
2022-07-18 13:40:34 +08:00
|
|
|
new UpdateableFlag(GetCountryCode(item))
|
2019-11-28 04:35:02 +08:00
|
|
|
{
|
2022-06-16 01:53:04 +08:00
|
|
|
Size = new Vector2(28, 20),
|
2022-07-16 11:07:53 +08:00
|
|
|
ShowPlaceholderOnUnknown = false,
|
2019-11-28 04:35:02 +08:00
|
|
|
},
|
|
|
|
CreateFlagContent(item)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-28 00:46:49 +08:00
|
|
|
protected class RankingsTableColumn : TableColumn
|
|
|
|
{
|
|
|
|
protected readonly bool Highlighted;
|
|
|
|
|
|
|
|
public RankingsTableColumn(LocalisableString? header = null, Anchor anchor = Anchor.TopLeft, Dimension dimension = null, bool highlighted = false)
|
|
|
|
: base(header, anchor, dimension)
|
|
|
|
{
|
|
|
|
Highlighted = highlighted;
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual HeaderText CreateHeaderText() => new HeaderText(Header, Highlighted);
|
|
|
|
}
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
protected partial class HeaderText : OsuSpriteText
|
2019-09-28 00:33:52 +08:00
|
|
|
{
|
2020-03-05 01:20:55 +08:00
|
|
|
private readonly bool isHighlighted;
|
2019-09-28 00:33:52 +08:00
|
|
|
|
2021-07-28 00:22:47 +08:00
|
|
|
public HeaderText(LocalisableString text, bool isHighlighted)
|
2019-09-28 00:33:52 +08:00
|
|
|
{
|
2020-03-05 01:20:55 +08:00
|
|
|
this.isHighlighted = isHighlighted;
|
2019-09-28 00:33:52 +08:00
|
|
|
|
|
|
|
Text = text;
|
|
|
|
Font = OsuFont.GetFont(size: 12);
|
2020-03-16 05:03:54 +08:00
|
|
|
Margin = new MarginPadding { Vertical = 5, Horizontal = 10 };
|
2019-09-28 00:33:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-02-04 02:22:37 +08:00
|
|
|
private void load(OverlayColourProvider colourProvider)
|
2019-09-28 00:33:52 +08:00
|
|
|
{
|
2020-03-16 01:31:44 +08:00
|
|
|
if (!isHighlighted)
|
2020-02-04 02:22:37 +08:00
|
|
|
Colour = colourProvider.Foreground1;
|
2019-09-28 00:33:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
protected partial class RowText : OsuSpriteText
|
2019-09-28 00:33:52 +08:00
|
|
|
{
|
2019-10-01 19:12:03 +08:00
|
|
|
public RowText()
|
2019-09-28 00:33:52 +08:00
|
|
|
{
|
2019-09-29 20:27:29 +08:00
|
|
|
Font = OsuFont.GetFont(size: TEXT_SIZE);
|
2020-02-28 05:25:49 +08:00
|
|
|
Margin = new MarginPadding { Horizontal = 10, Bottom = row_spacing };
|
2019-09-28 00:33:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
protected partial class ColouredRowText : RowText
|
2019-09-28 00:33:52 +08:00
|
|
|
{
|
|
|
|
[BackgroundDependencyLoader]
|
2020-02-04 02:22:37 +08:00
|
|
|
private void load(OverlayColourProvider colourProvider)
|
2019-09-28 00:33:52 +08:00
|
|
|
{
|
2020-02-04 02:22:37 +08:00
|
|
|
Colour = colourProvider.Foreground1;
|
2019-09-28 00:33:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|