refactor(SegmentedGraph): use (get/set)ters to expose TierColour

This commit is contained in:
tsrk 2023-01-12 10:13:16 +01:00
parent 5694487a7b
commit 7cbc03dce6
No known key found for this signature in database
GPG Key ID: EBD46BB3049B56D6
2 changed files with 44 additions and 9 deletions

View File

@ -10,7 +10,6 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osuTK;
using Vector4 = System.Numerics.Vector4;
namespace osu.Game.Tests.Visual.UserInterface
{
@ -22,7 +21,7 @@ namespace osu.Game.Tests.Visual.UserInterface
{
Children = new Drawable[]
{
graph = new SegmentedGraph<int>(10)
graph = new SegmentedGraph<int>(6)
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
@ -31,11 +30,15 @@ namespace osu.Game.Tests.Visual.UserInterface
},
};
for (int i = 0; i < graph.TierColours.Length; i++)
graph.TierColours = new[]
{
graph.TierColours[i] =
new Colour4(Vector4.Lerp(Colour4.Blue.Vector, Colour4.White.Vector, i * 1f / (graph.TierColours.Length - 1)));
}
Colour4.Red,
Colour4.OrangeRed,
Colour4.Orange,
Colour4.Yellow,
Colour4.YellowGreen,
Colour4.Green
};
AddStep("values from 1-10", () => graph.Values = Enumerable.Range(1, 10).ToArray());
AddStep("values from 1-100", () => graph.Values = Enumerable.Range(1, 100).ToArray());

View File

@ -29,7 +29,7 @@ namespace osu.Game.Graphics.UserInterface
public SegmentedGraph(int tierCount)
{
this.tierCount = tierCount;
TierColours = new Colour4[tierCount];
tierColours = new Colour4[tierCount];
segments = new SegmentManager(tierCount);
}
@ -45,7 +45,39 @@ namespace osu.Game.Graphics.UserInterface
}
}
public readonly Colour4[] TierColours;
private Colour4[] tierColours;
public Colour4[] TierColours
{
get => tierColours;
set
{
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];
}
graphNeedsUpdate = true;
}
}
private Texture texture = null!;
private IShader shader = null!;
@ -136,7 +168,7 @@ namespace osu.Game.Graphics.UserInterface
segments.Sort();
}
private Colour4 getTierColour(int tier) => tier >= 0 ? TierColours[tier] : new Colour4(0, 0, 0, 0);
private Colour4 getTierColour(int tier) => tier >= 0 ? tierColours[tier] : new Colour4(0, 0, 0, 0);
protected override DrawNode CreateDrawNode() => new SegmentedGraphDrawNode(this);