1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Add countdown display

This commit is contained in:
Dan Balasescu 2024-03-04 16:08:25 +09:00
parent bce3bd55e5
commit 6635d9be04
No known key found for this signature in database
3 changed files with 178 additions and 4 deletions

View File

@ -17,6 +17,7 @@ using osu.Game.Rulesets.UI;
using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Scoring;
using osu.Game.Screens.Play;
using osuTK;
namespace osu.Game.Rulesets.Catch.UI
{
@ -54,6 +55,6 @@ namespace osu.Game.Rulesets.Catch.UI
public override DrawableHitObject<CatchHitObject>? CreateDrawableRepresentation(CatchHitObject h) => null;
protected override ResumeOverlay CreateResumeOverlay() => new DelayedResumeOverlay();
protected override ResumeOverlay CreateResumeOverlay() => new DelayedResumeOverlay { Scale = new Vector2(0.65f) };
}
}

View File

@ -0,0 +1,44 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Play;
using osu.Game.Tests.Gameplay;
namespace osu.Game.Tests.Visual.Gameplay
{
public partial class TestSceneDelayedResumeOverlay : OsuTestScene
{
private ResumeOverlay resume = null!;
private bool resumeFired;
[Cached]
private GameplayState gameplayState;
public TestSceneDelayedResumeOverlay()
{
gameplayState = TestGameplayState.Create(new OsuRuleset());
}
[SetUp]
public void SetUp() => Schedule(loadContent);
[Test]
public void TestResume()
{
AddStep("show", () => resume.Show());
AddUntilStep("dismissed", () => resumeFired && resume.State.Value == Visibility.Hidden);
}
private void loadContent()
{
Child = resume = new DelayedResumeOverlay();
resumeFired = false;
resume.ResumeAction = () => resumeFired = true;
}
}
}

View File

@ -1,8 +1,18 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Framework.Threading;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Play
{
@ -11,21 +21,140 @@ namespace osu.Game.Screens.Play
/// </summary>
public partial class DelayedResumeOverlay : ResumeOverlay
{
private const double countdown_time = 800;
protected override LocalisableString Message => string.Empty;
[Resolved]
private OsuColour colours { get; set; } = null!;
private ScheduledDelegate? scheduledResume;
private int countdownCount = 3;
private double countdownStartTime;
private Drawable content = null!;
private Drawable background = null!;
private SpriteText countdown = null!;
public DelayedResumeOverlay()
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
}
[BackgroundDependencyLoader]
private void load()
{
Add(content = new CircularContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Masking = true,
BorderColour = colours.Yellow,
BorderThickness = 1,
Children = new[]
{
background = new Box
{
Size = new Vector2(250, 40),
Colour = Color4.Black,
Alpha = 0.8f
},
new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(5),
Colour = colours.Yellow,
Children = new Drawable[]
{
// new Box
// {
// Anchor = Anchor.Centre,
// Origin = Anchor.Centre,
// Size = new Vector2(40, 3)
// },
countdown = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
UseFullGlyphHeight = false,
AlwaysPresent = true,
Font = OsuFont.Numeric.With(size: 20, fixedWidth: true)
},
// new Box
// {
// Anchor = Anchor.Centre,
// Origin = Anchor.Centre,
// Size = new Vector2(40, 3)
// }
}
}
}
}
}
});
}
protected override void PopIn()
{
base.PopIn();
this.FadeIn();
content.FadeInFromZero(150, Easing.OutQuint);
content.ScaleTo(new Vector2(1.5f, 1)).Then().ScaleTo(1, 150, Easing.OutElasticQuarter);
countdownCount = 3;
countdownStartTime = Time.Current;
scheduledResume?.Cancel();
scheduledResume = Scheduler.AddDelayed(Resume, 800);
scheduledResume = Scheduler.AddDelayed(Resume, countdown_time);
}
protected override void Update()
{
base.Update();
updateCountdown();
}
private void updateCountdown()
{
double amountTimePassed = Math.Min(countdown_time, Time.Current - countdownStartTime) / countdown_time;
int newCount = 3 - (int)Math.Floor(amountTimePassed * 3);
if (newCount > 0)
{
countdown.Alpha = 1;
countdown.Text = newCount.ToString();
}
else
countdown.Alpha = 0;
if (newCount != countdownCount)
{
if (newCount == 0)
content.ScaleTo(new Vector2(1.5f, 1), 150, Easing.OutQuint);
else
content.ScaleTo(new Vector2(1.05f, 1), 50, Easing.OutQuint).Then().ScaleTo(1, 50, Easing.Out);
}
countdownCount = newCount;
}
protected override void PopOut()
{
base.PopOut();
this.Delay(150).FadeOut();
content.FadeOut(150, Easing.OutQuint);
scheduledResume?.Cancel();
}
}