2019-01-24 16:43:03 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-08-01 15:45:48 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-08-01 15:45:48 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-08-01 15:45:48 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A button with added default sound effects.
|
|
|
|
|
/// </summary>
|
2019-06-04 21:12:55 +08:00
|
|
|
|
public abstract class OsuButton : Button
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-08-01 15:45:48 +08:00
|
|
|
|
private Box hover;
|
|
|
|
|
|
2019-06-04 21:12:55 +08:00
|
|
|
|
protected OsuButton()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-08-01 15:45:48 +08:00
|
|
|
|
Height = 40;
|
|
|
|
|
|
|
|
|
|
Content.Masking = true;
|
|
|
|
|
Content.CornerRadius = 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
BackgroundColour = colours.BlueDark;
|
|
|
|
|
|
|
|
|
|
AddRange(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
hover = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Blending = BlendingMode.Additive,
|
|
|
|
|
Colour = Color4.White.Opacity(0.1f),
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Depth = -1
|
|
|
|
|
},
|
|
|
|
|
new HoverClickSounds(HoverSampleSet.Loud),
|
|
|
|
|
});
|
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
|
Enabled.ValueChanged += enabledChanged;
|
2018-08-01 15:45:48 +08:00
|
|
|
|
Enabled.TriggerChange();
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
|
private void enabledChanged(ValueChangedEvent<bool> e)
|
2018-08-01 15:45:48 +08:00
|
|
|
|
{
|
2019-02-21 17:56:34 +08:00
|
|
|
|
this.FadeColour(e.NewValue ? Color4.White : Color4.Gray, 200, Easing.OutQuint);
|
2018-08-01 15:45:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-08-01 15:45:48 +08:00
|
|
|
|
{
|
|
|
|
|
hover.FadeIn(200);
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnHover(e);
|
2018-08-01 15:45:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-08-01 15:45:48 +08:00
|
|
|
|
{
|
|
|
|
|
hover.FadeOut(200);
|
2018-10-02 11:02:47 +08:00
|
|
|
|
base.OnHoverLost(e);
|
2018-08-01 15:45:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
2018-08-01 15:45:48 +08:00
|
|
|
|
{
|
|
|
|
|
Content.ScaleTo(0.9f, 4000, Easing.OutQuint);
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnMouseDown(e);
|
2018-08-01 15:45:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnMouseUp(MouseUpEvent e)
|
2018-08-01 15:45:48 +08:00
|
|
|
|
{
|
|
|
|
|
Content.ScaleTo(1, 1000, Easing.OutElastic);
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnMouseUp(e);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2018-08-01 15:45:48 +08:00
|
|
|
|
|
|
|
|
|
protected override SpriteText CreateText() => new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Depth = -1,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2019-02-12 12:04:46 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold)
|
2018-08-01 15:45:48 +08:00
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|