mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 04:42:58 +08:00
Add the ability to set and show an offset value on timing distribution graph
This commit is contained in:
parent
d3e04fe594
commit
540d7d0e2c
@ -17,10 +17,13 @@ namespace osu.Game.Tests.Visual.Ranking
|
||||
{
|
||||
public class TestSceneHitEventTimingDistributionGraph : OsuTestScene
|
||||
{
|
||||
private HitEventTimingDistributionGraph graph;
|
||||
|
||||
[Test]
|
||||
public void TestManyDistributedEvents()
|
||||
{
|
||||
createTest(CreateDistributedHitEvents());
|
||||
AddStep("add adjustment", () => graph.UpdateOffset(10));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -68,7 +71,7 @@ namespace osu.Game.Tests.Visual.Ranking
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4Extensions.FromHex("#333")
|
||||
},
|
||||
new HitEventTimingDistributionGraph(events)
|
||||
graph = new HitEventTimingDistributionGraph(events)
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
|
@ -12,6 +12,7 @@ using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.Ranking.Statistics
|
||||
{
|
||||
@ -58,6 +59,8 @@ namespace osu.Game.Screens.Ranking.Statistics
|
||||
private double binSize;
|
||||
private double hitOffset;
|
||||
|
||||
private Bar[] barDrawables;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
@ -108,16 +111,20 @@ namespace osu.Game.Screens.Ranking.Statistics
|
||||
bins[index]++;
|
||||
}
|
||||
|
||||
int maxCount = bins.Max();
|
||||
var bars = new Drawable[total_timing_distribution_bins];
|
||||
|
||||
for (int i = 0; i < bars.Length; i++)
|
||||
if (barDrawables != null)
|
||||
{
|
||||
bars[i] = new Bar(i == timing_distribution_centre_bin_index)
|
||||
for (int i = 0; i < barDrawables.Length; i++)
|
||||
{
|
||||
Height = Math.Max(0.05f, (float)bins[i] / maxCount)
|
||||
};
|
||||
barDrawables[i].UpdateOffset(bins[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int maxCount = bins.Max();
|
||||
barDrawables = new Bar[total_timing_distribution_bins];
|
||||
|
||||
for (int i = 0; i < barDrawables.Length; i++)
|
||||
barDrawables[i] = new Bar(bins[i], maxCount, i == timing_distribution_centre_bin_index);
|
||||
|
||||
Container axisFlow;
|
||||
|
||||
@ -136,7 +143,7 @@ namespace osu.Game.Screens.Ranking.Statistics
|
||||
new GridContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Content = new[] { bars }
|
||||
Content = new[] { barDrawables }
|
||||
}
|
||||
},
|
||||
new Drawable[]
|
||||
@ -196,27 +203,59 @@ namespace osu.Game.Screens.Ranking.Statistics
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class Bar : CompositeDrawable
|
||||
{
|
||||
public Bar(bool isCentre)
|
||||
private readonly float value;
|
||||
private readonly float maxValue;
|
||||
|
||||
private readonly Circle boxOriginal;
|
||||
private readonly Circle boxAdjustment;
|
||||
|
||||
public Bar(float value, float maxValue, bool isCentre)
|
||||
{
|
||||
Anchor = Anchor.BottomCentre;
|
||||
Origin = Anchor.BottomCentre;
|
||||
this.value = value;
|
||||
this.maxValue = maxValue;
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
Masking = true;
|
||||
|
||||
var colour = Color4Extensions.FromHex("#66FFCC");
|
||||
|
||||
if (isCentre)
|
||||
colour = colour.Lighten(1);
|
||||
|
||||
InternalChild = new Circle
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
boxOriginal = new Circle
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colour
|
||||
Anchor = Anchor.BottomCentre,
|
||||
Origin = Anchor.BottomCentre,
|
||||
Colour = isCentre ? Color4.White : Color4Extensions.FromHex("#66FFCC"),
|
||||
Height = 0,
|
||||
},
|
||||
boxAdjustment = new Circle
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.BottomCentre,
|
||||
Origin = Anchor.BottomCentre,
|
||||
Colour = Color4.Yellow,
|
||||
Blending = BlendingParameters.Additive,
|
||||
Alpha = 0.6f,
|
||||
Height = 0,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private const double duration = 300;
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
boxOriginal.ResizeHeightTo(Math.Clamp(value / maxValue, 0.05f, 1), duration, Easing.OutQuint);
|
||||
}
|
||||
|
||||
public void UpdateOffset(float adjustment)
|
||||
{
|
||||
boxAdjustment.ResizeHeightTo(Math.Clamp(adjustment / maxValue, 0.05f, 1), duration, Easing.OutQuint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user