2017-01-27 17:24:49 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-01-28 02:18:57 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Framework.Graphics;
|
2017-01-27 17:24:49 +08:00
|
|
|
|
using osu.Framework.Graphics.Transformations;
|
2017-01-28 02:18:57 +08:00
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Audio;
|
2017-01-27 17:24:49 +08:00
|
|
|
|
using osu.Framework.Audio.Sample;
|
2017-01-28 02:18:57 +08:00
|
|
|
|
using osu.Game.Graphics.Backgrounds;
|
2017-01-27 17:24:49 +08:00
|
|
|
|
|
2017-01-28 02:18:57 +08:00
|
|
|
|
namespace osu.Game.Overlays.Pause
|
|
|
|
|
{
|
|
|
|
|
public class PauseButton : ClickableContainer
|
2017-01-27 17:24:49 +08:00
|
|
|
|
{
|
2017-01-28 02:18:57 +08:00
|
|
|
|
private float height = 70;
|
|
|
|
|
private float colourWidth = 0.8f;
|
|
|
|
|
private float colourExpandedWidth = 0.9f;
|
|
|
|
|
private float colourExpandTime = 500;
|
|
|
|
|
private float shear = 0.2f;
|
|
|
|
|
private float glowGradientEndAlpha = 0f;
|
2017-01-29 04:55:42 +08:00
|
|
|
|
private double pressExpandTime = 100;
|
2017-01-27 17:24:49 +08:00
|
|
|
|
|
2017-01-28 02:18:57 +08:00
|
|
|
|
private Color4 buttonColour;
|
|
|
|
|
private Color4 backgroundColour = OsuColour.Gray(34);
|
2017-01-27 17:24:49 +08:00
|
|
|
|
|
2017-01-28 02:18:57 +08:00
|
|
|
|
private AudioSample sampleClick;
|
|
|
|
|
private AudioSample sampleHover;
|
|
|
|
|
|
|
|
|
|
public PauseButtonType Type;
|
|
|
|
|
|
|
|
|
|
public string Text
|
2017-01-27 17:24:49 +08:00
|
|
|
|
{
|
2017-01-28 02:18:57 +08:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
switch (Type)
|
|
|
|
|
{
|
|
|
|
|
case PauseButtonType.Resume:
|
|
|
|
|
return "Continue";
|
|
|
|
|
|
|
|
|
|
case PauseButtonType.Retry:
|
|
|
|
|
return "Retry";
|
|
|
|
|
|
|
|
|
|
case PauseButtonType.Quit:
|
|
|
|
|
return "Quit to Main Menu";
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return "Unknown";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Container backgroundContainer;
|
|
|
|
|
private Container colourContainer;
|
|
|
|
|
private Container glowContainer;
|
|
|
|
|
|
|
|
|
|
public override bool Contains(Vector2 screenSpacePos) => backgroundContainer.Contains(screenSpacePos);
|
2017-01-27 17:24:49 +08:00
|
|
|
|
|
2017-01-29 04:55:42 +08:00
|
|
|
|
protected override bool OnMouseDown(Framework.Input.InputState state, MouseDownEventArgs args)
|
2017-01-28 02:18:57 +08:00
|
|
|
|
{
|
2017-01-29 04:55:42 +08:00
|
|
|
|
colourContainer.ResizeTo(new Vector2(1.1f, 1f), pressExpandTime, EasingTypes.In);
|
2017-01-28 02:18:57 +08:00
|
|
|
|
sampleClick?.Play();
|
2017-01-29 08:30:37 +08:00
|
|
|
|
Action?.Invoke();
|
2017-01-27 17:24:49 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(Framework.Input.InputState state)
|
|
|
|
|
{
|
2017-01-28 02:18:57 +08:00
|
|
|
|
colourContainer.ResizeTo(new Vector2(colourExpandedWidth, 1f), colourExpandTime, EasingTypes.OutElastic);
|
2017-01-29 04:55:42 +08:00
|
|
|
|
glowContainer.FadeTo(1f, colourExpandTime / 2, EasingTypes.Out);
|
2017-01-27 18:19:52 +08:00
|
|
|
|
sampleHover?.Play();
|
2017-01-27 17:24:49 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(Framework.Input.InputState state)
|
|
|
|
|
{
|
2017-01-28 02:18:57 +08:00
|
|
|
|
colourContainer.ResizeTo(new Vector2(colourWidth, 1f), colourExpandTime, EasingTypes.OutElastic);
|
2017-01-29 04:55:42 +08:00
|
|
|
|
glowContainer.FadeTo(0f, colourExpandTime / 2, EasingTypes.Out);
|
2017-01-27 17:24:49 +08:00
|
|
|
|
}
|
2017-01-28 02:18:57 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio, OsuColour colours)
|
2017-01-27 17:39:15 +08:00
|
|
|
|
{
|
2017-01-28 02:18:57 +08:00
|
|
|
|
switch (Type)
|
|
|
|
|
{
|
|
|
|
|
case PauseButtonType.Resume:
|
|
|
|
|
buttonColour = colours.Green;
|
|
|
|
|
sampleClick = audio.Sample.Get(@"Menu/menuback");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PauseButtonType.Retry:
|
|
|
|
|
buttonColour = colours.YellowDark;
|
|
|
|
|
sampleClick = audio.Sample.Get(@"Menu/menu-play-click");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PauseButtonType.Quit:
|
|
|
|
|
// For whatever reason the red from the mockup is not in the osu! palette
|
|
|
|
|
buttonColour = new Color4(170, 27, 39, 255);
|
|
|
|
|
sampleClick = audio.Sample.Get(@"Menu/menuback");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sampleHover = audio.Sample.Get(@"Menu/menuclick");
|
|
|
|
|
|
|
|
|
|
Add(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
backgroundContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Width = 1f,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-01-29 09:50:06 +08:00
|
|
|
|
Colour = backgroundColour
|
|
|
|
|
}
|
2017-01-28 02:18:57 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
glowContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Width = 1f,
|
|
|
|
|
Alpha = 0f,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
|
Width = 0.125f,
|
2017-01-29 09:50:06 +08:00
|
|
|
|
ColourInfo = ColourInfo.GradientHorizontal(new Color4(buttonColour.R, buttonColour.G, buttonColour.B, glowGradientEndAlpha), buttonColour)
|
|
|
|
|
},
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Width = 0.75f,
|
|
|
|
|
Colour = buttonColour
|
2017-01-28 02:18:57 +08:00
|
|
|
|
},
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Width = 0.125f,
|
2017-01-29 09:50:06 +08:00
|
|
|
|
ColourInfo = ColourInfo.GradientHorizontal(buttonColour, new Color4(buttonColour.R, buttonColour.G, buttonColour.B, glowGradientEndAlpha))
|
|
|
|
|
}
|
2017-01-28 02:18:57 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = height,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
colourContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Width = colourWidth,
|
|
|
|
|
Masking = true,
|
|
|
|
|
EdgeEffect = new EdgeEffect
|
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Colour = Color4.Black.Opacity(0.2f),
|
2017-01-29 09:50:06 +08:00
|
|
|
|
Radius = 5
|
2017-01-28 02:18:57 +08:00
|
|
|
|
},
|
|
|
|
|
Colour = buttonColour,
|
|
|
|
|
Shear = new Vector2(shear, 0),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
EdgeSmoothness = new Vector2(2, 0),
|
2017-01-29 09:50:06 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both
|
2017-01-28 02:18:57 +08:00
|
|
|
|
},
|
|
|
|
|
new Triangles
|
|
|
|
|
{
|
|
|
|
|
BlendingMode = BlendingMode.Additive,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
TriangleScale = 4,
|
|
|
|
|
Alpha = 0.05f,
|
2017-01-29 09:50:06 +08:00
|
|
|
|
Shear = new Vector2(-shear, 0)
|
|
|
|
|
}
|
2017-01-28 02:18:57 +08:00
|
|
|
|
}
|
2017-01-29 09:50:06 +08:00
|
|
|
|
}
|
2017-01-28 02:18:57 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2017-01-29 04:55:42 +08:00
|
|
|
|
new SpriteText
|
2017-01-28 02:18:57 +08:00
|
|
|
|
{
|
|
|
|
|
Text = Text,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
TextSize = 25,
|
|
|
|
|
Font = "Exo2.0-Bold",
|
|
|
|
|
Shadow = true,
|
|
|
|
|
ShadowColour = new Color4(0, 0, 0, 0.1f),
|
2017-01-29 09:50:06 +08:00
|
|
|
|
Colour = Color4.White
|
|
|
|
|
}
|
2017-01-28 02:18:57 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PauseButton()
|
|
|
|
|
{
|
|
|
|
|
Height = height;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum PauseButtonType
|
|
|
|
|
{
|
|
|
|
|
Resume,
|
|
|
|
|
Retry,
|
|
|
|
|
Quit
|
|
|
|
|
}
|
|
|
|
|
}
|