1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 04:57:27 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/ExternalLinkButton.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

106 lines
2.9 KiB
C#
Raw Normal View History

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