1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 15:12:57 +08:00

Merge branch 'master' into resizable-chat

This commit is contained in:
Dan Balasescu 2017-05-12 19:46:11 +09:00 committed by GitHub
commit a5ff3f4d32
5 changed files with 128 additions and 7 deletions

View File

@ -18,10 +18,14 @@ namespace osu.Desktop.VisualTests.Tests
private SongProgress progress;
private SongProgressGraph graph;
private StopwatchClock clock;
public override void Reset()
{
base.Reset();
clock = new StopwatchClock(true);
Add(progress = new SongProgress
{
RelativeSizeAxes = Axes.X,
@ -55,6 +59,9 @@ namespace osu.Desktop.VisualTests.Tests
progress.Objects = objects;
graph.Objects = objects;
progress.AudioClock = clock;
progress.OnSeek = pos => clock.Seek(pos);
}
}
}

View File

@ -28,10 +28,12 @@ namespace osu.Game.Screens.Play
private readonly SongProgressBar bar;
private readonly SongProgressGraph graph;
private readonly SongProgressInfo info;
public Action<double> OnSeek;
public IClock AudioClock;
private IClock audioClock;
public IClock AudioClock { set { audioClock = info.AudioClock = value; } }
private double lastHitTime => ((objects.Last() as IHasEndTime)?.EndTime ?? objects.Last().StartTime) + 1;
@ -44,6 +46,9 @@ namespace osu.Game.Screens.Play
set
{
graph.Objects = objects = value;
info.StartTime = firstHitTime;
info.EndTime = lastHitTime;
}
}
@ -62,6 +67,14 @@ namespace osu.Game.Screens.Play
Children = new Drawable[]
{
info = new SongProgressInfo
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Margin = new MarginPadding { Bottom = bottom_bar_height + graph_height },
},
graph = new SongProgressGraph
{
RelativeSizeAxes = Axes.X,
@ -130,10 +143,13 @@ namespace osu.Game.Screens.Play
if (objects == null)
return;
double progress = ((AudioClock?.CurrentTime ?? Time.Current) - firstHitTime) / lastHitTime;
double progress = ((audioClock?.CurrentTime ?? Time.Current) - firstHitTime) / (lastHitTime - firstHitTime);
if(progress < 1)
{
bar.UpdatePosition((float)progress);
graph.Progress = (int)(graph.ColumnCount * progress);
}
}
}
}

View File

@ -20,12 +20,13 @@ namespace osu.Game.Screens.Play
const int granularity = 200;
var firstHit = objects.First().StartTime;
var lastHit = (objects.Last() as IHasEndTime)?.EndTime ?? 0;
if (lastHit == 0)
lastHit = objects.Last().StartTime;
var interval = (lastHit + 1) / granularity;
var interval = (lastHit - firstHit + 1) / granularity;
var values = new int[granularity];
@ -33,8 +34,8 @@ namespace osu.Game.Screens.Play
{
IHasEndTime end = h as IHasEndTime;
int startRange = (int)(h.StartTime / interval);
int endRange = (int)((end?.EndTime > 0 ? end.EndTime : h.StartTime) / interval);
int startRange = (int)((h.StartTime - firstHit)/ interval);
int endRange = (int)(((end?.EndTime > 0 ? end.EndTime : h.StartTime) - firstHit) / interval);
for (int i = startRange; i <= endRange; i++)
values[i]++;
}

View File

@ -0,0 +1,96 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Timing;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using System;
namespace osu.Game.Screens.Play
{
public class SongProgressInfo : Container
{
private OsuSpriteText timeCurrent;
private OsuSpriteText timeLeft;
private OsuSpriteText progress;
private double startTime;
private double endTime;
private int? previousPercent;
private int? previousSecond;
private double songLength => endTime - startTime;
private const int margin = 10;
public IClock AudioClock;
public double StartTime { set { startTime = value; } }
public double EndTime { set { endTime = value; } }
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Children = new Drawable[]
{
timeCurrent = new OsuSpriteText
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Colour = colours.BlueLighter,
Font = @"Venera",
Margin = new MarginPadding
{
Left = margin,
},
},
progress = new OsuSpriteText
{
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
Colour = colours.BlueLighter,
Font = @"Venera",
},
timeLeft = new OsuSpriteText
{
Origin = Anchor.BottomRight,
Anchor = Anchor.BottomRight,
Colour = colours.BlueLighter,
Font = @"Venera",
Margin = new MarginPadding
{
Right = margin,
},
}
};
}
protected override void Update()
{
base.Update();
double songCurrentTime = AudioClock.CurrentTime - startTime;
int currentPercent = Math.Max(0, Math.Min(100, (int)(songCurrentTime / songLength * 100)));
int currentSecond = (int)Math.Floor(songCurrentTime / 1000.0);
if (currentPercent != previousPercent)
{
progress.Text = currentPercent.ToString() + @"%";
previousPercent = currentPercent;
}
if (currentSecond != previousSecond && songCurrentTime < songLength)
{
timeCurrent.Text = TimeSpan.FromSeconds(currentSecond).ToString(songCurrentTime < 0 ? @"\-m\:ss" : @"m\:ss");
timeLeft.Text = TimeSpan.FromMilliseconds(endTime - AudioClock.CurrentTime).ToString(@"\-m\:ss");
previousSecond = currentSecond;
}
}
}
}

View File

@ -227,6 +227,7 @@
<Compile Include="Screens\Charts\ChartInfo.cs" />
<Compile Include="Screens\Edit\Editor.cs" />
<Compile Include="Screens\Play\HotkeyRetryOverlay.cs" />
<Compile Include="Screens\Play\SongProgressInfo.cs" />
<Compile Include="Screens\Play\HUD\ModDisplay.cs" />
<Compile Include="Screens\Play\SquareGraph.cs" />
<Compile Include="Screens\Play\StandardHUDOverlay.cs" />