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;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.BreaksOverlay
|
|
|
|
|
{
|
|
|
|
|
public class RemainingTimeCounter : Container
|
|
|
|
|
{
|
|
|
|
|
private readonly OsuSpriteText counter;
|
|
|
|
|
|
|
|
|
|
private int? previousSecond;
|
|
|
|
|
|
2017-09-27 06:10:48 +08:00
|
|
|
|
private double endTime;
|
2017-09-21 03:33:07 +08:00
|
|
|
|
|
|
|
|
|
private bool isCounting;
|
|
|
|
|
|
|
|
|
|
public RemainingTimeCounter()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
Alpha = 0;
|
|
|
|
|
Child = counter = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
TextSize = 33,
|
|
|
|
|
Font = "Venera",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 06:10:48 +08:00
|
|
|
|
public void StartCounting(double endTime)
|
2017-09-21 03:33:07 +08:00
|
|
|
|
{
|
2017-09-27 06:10:48 +08:00
|
|
|
|
this.endTime = endTime;
|
2017-09-21 03:33:07 +08:00
|
|
|
|
isCounting = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
if (isCounting)
|
|
|
|
|
{
|
|
|
|
|
var currentTime = Clock.CurrentTime;
|
2017-09-27 06:10:48 +08:00
|
|
|
|
if (currentTime < endTime)
|
2017-09-21 03:33:07 +08:00
|
|
|
|
{
|
2017-09-27 06:10:48 +08:00
|
|
|
|
int currentSecond = (int)Math.Floor((endTime - Clock.CurrentTime) / 1000.0);
|
2017-09-21 03:33:07 +08:00
|
|
|
|
if (currentSecond != previousSecond)
|
|
|
|
|
{
|
|
|
|
|
counter.Text = currentSecond.ToString();
|
|
|
|
|
previousSecond = currentSecond;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else isCounting = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|