2017-09-21 03:33:07 +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 osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using System;
|
2017-10-05 09:38:13 +08:00
|
|
|
|
using osu.Game.Beatmaps.Timing;
|
2017-09-21 03:33:07 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.BreaksOverlay
|
|
|
|
|
{
|
2017-11-03 20:20:36 +08:00
|
|
|
|
public class RemainingTimeCounter : Container
|
2017-09-21 03:33:07 +08:00
|
|
|
|
{
|
2017-10-05 09:38:13 +08:00
|
|
|
|
private const double fade_duration = BreakPeriod.MIN_BREAK_DURATION / 2;
|
|
|
|
|
|
2017-09-21 03:33:07 +08:00
|
|
|
|
private readonly OsuSpriteText counter;
|
|
|
|
|
|
|
|
|
|
public RemainingTimeCounter()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
Child = counter = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
TextSize = 33,
|
|
|
|
|
Font = "Venera",
|
|
|
|
|
};
|
|
|
|
|
|
2017-11-03 20:20:36 +08:00
|
|
|
|
Alpha = 0;
|
2017-09-21 03:33:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-03 20:20:36 +08:00
|
|
|
|
public void CountTo(double duration)
|
2017-09-21 03:33:07 +08:00
|
|
|
|
{
|
2017-11-03 20:20:36 +08:00
|
|
|
|
double offset = 0;
|
2017-09-21 03:33:07 +08:00
|
|
|
|
|
2017-11-03 20:20:36 +08:00
|
|
|
|
while (duration > 0)
|
2017-09-21 03:33:07 +08:00
|
|
|
|
{
|
2017-11-03 20:20:36 +08:00
|
|
|
|
int seconds = (int)Math.Ceiling(duration / 1000);
|
|
|
|
|
counter.Delay(offset).TransformTextTo(seconds.ToString());
|
|
|
|
|
|
|
|
|
|
double localOffset = duration - (seconds - 1) * 1000 + 1; // +1 because we want the duration to be the next second when ceiled
|
|
|
|
|
|
|
|
|
|
offset += localOffset;
|
|
|
|
|
duration -= localOffset;
|
2017-09-21 03:33:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-05 09:38:13 +08:00
|
|
|
|
|
2017-11-03 20:20:36 +08:00
|
|
|
|
public override void Show() => this.FadeIn(fade_duration);
|
|
|
|
|
public override void Hide() => this.FadeOut(fade_duration);
|
2017-09-21 03:33:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|