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