Added displaying given values to the graph

This commit is contained in:
DrabWeb
2017-02-09 18:51:05 -04:00
parent 7fea233181
commit 4d7766b92b
2 changed files with 62 additions and 9 deletions

View File

@ -11,6 +11,8 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Game.Overlays; using osu.Game.Overlays;
using System.Collections.Generic;
using System;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
@ -49,6 +51,11 @@ namespace osu.Game.Screens.Play
} }
} }
public void DisplayValues(List<int> values)
{
graph.Values = values;
}
public SongProgress() public SongProgress()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
@ -77,7 +84,18 @@ namespace osu.Game.Screens.Play
current?.Track?.Start(); current?.Track?.Start();
} }
} }
}; };
// TODO: Remove
var random = new Random();
List<int> newValues = new List<int>();
for (int i = 0; i < 1000; i++)
{
newValues.Add(random.Next(1, 11));
}
DisplayValues(newValues);
} }
} }
} }

View File

@ -2,11 +2,9 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK; using OpenTK;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using System;
using osu.Framework.Graphics;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
@ -34,6 +32,22 @@ namespace osu.Game.Screens.Play
} }
} }
private List<int> calculatedValues = new List<int>(); // values but adjusted to fit the amount of columns
private List<int> values;
public List<int> Values
{
get
{
return values;
}
set
{
if (value == values) return;
values = value;
recreateGraph();
}
}
private void redrawProgress() private void redrawProgress()
{ {
for (int i = 0; i < columns.Count; i++) for (int i = 0; i < columns.Count; i++)
@ -44,25 +58,46 @@ namespace osu.Game.Screens.Play
ForceRedraw(); ForceRedraw();
} }
private void redrawFilled()
{
for (int i = 0; i < ColumnCount; i++)
{
columns[i].Filled = calculatedValues[i];
}
ForceRedraw();
}
private void recalculateValues()
{
calculatedValues.RemoveAll(delegate { return true; });
float step = (float)values.Count / (float)ColumnCount;
for (float i = 0; i < values.Count; i += step)
{
calculatedValues.Add(values[(int)i]);
}
}
private void recreateGraph() private void recreateGraph()
{ {
RemoveAll(delegate { return true; }, true); RemoveAll(delegate { return true; }, true);
columns.RemoveAll(delegate { return true; }); columns.RemoveAll(delegate { return true; });
// Random filled values used for testing for now for (int x = 0; x < DrawWidth; x += 3)
var random = new Random();
for (int column = 0; column < DrawWidth; column += 3)
{ {
columns.Add(new SongProgressGraphColumn columns.Add(new SongProgressGraphColumn
{ {
Position = new Vector2(column + 1, 0), Position = new Vector2(x + 1, 0),
Filled = random.Next(1, 11),
State = ColumnState.Dimmed State = ColumnState.Dimmed
}); });
Add(columns[columns.Count - 1]); Add(columns[columns.Count - 1]);
} }
recalculateValues();
redrawFilled();
redrawProgress(); redrawProgress();
} }