1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 06:52:56 +08:00

Make Rankings a ctor variable

This commit is contained in:
Andrei Zavatski 2019-11-28 20:09:05 +03:00
parent da01f0ee5a
commit 83e3ad9e69
6 changed files with 20 additions and 43 deletions

View File

@ -73,11 +73,7 @@ namespace osu.Game.Tests.Visual.Online
request = new GetCountryRankingsRequest(ruleset, page); request = new GetCountryRankingsRequest(ruleset, page);
((GetCountryRankingsRequest)request).Success += rankings => Schedule(() => ((GetCountryRankingsRequest)request).Success += rankings => Schedule(() =>
{ {
var table = new CountriesTable(page) var table = new CountriesTable(page, rankings.Countries);
{
Rankings = rankings.Countries,
};
loadTable(table); loadTable(table);
}); });
@ -91,11 +87,7 @@ namespace osu.Game.Tests.Visual.Online
request = new GetUserRankingsRequest(ruleset, country: country, page: page); request = new GetUserRankingsRequest(ruleset, country: country, page: page);
((GetUserRankingsRequest)request).Success += rankings => Schedule(() => ((GetUserRankingsRequest)request).Success += rankings => Schedule(() =>
{ {
var table = new PerformanceTable(page) var table = new PerformanceTable(page, rankings.Users);
{
Rankings = rankings.Users,
};
loadTable(table); loadTable(table);
}); });
@ -109,11 +101,7 @@ namespace osu.Game.Tests.Visual.Online
request = new GetUserRankingsRequest(ruleset, UserRankingsType.Score, page); request = new GetUserRankingsRequest(ruleset, UserRankingsType.Score, page);
((GetUserRankingsRequest)request).Success += rankings => Schedule(() => ((GetUserRankingsRequest)request).Success += rankings => Schedule(() =>
{ {
var table = new ScoresTable(page) var table = new ScoresTable(page, rankings.Users);
{
Rankings = rankings.Users,
};
loadTable(table); loadTable(table);
}); });

View File

@ -7,13 +7,14 @@ using System;
using osu.Game.Users; using osu.Game.Users;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics; using osu.Game.Graphics;
using System.Collections.Generic;
namespace osu.Game.Overlays.Rankings.Tables namespace osu.Game.Overlays.Rankings.Tables
{ {
public class CountriesTable : RankingsTable<CountryStatistics> public class CountriesTable : RankingsTable<CountryStatistics>
{ {
public CountriesTable(int page = 1) public CountriesTable(int page, IReadOnlyList<CountryStatistics> rankings)
: base(page) : base(page, rankings)
{ {
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Users; using osu.Game.Users;
@ -9,8 +10,8 @@ namespace osu.Game.Overlays.Rankings.Tables
{ {
public class PerformanceTable : UserBasedTable public class PerformanceTable : UserBasedTable
{ {
public PerformanceTable(int page = 1) public PerformanceTable(int page, IReadOnlyList<UserStatistics> rankings)
: base(page) : base(page, rankings)
{ {
} }

View File

@ -23,12 +23,9 @@ namespace osu.Game.Overlays.Rankings.Tables
private const float row_height = 25; private const float row_height = 25;
private const int items_per_page = 50; private const int items_per_page = 50;
private readonly int page; protected RankingsTable(int page, IReadOnlyList<TModel> rankings)
private readonly FillFlowContainer backgroundFlow;
protected RankingsTable(int page)
{ {
this.page = page; FillFlowContainer backgroundFlow;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
@ -42,23 +39,11 @@ namespace osu.Game.Overlays.Rankings.Tables
Depth = 1f, Depth = 1f,
Margin = new MarginPadding { Top = row_height } Margin = new MarginPadding { Top = row_height }
}); });
}
public IReadOnlyList<TModel> Rankings rankings.ForEach(_ => backgroundFlow.Add(new TableRowBackground()));
{
set
{
Content = null;
backgroundFlow.Clear();
if (value?.Any() != true) Columns = mainHeaders.Concat(CreateAdditionalHeaders()).ToArray();
return; Content = rankings.Select((s, i) => createContent((page - 1) * items_per_page + i, s)).ToArray().ToRectangular();
value.ForEach(_ => backgroundFlow.Add(new TableRowBackground()));
Columns = mainHeaders.Concat(CreateAdditionalHeaders()).ToArray();
Content = value.Select((s, i) => createContent((page - 1) * items_per_page + i, s)).ToArray().ToRectangular();
}
} }
private Drawable[] createContent(int index, TModel item) => new Drawable[] { createIndexDrawable(index), createMainContent(item) }.Concat(CreateAdditionalContent(item)).ToArray(); private Drawable[] createContent(int index, TModel item) => new Drawable[] { createIndexDrawable(index), createMainContent(item) }.Concat(CreateAdditionalContent(item)).ToArray();

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Users; using osu.Game.Users;
@ -9,8 +10,8 @@ namespace osu.Game.Overlays.Rankings.Tables
{ {
public class ScoresTable : UserBasedTable public class ScoresTable : UserBasedTable
{ {
public ScoresTable(int page = 1) public ScoresTable(int page, IReadOnlyList<UserStatistics> rankings)
: base(page) : base(page, rankings)
{ {
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -12,8 +13,8 @@ namespace osu.Game.Overlays.Rankings.Tables
{ {
public abstract class UserBasedTable : RankingsTable<UserStatistics> public abstract class UserBasedTable : RankingsTable<UserStatistics>
{ {
protected UserBasedTable(int page) protected UserBasedTable(int page, IReadOnlyList<UserStatistics> rankings)
: base(page) : base(page, rankings)
{ {
} }