mirror of
https://github.com/osukey/osukey.git
synced 2025-05-29 09:27:18 +09:00
refactor(SegmentedGraph): use (get/set)ters to expose TierColour
This commit is contained in:
parent
5694487a7b
commit
7cbc03dce6
@ -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());
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user