mirror of
https://github.com/ppy/osu.git
synced 2024-12-16 06:52:55 +08:00
182 lines
6.5 KiB
C#
182 lines
6.5 KiB
C#
using System;
|
|
using OpenTK;
|
|
using OpenTK.Input;
|
|
using OpenTK.Graphics;
|
|
using osu.Game.Graphics;
|
|
using osu.Framework.Input;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Sprites;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Framework.Graphics.Transformations;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace osu.Game.Overlays.Pause
|
|
{
|
|
public class PauseOverlay : OverlayContainer
|
|
{
|
|
private const int fadeDuration = 200;
|
|
private const int buttonHeight = 70;
|
|
|
|
public Action OnResume;
|
|
public Action OnRetry;
|
|
public Action OnQuit;
|
|
|
|
private SpriteText retryCounter;
|
|
|
|
public override bool Contains(Vector2 screenSpacePos) => true;
|
|
public override bool HandleInput => State == Visibility.Visible;
|
|
|
|
protected override void PopIn() => FadeIn(fadeDuration, EasingTypes.In);
|
|
protected override void PopOut() => FadeOut(fadeDuration, EasingTypes.In);
|
|
|
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
|
{
|
|
switch (args.Key)
|
|
{
|
|
case Key.Escape:
|
|
if (State == Visibility.Hidden) return false;
|
|
Hide();
|
|
Task.Delay(fadeDuration * 2).ContinueWith(task => OnResume?.Invoke());
|
|
return true;
|
|
}
|
|
return base.OnKeyDown(state, args);
|
|
}
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load(OsuColour colours)
|
|
{
|
|
Children = new Drawable[]
|
|
{
|
|
new Container
|
|
{
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
{
|
|
new Box
|
|
{
|
|
RelativeSizeAxes = Axes.Both,
|
|
Colour = Color4.Black,
|
|
Alpha = 0.75f,
|
|
}
|
|
}
|
|
},
|
|
new SpriteText
|
|
{
|
|
Text = @"paused",
|
|
Origin = Anchor.BottomCentre,
|
|
Anchor = Anchor.Centre,
|
|
Position = new Vector2(0, -175),
|
|
Font = @"Exo2.0-Medium",
|
|
Spacing = new Vector2(5, 0),
|
|
TextSize = 30,
|
|
Colour = colours.Yellow,
|
|
Shadow = true,
|
|
ShadowColour = new Color4(0, 0, 0, 0.25f),
|
|
},
|
|
new SpriteText
|
|
{
|
|
Text = @"you're not going to do what i think you're going to do, ain't ya?",
|
|
Origin = Anchor.BottomCentre,
|
|
Anchor = Anchor.Centre,
|
|
Width = 100,
|
|
Position = new Vector2(0, -125),
|
|
Shadow = true,
|
|
ShadowColour = new Color4(0, 0, 0, 0.25f),
|
|
},
|
|
retryCounter = new SpriteText
|
|
{
|
|
Origin = Anchor.TopCentre,
|
|
Anchor = Anchor.Centre,
|
|
Width = 100,
|
|
Position = new Vector2(0, 175),
|
|
Shadow = true,
|
|
ShadowColour = new Color4(0, 0, 0, 0.25f),
|
|
TextSize = 18,
|
|
},
|
|
new PauseProgressBar
|
|
{
|
|
Origin = Anchor.BottomCentre,
|
|
Anchor = Anchor.BottomCentre,
|
|
Width = 1f,
|
|
},
|
|
new FlowContainer
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
AutoSizeAxes = Axes.Y,
|
|
Origin = Anchor.Centre,
|
|
Anchor = Anchor.Centre,
|
|
Position = new Vector2(0, 25),
|
|
Masking = true,
|
|
EdgeEffect = new EdgeEffect
|
|
{
|
|
Type = EdgeEffectType.Shadow,
|
|
Colour = new Color4(0, 0, 0, 150),
|
|
Radius = 50,
|
|
Offset = new Vector2(0, 0),
|
|
},
|
|
Children = new Drawable[]
|
|
{
|
|
new PauseButton
|
|
{
|
|
Type = PauseButtonType.Resume,
|
|
RelativeSizeAxes = Axes.X,
|
|
Origin = Anchor.TopCentre,
|
|
Anchor = Anchor.TopCentre,
|
|
Height = buttonHeight,
|
|
Action = (delegate
|
|
{
|
|
Hide();
|
|
Task.Delay(fadeDuration * 2).ContinueWith(task => OnResume?.Invoke());
|
|
}),
|
|
},
|
|
new PauseButton
|
|
{
|
|
Type = PauseButtonType.Retry,
|
|
RelativeSizeAxes = Axes.X,
|
|
Origin = Anchor.TopCentre,
|
|
Anchor = Anchor.TopCentre,
|
|
Height = buttonHeight,
|
|
Action = (delegate
|
|
{
|
|
Hide();
|
|
OnRetry?.Invoke();
|
|
}),
|
|
},
|
|
new PauseButton
|
|
{
|
|
Type = PauseButtonType.Quit,
|
|
RelativeSizeAxes = Axes.X,
|
|
Origin = Anchor.TopCentre,
|
|
Anchor = Anchor.TopCentre,
|
|
Height = buttonHeight,
|
|
Action = (delegate
|
|
{
|
|
Hide();
|
|
OnQuit?.Invoke();
|
|
}),
|
|
},
|
|
}
|
|
},
|
|
};
|
|
|
|
SetRetries(0);
|
|
}
|
|
|
|
public void SetRetries(int count)
|
|
{
|
|
if (retryCounter != null)
|
|
// "You've retried 1,065 times in this session"
|
|
// "You've retried 1 time in this session"
|
|
retryCounter.Text = $"You've retried {String.Format("{0:n0}", count)} time{(count == 1) ? "" : "s"} in this session";
|
|
}
|
|
|
|
public PauseOverlay()
|
|
{
|
|
RelativeSizeAxes = Axes.Both;
|
|
AutoSizeAxes = Axes.Both;
|
|
}
|
|
}
|
|
}
|