Display placeholder if no statistics available

This commit is contained in:
smoogipoo
2020-06-18 22:21:30 +09:00
parent 20db5b33ab
commit ecdfcb1955
3 changed files with 63 additions and 21 deletions

View File

@ -1,8 +1,11 @@
// 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.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Online.Placeholders;
using osu.Game.Scoring;
using osuTK;
@ -12,15 +15,14 @@ namespace osu.Game.Screens.Ranking.Statistics
{
public const float SIDE_PADDING = 30;
public readonly Bindable<ScoreInfo> Score = new Bindable<ScoreInfo>();
protected override bool StartHidden => true;
public StatisticsPanel(ScoreInfo score)
private readonly Container content;
public StatisticsPanel()
{
// Todo: Not correct.
RelativeSizeAxes = Axes.Both;
FillFlowContainer statisticRows;
InternalChild = new Container
{
RelativeSizeAxes = Axes.Both,
@ -31,24 +33,47 @@ namespace osu.Game.Screens.Ranking.Statistics
Top = SIDE_PADDING,
Bottom = 50 // Approximate padding to the bottom of the score panel.
},
Child = statisticRows = new FillFlowContainer
Child = content = new Container { RelativeSizeAxes = Axes.Both },
};
}
[BackgroundDependencyLoader]
private void load()
{
Score.BindValueChanged(populateStatistics, true);
}
private void populateStatistics(ValueChangedEvent<ScoreInfo> score)
{
foreach (var child in content)
child.FadeOut(150).Expire();
var newScore = score.NewValue;
if (newScore.HitEvents == null || newScore.HitEvents.Count == 0)
content.Add(new MessagePlaceholder("Score has no statistics :("));
else
{
var rows = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(30, 15),
}
};
};
foreach (var s in score.Ruleset.CreateInstance().CreateStatistics(score))
{
statisticRows.Add(new GridContainer
foreach (var row in newScore.Ruleset.CreateInstance().CreateStatistics(newScore))
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Content = new[] { s.Content },
ColumnDimensions = s.ColumnDimensions,
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }
});
rows.Add(new GridContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Content = new[] { row.Content },
ColumnDimensions = row.ColumnDimensions,
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }
});
}
content.Add(rows);
}
}