2019-01-24 08:43:03 +00: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-05-22 13:41:10 +00:00
|
|
|
|
|
2018-05-22 13:29:52 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2019-03-27 10:29:27 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-06-19 11:19:52 +00:00
|
|
|
|
using osu.Framework.Platform;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-05-22 13:29:52 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
|
|
|
|
public class ExternalLinkButton : CompositeDrawable, IHasTooltip
|
|
|
|
|
{
|
|
|
|
|
public string Link { get; set; }
|
|
|
|
|
|
|
|
|
|
private Color4 hoverColour;
|
2018-06-19 11:19:52 +00:00
|
|
|
|
private GameHost host;
|
2018-05-22 13:29:52 +00:00
|
|
|
|
|
|
|
|
|
public ExternalLinkButton(string link = null)
|
|
|
|
|
{
|
|
|
|
|
Link = link;
|
2018-05-25 09:51:57 +00:00
|
|
|
|
Size = new Vector2(12);
|
2018-05-22 13:29:52 +00:00
|
|
|
|
InternalChild = new SpriteIcon
|
|
|
|
|
{
|
2019-04-02 10:55:24 +00:00
|
|
|
|
Icon = FontAwesome.Solid.ExternalLinkAlt,
|
2018-05-22 13:29:52 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2018-06-19 11:19:52 +00:00
|
|
|
|
private void load(OsuColour colours, GameHost host)
|
2018-05-22 13:29:52 +00:00
|
|
|
|
{
|
|
|
|
|
hoverColour = colours.Yellow;
|
2018-06-19 11:19:52 +00:00
|
|
|
|
this.host = host;
|
2018-05-22 13:29:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-05-22 13:29:52 +00:00
|
|
|
|
{
|
|
|
|
|
InternalChild.FadeColour(hoverColour, 500, Easing.OutQuint);
|
2018-10-02 03:02:47 +00:00
|
|
|
|
return base.OnHover(e);
|
2018-05-22 13:29:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-05-22 13:29:52 +00:00
|
|
|
|
{
|
|
|
|
|
InternalChild.FadeColour(Color4.White, 500, Easing.OutQuint);
|
2018-10-02 03:02:47 +00:00
|
|
|
|
base.OnHoverLost(e);
|
2018-05-22 13:29:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
2018-05-22 13:29:52 +00:00
|
|
|
|
{
|
2019-02-28 04:31:40 +00:00
|
|
|
|
if (Link != null)
|
2018-06-19 11:19:52 +00:00
|
|
|
|
host.OpenUrlExternally(Link);
|
2018-05-22 13:29:52 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string TooltipText => "View in browser";
|
|
|
|
|
}
|
|
|
|
|
}
|