2017-02-08 01:26:17 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using OpenTK;
|
2017-02-07 13:49:41 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2017-02-08 01:02:56 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-02-04 03:22:02 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2017-02-07 13:49:41 +08:00
|
|
|
|
public class SongProgressGraph : BufferedContainer
|
2017-02-04 03:22:02 +08:00
|
|
|
|
{
|
2017-02-07 13:49:41 +08:00
|
|
|
|
private List<SongProgressGraphColumn> columns = new List<SongProgressGraphColumn>();
|
2017-02-08 01:02:56 +08:00
|
|
|
|
private float lastDrawWidth;
|
2017-02-07 13:49:41 +08:00
|
|
|
|
|
|
|
|
|
public override bool HandleInput => false;
|
|
|
|
|
|
|
|
|
|
private float progress;
|
|
|
|
|
public float Progress
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return progress;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == progress) return;
|
|
|
|
|
progress = value;
|
|
|
|
|
|
2017-02-08 01:02:56 +08:00
|
|
|
|
redrawProgress();
|
2017-02-07 13:49:41 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-08 01:02:56 +08:00
|
|
|
|
private void redrawProgress()
|
2017-02-07 13:49:41 +08:00
|
|
|
|
{
|
2017-02-08 01:02:56 +08:00
|
|
|
|
for (int i = 0; i < columns.Count; i++)
|
2017-02-07 13:49:41 +08:00
|
|
|
|
{
|
2017-02-08 01:02:56 +08:00
|
|
|
|
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; });
|
2017-02-07 13:49:41 +08:00
|
|
|
|
|
2017-02-08 01:02:56 +08:00
|
|
|
|
// Random filled values used for testing
|
2017-02-07 13:49:41 +08:00
|
|
|
|
var random = new Random();
|
2017-02-08 01:02:56 +08:00
|
|
|
|
for (int column = 0; column < DrawWidth; column += 3)
|
2017-02-07 13:49:41 +08:00
|
|
|
|
{
|
|
|
|
|
columns.Add(new SongProgressGraphColumn
|
|
|
|
|
{
|
2017-02-08 01:02:56 +08:00
|
|
|
|
Position = new Vector2(column + 1, 0),
|
2017-02-07 13:49:41 +08:00
|
|
|
|
Filled = random.Next(1, 11),
|
2017-02-08 01:02:56 +08:00
|
|
|
|
State = ColumnState.Dimmed
|
2017-02-07 13:49:41 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Add(columns[columns.Count - 1]);
|
|
|
|
|
}
|
2017-02-08 01:02:56 +08:00
|
|
|
|
|
|
|
|
|
redrawProgress();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
if (DrawWidth == lastDrawWidth) return;
|
|
|
|
|
recreateGraph();
|
|
|
|
|
lastDrawWidth = DrawWidth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SongProgressGraph()
|
|
|
|
|
{
|
|
|
|
|
CacheDrawnFrameBuffer = true;
|
|
|
|
|
PixelSnapping = true;
|
2017-02-07 13:49:41 +08:00
|
|
|
|
}
|
2017-02-04 03:22:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|