1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 11:42:56 +08:00

refactor(SegmentedGraph): adjust tierCount based on passed Colours

This commit is contained in:
tsrk 2023-01-12 10:57:12 +01:00
parent 7cbc03dce6
commit bb2ece5c71
No known key found for this signature in database
GPG Key ID: EBD46BB3049B56D6
2 changed files with 30 additions and 22 deletions

View File

@ -52,6 +52,28 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("beatmap density with granularity of 200", () => beatmapDensity());
AddStep("beatmap density with granularity of 300", () => beatmapDensity(300));
AddStep("reversed values from 1-10", () => graph.Values = Enumerable.Range(1, 10).Reverse().ToArray());
AddStep("change colour", () =>
{
graph.TierColours = new[]
{
Colour4.White,
Colour4.LightBlue,
Colour4.Aqua,
Colour4.Blue
};
});
AddStep("reset colour", () =>
{
graph.TierColours = new[]
{
Colour4.Red,
Colour4.OrangeRed,
Colour4.Orange,
Colour4.Yellow,
Colour4.YellowGreen,
Colour4.Green
};
});
}
private void sinFunction(int size = 100)

View File

@ -24,12 +24,15 @@ namespace osu.Game.Graphics.UserInterface
private int[] tiers = Array.Empty<int>();
private readonly SegmentManager segments;
private readonly int tierCount;
private int tierCount;
public SegmentedGraph(int tierCount)
public SegmentedGraph(int tierCount = 1)
{
this.tierCount = tierCount;
tierColours = new Colour4[tierCount];
tierColours = new[]
{
new Colour4(0, 0, 0, 0)
};
segments = new SegmentManager(tierCount);
}
@ -55,25 +58,8 @@ namespace osu.Game.Graphics.UserInterface
if (value.Length == 0 || value == tierColours)
return;
if (value.Length == tierCount)
{
tierColours = value;
}
else if (value.Length < tierCount)
{
var colourList = new List<Colour4>(value);
for (int i = value.Length; i < tierCount; i++)
{
colourList.Add(value.Last());
}
tierColours = colourList.ToArray();
}
else
{
tierColours = value[..tierCount];
}
tierCount = value.Length;
tierColours = value;
graphNeedsUpdate = true;
}