1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 16:52:55 +08:00

Update visible triangles colour when dark or light colour is ch… (#7449)

Update visible triangles colour when dark or light colour is changed

Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
Dean Herbert 2020-01-07 10:48:45 +09:00 committed by GitHub
commit 63d0b09f96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,8 +29,33 @@ namespace osu.Game.Graphics.Backgrounds
/// </summary>
private const float edge_smoothness = 1;
public Color4 ColourLight = Color4.White;
public Color4 ColourDark = Color4.Black;
private Color4 colourLight = Color4.White;
public Color4 ColourLight
{
get => colourLight;
set
{
if (colourLight == value) return;
colourLight = value;
updateColours();
}
}
private Color4 colourDark = Color4.Black;
public Color4 ColourDark
{
get => colourDark;
set
{
if (colourDark == value) return;
colourDark = value;
updateColours();
}
}
/// <summary>
/// Whether we want to expire triangles as they exit our draw area completely.
@ -151,7 +176,8 @@ namespace osu.Game.Graphics.Backgrounds
TriangleParticle particle = CreateTriangle();
particle.Position = new Vector2(RNG.NextSingle(), randomY ? RNG.NextSingle() : 1);
particle.Colour = CreateTriangleShade();
particle.ColourShade = RNG.NextSingle();
particle.Colour = CreateTriangleShade(particle.ColourShade);
return particle;
}
@ -177,7 +203,17 @@ namespace osu.Game.Graphics.Backgrounds
/// Creates a shade of colour for the triangles.
/// </summary>
/// <returns>The colour.</returns>
protected virtual Color4 CreateTriangleShade() => Interpolation.ValueAt(RNG.NextSingle(), ColourDark, ColourLight, 0, 1);
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);
parts[i] = newParticle;
}
}
protected override DrawNode CreateDrawNode() => new TrianglesDrawNode(this);
@ -264,6 +300,12 @@ namespace osu.Game.Graphics.Backgrounds
/// </summary>
public Vector2 Position;
/// <summary>
/// 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;
/// <summary>
/// The colour of the triangle.
/// </summary>