2019-09-28 00:33:52 +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.
|
|
|
|
|
|
|
|
|
|
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;
|
2019-11-28 04:35:02 +08:00
|
|
|
|
using osu.Game.Users;
|
|
|
|
|
using osu.Game.Users.Drawables;
|
|
|
|
|
using osuTK;
|
2019-09-28 00:33:52 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Rankings.Tables
|
|
|
|
|
{
|
|
|
|
|
public abstract class RankingsTable<TModel> : TableContainer
|
|
|
|
|
{
|
|
|
|
|
protected const int TEXT_SIZE = 14;
|
|
|
|
|
private const float horizontal_inset = 20;
|
|
|
|
|
private const float row_height = 25;
|
|
|
|
|
private const int items_per_page = 50;
|
|
|
|
|
|
|
|
|
|
private readonly int page;
|
|
|
|
|
private readonly FillFlowContainer backgroundFlow;
|
|
|
|
|
|
|
|
|
|
protected RankingsTable(int page)
|
|
|
|
|
{
|
|
|
|
|
this.page = page;
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
|
|
Padding = new MarginPadding { Horizontal = horizontal_inset };
|
|
|
|
|
RowSize = new Dimension(GridSizeMode.Absolute, row_height);
|
|
|
|
|
|
|
|
|
|
AddInternal(backgroundFlow = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Depth = 1f,
|
|
|
|
|
Margin = new MarginPadding { Top = row_height }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-28 02:37:34 +08:00
|
|
|
|
public IReadOnlyList<TModel> Rankings
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Content = null;
|
|
|
|
|
backgroundFlow.Clear();
|
|
|
|
|
|
|
|
|
|
if (value?.Any() != true)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
value.ForEach(_ => backgroundFlow.Add(new TableRowBackground()));
|
|
|
|
|
|
2019-11-28 02:46:41 +08:00
|
|
|
|
Columns = mainHeaders.Concat(CreateAdditionalHeaders()).ToArray();
|
2019-11-28 04:35:02 +08:00
|
|
|
|
Content = value.Select((s, i) => createContent((page - 1) * items_per_page + i, s)).ToArray().ToRectangular();
|
2019-11-28 02:37:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-28 04:35:02 +08:00
|
|
|
|
private Drawable[] createContent(int index, TModel item) => new Drawable[] { createIndexDrawable(index), createMainContent(item) }.Concat(CreateAdditionalContent(item)).ToArray();
|
|
|
|
|
|
2019-11-28 02:46:41 +08:00
|
|
|
|
private static TableColumn[] mainHeaders => new[]
|
|
|
|
|
{
|
|
|
|
|
new TableColumn(string.Empty, Anchor.Centre, new Dimension(GridSizeMode.Absolute, 50)), // place
|
|
|
|
|
new TableColumn(string.Empty, Anchor.CentreLeft, new Dimension(GridSizeMode.Distributed)), // flag and username (country name)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
protected abstract TableColumn[] 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
|
|
|
|
|
|
|
|
|
protected override Drawable CreateHeader(int index, TableColumn column) => new HeaderText(column?.Header ?? string.Empty, HighlightedColumn());
|
|
|
|
|
|
2019-11-28 04:35:02 +08:00
|
|
|
|
protected abstract Country GetCountry(TModel item);
|
|
|
|
|
|
|
|
|
|
protected abstract Drawable CreateFlagContent(TModel item);
|
|
|
|
|
|
|
|
|
|
private OsuSpriteText createIndexDrawable(int index) => new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = $"#{index + 1}",
|
|
|
|
|
Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Bold)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private FillFlowContainer createMainContent(TModel item) => new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(7, 0),
|
2019-11-28 04:58:31 +08:00
|
|
|
|
Children = new[]
|
2019-11-28 04:35:02 +08:00
|
|
|
|
{
|
|
|
|
|
new UpdateableFlag(GetCountry(item))
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(20, 13),
|
|
|
|
|
ShowPlaceholderOnNull = false,
|
|
|
|
|
},
|
|
|
|
|
CreateFlagContent(item)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-28 00:33:52 +08:00
|
|
|
|
protected virtual string HighlightedColumn() => @"Performance";
|
|
|
|
|
|
|
|
|
|
private class HeaderText : OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
private readonly string highlighted;
|
|
|
|
|
|
|
|
|
|
public HeaderText(string text, string highlighted)
|
|
|
|
|
{
|
|
|
|
|
this.highlighted = highlighted;
|
|
|
|
|
|
|
|
|
|
Text = text;
|
|
|
|
|
Font = OsuFont.GetFont(size: 12);
|
2019-11-06 18:07:25 +08:00
|
|
|
|
Margin = new MarginPadding { Horizontal = 10 };
|
2019-09-28 00:33:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
if (Text != highlighted)
|
|
|
|
|
Colour = colours.GreySeafoamLighter;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-01 19:12:03 +08:00
|
|
|
|
protected 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);
|
2019-11-03 19:31:23 +08:00
|
|
|
|
Margin = new MarginPadding { Horizontal = 10 };
|
2019-09-28 00:33:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-01 19:12:03 +08:00
|
|
|
|
protected class ColoredRowText : RowText
|
2019-09-28 00:33:52 +08:00
|
|
|
|
{
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
Colour = colours.GreySeafoamLighter;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|