1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 08:02:55 +08:00

Merge branch 'song-progress-graph' of https://github.com/DrabWeb/osu into song-progress-graph

This commit is contained in:
DrabWeb 2017-03-23 07:15:53 -03:00
commit 546a3d0914
6 changed files with 162 additions and 33 deletions

View File

@ -21,9 +21,10 @@ namespace osu.Desktop.VisualTests.Tests
Add(progress = new SongProgress
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
RelativeSizeAxes = Axes.X
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
Length = 100,
});
AddButton("Toggle Bar", progress.ToggleVisibility);
@ -40,7 +41,8 @@ namespace osu.Desktop.VisualTests.Tests
newValues.Add(RNG.Next(0, 11));
}
progress.DisplayValues(newValues.ToArray());
progress.Values = newValues.ToArray();
progress.CurrentTime = RNG.Next(0, 100);
}
}
}

View File

@ -56,7 +56,8 @@ namespace osu.Game.Modes.UI
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
Depth = -2, //make it on top of the pause overlay
Depth = -2, //todo: find out why this doesn't put progress on top of PauseOverlay
Values = new int[] { 3 }, //todo: removeme
};
}
}

View File

@ -125,7 +125,8 @@ namespace osu.Game.Screens.Play
Depth = -1,
OnResume = delegate
{
hudOverlay.Progress.State = Visibility.Visible;
hudOverlay.Progress.Hide();
Delay(400);
Schedule(Resume);
},
@ -138,6 +139,7 @@ namespace osu.Game.Screens.Play
hitRenderer.InputManager.ReplayInputHandler = ReplayInputHandler;
hudOverlay.BindHitRenderer(hitRenderer);
hudOverlay.Progress.Length = Beatmap.Track.Length;
//bind HitRenderer to ScoreProcessor and ourselves (for a pass situation)
hitRenderer.OnAllJudged += onCompletion;
@ -165,6 +167,13 @@ namespace osu.Game.Screens.Play
};
}
protected override void Update()
{
base.Update();
hudOverlay.Progress.CurrentTime = Beatmap.Track.CurrentTime;
}
private void initializeSkipButton()
{
const double skip_required_cutoff = 3000;
@ -198,6 +207,7 @@ namespace osu.Game.Screens.Play
{
lastPauseActionTime = Time.Current;
hudOverlay.KeyCounter.IsCounting = false;
hudOverlay.Progress.Show();
pauseOverlay.Retries = RestartCount;
pauseOverlay.Show();
sourceClock.Stop();
@ -213,7 +223,7 @@ namespace osu.Game.Screens.Play
{
lastPauseActionTime = Time.Current;
hudOverlay.KeyCounter.IsCounting = true;
hudOverlay.Progress.State = Visibility.Hidden;
hudOverlay.Progress.Hide();
pauseOverlay.Hide();
sourceClock.Start();
IsPaused = false;

View File

@ -17,7 +17,7 @@ namespace osu.Game.Screens.Play
private readonly int graph_height = 34;
private readonly Vector2 handle_size = new Vector2(14, 25);
private readonly Color4 fill_colour = new Color4(221, 255, 255, 255);
private const float transition_duration = 100;
private const float transition_duration = 200;
private SongProgressBar bar;
private SongProgressGraph graph;
@ -35,21 +35,27 @@ namespace osu.Game.Screens.Play
}
}
private double duration;
public double Duration
private double length;
public double Length
{
get { return duration; }
get { return length; }
set
{
duration = value;
length = value;
updateProgress();
}
}
public int[] Values
{
get { return graph.Values; }
set { graph.Values = value; }
}
public SongProgress()
{
RelativeSizeAxes = Axes.X;
Height = bar_height + graph_height + handle_size.Y;
Height = bar_height + graph_height + SongProgressGraph.Column.HEIGHT + handle_size.Y;
Children = new Drawable[]
{
@ -71,32 +77,31 @@ namespace osu.Game.Screens.Play
Height = bar_height,
SeekRequested = delegate (float position)
{
OnSeek?.Invoke(Duration * position);
OnSeek?.Invoke(Length * position);
}
}
};
}
public void DisplayValues(int[] values)
{
graph.Values = values;
}
private void updateProgress()
{
float currentProgress = (float)(CurrentTime / Duration);
float currentProgress = (float)(CurrentTime / Length);
bar.UpdatePosition(currentProgress);
graph.Progress = (int)(graph.ColumnCount * currentProgress);
}
protected override void PopIn()
{
bar.IsEnabled = true;
updateProgress(); //in case progress was changed while the bar was hidden
bar.FadeTo(1f, transition_duration, EasingTypes.In);
MoveTo(Vector2.Zero, transition_duration, EasingTypes.In);
}
protected override void PopOut()
{
bar.IsEnabled = false;
bar.FadeTo(0f, transition_duration, EasingTypes.In);
MoveTo(new Vector2(0f, bar_height), transition_duration, EasingTypes.In);
}

View File

@ -2,10 +2,11 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using OpenTK.Graphics;
using System.Linq;
using System.Collections.Generic;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using OpenTK.Graphics;
using osu.Framework;
using osu.Framework.Extensions.Color4Extensions;
@ -13,7 +14,7 @@ namespace osu.Game.Screens.Play
{
public class SongProgressGraph : BufferedContainer
{
private Column[] columns;
private Column[] columns = { };
private float lastDrawWidth;
public int ColumnCount => columns.Length;
@ -82,7 +83,7 @@ namespace osu.Game.Screens.Play
{
for (int i = 0; i < ColumnCount; i++)
{
columns[i].Filled = calculatedValues[i];
columns[i].Filled = calculatedValues.ElementAtOrDefault(i);
}
}
@ -119,11 +120,11 @@ namespace osu.Game.Screens.Play
{
var newColumns = new List<Column>();
for (int x = 0; x < DrawWidth; x += 3)
for (float x = 0; x < DrawWidth; x += Column.WIDTH)
{
newColumns.Add(new Column
{
Position = new Vector2(x + 1, 0),
Position = new Vector2(x, 0),
State = ColumnState.Dimmed,
});
}
@ -136,14 +137,19 @@ namespace osu.Game.Screens.Play
redrawProgress();
}
private class Column : Container, IStateful<ColumnState>
public class Column : Container, IStateful<ColumnState>
{
private readonly int rows = 11;
private readonly Color4 emptyColour = Color4.White.Opacity(100);
private readonly Color4 litColour = new Color4(221, 255, 255, 255);
private readonly Color4 dimmedColour = Color4.White.Opacity(175);
private List<Box> drawableRows = new List<Box>();
private const float cube_count = 6;
private const float cube_size = 4;
private const float padding = 2;
public const float WIDTH = cube_size + padding;
public const float HEIGHT = cube_count * WIDTH;
private readonly List<Box> drawableRows = new List<Box>();
private int filled;
public int Filled
@ -173,14 +179,15 @@ namespace osu.Game.Screens.Play
public Column()
{
Size = new Vector2(4, rows * 3);
Size = new Vector2(WIDTH, HEIGHT);
for (int row = 0; row < rows * 3; row += 3)
for (int r = 0; r<cube_count; r++)
{
drawableRows.Add(new Box
{
Size = new Vector2(2),
Position = new Vector2(0, row + 1)
EdgeSmoothness = new Vector2(padding / 4),
Size = new Vector2(cube_size),
Position = new Vector2(0, r* WIDTH + padding)
});
Add(drawableRows[drawableRows.Count - 1]);
@ -208,7 +215,7 @@ namespace osu.Game.Screens.Play
}
}
private enum ColumnState
public enum ColumnState
{
Lit,
Dimmed

View File

@ -0,0 +1,104 @@
// 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;
using OpenTK.Graphics;
using System.Collections.Generic;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Extensions.Color4Extensions;
namespace osu.Game.Screens.Play
{
public class SongProgressGraphColumn : Container
{
private const float cube_count = 6;
private const float cube_size = 4;
private const float padding = 2;
public const float WIDTH = cube_size + padding;
public const float HEIGHT = cube_count * WIDTH;
private readonly Color4 emptyColour = Color4.White.Opacity(100);
private readonly Color4 litColour = SongProgress.FILL_COLOUR;
private readonly Color4 dimmedColour = Color4.White.Opacity(175);
private readonly List<Box> drawableRows = new List<Box>();
private int filled;
public int Filled
{
get
{
return filled;
}
set
{
if (value == filled) return;
filled = value;
fillActive();
}
}
private ColumnState state;
public ColumnState State
{
get
{
return state;
}
set
{
if (value == state) return;
state = value;
fillActive();
}
}
public SongProgressGraphColumn()
{
Size = new Vector2(WIDTH, HEIGHT);
for (int r = 0; r < cube_count; r++)
{
drawableRows.Add(new Box
{
EdgeSmoothness = new Vector2(padding / 4),
Size = new Vector2(cube_size),
Position = new Vector2(0, r * WIDTH + padding)
});
Add(drawableRows[drawableRows.Count - 1]);
}
// Reverse drawableRows so when iterating through them they start at the bottom
drawableRows.Reverse();
}
private void fillActive()
{
Color4 colour = State == ColumnState.Lit ? litColour : dimmedColour;
for (int i = 0; i < drawableRows.Count; i++)
{
if (Filled == 0) // i <= Filled doesn't work for zero fill
{
drawableRows[i].Colour = emptyColour;
}
else
{
drawableRows[i].Colour = i <= Filled ? colour : emptyColour;
}
}
}
}
public enum ColumnState
{
Lit,
Dimmed
}
}