1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 21:57:55 +08:00
osu-lazer/osu.Game/Screens/Play/BreaksOverlay/RemainingTimeCounter.cs

66 lines
1.9 KiB
C#
Raw Normal View History

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-10-05 09:38:13 +08:00
public class RemainingTimeCounter : VisibilityContainer
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;
private int? previousSecond;
private double endTime;
2017-09-21 03:33:07 +08:00
private bool isCounting;
public RemainingTimeCounter()
{
AutoSizeAxes = Axes.Both;
Child = counter = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
TextSize = 33,
Font = "Venera",
};
}
public void StartCounting(double endTime)
2017-09-21 03:33:07 +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;
if (currentTime < endTime)
2017-09-21 03:33:07 +08:00
{
2017-10-02 04:38:11 +08:00
int currentSecond = (int)Math.Ceiling((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;
}
}
2017-10-05 09:38:13 +08:00
protected override void PopIn() => this.FadeIn(fade_duration);
protected override void PopOut() => this.FadeOut(fade_duration);
2017-09-21 03:33:07 +08:00
}
}