Move colour generation to TriangleParticle

This commit is contained in:
Sebastian Krajewski 2020-01-06 12:51:38 +01:00
parent d1f3cb3dbd
commit de4c62788c

View File

@ -176,8 +176,7 @@ namespace osu.Game.Graphics.Backgrounds
TriangleParticle particle = CreateTriangle();
particle.Position = new Vector2(RNG.NextSingle(), randomY ? RNG.NextSingle() : 1);
particle.ColourShade = RNG.NextSingle();
particle.Colour = CreateTriangleShade(particle.ColourShade);
particle.UpdateColour(colourDark, colourLight);
return particle;
}
@ -199,18 +198,12 @@ namespace osu.Game.Graphics.Backgrounds
return new TriangleParticle { Scale = scale };
}
/// <summary>
/// Creates a shade of colour for the triangles.
/// </summary>
/// <returns>The colour.</returns>
protected virtual Color4 CreateTriangleShade(float shade) => Interpolation.ValueAt(shade, colourDark, colourLight, 0, 1);
private void updateColours()
{
for (int i = 0; i < parts.Count; i++)
{
TriangleParticle newParticle = parts[i];
newParticle.Colour = CreateTriangleShade(newParticle.ColourShade);
newParticle.UpdateColour(colourDark, colourLight);
parts[i] = newParticle;
}
}
@ -293,7 +286,7 @@ namespace osu.Game.Graphics.Backgrounds
}
}
protected struct TriangleParticle : IComparable<TriangleParticle>
protected class TriangleParticle : IComparable<TriangleParticle>
{
/// <summary>
/// The position of the top vertex of the triangle.
@ -304,7 +297,7 @@ namespace osu.Game.Graphics.Backgrounds
/// The colour shade of the triangle.
/// This is needed for colour recalculation of visible triangles when <see cref="ColourDark"/> or <see cref="ColourLight"/> is changed.
/// </summary>
public float ColourShade;
private readonly float colourShade = RNG.NextSingle();
/// <summary>
/// The colour of the triangle.
@ -316,6 +309,11 @@ namespace osu.Game.Graphics.Backgrounds
/// </summary>
public float Scale;
public void UpdateColour(Color4 colourDark, Color4 colourLight)
{
Colour = Interpolation.ValueAt(colourShade, colourDark, colourLight, 0, 1);
}
/// <summary>
/// Compares two <see cref="TriangleParticle"/>s. This is a reverse comparer because when the
/// triangles are added to the particles list, they should be drawn from largest to smallest