1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:33:30 +08:00

Add initial implementation of the statistics panel

This commit is contained in:
smoogipoo 2020-06-15 22:45:18 +09:00
parent 900da88498
commit 89b54be673
7 changed files with 179 additions and 2 deletions

View File

@ -29,6 +29,8 @@ using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Skinning;
using System;
using osu.Game.Rulesets.Osu.Statistics;
using osu.Game.Screens.Ranking.Statistics;
namespace osu.Game.Rulesets.Osu
{
@ -186,5 +188,17 @@ namespace osu.Game.Rulesets.Osu
public override IConvertibleReplayFrame CreateConvertibleReplayFrame() => new OsuReplayFrame();
public override IRulesetConfigManager CreateConfig(SettingsStore settings) => new OsuRulesetConfigManager(settings, RulesetInfo);
public override IEnumerable<StatisticContainer> CreateStatistics(ScoreInfo score) => new[]
{
new StatisticContainer("Timing Distribution")
{
Child = new TimingDistributionGraph((TimingDistribution)score.ExtraStatistics.GetValueOrDefault("timing_distribution"))
},
new StatisticContainer("Accuracy Heatmap")
{
Child = new Heatmap((List<HitOffset>)score.ExtraStatistics.GetValueOrDefault("hit_offsets"))
},
};
}
}

View File

@ -2,12 +2,14 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Rulesets.Osu.Scoring;
using osuTK;
using osuTK.Graphics;
@ -29,10 +31,13 @@ namespace osu.Game.Rulesets.Osu.Statistics
private const float rotation = 45;
private const float point_size = 4;
private readonly IReadOnlyList<HitOffset> offsets;
private Container<HitPoint> allPoints;
public Heatmap()
public Heatmap(IReadOnlyList<HitOffset> offsets)
{
this.offsets = offsets;
Size = new Vector2(size);
}
@ -122,6 +127,9 @@ namespace osu.Game.Rulesets.Osu.Statistics
});
}
}
foreach (var o in offsets)
AddPoint(o.Position1, o.Position2, o.HitPosition, o.Radius);
}
public void AddPoint(Vector2 start, Vector2 end, Vector2 hitPoint, float radius)

View File

@ -1,12 +1,14 @@
// 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 System.Collections.Generic;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Framework.Utils;
using osu.Game.Rulesets.Osu.Scoring;
using osu.Game.Rulesets.Osu.Statistics;
using osuTK;
using osuTK.Graphics;
@ -38,7 +40,7 @@ namespace osu.Game.Tests.Visual.Ranking
{
Position = new Vector2(500, 300),
},
heatmap = new Heatmap
heatmap = new Heatmap(new List<HitOffset>())
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,

View File

@ -0,0 +1,24 @@
// 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 NUnit.Framework;
using osu.Game.Rulesets.Osu;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking.Statistics;
namespace osu.Game.Tests.Visual.Ranking
{
public class TestScreenStatisticsPanel : OsuTestScene
{
[Test]
public void TestScore()
{
loadPanel(new TestScoreInfo(new OsuRuleset().RulesetInfo));
}
private void loadPanel(ScoreInfo score) => AddStep("load panel", () =>
{
Child = new StatisticsPanel(score);
});
}
}

View File

@ -23,6 +23,7 @@ using osu.Game.Scoring;
using osu.Game.Skinning;
using osu.Game.Users;
using JetBrains.Annotations;
using osu.Game.Screens.Ranking.Statistics;
namespace osu.Game.Rulesets
{
@ -208,5 +209,7 @@ namespace osu.Game.Rulesets
/// </summary>
/// <returns>An empty frame for the current ruleset, or null if unsupported.</returns>
public virtual IConvertibleReplayFrame CreateConvertibleReplayFrame() => null;
public virtual IEnumerable<StatisticContainer> CreateStatistics(ScoreInfo score) => Enumerable.Empty<StatisticContainer>();
}
}

View File

@ -0,0 +1,70 @@
// 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.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK;
namespace osu.Game.Screens.Ranking.Statistics
{
public class StatisticContainer : Container
{
protected override Container<Drawable> Content => content;
private readonly Container content;
public StatisticContainer(string name)
{
InternalChild = new GridContainer
{
RelativeSizeAxes = Axes.X,
Content = new[]
{
new Drawable[]
{
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5, 0),
Children = new Drawable[]
{
new Circle
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Height = 9,
Width = 4,
Colour = Color4Extensions.FromHex("#00FFAA")
},
new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = name,
Font = OsuFont.GetFont(size: 14, weight: FontWeight.SemiBold),
}
}
}
},
new Drawable[]
{
content = new Container
{
RelativeSizeAxes = Axes.Both
}
},
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
}
};
}
}
}

View File

@ -0,0 +1,56 @@
// 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.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Scoring;
using osuTK;
namespace osu.Game.Screens.Ranking.Statistics
{
public class StatisticsPanel : CompositeDrawable
{
public StatisticsPanel(ScoreInfo score)
{
// Todo: Not correct.
RelativeSizeAxes = Axes.Both;
Container<StatisticContainer> statistics;
InternalChildren = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex("#333")
},
new ScorePanel(score) // Todo: Temporary
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
State = PanelState.Expanded,
X = 30
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding
{
Left = ScorePanel.EXPANDED_WIDTH + 30 + 50,
Right = 50
},
Child = statistics = new FillFlowContainer<StatisticContainer>
{
RelativeSizeAxes = Axes.Both,
Spacing = new Vector2(30, 15),
}
}
};
foreach (var s in score.Ruleset.CreateInstance().CreateStatistics(score))
statistics.Add(s);
}
}
}