1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 09:22:54 +08:00

Introduce IStatisticRow interface

This commit is contained in:
Bartłomiej Dach 2020-08-26 19:19:42 +02:00
parent 66fb5d4174
commit 927a2a3d2d
3 changed files with 45 additions and 23 deletions

View File

@ -0,0 +1,18 @@
// 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;
namespace osu.Game.Screens.Ranking.Statistics
{
/// <summary>
/// A row of statistics to be displayed on the results screen.
/// </summary>
public interface IStatisticRow
{
/// <summary>
/// Creates the visual representation of this row.
/// </summary>
Drawable CreateDrawableStatisticRow();
}
}

View File

@ -1,19 +1,41 @@
// 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.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Screens.Ranking.Statistics namespace osu.Game.Screens.Ranking.Statistics
{ {
/// <summary> /// <summary>
/// A row of statistics to be displayed in the results screen. /// A row of graphically detailed <see cref="StatisticItem"/>s to be displayed in the results screen.
/// </summary> /// </summary>
public class StatisticRow public class StatisticRow : IStatisticRow
{ {
/// <summary> /// <summary>
/// The columns of this <see cref="StatisticRow"/>. /// The columns of this <see cref="StatisticRow"/>.
/// </summary> /// </summary>
[ItemNotNull] [ItemNotNull]
public StatisticItem[] Columns; public StatisticItem[] Columns;
public Drawable CreateDrawableStatisticRow() => new GridContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Content = new[]
{
Columns?.Select(c => new StatisticContainer(c)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}).Cast<Drawable>().ToArray()
},
ColumnDimensions = Enumerable.Range(0, Columns?.Length ?? 0)
.Select(i => Columns[i].Dimension ?? new Dimension()).ToArray(),
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }
};
} }
} }

View File

@ -96,27 +96,9 @@ namespace osu.Game.Screens.Ranking.Statistics
Spacing = new Vector2(30, 15), Spacing = new Vector2(30, 15),
}; };
foreach (var row in newScore.Ruleset.CreateInstance().CreateStatisticsForScore(newScore, playableBeatmap)) rows.AddRange(newScore.Ruleset.CreateInstance()
{ .CreateStatisticsForScore(newScore, playableBeatmap)
rows.Add(new GridContainer .Select(row => row.CreateDrawableStatisticRow()));
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Content = new[]
{
row.Columns?.Select(c => new StatisticContainer(c)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}).Cast<Drawable>().ToArray()
},
ColumnDimensions = Enumerable.Range(0, row.Columns?.Length ?? 0)
.Select(i => row.Columns[i].Dimension ?? new Dimension()).ToArray(),
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }
});
}
LoadComponentAsync(rows, d => LoadComponentAsync(rows, d =>
{ {