Make RemainingTimeCounter into a Counter

This commit is contained in:
smoogipoo 2017-11-06 14:58:05 +09:00
parent 4854302aaa
commit 2fbd490626
2 changed files with 6 additions and 18 deletions

View File

@ -7,6 +7,7 @@
using osu.Game.Beatmaps.Timing;
using osu.Game.Rulesets.Scoring;
using System.Collections.Generic;
using osu.Framework.Graphics.UserInterface;
namespace osu.Game.Screens.Play.BreaksOverlay
{
@ -115,7 +116,7 @@ private void initializeBreaks()
.Then()
.ResizeWidthTo(1);
remainingTimeCounter.CountTo(b.Duration);
remainingTimeCounter.CountTo(b.Duration).CountTo(0, b.Duration);
}
using (BeginAbsoluteSequence(b.StartTime))

View File

@ -6,10 +6,11 @@
using osu.Framework.Graphics;
using System;
using osu.Game.Beatmaps.Timing;
using osu.Framework.Graphics.UserInterface;
namespace osu.Game.Screens.Play.BreaksOverlay
{
public class RemainingTimeCounter : Container
public class RemainingTimeCounter : Counter
{
private const double fade_duration = BreakPeriod.MIN_BREAK_DURATION / 2;
@ -18,7 +19,7 @@ public class RemainingTimeCounter : Container
public RemainingTimeCounter()
{
AutoSizeAxes = Axes.Both;
Child = counter = new OsuSpriteText
InternalChild = counter = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
@ -29,21 +30,7 @@ public RemainingTimeCounter()
Alpha = 0;
}
public void CountTo(double duration)
{
double offset = 0;
while (duration > 0)
{
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;
}
}
protected override void OnCountChanged(double count) => counter.Text = ((int)Math.Ceiling(count / 1000)).ToString();
public override void Show() => this.FadeIn(fade_duration);
public override void Hide() => this.FadeOut(fade_duration);