2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2017-02-06 03:16:40 +08:00
|
|
|
|
|
|
|
|
|
using OpenTK;
|
2017-01-27 17:24:49 +08:00
|
|
|
|
using OpenTK.Graphics;
|
2017-01-28 02:18:57 +08:00
|
|
|
|
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;
|
2017-01-27 17:24:49 +08:00
|
|
|
|
using osu.Framework.Audio.Sample;
|
2017-01-30 16:08:14 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2017-01-28 02:18:57 +08:00
|
|
|
|
using osu.Game.Graphics.Backgrounds;
|
2017-02-15 20:37:43 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
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-02-07 15:15:45 +08:00
|
|
|
|
private const float hover_width = 0.9f;
|
|
|
|
|
private const float hover_duration = 500;
|
|
|
|
|
private const float glow_fade_duration = 250;
|
|
|
|
|
private const float click_duration = 200;
|
2017-01-27 17:24:49 +08:00
|
|
|
|
|
2017-01-28 02:18:57 +08:00
|
|
|
|
private Color4 backgroundColour = OsuColour.Gray(34);
|
2017-01-27 17:24:49 +08:00
|
|
|
|
|
2017-01-30 20:04:39 +08:00
|
|
|
|
private Color4 buttonColour;
|
|
|
|
|
public Color4 ButtonColour
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return buttonColour;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
buttonColour = value;
|
2017-01-31 21:17:47 +08:00
|
|
|
|
updateGlow();
|
2017-01-30 20:04:39 +08:00
|
|
|
|
if (colourContainer == null) return;
|
|
|
|
|
colourContainer.Colour = ButtonColour;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-28 02:18:57 +08:00
|
|
|
|
|
2017-01-30 20:04:39 +08:00
|
|
|
|
private string text;
|
2017-01-28 02:18:57 +08:00
|
|
|
|
public string Text
|
2017-01-27 17:24:49 +08:00
|
|
|
|
{
|
2017-01-28 02:18:57 +08:00
|
|
|
|
get
|
|
|
|
|
{
|
2017-01-30 20:04:39 +08:00
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
text = value;
|
|
|
|
|
if (spriteText == null) return;
|
|
|
|
|
spriteText.Text = Text;
|
2017-01-28 02:18:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-30 20:04:39 +08:00
|
|
|
|
public AudioSample SampleClick, SampleHover;
|
2017-01-30 17:04:57 +08:00
|
|
|
|
|
2017-01-30 20:04:39 +08:00
|
|
|
|
private Container backgroundContainer, colourContainer, glowContainer;
|
2017-01-30 20:19:44 +08:00
|
|
|
|
private Box leftGlow, centerGlow, rightGlow;
|
2017-01-30 17:04:57 +08:00
|
|
|
|
private SpriteText spriteText;
|
2017-01-28 02:18:57 +08:00
|
|
|
|
|
2017-01-30 20:45:10 +08:00
|
|
|
|
private bool didClick; // Used for making sure that the OnMouseDown animation can call instead of OnHoverLost's when clicking
|
2017-01-30 16:08:14 +08:00
|
|
|
|
|
2017-01-28 02:18:57 +08:00
|
|
|
|
public override bool Contains(Vector2 screenSpacePos) => backgroundContainer.Contains(screenSpacePos);
|
2017-01-27 17:24:49 +08:00
|
|
|
|
|
2017-02-06 03:17:02 +08:00
|
|
|
|
protected override bool OnClick(Framework.Input.InputState state)
|
2017-01-28 02:18:57 +08:00
|
|
|
|
{
|
2017-01-30 16:08:14 +08:00
|
|
|
|
didClick = true;
|
2017-02-07 15:15:45 +08:00
|
|
|
|
colourContainer.ResizeTo(new Vector2(1.5f, 1f), click_duration, EasingTypes.In);
|
2017-01-31 20:07:05 +08:00
|
|
|
|
flash();
|
2017-01-30 20:04:39 +08:00
|
|
|
|
SampleClick?.Play();
|
2017-01-29 08:30:37 +08:00
|
|
|
|
Action?.Invoke();
|
2017-01-30 16:08:14 +08:00
|
|
|
|
|
2017-02-07 15:15:45 +08:00
|
|
|
|
Delay(click_duration);
|
2017-01-30 16:08:14 +08:00
|
|
|
|
Schedule(delegate {
|
2017-01-30 20:45:10 +08:00
|
|
|
|
colourContainer.ResizeTo(new Vector2(0.8f, 1f), 0, EasingTypes.None);
|
2017-01-30 17:04:57 +08:00
|
|
|
|
spriteText.Spacing = Vector2.Zero;
|
2017-01-31 04:18:11 +08:00
|
|
|
|
glowContainer.FadeOut();
|
2017-01-30 16:08:14 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-01-27 17:24:49 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(Framework.Input.InputState state)
|
|
|
|
|
{
|
2017-02-07 15:15:45 +08:00
|
|
|
|
colourContainer.ResizeTo(new Vector2(hover_width, 1f), hover_duration, EasingTypes.OutElastic);
|
|
|
|
|
spriteText.TransformSpacingTo(new Vector2(3f, 0f), hover_duration, EasingTypes.OutElastic);
|
|
|
|
|
glowContainer.FadeIn(glow_fade_duration, EasingTypes.Out);
|
2017-01-30 20:04:39 +08:00
|
|
|
|
SampleHover?.Play();
|
2017-01-27 17:24:49 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(Framework.Input.InputState state)
|
|
|
|
|
{
|
2017-01-30 16:08:14 +08:00
|
|
|
|
if (!didClick)
|
|
|
|
|
{
|
2017-02-07 15:15:45 +08:00
|
|
|
|
colourContainer.ResizeTo(new Vector2(0.8f, 1f), hover_duration, EasingTypes.OutElastic);
|
|
|
|
|
spriteText.TransformSpacingTo(Vector2.Zero, hover_duration, EasingTypes.OutElastic);
|
|
|
|
|
glowContainer.FadeOut(glow_fade_duration, EasingTypes.Out);
|
2017-01-30 16:08:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
didClick = false;
|
2017-01-27 17:24:49 +08:00
|
|
|
|
}
|
2017-01-28 02:18:57 +08:00
|
|
|
|
|
2017-01-31 20:07:05 +08:00
|
|
|
|
private void flash()
|
|
|
|
|
{
|
|
|
|
|
var flash = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
colourContainer.Add(flash);
|
|
|
|
|
|
|
|
|
|
flash.Colour = ButtonColour;
|
|
|
|
|
flash.BlendingMode = BlendingMode.Additive;
|
|
|
|
|
flash.Alpha = 0.3f;
|
2017-02-07 15:15:45 +08:00
|
|
|
|
flash.FadeOutFromOne(click_duration);
|
2017-01-31 20:07:05 +08:00
|
|
|
|
flash.Expire();
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-31 21:17:47 +08:00
|
|
|
|
private void updateGlow()
|
2017-01-30 20:19:44 +08:00
|
|
|
|
{
|
|
|
|
|
leftGlow.ColourInfo = ColourInfo.GradientHorizontal(new Color4(ButtonColour.R, ButtonColour.G, ButtonColour.B, 0f), ButtonColour);
|
|
|
|
|
centerGlow.Colour = ButtonColour;
|
|
|
|
|
rightGlow.ColourInfo = ColourInfo.GradientHorizontal(ButtonColour, new Color4(ButtonColour.R, ButtonColour.G, ButtonColour.B, 0f));
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-30 20:04:39 +08:00
|
|
|
|
public PauseButton()
|
2017-01-27 17:39:15 +08:00
|
|
|
|
{
|
2017-01-30 21:26:24 +08:00
|
|
|
|
Children = new Drawable[]
|
2017-01-28 02:18:57 +08:00
|
|
|
|
{
|
|
|
|
|
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[]
|
|
|
|
|
{
|
2017-01-30 20:19:44 +08:00
|
|
|
|
leftGlow = new Box
|
2017-01-28 02:18:57 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
|
Anchor = Anchor.TopLeft,
|
2017-01-30 21:26:24 +08:00
|
|
|
|
Width = 0.125f
|
2017-01-29 09:50:06 +08:00
|
|
|
|
},
|
2017-01-30 20:19:44 +08:00
|
|
|
|
centerGlow = new Box
|
2017-01-29 09:50:06 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2017-01-30 21:26:24 +08:00
|
|
|
|
Width = 0.75f
|
2017-01-28 02:18:57 +08:00
|
|
|
|
},
|
2017-01-30 20:19:44 +08:00
|
|
|
|
rightGlow = new Box
|
2017-01-28 02:18:57 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
Anchor = Anchor.TopRight,
|
2017-01-30 21:26:24 +08:00
|
|
|
|
Width = 0.125f
|
2017-01-29 09:50:06 +08:00
|
|
|
|
}
|
2017-01-28 02:18:57 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
2017-01-30 16:43:06 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-01-28 02:18:57 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
colourContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2017-01-30 20:45:10 +08:00
|
|
|
|
Width = 0.8f,
|
2017-01-28 02:18:57 +08:00
|
|
|
|
Masking = true,
|
2017-02-04 18:06:26 +08:00
|
|
|
|
MaskingSmoothness = 2,
|
2017-01-28 02:18:57 +08:00
|
|
|
|
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
|
|
|
|
},
|
2017-01-30 20:04:39 +08:00
|
|
|
|
Colour = ButtonColour,
|
2017-01-30 20:45:10 +08:00
|
|
|
|
Shear = new Vector2(0.2f, 0),
|
2017-01-28 02:18:57 +08:00
|
|
|
|
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
|
|
|
|
},
|
2017-02-05 23:34:47 +08:00
|
|
|
|
new Container
|
2017-01-28 02:18:57 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-02-05 23:34:47 +08:00
|
|
|
|
Masking = true,
|
|
|
|
|
MaskingSmoothness = 0,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new Triangles
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
TriangleScale = 4,
|
|
|
|
|
ColourDark = OsuColour.Gray(0.88f),
|
|
|
|
|
Shear = new Vector2(-0.2f, 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-02-15 20:37:43 +08:00
|
|
|
|
spriteText = new OsuSpriteText
|
2017-01-28 02:18:57 +08:00
|
|
|
|
{
|
|
|
|
|
Text = Text,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2017-01-30 17:04:57 +08:00
|
|
|
|
TextSize = 28,
|
2017-01-28 02:18:57 +08:00
|
|
|
|
Font = "Exo2.0-Bold",
|
|
|
|
|
Shadow = true,
|
|
|
|
|
ShadowColour = new Color4(0, 0, 0, 0.1f),
|
2017-01-30 20:45:10 +08:00
|
|
|
|
Colour = Color4.White
|
2017-01-29 09:50:06 +08:00
|
|
|
|
}
|
2017-01-30 21:26:24 +08:00
|
|
|
|
};
|
2017-01-30 20:19:44 +08:00
|
|
|
|
|
2017-01-31 21:17:47 +08:00
|
|
|
|
updateGlow();
|
2017-01-28 02:18:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|