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

@ -3,6 +3,8 @@
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens.Ranking.Statistics; using osu.Game.Screens.Ranking.Statistics;
@ -12,7 +14,7 @@ namespace osu.Game.Tests.Visual.Ranking
public class TestSceneStatisticsPanel : OsuTestScene public class TestSceneStatisticsPanel : OsuTestScene
{ {
[Test] [Test]
public void TestScore() public void TestScoreWithStatistics()
{ {
var score = new TestScoreInfo(new OsuRuleset().RulesetInfo) var score = new TestScoreInfo(new OsuRuleset().RulesetInfo)
{ {
@ -22,9 +24,20 @@ namespace osu.Game.Tests.Visual.Ranking
loadPanel(score); loadPanel(score);
} }
[Test]
public void TestScoreWithoutStatistics()
{
loadPanel(new TestScoreInfo(new OsuRuleset().RulesetInfo));
}
private void loadPanel(ScoreInfo score) => AddStep("load panel", () => private void loadPanel(ScoreInfo score) => AddStep("load panel", () =>
{ {
Child = new StatisticsPanel(score); Child = new StatisticsPanel
{
RelativeSizeAxes = Axes.Both,
State = { Value = Visibility.Visible },
Score = { Value = score }
};
}); });
} }
} }

View File

@ -89,7 +89,11 @@ namespace osu.Game.Screens.Ranking
SelectedScore = { BindTarget = SelectedScore }, SelectedScore = { BindTarget = SelectedScore },
PostExpandAction = onExpandedPanelClicked PostExpandAction = onExpandedPanelClicked
}, },
statisticsPanel = new StatisticsPanel(Score) { RelativeSizeAxes = Axes.Both } statisticsPanel = new StatisticsPanel
{
RelativeSizeAxes = Axes.Both,
Score = { BindTarget = SelectedScore }
}
} }
} }
}, },

View File

@ -1,8 +1,11 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Online.Placeholders;
using osu.Game.Scoring; using osu.Game.Scoring;
using osuTK; using osuTK;
@ -12,15 +15,14 @@ namespace osu.Game.Screens.Ranking.Statistics
{ {
public const float SIDE_PADDING = 30; public const float SIDE_PADDING = 30;
public readonly Bindable<ScoreInfo> Score = new Bindable<ScoreInfo>();
protected override bool StartHidden => true; 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 InternalChild = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
@ -31,24 +33,47 @@ namespace osu.Game.Screens.Ranking.Statistics
Top = SIDE_PADDING, Top = SIDE_PADDING,
Bottom = 50 // Approximate padding to the bottom of the score panel. 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, RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
Spacing = new Vector2(30, 15), Spacing = new Vector2(30, 15),
} };
};
foreach (var s in score.Ruleset.CreateInstance().CreateStatistics(score)) foreach (var row in newScore.Ruleset.CreateInstance().CreateStatistics(newScore))
{
statisticRows.Add(new GridContainer
{ {
RelativeSizeAxes = Axes.X, rows.Add(new GridContainer
AutoSizeAxes = Axes.Y, {
Content = new[] { s.Content }, RelativeSizeAxes = Axes.X,
ColumnDimensions = s.ColumnDimensions, AutoSizeAxes = Axes.Y,
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) } Content = new[] { row.Content },
}); ColumnDimensions = row.ColumnDimensions,
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }
});
}
content.Add(rows);
} }
} }