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

View File

@ -9,6 +9,7 @@
using System.Collections.Generic;
using osu.Framework.Platform;
using osu.Game.Overlays;
using osu.Game.Overlays.Chat;
using osu.Game.Overlays.Notifications;
namespace osu.Game.Graphics.Containers
@ -24,13 +25,15 @@ public LinkFlowContainer(Action<SpriteText> defaultCreationParameters = null)
private Action showNotImplementedError;
private GameHost host;
private DialogOverlay dialogOverlay;
[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
this.game = game;
this.host = host;
this.dialogOverlay = dialogOverlay;
showNotImplementedError = () => notifications?.Post(new SimpleNotification
{
@ -88,7 +91,7 @@ public void AddLink(string text, string url, LinkAction linkType = LinkAction.Ex
showNotImplementedError?.Invoke();
break;
case LinkAction.External:
host.OpenUrlExternally(url);
dialogOverlay.Push(new ExternalLinkDialog(url, () => host.OpenUrlExternally(url)));
break;
case LinkAction.OpenUserProfile:
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!"
},
};
}
}
}