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-05-22 21:41:10 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-05-22 21:29:52 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2021-06-26 01:10:04 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2018-06-19 19:19:52 +08:00
|
|
|
|
using osu.Framework.Platform;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-05-22 21:29:52 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
|
|
|
|
public class ExternalLinkButton : CompositeDrawable, IHasTooltip
|
|
|
|
|
{
|
|
|
|
|
public string Link { get; set; }
|
|
|
|
|
|
|
|
|
|
private Color4 hoverColour;
|
2020-02-14 21:14:00 +08:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private GameHost host { get; set; }
|
2018-05-22 21:29:52 +08:00
|
|
|
|
|
2021-07-30 20:32:08 +08:00
|
|
|
|
private readonly SpriteIcon linkIcon;
|
|
|
|
|
|
2018-05-22 21:29:52 +08:00
|
|
|
|
public ExternalLinkButton(string link = null)
|
|
|
|
|
{
|
|
|
|
|
Link = link;
|
2018-05-25 17:51:57 +08:00
|
|
|
|
Size = new Vector2(12);
|
2021-07-30 20:32:08 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
2018-05-22 21:29:52 +08:00
|
|
|
|
{
|
2021-07-30 20:32:08 +08:00
|
|
|
|
linkIcon = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Icon = FontAwesome.Solid.ExternalLinkAlt,
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
},
|
2022-06-01 20:00:14 +08:00
|
|
|
|
new HoverClickSounds()
|
2018-05-22 21:29:52 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-02-14 21:14:00 +08:00
|
|
|
|
private void load(OsuColour colours)
|
2018-05-22 21:29:52 +08:00
|
|
|
|
{
|
|
|
|
|
hoverColour = colours.Yellow;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-05-22 21:29:52 +08:00
|
|
|
|
{
|
2021-07-30 20:32:08 +08:00
|
|
|
|
linkIcon.FadeColour(hoverColour, 500, Easing.OutQuint);
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnHover(e);
|
2018-05-22 21:29:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-05-22 21:29:52 +08:00
|
|
|
|
{
|
2021-07-30 20:32:08 +08:00
|
|
|
|
linkIcon.FadeColour(Color4.White, 500, Easing.OutQuint);
|
2018-10-02 11:02:47 +08:00
|
|
|
|
base.OnHoverLost(e);
|
2018-05-22 21:29:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
2018-05-22 21:29:52 +08:00
|
|
|
|
{
|
2019-02-28 12:31:40 +08:00
|
|
|
|
if (Link != null)
|
2018-06-19 19:19:52 +08:00
|
|
|
|
host.OpenUrlExternally(Link);
|
2018-05-22 21:29:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-26 01:10:04 +08:00
|
|
|
|
public LocalisableString TooltipText => "view in browser";
|
2018-05-22 21:29:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|