mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 12:17:46 +08:00
Flexible cube count (and thus graph height).
This also scaled the graph to the height of the maximum value. And much tidying.
This commit is contained in:
parent
3b21340e1b
commit
1071645dca
@ -53,7 +53,9 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
public SongProgress()
|
public SongProgress()
|
||||||
{
|
{
|
||||||
Height = bottom_bar_height + SquareGraph.Column.HEIGHT + handle_size.Y;
|
const float graph_height = SquareGraph.Column.WIDTH * 6;
|
||||||
|
|
||||||
|
Height = bottom_bar_height + graph_height + handle_size.Y;
|
||||||
Y = bottom_bar_height;
|
Y = bottom_bar_height;
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
@ -63,10 +65,10 @@ namespace osu.Game.Screens.Play
|
|||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Origin = Anchor.BottomLeft,
|
Origin = Anchor.BottomLeft,
|
||||||
Anchor = Anchor.BottomLeft,
|
Anchor = Anchor.BottomLeft,
|
||||||
Height = SquareGraph.Column.HEIGHT,
|
Height = graph_height,
|
||||||
Margin = new MarginPadding { Bottom = bottom_bar_height },
|
Margin = new MarginPadding { Bottom = bottom_bar_height },
|
||||||
},
|
},
|
||||||
bar = new SongProgressBar(bottom_bar_height, SquareGraph.Column.HEIGHT, handle_size)
|
bar = new SongProgressBar(bottom_bar_height, graph_height, handle_size)
|
||||||
{
|
{
|
||||||
Alpha = 0,
|
Alpha = 0,
|
||||||
Anchor = Anchor.BottomLeft,
|
Anchor = Anchor.BottomLeft,
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework;
|
using osu.Framework;
|
||||||
|
using osu.Framework.Caching;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -34,7 +35,8 @@ namespace osu.Game.Screens.Play
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int[] calculatedValues = { }; // values but adjusted to fit the amount of columns
|
private float[] calculatedValues = { }; // values but adjusted to fit the amount of columns
|
||||||
|
|
||||||
private int[] values;
|
private int[] values;
|
||||||
public int[] Values
|
public int[] Values
|
||||||
{
|
{
|
||||||
@ -66,15 +68,19 @@ namespace osu.Game.Screens.Play
|
|||||||
PixelSnapping = true;
|
PixelSnapping = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private float lastDrawWidth;
|
private Cached layout = new Cached();
|
||||||
|
|
||||||
|
public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
|
||||||
|
{
|
||||||
|
if ((invalidation & Invalidation.SizeInParentSpace) > 0)
|
||||||
|
layout.Invalidate();
|
||||||
|
return base.Invalidate(invalidation, source, shallPropagate);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
|
layout.Refresh(recreateGraph);
|
||||||
// todo: Recreating in update is probably not the best idea
|
|
||||||
if (DrawWidth == lastDrawWidth) return;
|
|
||||||
recreateGraph();
|
|
||||||
lastDrawWidth = DrawWidth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -106,7 +112,7 @@ namespace osu.Game.Screens.Play
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void recalculateValues()
|
private void recalculateValues()
|
||||||
{
|
{
|
||||||
var newValues = new List<int>();
|
var newValues = new List<float>();
|
||||||
|
|
||||||
if (values == null)
|
if (values == null)
|
||||||
{
|
{
|
||||||
@ -116,10 +122,12 @@ namespace osu.Game.Screens.Play
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var max = values.Max();
|
||||||
|
|
||||||
float step = values.Length / (float)ColumnCount;
|
float step = values.Length / (float)ColumnCount;
|
||||||
for (float i = 0; i < values.Length; i += step)
|
for (float i = 0; i < values.Length; i += step)
|
||||||
{
|
{
|
||||||
newValues.Add(values[(int)i]);
|
newValues.Add((float)values[(int)i] / max);
|
||||||
}
|
}
|
||||||
|
|
||||||
calculatedValues = newValues.ToArray();
|
calculatedValues = newValues.ToArray();
|
||||||
@ -138,6 +146,7 @@ namespace osu.Game.Screens.Play
|
|||||||
{
|
{
|
||||||
Anchor = Anchor.BottomLeft,
|
Anchor = Anchor.BottomLeft,
|
||||||
Origin = Anchor.BottomLeft,
|
Origin = Anchor.BottomLeft,
|
||||||
|
Height = DrawHeight,
|
||||||
Position = new Vector2(x, 0),
|
Position = new Vector2(x, 0),
|
||||||
State = ColumnState.Dimmed,
|
State = ColumnState.Dimmed,
|
||||||
});
|
});
|
||||||
@ -157,16 +166,15 @@ namespace osu.Game.Screens.Play
|
|||||||
private readonly Color4 litColour;
|
private readonly Color4 litColour;
|
||||||
private readonly Color4 dimmedColour = Color4.White.Opacity(175);
|
private readonly Color4 dimmedColour = Color4.White.Opacity(175);
|
||||||
|
|
||||||
private const float cube_count = 6;
|
private float cubeCount => DrawHeight / WIDTH;
|
||||||
private const float cube_size = 4;
|
private const float cube_size = 4;
|
||||||
private const float padding = 2;
|
private const float padding = 2;
|
||||||
public const float WIDTH = cube_size + padding;
|
public const float WIDTH = cube_size + padding;
|
||||||
public const float HEIGHT = cube_count * WIDTH + padding;
|
|
||||||
|
|
||||||
private readonly List<Box> drawableRows = new List<Box>();
|
private readonly List<Box> drawableRows = new List<Box>();
|
||||||
|
|
||||||
private int filled;
|
private float filled;
|
||||||
public int Filled
|
public float Filled
|
||||||
{
|
{
|
||||||
get { return filled; }
|
get { return filled; }
|
||||||
set
|
set
|
||||||
@ -193,10 +201,13 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
public Column(Color4 litColour)
|
public Column(Color4 litColour)
|
||||||
{
|
{
|
||||||
Size = new Vector2(WIDTH, HEIGHT);
|
Width = WIDTH;
|
||||||
this.litColour = litColour;
|
this.litColour = litColour;
|
||||||
|
}
|
||||||
|
|
||||||
for (int r = 0; r < cube_count; r++)
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
for (int r = 0; r < cubeCount; r++)
|
||||||
{
|
{
|
||||||
drawableRows.Add(new Box
|
drawableRows.Add(new Box
|
||||||
{
|
{
|
||||||
@ -210,19 +221,18 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
// Reverse drawableRows so when iterating through them they start at the bottom
|
// Reverse drawableRows so when iterating through them they start at the bottom
|
||||||
drawableRows.Reverse();
|
drawableRows.Reverse();
|
||||||
|
|
||||||
|
fillActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillActive()
|
private void fillActive()
|
||||||
{
|
{
|
||||||
Color4 colour = State == ColumnState.Lit ? litColour : dimmedColour;
|
Color4 colour = State == ColumnState.Lit ? litColour : dimmedColour;
|
||||||
|
|
||||||
|
int countFilled = (int)MathHelper.Clamp(filled * drawableRows.Count, 0, drawableRows.Count);
|
||||||
|
|
||||||
for (int i = 0; i < drawableRows.Count; i++)
|
for (int i = 0; i < drawableRows.Count; i++)
|
||||||
{
|
drawableRows[i].Colour = i < countFilled ? colour : emptyColour;
|
||||||
if (Filled == 0) // i <= Filled doesn't work for zero fill
|
|
||||||
drawableRows[i].Colour = emptyColour;
|
|
||||||
else
|
|
||||||
drawableRows[i].Colour = i <= Filled ? colour : emptyColour;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user