1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 09:12:54 +08:00
This commit is contained in:
DrabWeb 2017-03-23 06:37:12 -03:00
parent 4d61424abd
commit 0337f18fb9
6 changed files with 178 additions and 185 deletions

View File

@ -56,6 +56,7 @@ namespace osu.Game.Modes.UI
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Depth = -2, //make it on top of the pause overlay
}; };
} }
} }

View File

@ -3,72 +3,53 @@
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Game.Beatmaps;
using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Transforms; using osu.Framework.Graphics.Transforms;
using System;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
public class SongProgress : OverlayContainer public class SongProgress : OverlayContainer
{ {
public static readonly int BAR_HEIGHT = 5; private readonly int bar_height = 5;
public static readonly int GRAPH_HEIGHT = 34; private readonly int graph_height = 34;
public static readonly Color4 FILL_COLOUR = new Color4(221, 255, 255, 255); private readonly Vector2 handle_size = new Vector2(14, 25);
public static readonly Color4 GLOW_COLOUR = new Color4(221, 255, 255, 150); private readonly Color4 fill_colour = new Color4(221, 255, 255, 255);
private const float progress_transition_duration = 100; private const float transition_duration = 100;
private SongProgressBar progress; private SongProgressBar bar;
private SongProgressGraph graph; private SongProgressGraph graph;
private WorkingBeatmap current;
[BackgroundDependencyLoader] public Action<double> OnSeek;
private void load(OsuGameBase osuGame)
private double currentTime;
public double CurrentTime
{ {
current = osuGame.Beatmap.Value; get { return currentTime; }
} set
protected override void Update()
{
base.Update();
if (current?.TrackLoaded ?? false)
{ {
float currentProgress = (float)(current.Track.CurrentTime / current.Track.Length); currentTime = value;
updateProgress();
progress.IsEnabled = true;
progress.UpdatePosition(currentProgress);
graph.Progress = (int)(graph.ColumnCount * currentProgress);
}
else
{
progress.IsEnabled = false;
} }
} }
public void DisplayValues(int[] values) private double duration;
public double Duration
{ {
graph.Values = values; get { return duration; }
} set
{
protected override void PopIn() duration = value;
{ updateProgress();
progress.FadeTo(1f, progress_transition_duration, EasingTypes.In); }
MoveTo(Vector2.Zero, progress_transition_duration, EasingTypes.In);
}
protected override void PopOut()
{
progress.FadeTo(0f, progress_transition_duration, EasingTypes.In);
MoveTo(new Vector2(0f, BAR_HEIGHT), progress_transition_duration, EasingTypes.In);
} }
public SongProgress() public SongProgress()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
Height = BAR_HEIGHT + GRAPH_HEIGHT + SongProgressBar.HANDLE_SIZE.Y; Height = bar_height + graph_height + handle_size.Y;
Children = new Drawable[] Children = new Drawable[]
{ {
@ -77,23 +58,47 @@ namespace osu.Game.Screens.Play
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Origin = Anchor.BottomCentre, Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre, Anchor = Anchor.BottomCentre,
Height = GRAPH_HEIGHT, Height = graph_height,
Margin = new MarginPadding Margin = new MarginPadding
{ {
Bottom = BAR_HEIGHT Bottom = bar_height
} }
}, },
progress = new SongProgressBar bar = new SongProgressBar(bar_height + graph_height, handle_size, fill_colour)
{ {
Origin = Anchor.BottomCentre, Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre, Anchor = Anchor.BottomCentre,
Height = bar_height,
SeekRequested = delegate (float position) SeekRequested = delegate (float position)
{ {
current?.Track?.Seek(current.Track.Length * position); OnSeek?.Invoke(Duration * position);
current?.Track?.Start();
} }
} }
}; };
} }
public void DisplayValues(int[] values)
{
graph.Values = values;
}
private void updateProgress()
{
float currentProgress = (float)(CurrentTime / Duration);
bar.UpdatePosition(currentProgress);
graph.Progress = (int)(graph.ColumnCount * currentProgress);
}
protected override void PopIn()
{
bar.FadeTo(1f, transition_duration, EasingTypes.In);
MoveTo(Vector2.Zero, transition_duration, EasingTypes.In);
}
protected override void PopOut()
{
bar.FadeTo(0f, transition_duration, EasingTypes.In);
MoveTo(new Vector2(0f, bar_height), transition_duration, EasingTypes.In);
}
} }
} }

View File

@ -12,12 +12,9 @@ namespace osu.Game.Screens.Play
{ {
public class SongProgressBar : DragBar public class SongProgressBar : DragBar
{ {
public static readonly Vector2 HANDLE_SIZE = new Vector2(14, 25); public SongProgressBar(float barHeight, Vector2 handleSize, Color4 fillColour)
public SongProgressBar()
{ {
Fill.Colour = SongProgress.FILL_COLOUR; Fill.Colour = fillColour;
Height = SongProgress.BAR_HEIGHT;
Add(new Box Add(new Box
{ {
@ -31,7 +28,7 @@ namespace osu.Game.Screens.Play
Origin = Anchor.BottomRight, Origin = Anchor.BottomRight,
Anchor = Anchor.BottomRight, Anchor = Anchor.BottomRight,
Width = 2, Width = 2,
Height = SongProgress.BAR_HEIGHT + SongProgress.GRAPH_HEIGHT, Height = barHeight,
Colour = Color4.White, Colour = Color4.White,
Position = new Vector2(2, 0), Position = new Vector2(2, 0),
Children = new Drawable[] Children = new Drawable[]
@ -44,7 +41,7 @@ namespace osu.Game.Screens.Play
{ {
Origin = Anchor.BottomCentre, Origin = Anchor.BottomCentre,
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Size = HANDLE_SIZE, Size = handleSize,
CornerRadius = 5, CornerRadius = 5,
Masking = true, Masking = true,
Children = new Drawable[] Children = new Drawable[]

View File

@ -4,24 +4,26 @@
using OpenTK; using OpenTK;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using OpenTK.Graphics;
using osu.Framework;
using osu.Framework.Extensions.Color4Extensions;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
public class SongProgressGraph : BufferedContainer public class SongProgressGraph : BufferedContainer
{ {
private List<SongProgressGraphColumn> columns = new List<SongProgressGraphColumn>(); private Column[] columns;
private float lastDrawWidth; private float lastDrawWidth;
public int ColumnCount => columns.Length;
public override bool HandleInput => false; public override bool HandleInput => false;
public int ColumnCount => columns.Count;
private int progress; private int progress;
public int Progress public int Progress
{ {
get get { return progress; }
{
return progress;
}
set set
{ {
if (value == progress) return; if (value == progress) return;
@ -31,14 +33,11 @@ namespace osu.Game.Screens.Play
} }
} }
private List<int> calculatedValues = new List<int>(); // values but adjusted to fit the amount of columns private int[] calculatedValues = { }; // values but adjusted to fit the amount of columns
private int[] values; private int[] values;
public int[] Values public int[] Values
{ {
get get { return values; }
{
return values;
}
set set
{ {
if (value == values) return; if (value == values) return;
@ -47,9 +46,28 @@ namespace osu.Game.Screens.Play
} }
} }
public SongProgressGraph()
{
CacheDrawnFrameBuffer = true;
PixelSnapping = true;
}
protected override void Update()
{
base.Update();
// todo: Recreating in update is probably not the best idea
if (DrawWidth == lastDrawWidth) return;
recreateGraph();
lastDrawWidth = DrawWidth;
}
/// <summary>
/// Redraws all the columns to match their lit/dimmed state.
/// </summary>
private void redrawProgress() private void redrawProgress()
{ {
for (int i = 0; i < columns.Count; i++) for (int i = 0; i < columns.Length; i++)
{ {
columns[i].State = i <= progress ? ColumnState.Lit : ColumnState.Dimmed; columns[i].State = i <= progress ? ColumnState.Lit : ColumnState.Dimmed;
} }
@ -57,28 +75,29 @@ namespace osu.Game.Screens.Play
ForceRedraw(); ForceRedraw();
} }
/// <summary>
/// Redraws the filled amount of all the columns.
/// </summary>
private void redrawFilled() private void redrawFilled()
{ {
for (int i = 0; i < ColumnCount; i++) for (int i = 0; i < ColumnCount; i++)
{ {
columns[i].Filled = calculatedValues[i]; columns[i].Filled = calculatedValues[i];
} }
ForceRedraw();
} }
/// <summary>
/// Takes <see cref="Values"> and adjusts it to fit the amount of columns.
/// </summary>
private void recalculateValues() private void recalculateValues()
{ {
// Resizes values to fit the amount of columns and stores it in calculatedValues var newValues = new List<int>();
// Defaults to all zeros if values is null
calculatedValues.RemoveAll(delegate { return true; });
if (values == null) if (values == null)
{ {
for (float i = 0; i < ColumnCount; i++) for (float i = 0; i < ColumnCount; i++)
{ {
calculatedValues.Add(0); newValues.Add(0);
} }
return; return;
@ -87,44 +106,112 @@ namespace osu.Game.Screens.Play
float step = values.Length / (float)ColumnCount; float step = values.Length / (float)ColumnCount;
for (float i = 0; i < values.Length; i += step) for (float i = 0; i < values.Length; i += step)
{ {
calculatedValues.Add(values[(int)i]); newValues.Add(values[(int)i]);
} }
calculatedValues = newValues.ToArray();
} }
/// <summary>
/// Recreates the entire graph.
/// </summary>
private void recreateGraph() private void recreateGraph()
{ {
RemoveAll(delegate { return true; }); var newColumns = new List<Column>();
columns.RemoveAll(delegate { return true; });
for (int x = 0; x < DrawWidth; x += 3) for (int x = 0; x < DrawWidth; x += 3)
{ {
columns.Add(new SongProgressGraphColumn newColumns.Add(new Column
{ {
Position = new Vector2(x + 1, 0), Position = new Vector2(x + 1, 0),
State = ColumnState.Dimmed, State = ColumnState.Dimmed,
}); });
Add(columns[columns.Count - 1]);
} }
columns = newColumns.ToArray();
Children = columns;
recalculateValues(); recalculateValues();
redrawFilled(); redrawFilled();
redrawProgress(); redrawProgress();
} }
protected override void Update() private class Column : Container, IStateful<ColumnState>
{ {
base.Update(); 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);
if (DrawWidth == lastDrawWidth) return; private List<Box> drawableRows = new List<Box>();
recreateGraph();
lastDrawWidth = DrawWidth; 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 Column()
{
Size = new Vector2(4, rows * 3);
for (int row = 0; row < rows * 3; row += 3)
{
drawableRows.Add(new Box
{
Size = new Vector2(2),
Position = new Vector2(0, row + 1)
});
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 SongProgressGraph() private enum ColumnState
{ {
CacheDrawnFrameBuffer = true; Lit,
PixelSnapping = true; Dimmed
} }
} }
} }

View File

@ -1,96 +0,0 @@
// 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 readonly int rows = 11;
private readonly Color4 emptyColour = Color4.White.Opacity(100);
private readonly Color4 litColour = SongProgress.FILL_COLOUR;
private readonly Color4 dimmedColour = Color4.White.Opacity(175);
private 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();
}
}
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 SongProgressGraphColumn()
{
Size = new Vector2(4, rows * 3);
for (int row = 0; row < rows * 3; row += 3)
{
drawableRows.Add(new Box
{
Size = new Vector2(2),
Position = new Vector2(0, row + 1)
});
Add(drawableRows[drawableRows.Count - 1]);
}
// Reverse drawableRows so when iterating through them they start at the bottom
drawableRows.Reverse();
}
}
public enum ColumnState
{
Lit,
Dimmed
}
}

View File

@ -333,7 +333,6 @@
<Compile Include="Screens\Select\Footer.cs" /> <Compile Include="Screens\Select\Footer.cs" />
<Compile Include="Screens\Play\SongProgress.cs" /> <Compile Include="Screens\Play\SongProgress.cs" />
<Compile Include="Screens\Play\SongProgressGraph.cs" /> <Compile Include="Screens\Play\SongProgressGraph.cs" />
<Compile Include="Screens\Play\SongProgressGraphColumn.cs" />
<Compile Include="Screens\Play\SongProgressBar.cs" /> <Compile Include="Screens\Play\SongProgressBar.cs" />
<Compile Include="Screens\Play\PauseOverlay.cs" /> <Compile Include="Screens\Play\PauseOverlay.cs" />
<Compile Include="Screens\Play\Pause\PauseProgressBar.cs" /> <Compile Include="Screens\Play\Pause\PauseProgressBar.cs" />