1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-05 02:03:04 +08:00

Show a warning prior to opening external links

This commit is contained in:
Roman Kapustin 2018-10-22 23:16:57 +03:00
parent d210383d8f
commit b4c68f4cf7
3 changed files with 40 additions and 2 deletions

View File

@ -23,6 +23,7 @@ namespace osu.Game.Tests.Visual
public class TestCaseChatLink : OsuTestCase public class TestCaseChatLink : OsuTestCase
{ {
private readonly TestChatLineContainer textContainer; private readonly TestChatLineContainer textContainer;
private readonly DialogOverlay dialogOverlay;
private Color4 linkColour; private Color4 linkColour;
public override IReadOnlyList<Type> RequiredTypes => new[] public override IReadOnlyList<Type> RequiredTypes => new[]
@ -37,6 +38,7 @@ namespace osu.Game.Tests.Visual
public TestCaseChatLink() public TestCaseChatLink()
{ {
Add(dialogOverlay = new DialogOverlay { Depth = float.MinValue });
Add(textContainer = new TestChatLineContainer Add(textContainer = new TestChatLineContainer
{ {
Padding = new MarginPadding { Left = 20, Right = 20 }, Padding = new MarginPadding { Left = 20, Right = 20 },
@ -50,6 +52,7 @@ namespace osu.Game.Tests.Visual
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
linkColour = colours.Blue; linkColour = colours.Blue;
Dependencies.Cache(dialogOverlay);
Dependencies.Cache(new ChatOverlay Dependencies.Cache(new ChatOverlay
{ {
AvailableChannels = AvailableChannels =

View File

@ -9,6 +9,7 @@ using osu.Framework.Graphics.Sprites;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.Chat;
using osu.Game.Overlays.Notifications; using osu.Game.Overlays.Notifications;
namespace osu.Game.Graphics.Containers namespace osu.Game.Graphics.Containers
@ -24,13 +25,15 @@ namespace osu.Game.Graphics.Containers
private Action showNotImplementedError; private Action showNotImplementedError;
private GameHost host; private GameHost host;
private DialogOverlay dialogOverlay;
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(OsuGame game, NotificationOverlay notifications, GameHost host) private void load(OsuGame game, NotificationOverlay notifications, GameHost host, DialogOverlay dialogOverlay)
{ {
// will be null in tests // will be null in tests
this.game = game; this.game = game;
this.host = host; this.host = host;
this.dialogOverlay = dialogOverlay;
showNotImplementedError = () => notifications?.Post(new SimpleNotification showNotImplementedError = () => notifications?.Post(new SimpleNotification
{ {
@ -88,7 +91,7 @@ namespace osu.Game.Graphics.Containers
showNotImplementedError?.Invoke(); showNotImplementedError?.Invoke();
break; break;
case LinkAction.External: case LinkAction.External:
host.OpenUrlExternally(url); dialogOverlay.Push(new ExternalLinkDialog(url, () => host.OpenUrlExternally(url)));
break; break;
case LinkAction.OpenUserProfile: case LinkAction.OpenUserProfile:
if (long.TryParse(linkArgument, out long userId)) if (long.TryParse(linkArgument, out long userId))

View File

@ -0,0 +1,32 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Game.Graphics;
using osu.Game.Overlays.Dialog;
namespace osu.Game.Overlays.Chat
{
public class ExternalLinkDialog : PopupDialog
{
public ExternalLinkDialog(string url, Action openExternalLinkAction)
{
BodyText = url;
Icon = FontAwesome.fa_warning;
HeaderText = "Confirm opening external link";
Buttons = new PopupDialogButton[]
{
new PopupDialogOkButton
{
Text = @"Yes. Go for it.",
Action = openExternalLinkAction
},
new PopupDialogCancelButton
{
Text = @"No! Abort mission!"
},
};
}
}
}