2019-01-24 17:43:03 +09: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 15:41:10 +02:00
|
|
|
|
|
2022-07-25 04:07:33 -04:00
|
|
|
|
using System.Collections.Generic;
|
2018-05-22 15:29:52 +02:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2019-03-27 19:29:27 +09:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2022-07-25 17:16:33 -04:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-10-02 12:02:47 +09:00
|
|
|
|
using osu.Framework.Input.Events;
|
2021-06-25 19:10:04 +02:00
|
|
|
|
using osu.Framework.Localisation;
|
2018-06-19 20:19:52 +09:00
|
|
|
|
using osu.Framework.Platform;
|
2022-07-27 02:25:40 -04:00
|
|
|
|
using osu.Game.Overlays;
|
2022-10-13 23:57:25 +03:00
|
|
|
|
using osu.Game.Overlays.OSD;
|
2018-11-20 16:51:59 +09:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-05-22 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2022-11-24 14:32:20 +09:00
|
|
|
|
public partial class ExternalLinkButton : CompositeDrawable, IHasTooltip, IHasContextMenu
|
2018-05-22 15:29:52 +02:00
|
|
|
|
{
|
2022-07-28 12:12:46 +09:00
|
|
|
|
public string? Link { get; set; }
|
2018-05-22 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
private Color4 hoverColour;
|
2020-02-14 20:14:00 +07:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
2022-07-28 12:12:46 +09:00
|
|
|
|
private GameHost host { get; set; } = null!;
|
2018-05-22 15:29:52 +02:00
|
|
|
|
|
2023-07-11 11:42:31 +02:00
|
|
|
|
[Resolved]
|
|
|
|
|
private Clipboard clipboard { get; set; } = null!;
|
|
|
|
|
|
2022-07-28 12:12:46 +09:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OnScreenDisplay? onScreenDisplay { get; set; }
|
2022-07-27 02:25:40 -04:00
|
|
|
|
|
2021-07-30 21:32:08 +09:00
|
|
|
|
private readonly SpriteIcon linkIcon;
|
|
|
|
|
|
2022-07-28 12:12:46 +09:00
|
|
|
|
public ExternalLinkButton(string? link = null)
|
2018-05-22 15:29:52 +02:00
|
|
|
|
{
|
|
|
|
|
Link = link;
|
2018-05-25 18:51:57 +09:00
|
|
|
|
Size = new Vector2(12);
|
2021-07-30 21:32:08 +09:00
|
|
|
|
InternalChildren = new Drawable[]
|
2018-05-22 15:29:52 +02:00
|
|
|
|
{
|
2021-07-30 21:32:08 +09:00
|
|
|
|
linkIcon = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Icon = FontAwesome.Solid.ExternalLinkAlt,
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
},
|
2022-06-01 21:00:14 +09:00
|
|
|
|
new HoverClickSounds()
|
2018-05-22 15:29:52 +02:00
|
|
|
|
};
|
|
|
|
|
}
|
2022-07-25 04:13:05 -04:00
|
|
|
|
|
2018-05-22 15:29:52 +02:00
|
|
|
|
[BackgroundDependencyLoader]
|
2020-02-14 20:14:00 +07:00
|
|
|
|
private void load(OsuColour colours)
|
2018-05-22 15:29:52 +02:00
|
|
|
|
{
|
|
|
|
|
hoverColour = colours.Yellow;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 12:02:47 +09:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-05-22 15:29:52 +02:00
|
|
|
|
{
|
2021-07-30 21:32:08 +09:00
|
|
|
|
linkIcon.FadeColour(hoverColour, 500, Easing.OutQuint);
|
2018-10-02 12:02:47 +09:00
|
|
|
|
return base.OnHover(e);
|
2018-05-22 15:29:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 12:02:47 +09:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-05-22 15:29:52 +02:00
|
|
|
|
{
|
2021-07-30 21:32:08 +09:00
|
|
|
|
linkIcon.FadeColour(Color4.White, 500, Easing.OutQuint);
|
2018-10-02 12:02:47 +09:00
|
|
|
|
base.OnHoverLost(e);
|
2018-05-22 15:29:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 12:02:47 +09:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
2018-05-22 15:29:52 +02:00
|
|
|
|
{
|
2019-02-28 13:31:40 +09:00
|
|
|
|
if (Link != null)
|
2018-06-19 20:19:52 +09:00
|
|
|
|
host.OpenUrlExternally(Link);
|
2018-05-22 15:29:52 +02:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-25 19:10:04 +02:00
|
|
|
|
public LocalisableString TooltipText => "view in browser";
|
2022-07-27 21:52:38 -04:00
|
|
|
|
|
2022-07-28 12:13:45 +09:00
|
|
|
|
public MenuItem[] ContextMenuItems
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
List<MenuItem> items = new List<MenuItem>();
|
|
|
|
|
|
|
|
|
|
if (Link != null)
|
|
|
|
|
{
|
2022-12-26 20:45:32 -08:00
|
|
|
|
items.Add(new OsuMenuItem("Open", MenuItemType.Highlighted, () => host.OpenUrlExternally(Link)));
|
2022-07-28 12:13:45 +09:00
|
|
|
|
items.Add(new OsuMenuItem("Copy URL", MenuItemType.Standard, copyUrl));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return items.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void copyUrl()
|
|
|
|
|
{
|
2023-07-11 11:42:31 +02:00
|
|
|
|
if (Link != null)
|
|
|
|
|
{
|
|
|
|
|
clipboard.SetText(Link);
|
|
|
|
|
onScreenDisplay?.Display(new CopyUrlToast());
|
|
|
|
|
}
|
2022-07-27 21:52:38 -04:00
|
|
|
|
}
|
2018-05-22 15:29:52 +02:00
|
|
|
|
}
|
|
|
|
|
}
|