mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 03:22:55 +08:00
Cleaning
This commit is contained in:
parent
4d61424abd
commit
0337f18fb9
@ -56,6 +56,7 @@ namespace osu.Game.Modes.UI
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Depth = -2, //make it on top of the pause overlay
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -3,72 +3,53 @@
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.Graphics.Transforms;
|
||||
using System;
|
||||
|
||||
namespace osu.Game.Screens.Play
|
||||
{
|
||||
public class SongProgress : OverlayContainer
|
||||
{
|
||||
public static readonly int BAR_HEIGHT = 5;
|
||||
public static readonly int GRAPH_HEIGHT = 34;
|
||||
public static readonly Color4 FILL_COLOUR = new Color4(221, 255, 255, 255);
|
||||
public static readonly Color4 GLOW_COLOUR = new Color4(221, 255, 255, 150);
|
||||
private const float progress_transition_duration = 100;
|
||||
private readonly int bar_height = 5;
|
||||
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 SongProgressBar progress;
|
||||
private SongProgressBar bar;
|
||||
private SongProgressGraph graph;
|
||||
private WorkingBeatmap current;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase osuGame)
|
||||
{
|
||||
current = osuGame.Beatmap.Value;
|
||||
}
|
||||
public Action<double> OnSeek;
|
||||
|
||||
protected override void Update()
|
||||
private double currentTime;
|
||||
public double CurrentTime
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (current?.TrackLoaded ?? false)
|
||||
get { return currentTime; }
|
||||
set
|
||||
{
|
||||
float currentProgress = (float)(current.Track.CurrentTime / current.Track.Length);
|
||||
|
||||
progress.IsEnabled = true;
|
||||
progress.UpdatePosition(currentProgress);
|
||||
graph.Progress = (int)(graph.ColumnCount * currentProgress);
|
||||
}
|
||||
else
|
||||
{
|
||||
progress.IsEnabled = false;
|
||||
currentTime = value;
|
||||
updateProgress();
|
||||
}
|
||||
}
|
||||
|
||||
public void DisplayValues(int[] values)
|
||||
private double duration;
|
||||
public double Duration
|
||||
{
|
||||
graph.Values = values;
|
||||
get { return duration; }
|
||||
set
|
||||
{
|
||||
duration = value;
|
||||
updateProgress();
|
||||
}
|
||||
|
||||
protected override void PopIn()
|
||||
{
|
||||
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()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = BAR_HEIGHT + GRAPH_HEIGHT + SongProgressBar.HANDLE_SIZE.Y;
|
||||
Height = bar_height + graph_height + handle_size.Y;
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
@ -77,23 +58,47 @@ namespace osu.Game.Screens.Play
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Origin = Anchor.BottomCentre,
|
||||
Anchor = Anchor.BottomCentre,
|
||||
Height = GRAPH_HEIGHT,
|
||||
Height = graph_height,
|
||||
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,
|
||||
Anchor = Anchor.BottomCentre,
|
||||
Height = bar_height,
|
||||
SeekRequested = delegate (float position)
|
||||
{
|
||||
current?.Track?.Seek(current.Track.Length * position);
|
||||
current?.Track?.Start();
|
||||
OnSeek?.Invoke(Duration * position);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,12 +12,9 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
public class SongProgressBar : DragBar
|
||||
{
|
||||
public static readonly Vector2 HANDLE_SIZE = new Vector2(14, 25);
|
||||
|
||||
public SongProgressBar()
|
||||
public SongProgressBar(float barHeight, Vector2 handleSize, Color4 fillColour)
|
||||
{
|
||||
Fill.Colour = SongProgress.FILL_COLOUR;
|
||||
Height = SongProgress.BAR_HEIGHT;
|
||||
Fill.Colour = fillColour;
|
||||
|
||||
Add(new Box
|
||||
{
|
||||
@ -31,7 +28,7 @@ namespace osu.Game.Screens.Play
|
||||
Origin = Anchor.BottomRight,
|
||||
Anchor = Anchor.BottomRight,
|
||||
Width = 2,
|
||||
Height = SongProgress.BAR_HEIGHT + SongProgress.GRAPH_HEIGHT,
|
||||
Height = barHeight,
|
||||
Colour = Color4.White,
|
||||
Position = new Vector2(2, 0),
|
||||
Children = new Drawable[]
|
||||
@ -44,7 +41,7 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
Origin = Anchor.BottomCentre,
|
||||
Anchor = Anchor.TopCentre,
|
||||
Size = HANDLE_SIZE,
|
||||
Size = handleSize,
|
||||
CornerRadius = 5,
|
||||
Masking = true,
|
||||
Children = new Drawable[]
|
||||
|
@ -4,24 +4,26 @@
|
||||
using OpenTK;
|
||||
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;
|
||||
|
||||
namespace osu.Game.Screens.Play
|
||||
{
|
||||
public class SongProgressGraph : BufferedContainer
|
||||
{
|
||||
private List<SongProgressGraphColumn> columns = new List<SongProgressGraphColumn>();
|
||||
private Column[] columns;
|
||||
private float lastDrawWidth;
|
||||
|
||||
public int ColumnCount => columns.Length;
|
||||
|
||||
public override bool HandleInput => false;
|
||||
public int ColumnCount => columns.Count;
|
||||
|
||||
private int progress;
|
||||
public int Progress
|
||||
{
|
||||
get
|
||||
{
|
||||
return progress;
|
||||
}
|
||||
get { return progress; }
|
||||
set
|
||||
{
|
||||
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;
|
||||
public int[] Values
|
||||
{
|
||||
get
|
||||
{
|
||||
return values;
|
||||
}
|
||||
get { return values; }
|
||||
set
|
||||
{
|
||||
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()
|
||||
{
|
||||
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;
|
||||
}
|
||||
@ -57,28 +75,29 @@ namespace osu.Game.Screens.Play
|
||||
ForceRedraw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redraws the filled amount of all the columns.
|
||||
/// </summary>
|
||||
private void redrawFilled()
|
||||
{
|
||||
for (int i = 0; i < ColumnCount; 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()
|
||||
{
|
||||
// Resizes values to fit the amount of columns and stores it in calculatedValues
|
||||
// Defaults to all zeros if values is null
|
||||
|
||||
calculatedValues.RemoveAll(delegate { return true; });
|
||||
var newValues = new List<int>();
|
||||
|
||||
if (values == null)
|
||||
{
|
||||
for (float i = 0; i < ColumnCount; i++)
|
||||
{
|
||||
calculatedValues.Add(0);
|
||||
newValues.Add(0);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -87,44 +106,112 @@ namespace osu.Game.Screens.Play
|
||||
float step = values.Length / (float)ColumnCount;
|
||||
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()
|
||||
{
|
||||
RemoveAll(delegate { return true; });
|
||||
columns.RemoveAll(delegate { return true; });
|
||||
var newColumns = new List<Column>();
|
||||
|
||||
for (int x = 0; x < DrawWidth; x += 3)
|
||||
{
|
||||
columns.Add(new SongProgressGraphColumn
|
||||
newColumns.Add(new Column
|
||||
{
|
||||
Position = new Vector2(x + 1, 0),
|
||||
State = ColumnState.Dimmed,
|
||||
});
|
||||
|
||||
Add(columns[columns.Count - 1]);
|
||||
}
|
||||
|
||||
columns = newColumns.ToArray();
|
||||
Children = columns;
|
||||
|
||||
recalculateValues();
|
||||
redrawFilled();
|
||||
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;
|
||||
recreateGraph();
|
||||
lastDrawWidth = DrawWidth;
|
||||
private List<Box> drawableRows = new List<Box>();
|
||||
|
||||
private int filled;
|
||||
public int Filled
|
||||
{
|
||||
get { return filled; }
|
||||
set
|
||||
{
|
||||
if (value == filled) return;
|
||||
filled = value;
|
||||
|
||||
fillActive();
|
||||
}
|
||||
}
|
||||
|
||||
public SongProgressGraph()
|
||||
private ColumnState state;
|
||||
public ColumnState State
|
||||
{
|
||||
CacheDrawnFrameBuffer = true;
|
||||
PixelSnapping = true;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum ColumnState
|
||||
{
|
||||
Lit,
|
||||
Dimmed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
@ -333,7 +333,6 @@
|
||||
<Compile Include="Screens\Select\Footer.cs" />
|
||||
<Compile Include="Screens\Play\SongProgress.cs" />
|
||||
<Compile Include="Screens\Play\SongProgressGraph.cs" />
|
||||
<Compile Include="Screens\Play\SongProgressGraphColumn.cs" />
|
||||
<Compile Include="Screens\Play\SongProgressBar.cs" />
|
||||
<Compile Include="Screens\Play\PauseOverlay.cs" />
|
||||
<Compile Include="Screens\Play\Pause\PauseProgressBar.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user