1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 21:02:55 +08:00

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 NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Osu;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking.Statistics;
@ -12,7 +14,7 @@ namespace osu.Game.Tests.Visual.Ranking
public class TestSceneStatisticsPanel : OsuTestScene
{
[Test]
public void TestScore()
public void TestScoreWithStatistics()
{
var score = new TestScoreInfo(new OsuRuleset().RulesetInfo)
{
@ -22,9 +24,20 @@ namespace osu.Game.Tests.Visual.Ranking
loadPanel(score);
}
[Test]
public void TestScoreWithoutStatistics()
{
loadPanel(new TestScoreInfo(new OsuRuleset().RulesetInfo));
}
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 },
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.
// 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);
}
}