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

124 lines
3.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;
namespace osu.Game.Overlays.Pause
{
public class PauseOverlay : OverlayContainer
{
private bool paused = false;
private int fadeDuration = 100;
2017-01-27 17:24:49 +08:00
public event Action OnPause;
public event Action OnResume;
2017-01-27 17:24:49 +08:00
public event Action OnRetry;
public event Action OnQuit;
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
Alpha = 0.6f,
},
new PauseButton
{
Text = @"Resume",
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Position = new Vector2(0, -200),
Action = Resume
2017-01-27 17:24:49 +08:00
},
new PauseButton
{
Text = @"Retry",
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Action = Retry
2017-01-27 17:24:49 +08:00
},
new PauseButton
{
Text = @"Quit",
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Position = new Vector2(0, 200),
Action = Quit
2017-01-27 17:24:49 +08:00
}
};
}
protected override void PopIn()
{
this.FadeTo(1, fadeDuration, EasingTypes.In);
paused = true;
2017-01-27 17:24:49 +08:00
}
protected override void PopOut()
{
this.FadeTo(0, fadeDuration, EasingTypes.In);
paused = false;
2017-01-27 17:24:49 +08:00
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
switch (args.Key)
{
case Key.Escape:
TogglePaused();
2017-01-27 17:24:49 +08:00
return true;
}
return base.OnKeyDown(state, args);
}
public void Pause()
2017-01-27 17:24:49 +08:00
{
Show();
OnPause?.Invoke();
}
public void Resume()
2017-01-27 17:24:49 +08:00
{
Hide();
OnResume?.Invoke();
}
public void TogglePaused()
{
ToggleVisibility();
(paused ? (Action)Pause : Resume)?.Invoke();
2017-01-27 17:24:49 +08:00
}
private void Retry()
{
Hide();
2017-01-27 17:24:49 +08:00
OnRetry?.Invoke();
}
private void Quit()
{
Hide();
2017-01-27 17:24:49 +08:00
OnQuit?.Invoke();
}
public PauseOverlay()
{
RelativeSizeAxes = Axes.Both;
AutoSizeAxes = Axes.Both;
Depth = -1;
2017-01-27 17:24:49 +08:00
}
}
2017-01-27 17:39:15 +08:00
}