mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 08:02:55 +08:00
Further work on the progress graph, column states moved to an enum, SongProgressGraphColumnState -> ColumnState, graph can resize dynamically
This commit is contained in:
parent
3d0feb4de9
commit
dfc53be095
@ -5,6 +5,7 @@ using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
@ -119,6 +120,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
Anchor = Anchor.BottomRight,
|
||||
Width = 2,
|
||||
Height = bar_height + graph_height,
|
||||
Position = new Vector2(2, 0),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
|
@ -3,12 +3,14 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.Graphics;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public class SongProgressGraph : BufferedContainer
|
||||
{
|
||||
private List<SongProgressGraphColumn> columns = new List<SongProgressGraphColumn>();
|
||||
private float lastDrawWidth;
|
||||
|
||||
public override bool HandleInput => false;
|
||||
|
||||
@ -24,38 +26,55 @@ namespace osu.Game.Graphics.UserInterface
|
||||
if (value == progress) return;
|
||||
progress = value;
|
||||
|
||||
for (int i = 0; i < columns.Count; i++)
|
||||
{
|
||||
columns[i].State = i <= (columns.Count * progress) ? SongProgressGraphColumnState.Lit : SongProgressGraphColumnState.Dimmed;
|
||||
}
|
||||
|
||||
ForceRedraw();
|
||||
redrawProgress();
|
||||
}
|
||||
}
|
||||
|
||||
private void redrawProgress()
|
||||
{
|
||||
for (int i = 0; i < columns.Count; i++)
|
||||
{
|
||||
columns[i].State = i <= (columns.Count * progress) ? ColumnState.Lit : ColumnState.Dimmed;
|
||||
}
|
||||
|
||||
ForceRedraw();
|
||||
}
|
||||
|
||||
private void recreateGraph()
|
||||
{
|
||||
RemoveAll(delegate { return true; }, true);
|
||||
columns.RemoveAll(delegate { return true; });
|
||||
|
||||
// Random filled values used for testing
|
||||
var random = new Random();
|
||||
for (int column = 0; column < DrawWidth; column += 3)
|
||||
{
|
||||
columns.Add(new SongProgressGraphColumn
|
||||
{
|
||||
Position = new Vector2(column + 1, 0),
|
||||
Filled = random.Next(1, 11),
|
||||
State = ColumnState.Dimmed
|
||||
});
|
||||
|
||||
Add(columns[columns.Count - 1]);
|
||||
}
|
||||
|
||||
redrawProgress();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (DrawWidth == lastDrawWidth) return;
|
||||
recreateGraph();
|
||||
lastDrawWidth = DrawWidth;
|
||||
}
|
||||
|
||||
public SongProgressGraph()
|
||||
{
|
||||
CacheDrawnFrameBuffer = true;
|
||||
PixelSnapping = true;
|
||||
|
||||
Margin = new MarginPadding
|
||||
{
|
||||
Left = 1,
|
||||
Right = 1
|
||||
};
|
||||
|
||||
var random = new Random();
|
||||
for (int column = 0; column < 1200; column += 3)
|
||||
{
|
||||
columns.Add(new SongProgressGraphColumn
|
||||
{
|
||||
Position = new Vector2(column, 0),
|
||||
Filled = random.Next(1, 11),
|
||||
State = SongProgressGraphColumnState.Dimmed
|
||||
});
|
||||
|
||||
Add(columns[columns.Count - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ namespace osu.Game.Graphics.UserInterface
|
||||
}
|
||||
}
|
||||
|
||||
private SongProgressGraphColumnState state;
|
||||
public SongProgressGraphColumnState State
|
||||
private ColumnState state;
|
||||
public ColumnState State
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -42,7 +42,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
if (value == state) return;
|
||||
state = value;
|
||||
|
||||
fillActive(value == SongProgressGraphColumnState.Lit ? lit_colour : dimmed_colour);
|
||||
fillActive(value == ColumnState.Lit ? lit_colour : dimmed_colour);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
}
|
||||
}
|
||||
|
||||
public enum SongProgressGraphColumnState
|
||||
public enum ColumnState
|
||||
{
|
||||
Lit, Dimmed
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user