mirror of
https://github.com/ppy/osu.git
synced 2025-03-28 10:17:19 +08:00
Merge pull request #3625 from UselessToucan/external_link_warning
Show a warning prior to opening external links
This commit is contained in:
commit
c22ab0a529
@ -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 },
|
||||||
@ -57,6 +59,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
Dependencies.Cache(chatManager);
|
Dependencies.Cache(chatManager);
|
||||||
|
|
||||||
Dependencies.Cache(new ChatOverlay());
|
Dependencies.Cache(new ChatOverlay());
|
||||||
|
Dependencies.Cache(dialogOverlay);
|
||||||
|
|
||||||
testLinksGeneral();
|
testLinksGeneral();
|
||||||
testEcho();
|
testEcho();
|
||||||
|
@ -42,6 +42,8 @@ namespace osu.Game.Configuration
|
|||||||
if (!val) Set(OsuSetting.SavePassword, false);
|
if (!val) Set(OsuSetting.SavePassword, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Set(OsuSetting.ExternalLinkWarning, true);
|
||||||
|
|
||||||
// Audio
|
// Audio
|
||||||
Set(OsuSetting.VolumeInactive, 0.25, 0, 1, 0.01);
|
Set(OsuSetting.VolumeInactive, 0.25, 0, 1, 0.01);
|
||||||
|
|
||||||
@ -148,6 +150,7 @@ namespace osu.Game.Configuration
|
|||||||
BeatmapSkins,
|
BeatmapSkins,
|
||||||
BeatmapHitsounds,
|
BeatmapHitsounds,
|
||||||
IncreaseFirstObjectVisibility,
|
IncreaseFirstObjectVisibility,
|
||||||
ScoreDisplayMode
|
ScoreDisplayMode,
|
||||||
|
ExternalLinkWarning
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Notifications;
|
using osu.Game.Overlays.Notifications;
|
||||||
|
|
||||||
@ -24,14 +23,12 @@ namespace osu.Game.Graphics.Containers
|
|||||||
private OsuGame game;
|
private OsuGame game;
|
||||||
private ChannelManager channelManager;
|
private ChannelManager channelManager;
|
||||||
private Action showNotImplementedError;
|
private Action showNotImplementedError;
|
||||||
private GameHost host;
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader(true)]
|
[BackgroundDependencyLoader(true)]
|
||||||
private void load(OsuGame game, NotificationOverlay notifications, GameHost host, ChannelManager channelManager)
|
private void load(OsuGame game, NotificationOverlay notifications, ChannelManager channelManager)
|
||||||
{
|
{
|
||||||
// will be null in tests
|
// will be null in tests
|
||||||
this.game = game;
|
this.game = game;
|
||||||
this.host = host;
|
|
||||||
this.channelManager = channelManager;
|
this.channelManager = channelManager;
|
||||||
|
|
||||||
showNotImplementedError = () => notifications?.Post(new SimpleNotification
|
showNotImplementedError = () => notifications?.Post(new SimpleNotification
|
||||||
@ -98,7 +95,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
showNotImplementedError?.Invoke();
|
showNotImplementedError?.Invoke();
|
||||||
break;
|
break;
|
||||||
case LinkAction.External:
|
case LinkAction.External:
|
||||||
host.OpenUrlExternally(url);
|
game?.OpenUrlExternally(url);
|
||||||
break;
|
break;
|
||||||
case LinkAction.OpenUserProfile:
|
case LinkAction.OpenUserProfile:
|
||||||
if (long.TryParse(linkArgument, out long userId))
|
if (long.TryParse(linkArgument, out long userId))
|
||||||
|
36
osu.Game/Online/Chat/ExternalLinkOpener.cs
Normal file
36
osu.Game/Online/Chat/ExternalLinkOpener.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Configuration;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Platform;
|
||||||
|
using osu.Game.Configuration;
|
||||||
|
using osu.Game.Overlays;
|
||||||
|
using osu.Game.Overlays.Chat;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.Chat
|
||||||
|
{
|
||||||
|
public class ExternalLinkOpener : Component
|
||||||
|
{
|
||||||
|
private GameHost host;
|
||||||
|
private DialogOverlay dialogOverlay;
|
||||||
|
private Bindable<bool> externalLinkWarning;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader(true)]
|
||||||
|
private void load(GameHost host, DialogOverlay dialogOverlay, OsuConfigManager config)
|
||||||
|
{
|
||||||
|
this.host = host;
|
||||||
|
this.dialogOverlay = dialogOverlay;
|
||||||
|
externalLinkWarning = config.GetBindable<bool>(OsuSetting.ExternalLinkWarning);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OpenUrlExternally(string url)
|
||||||
|
{
|
||||||
|
if (externalLinkWarning)
|
||||||
|
dialogOverlay.Push(new ExternalLinkDialog(url, () => host.OpenUrlExternally(url)));
|
||||||
|
else
|
||||||
|
host.OpenUrlExternally(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -181,6 +181,9 @@ namespace osu.Game
|
|||||||
LocalConfig.BindWith(OsuSetting.VolumeInactive, inactiveVolumeAdjust);
|
LocalConfig.BindWith(OsuSetting.VolumeInactive, inactiveVolumeAdjust);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ExternalLinkOpener externalLinkOpener;
|
||||||
|
public void OpenUrlExternally(string url) => externalLinkOpener.OpenUrlExternally(url);
|
||||||
|
|
||||||
private ScheduledDelegate scoreLoad;
|
private ScheduledDelegate scoreLoad;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -382,6 +385,8 @@ namespace osu.Game
|
|||||||
dependencies.Cache(notifications);
|
dependencies.Cache(notifications);
|
||||||
dependencies.Cache(dialogOverlay);
|
dependencies.Cache(dialogOverlay);
|
||||||
|
|
||||||
|
Add(externalLinkOpener = new ExternalLinkOpener());
|
||||||
|
|
||||||
var singleDisplaySideOverlays = new OverlayContainer[] { settings, notifications };
|
var singleDisplaySideOverlays = new OverlayContainer[] { settings, notifications };
|
||||||
overlays.AddRange(singleDisplaySideOverlays);
|
overlays.AddRange(singleDisplaySideOverlays);
|
||||||
|
|
||||||
|
33
osu.Game/Overlays/Chat/ExternalLinkDialog.cs
Normal file
33
osu.Game/Overlays/Chat/ExternalLinkDialog.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// 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)
|
||||||
|
{
|
||||||
|
HeaderText = "Just checking...";
|
||||||
|
BodyText = $"You are about to leave osu! and open the following link in a web browser:\n\n{url}";
|
||||||
|
|
||||||
|
Icon = FontAwesome.fa_warning;
|
||||||
|
|
||||||
|
Buttons = new PopupDialogButton[]
|
||||||
|
{
|
||||||
|
new PopupDialogOkButton
|
||||||
|
{
|
||||||
|
Text = @"Yes. Go for it.",
|
||||||
|
Action = openExternalLinkAction
|
||||||
|
},
|
||||||
|
new PopupDialogCancelButton
|
||||||
|
{
|
||||||
|
Text = @"No! Abort mission!"
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,12 +7,10 @@ using osu.Framework.Extensions.Color4Extensions;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Graphics.Sprites;
|
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Backgrounds;
|
using osu.Game.Graphics.Backgrounds;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.Sprites;
|
|
||||||
using osu.Game.Input.Bindings;
|
using osu.Game.Input.Bindings;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
@ -35,7 +33,7 @@ namespace osu.Game.Overlays.Dialog
|
|||||||
private readonly Container ring;
|
private readonly Container ring;
|
||||||
private readonly FillFlowContainer<PopupDialogButton> buttonsContainer;
|
private readonly FillFlowContainer<PopupDialogButton> buttonsContainer;
|
||||||
private readonly SpriteIcon icon;
|
private readonly SpriteIcon icon;
|
||||||
private readonly SpriteText header;
|
private readonly TextFlowContainer header;
|
||||||
private readonly TextFlowContainer body;
|
private readonly TextFlowContainer body;
|
||||||
|
|
||||||
private bool actionInvoked;
|
private bool actionInvoked;
|
||||||
@ -46,10 +44,19 @@ namespace osu.Game.Overlays.Dialog
|
|||||||
set => icon.Icon = value;
|
set => icon.Icon = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string text;
|
||||||
|
|
||||||
public string HeaderText
|
public string HeaderText
|
||||||
{
|
{
|
||||||
get => header.Text;
|
get => text;
|
||||||
set => header.Text = value;
|
set
|
||||||
|
{
|
||||||
|
if (text == value)
|
||||||
|
return;
|
||||||
|
text = value;
|
||||||
|
|
||||||
|
header.Text = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string BodyText
|
public string BodyText
|
||||||
@ -164,18 +171,20 @@ namespace osu.Game.Overlays.Dialog
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
header = new OsuSpriteText
|
header = new OsuTextFlowContainer(t => t.TextSize = 25)
|
||||||
{
|
{
|
||||||
Origin = Anchor.TopCentre,
|
Origin = Anchor.TopCentre,
|
||||||
Anchor = Anchor.TopCentre,
|
Anchor = Anchor.TopCentre,
|
||||||
TextSize = 25,
|
RelativeSizeAxes = Axes.X,
|
||||||
Shadow = true,
|
AutoSizeAxes = Axes.Y,
|
||||||
|
Padding = new MarginPadding(15),
|
||||||
|
TextAnchor = Anchor.TopCentre,
|
||||||
},
|
},
|
||||||
body = new OsuTextFlowContainer(t => t.TextSize = 18)
|
body = new OsuTextFlowContainer(t => t.TextSize = 18)
|
||||||
{
|
{
|
||||||
Padding = new MarginPadding(15),
|
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
|
Padding = new MarginPadding(15),
|
||||||
TextAnchor = Anchor.TopCentre,
|
TextAnchor = Anchor.TopCentre,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
27
osu.Game/Overlays/Settings/Sections/Online/WebSettings.cs
Normal file
27
osu.Game/Overlays/Settings/Sections/Online/WebSettings.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game.Configuration;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Settings.Sections.Online
|
||||||
|
{
|
||||||
|
public class WebSettings : SettingsSubsection
|
||||||
|
{
|
||||||
|
protected override string Header => "Web";
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuConfigManager config)
|
||||||
|
{
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new SettingsCheckbox
|
||||||
|
{
|
||||||
|
LabelText = "Warn about opening external links",
|
||||||
|
Bindable = config.GetBindable<bool>(OsuSetting.ExternalLinkWarning)
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Overlays.Settings.Sections.Online;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Settings.Sections
|
namespace osu.Game.Overlays.Settings.Sections
|
||||||
{
|
{
|
||||||
@ -15,6 +16,7 @@ namespace osu.Game.Overlays.Settings.Sections
|
|||||||
{
|
{
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
|
new WebSettings()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user