1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-24 00:07:26 +08:00
osu-lazer/osu.Game/Overlays/Pause/PauseOverlay.cs

175 lines
6.1 KiB
C#
Raw Normal View History

2017-01-27 17:24:49 +08:00
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;
2017-01-27 17:24:49 +08:00
namespace osu.Game.Overlays.Pause
{
public class PauseOverlay : OverlayContainer
{
private int fadeDuration = 200;
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);
}
2017-01-27 17:24:49 +08:00
[BackgroundDependencyLoader]
2017-01-28 02:18:57 +08:00
private void load(OsuColour colours)
{
2017-01-27 17:24:49 +08:00
Children = new Drawable[]
{
new Container
2017-01-27 17:24:49 +08:00
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
Alpha = 0.75f,
}
}
2017-01-27 17:24:49 +08:00
},
2017-01-28 02:18:57 +08:00
new SpriteText
{
2017-01-28 02:18:57 +08:00
Text = @"paused",
Origin = Anchor.BottomCentre,
2017-01-27 17:24:49 +08:00
Anchor = Anchor.Centre,
2017-01-28 02:18:57 +08:00
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),
2017-01-27 17:24:49 +08:00
},
2017-01-28 02:18:57 +08:00
new SpriteText
2017-01-27 17:24:49 +08:00
{
2017-01-28 02:18:57 +08:00
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
2017-01-28 02:18:57 +08:00
{
Origin = Anchor.TopCentre,
Anchor = Anchor.Centre,
2017-01-28 02:18:57 +08:00
Width = 100,
Position = new Vector2(0, 175),
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f),
TextSize = 18,
2017-01-27 17:24:49 +08:00
},
new PauseProgressBar
{
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
Width = 1f,
},
2017-01-28 02:18:57 +08:00
new FlowContainer
2017-01-27 17:24:49 +08:00
{
2017-01-28 02:18:57 +08:00
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
2017-01-27 17:24:49 +08:00
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
2017-01-28 02:18:57 +08:00
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,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Action = (delegate
{
Hide();
Task.Delay(fadeDuration * 2).ContinueWith(task => OnResume?.Invoke());
}),
2017-01-28 02:18:57 +08:00
},
new PauseButton
{
Type = PauseButtonType.Retry,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Action = (delegate
{
Hide();
OnRetry?.Invoke();
}),
2017-01-28 02:18:57 +08:00
},
new PauseButton
{
Type = PauseButtonType.Quit,
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Action = (delegate
{
Hide();
OnQuit?.Invoke();
}),
},
2017-01-28 02:18:57 +08:00
}
},
};
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";
2017-01-27 17:24:49 +08:00
}
public PauseOverlay()
{
RelativeSizeAxes = Axes.Both;
2017-01-28 02:18:57 +08:00
AutoSizeAxes = Axes.Both;
2017-01-27 17:24:49 +08:00
}
}
2017-01-27 17:39:15 +08:00
}