1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 05:52:54 +08:00
osu-lazer/osu.Game/Screens/Play/DelayedResumeOverlay.cs

203 lines
7.2 KiB
C#
Raw Normal View History

// 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.
2024-03-04 15:08:25 +08:00
using System;
using osu.Framework.Allocation;
2024-03-21 11:45:46 +08:00
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
2024-03-04 15:08:25 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Localisation;
2024-03-04 15:08:25 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays;
2024-03-04 15:08:25 +08:00
using osuTK;
namespace osu.Game.Screens.Play
{
/// <summary>
2024-03-20 01:26:39 +08:00
/// Simple <see cref="ResumeOverlay"/> that resumes after a short delay.
/// </summary>
public partial class DelayedResumeOverlay : ResumeOverlay
{
// todo: this shouldn't define its own colour provider, but nothing in DrawableRuleset guarantees this, so let's do it locally for now.
// (of note, Player does cache one but any test which uses a DrawableRuleset without Player will fail without this).
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
private const float outer_size = 200;
private const float inner_size = 150;
private const float progress_stroke_width = 7;
private const float progress_size = inner_size + progress_stroke_width / 2f;
private const double countdown_time = 2000;
2024-03-04 15:08:25 +08:00
private const int total_count = 3;
protected override LocalisableString Message => string.Empty;
private int? countdownCount;
2024-03-04 15:08:25 +08:00
private double countdownStartTime;
private bool countdownComplete;
private Drawable outerContent = null!;
private Container innerContent = null!;
2024-03-04 15:08:25 +08:00
private Container countdownComponents = null!;
private Drawable countdownBackground = null!;
private SpriteText countdownText = null!;
private CircularProgress countdownProgress = null!;
2024-03-04 15:08:25 +08:00
2024-03-21 11:45:46 +08:00
private Sample? sampleCountdown;
2024-03-04 15:08:25 +08:00
public DelayedResumeOverlay()
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
}
[BackgroundDependencyLoader]
2024-03-21 11:45:46 +08:00
private void load(AudioManager audio)
2024-03-04 15:08:25 +08:00
{
Add(outerContent = new Circle
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(outer_size),
Colour = colourProvider.Background6,
});
Add(innerContent = new Container
2024-03-04 15:08:25 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Children = new[]
2024-03-04 15:08:25 +08:00
{
countdownBackground = new Circle
2024-03-04 15:08:25 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(inner_size),
Colour = colourProvider.Background4,
},
countdownComponents = new Container
{
RelativeSizeAxes = Axes.Both,
2024-03-04 15:08:25 +08:00
Children = new Drawable[]
{
countdownProgress = new CircularProgress
2024-03-04 15:08:25 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(progress_size),
InnerRadius = progress_stroke_width / progress_size,
RoundedCaps = true
},
countdownText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
UseFullGlyphHeight = false,
AlwaysPresent = true,
Font = OsuFont.Torus.With(size: 70, weight: FontWeight.Light)
2024-03-04 15:08:25 +08:00
}
}
}
}
});
2024-03-21 11:45:46 +08:00
sampleCountdown = audio.Samples.Get(@"Gameplay/resume-countdown");
2024-03-04 15:08:25 +08:00
}
protected override void PopIn()
{
2024-03-04 15:08:25 +08:00
this.FadeIn();
// The transition effects.
outerContent.FadeIn().ScaleTo(Vector2.Zero).Then().ScaleTo(Vector2.One, 200, Easing.OutQuint);
innerContent.FadeIn().ScaleTo(Vector2.Zero).Then().ScaleTo(Vector2.One, 400, Easing.OutElasticHalf);
2024-03-14 22:38:59 +08:00
countdownComponents.FadeOut().Delay(50).FadeTo(1, 100);
countdownProgress.Progress = 0;
// Reset states for various components.
countdownBackground.FadeIn();
countdownText.FadeIn();
countdownText.Text = string.Empty;
countdownProgress.FadeIn().ScaleTo(1);
2024-03-04 15:08:25 +08:00
countdownComplete = false;
countdownCount = null;
countdownStartTime = Time.Current + 200;
2024-03-04 15:08:25 +08:00
}
2024-03-14 22:44:26 +08:00
protected override void PopOut()
{
this.Delay(300).FadeOut();
outerContent.FadeOut();
countdownBackground.FadeOut();
countdownText.FadeOut();
if (countdownComplete)
{
countdownProgress.ScaleTo(2f, 300, Easing.OutQuint);
countdownProgress.FadeOut(300, Easing.OutQuint);
2024-03-14 22:44:26 +08:00
}
else
countdownProgress.FadeOut();
}
2024-03-04 15:08:25 +08:00
protected override void Update()
{
base.Update();
updateCountdown();
}
private void updateCountdown()
{
if (State.Value == Visibility.Hidden || countdownComplete || Time.Current < countdownStartTime)
return;
double amountTimePassed = Math.Clamp((Time.Current - countdownStartTime) / countdown_time, 0, countdown_time);
int newCount = Math.Clamp(total_count - (int)Math.Floor(amountTimePassed * total_count), 0, total_count);
2024-03-04 15:08:25 +08:00
2024-03-14 11:24:12 +08:00
countdownProgress.Progress = amountTimePassed;
countdownProgress.InnerRadius = progress_stroke_width / progress_size / countdownProgress.Scale.X;
2024-03-04 15:08:25 +08:00
Alpha = 0.2f + 0.8f * newCount / total_count;
2024-03-21 11:45:46 +08:00
if (countdownCount != newCount)
2024-03-04 15:08:25 +08:00
{
2024-03-21 11:45:46 +08:00
if (newCount > 0)
{
countdownText.Text = Math.Max(1, newCount).ToString();
countdownText.ScaleTo(0.25f).Then().ScaleTo(1, 200, Easing.OutQuint);
outerContent.Delay(25).Then().ScaleTo(1.05f, 100).Then().ScaleTo(1f, 200, Easing.Out);
countdownBackground.FlashColour(colourProvider.Background3, 400, Easing.Out);
}
var chan = sampleCountdown?.GetChannel();
2024-03-21 11:45:46 +08:00
if (chan != null)
{
chan.Frequency.Value = newCount == 0 ? 0.5f : 1;
chan.Play();
}
2024-03-04 15:08:25 +08:00
}
countdownCount = newCount;
if (countdownCount == 0)
{
countdownComplete = true;
Resume();
}
}
}
}