mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
Added current work on pause overlay
This commit is contained in:
54
osu.Game/Overlays/Pause/PauseButton.cs
Normal file
54
osu.Game/Overlays/Pause/PauseButton.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
|
||||
namespace osu.Game.Overlays.Pause
|
||||
{
|
||||
public class PauseButton : Button
|
||||
{
|
||||
private float height = 100;
|
||||
private float width = 300;
|
||||
private float expandedWidth = 350;
|
||||
|
||||
private AudioSample sampleClick;
|
||||
private AudioSample sampleHover;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio)
|
||||
{
|
||||
// Placeholder till the actual samples are added to osu-resources
|
||||
sampleClick = audio.Sample.Get(@"Menu/menuhit");
|
||||
sampleHover = audio.Sample.Get(@"Menu/menuclick");
|
||||
}
|
||||
|
||||
protected override bool OnMouseDown(Framework.Input.InputState state, Framework.Graphics.MouseDownEventArgs args)
|
||||
{
|
||||
sampleClick.Play();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnHover(Framework.Input.InputState state)
|
||||
{
|
||||
sampleHover.Play();
|
||||
ResizeTo(new Vector2(expandedWidth, height), 500, EasingTypes.OutElastic);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(Framework.Input.InputState state)
|
||||
{
|
||||
ResizeTo(new Vector2(width, height), 500, EasingTypes.OutElastic);
|
||||
}
|
||||
|
||||
public PauseButton()
|
||||
{
|
||||
Size = new Vector2(width, height);
|
||||
Colour = Color4.Black;
|
||||
Shear = new Vector2(0.1f, 0);
|
||||
}
|
||||
}
|
114
osu.Game/Overlays/Pause/PauseOverlay.cs
Normal file
114
osu.Game/Overlays/Pause/PauseOverlay.cs
Normal file
@ -0,0 +1,114 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user