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

115 lines
2.9 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.Screens;
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.UserInterface;
using osu.Framework.Graphics.Transformations;
namespace osu.Game.Overlays.Pause
{
public class PauseOverlay : OverlayContainer
{
private bool paused = false;
public event Action OnPause;
public event Action OnPlay;
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 = Play
},
new PauseButton
{
Text = @"Retry",
Origin = Anchor.Centre,
Anchor = Anchor.Centre
},
new PauseButton
{
Text = @"Quit",
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Position = new Vector2(0, 200)
}
};
}
protected override void PopIn()
{
this.FadeTo(1, 100, EasingTypes.In);
}
protected override void PopOut()
{
this.FadeTo(0, 100, EasingTypes.In);
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
switch (args.Key)
{
case Key.Escape:
paused = !paused;
(paused ? (Action)Pause : Play)?.Invoke();
return true;
}
return base.OnKeyDown(state, args);
}
private void Pause()
{
paused = true;
Show();
OnPause?.Invoke();
}
private void Play()
{
paused = false;
Hide();
OnPlay?.Invoke();
}
private void Retry()
{
OnRetry?.Invoke();
}
private void Quit()
{
OnQuit?.Invoke();
}
public PauseOverlay()
{
RelativeSizeAxes = Axes.Both;
AutoSizeAxes = Axes.Both;
}
}
2017-01-27 17:39:15 +08:00
}