2017-02-07 04:59:30 +00: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-05 19:16:40 +00:00
|
|
|
|
|
|
|
|
|
using OpenTK;
|
2017-01-27 09:24:49 +00:00
|
|
|
|
using OpenTK.Graphics;
|
2017-01-27 18:18:57 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Colour;
|
2017-06-20 05:54:23 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-01-27 18:18:57 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics.Backgrounds;
|
2017-02-15 12:37:43 +00:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-03-04 18:42:37 +00:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-06-27 12:05:49 +00:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2017-01-27 09:24:49 +00:00
|
|
|
|
|
2017-02-27 03:35:13 +00:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
2017-01-27 18:18:57 +00:00
|
|
|
|
{
|
2017-06-27 12:05:49 +00:00
|
|
|
|
public class DialogButton : OsuClickableContainer
|
2017-01-27 09:24:49 +00:00
|
|
|
|
{
|
2017-02-07 07:15:45 +00: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 09:24:49 +00:00
|
|
|
|
|
2017-02-28 01:38:25 +00:00
|
|
|
|
private Color4 buttonColour;
|
|
|
|
|
public Color4 ButtonColour
|
2017-01-30 12:04:39 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-02-28 01:38:25 +00:00
|
|
|
|
return buttonColour;
|
2017-01-30 12:04:39 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-02-28 01:38:25 +00:00
|
|
|
|
buttonColour = value;
|
2017-01-31 13:17:47 +00:00
|
|
|
|
updateGlow();
|
2017-02-27 03:35:13 +00:00
|
|
|
|
colourContainer.Colour = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 backgroundColour = OsuColour.Gray(34);
|
|
|
|
|
public Color4 BackgroundColour
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return backgroundColour;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
backgroundColour = value;
|
|
|
|
|
background.Colour = value;
|
2017-01-30 12:04:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-27 18:18:57 +00:00
|
|
|
|
|
2017-01-30 12:04:39 +00:00
|
|
|
|
private string text;
|
2017-01-27 18:18:57 +00:00
|
|
|
|
public string Text
|
2017-01-27 09:24:49 +00:00
|
|
|
|
{
|
2017-01-27 18:18:57 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
2017-01-30 12:04:39 +00:00
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
text = value;
|
|
|
|
|
spriteText.Text = Text;
|
2017-01-27 18:18:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-27 03:35:13 +00:00
|
|
|
|
private float textSize = 28;
|
|
|
|
|
internal float TextSize
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return textSize;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
textSize = value;
|
|
|
|
|
spriteText.TextSize = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 04:41:50 +00:00
|
|
|
|
private readonly Container backgroundContainer;
|
|
|
|
|
private readonly Container colourContainer;
|
|
|
|
|
private readonly Container glowContainer;
|
|
|
|
|
private readonly Box leftGlow;
|
|
|
|
|
private readonly Box centerGlow;
|
|
|
|
|
private readonly Box rightGlow;
|
|
|
|
|
private readonly Box background;
|
|
|
|
|
private readonly SpriteText spriteText;
|
2017-02-28 01:30:10 +00:00
|
|
|
|
private Vector2 hoverSpacing => new Vector2(3f, 0f);
|
2017-01-27 18:18:57 +00:00
|
|
|
|
|
2017-01-30 12:45:10 +00:00
|
|
|
|
private bool didClick; // Used for making sure that the OnMouseDown animation can call instead of OnHoverLost's when clicking
|
2017-01-30 08:08:14 +00:00
|
|
|
|
|
2017-06-30 06:54:03 +00:00
|
|
|
|
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => backgroundContainer.ReceiveMouseInputAt(screenSpacePos);
|
2017-01-27 09:24:49 +00:00
|
|
|
|
|
2017-02-05 19:17:02 +00:00
|
|
|
|
protected override bool OnClick(Framework.Input.InputState state)
|
2017-01-27 18:18:57 +00:00
|
|
|
|
{
|
2017-01-30 08:08:14 +00:00
|
|
|
|
didClick = true;
|
2017-07-22 18:50:25 +00:00
|
|
|
|
colourContainer.ResizeTo(new Vector2(1.5f, 1f), click_duration, Easing.In);
|
2017-01-31 12:07:05 +00:00
|
|
|
|
flash();
|
2017-01-30 08:08:14 +00:00
|
|
|
|
|
2017-07-17 13:51:21 +00:00
|
|
|
|
this.Delay(click_duration).Schedule(delegate {
|
2017-03-07 01:59:19 +00:00
|
|
|
|
colourContainer.ResizeTo(new Vector2(0.8f, 1f));
|
2017-01-30 09:04:57 +00:00
|
|
|
|
spriteText.Spacing = Vector2.Zero;
|
2017-01-30 20:18:11 +00:00
|
|
|
|
glowContainer.FadeOut();
|
2017-01-30 08:08:14 +00:00
|
|
|
|
});
|
|
|
|
|
|
2017-06-27 12:05:49 +00:00
|
|
|
|
return base.OnClick(state);
|
2017-01-27 09:24:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(Framework.Input.InputState state)
|
|
|
|
|
{
|
2017-07-22 18:50:25 +00:00
|
|
|
|
spriteText.TransformSpacingTo(hoverSpacing, hover_duration, Easing.OutElastic);
|
2017-02-27 03:35:13 +00:00
|
|
|
|
|
2017-07-22 18:50:25 +00:00
|
|
|
|
colourContainer.ResizeTo(new Vector2(hover_width, 1f), hover_duration, Easing.OutElastic);
|
|
|
|
|
glowContainer.FadeIn(glow_fade_duration, Easing.Out);
|
2017-06-27 12:05:49 +00:00
|
|
|
|
base.OnHover(state);
|
2017-01-27 09:24:49 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(Framework.Input.InputState state)
|
|
|
|
|
{
|
2017-01-30 08:08:14 +00:00
|
|
|
|
if (!didClick)
|
|
|
|
|
{
|
2017-07-22 18:50:25 +00:00
|
|
|
|
colourContainer.ResizeTo(new Vector2(0.8f, 1f), hover_duration, Easing.OutElastic);
|
|
|
|
|
spriteText.TransformSpacingTo(Vector2.Zero, hover_duration, Easing.OutElastic);
|
|
|
|
|
glowContainer.FadeOut(glow_fade_duration, Easing.Out);
|
2017-01-30 08:08:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
didClick = false;
|
2017-01-27 09:24:49 +00:00
|
|
|
|
}
|
2017-01-27 18:18:57 +00:00
|
|
|
|
|
2017-01-31 12:07:05 +00:00
|
|
|
|
private void flash()
|
|
|
|
|
{
|
|
|
|
|
var flash = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
colourContainer.Add(flash);
|
|
|
|
|
|
2017-02-28 01:38:25 +00:00
|
|
|
|
flash.Colour = ButtonColour;
|
2017-01-31 12:07:05 +00:00
|
|
|
|
flash.BlendingMode = BlendingMode.Additive;
|
|
|
|
|
flash.Alpha = 0.3f;
|
2017-02-07 07:15:45 +00:00
|
|
|
|
flash.FadeOutFromOne(click_duration);
|
2017-01-31 12:07:05 +00:00
|
|
|
|
flash.Expire();
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-31 13:17:47 +00:00
|
|
|
|
private void updateGlow()
|
2017-01-30 12:19:44 +00:00
|
|
|
|
{
|
2017-07-23 05:30:50 +00:00
|
|
|
|
leftGlow.Colour = ColourInfo.GradientHorizontal(new Color4(ButtonColour.R, ButtonColour.G, ButtonColour.B, 0f), ButtonColour);
|
2017-02-28 01:38:25 +00:00
|
|
|
|
centerGlow.Colour = ButtonColour;
|
2017-07-23 05:30:50 +00:00
|
|
|
|
rightGlow.Colour = ColourInfo.GradientHorizontal(ButtonColour, new Color4(ButtonColour.R, ButtonColour.G, ButtonColour.B, 0f));
|
2017-01-30 12:19:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-27 03:35:13 +00:00
|
|
|
|
public DialogButton()
|
2017-01-27 09:39:15 +00:00
|
|
|
|
{
|
2017-02-27 03:35:13 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
|
2017-01-30 13:26:24 +00:00
|
|
|
|
Children = new Drawable[]
|
2017-01-27 18:18:57 +00:00
|
|
|
|
{
|
|
|
|
|
backgroundContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Width = 1f,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-02-27 03:35:13 +00:00
|
|
|
|
background = new Box
|
2017-01-27 18:18:57 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-02-27 03:35:13 +00:00
|
|
|
|
Colour = backgroundColour,
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-01-27 18:18:57 +00:00
|
|
|
|
},
|
|
|
|
|
glowContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Width = 1f,
|
|
|
|
|
Alpha = 0f,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-01-30 12:19:44 +00:00
|
|
|
|
leftGlow = new Box
|
2017-01-27 18:18:57 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
|
Anchor = Anchor.TopLeft,
|
2017-02-27 03:35:13 +00:00
|
|
|
|
Width = 0.125f,
|
2017-01-29 01:50:06 +00:00
|
|
|
|
},
|
2017-01-30 12:19:44 +00:00
|
|
|
|
centerGlow = new Box
|
2017-01-29 01:50:06 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2017-02-27 03:35:13 +00:00
|
|
|
|
Width = 0.75f,
|
2017-01-27 18:18:57 +00:00
|
|
|
|
},
|
2017-01-30 12:19:44 +00:00
|
|
|
|
rightGlow = new Box
|
2017-01-27 18:18:57 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
Anchor = Anchor.TopRight,
|
2017-02-27 03:35:13 +00:00
|
|
|
|
Width = 0.125f,
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-01-27 18:18:57 +00:00
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
2017-01-30 08:43:06 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-01-27 18:18:57 +00: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 12:45:10 +00:00
|
|
|
|
Width = 0.8f,
|
2017-01-27 18:18:57 +00:00
|
|
|
|
Masking = true,
|
2017-02-04 10:06:26 +00:00
|
|
|
|
MaskingSmoothness = 2,
|
2017-06-12 03:48:47 +00:00
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
2017-01-27 18:18:57 +00:00
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Colour = Color4.Black.Opacity(0.2f),
|
2017-02-27 03:35:13 +00:00
|
|
|
|
Radius = 5,
|
2017-01-27 18:18:57 +00:00
|
|
|
|
},
|
2017-02-28 01:38:25 +00:00
|
|
|
|
Colour = ButtonColour,
|
2017-01-30 12:45:10 +00:00
|
|
|
|
Shear = new Vector2(0.2f, 0),
|
2017-01-27 18:18:57 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
EdgeSmoothness = new Vector2(2, 0),
|
2017-02-27 03:35:13 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-01-27 18:18:57 +00:00
|
|
|
|
},
|
2017-02-05 15:34:47 +00:00
|
|
|
|
new Container
|
2017-01-27 18:18:57 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-02-05 15:34:47 +00:00
|
|
|
|
Masking = true,
|
|
|
|
|
MaskingSmoothness = 0,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new Triangles
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
TriangleScale = 4,
|
|
|
|
|
ColourDark = OsuColour.Gray(0.88f),
|
2017-02-27 03:35:13 +00:00
|
|
|
|
Shear = new Vector2(-0.2f, 0),
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-02-05 15:34:47 +00:00
|
|
|
|
},
|
2017-02-27 03:35:13 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-01-27 18:18:57 +00:00
|
|
|
|
},
|
2017-02-15 12:37:43 +00:00
|
|
|
|
spriteText = new OsuSpriteText
|
2017-01-27 18:18:57 +00:00
|
|
|
|
{
|
|
|
|
|
Text = Text,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2017-01-30 09:04:57 +00:00
|
|
|
|
TextSize = 28,
|
2017-01-27 18:18:57 +00:00
|
|
|
|
Font = "Exo2.0-Bold",
|
|
|
|
|
Shadow = true,
|
|
|
|
|
ShadowColour = new Color4(0, 0, 0, 0.1f),
|
2017-02-27 03:35:13 +00:00
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
},
|
2017-01-30 13:26:24 +00:00
|
|
|
|
};
|
2017-01-30 12:19:44 +00:00
|
|
|
|
|
2017-01-31 13:17:47 +00:00
|
|
|
|
updateGlow();
|
2017-01-27 18:18:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|