1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-07 05:27:51 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/SongProgressGraph.cs

84 lines
2.3 KiB
C#
Raw Normal View History

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;
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>();
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;
redrawProgress();
2017-02-07 13:49:41 +08:00
}
}
private void redrawProgress()
2017-02-07 13:49:41 +08:00
{
for (int i = 0; i < columns.Count; i++)
2017-02-07 13:49:41 +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
// Random filled values used for testing
2017-02-07 13:49:41 +08:00
var random = new Random();
for (int column = 0; column < DrawWidth; column += 3)
2017-02-07 13:49:41 +08:00
{
columns.Add(new SongProgressGraphColumn
{
Position = new Vector2(column + 1, 0),
2017-02-07 13:49:41 +08:00
Filled = random.Next(1, 11),
State = ColumnState.Dimmed
2017-02-07 13:49:41 +08:00
});
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;
2017-02-07 13:49:41 +08:00
}
2017-02-04 03:22:02 +08:00
}
}