Move copy-to-url method to OsuGame to centralise toast popup support

This commit is contained in:
Dean Herbert 2024-08-22 13:43:10 +09:00
parent ac5a3a0959
commit f068b7a521
No known key found for this signature in database
5 changed files with 24 additions and 28 deletions

View File

@ -10,9 +10,6 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Framework.Platform;
using osu.Game.Overlays;
using osu.Game.Overlays.OSD;
using osuTK;
using osuTK.Graphics;
@ -25,13 +22,7 @@ namespace osu.Game.Graphics.UserInterface
private Color4 hoverColour;
[Resolved]
private GameHost host { get; set; } = null!;
[Resolved]
private Clipboard clipboard { get; set; } = null!;
[Resolved]
private OnScreenDisplay? onScreenDisplay { get; set; }
private OsuGame? game { get; set; }
private readonly SpriteIcon linkIcon;
@ -71,7 +62,7 @@ namespace osu.Game.Graphics.UserInterface
protected override bool OnClick(ClickEvent e)
{
if (Link != null)
host.OpenUrlExternally(Link);
game?.OpenUrlExternally(Link);
return true;
}
@ -85,7 +76,7 @@ namespace osu.Game.Graphics.UserInterface
if (Link != null)
{
items.Add(new OsuMenuItem("Open", MenuItemType.Highlighted, () => host.OpenUrlExternally(Link)));
items.Add(new OsuMenuItem("Open", MenuItemType.Highlighted, () => game?.OpenUrlExternally(Link)));
items.Add(new OsuMenuItem("Copy link", MenuItemType.Standard, copyUrl));
}
@ -95,11 +86,9 @@ namespace osu.Game.Graphics.UserInterface
private void copyUrl()
{
if (Link != null)
{
clipboard.SetText(Link);
onScreenDisplay?.Display(new CopyUrlToast());
}
if (Link == null) return;
game?.CopyUrlToClipboard(Link);
}
}
}

View File

@ -45,9 +45,9 @@ namespace osu.Game.Localisation
public static LocalisableString SkinSaved => new TranslatableString(getKey(@"skin_saved"), @"Skin saved");
/// <summary>
/// "URL copied"
/// "Link copied to clipboard"
/// </summary>
public static LocalisableString UrlCopied => new TranslatableString(getKey(@"url_copied"), @"URL copied");
public static LocalisableString UrlCopied => new TranslatableString(getKey(@"url_copied"), @"Link copied to clipboard");
/// <summary>
/// "Speed changed to {0:N2}x"

View File

@ -54,6 +54,7 @@ using osu.Game.Overlays.BeatmapListing;
using osu.Game.Overlays.Mods;
using osu.Game.Overlays.Music;
using osu.Game.Overlays.Notifications;
using osu.Game.Overlays.OSD;
using osu.Game.Overlays.SkinEditor;
using osu.Game.Overlays.Toolbar;
using osu.Game.Overlays.Volume;
@ -142,6 +143,8 @@ namespace osu.Game
private Container overlayOffsetContainer;
private OnScreenDisplay onScreenDisplay;
[Resolved]
private FrameworkConfigManager frameworkConfig { get; set; }
@ -497,6 +500,12 @@ namespace osu.Game
}
});
public void CopyUrlToClipboard(string url) => waitForReady(() => onScreenDisplay, _ =>
{
dependencies.Get<Clipboard>().SetText(url);
onScreenDisplay.Display(new CopyUrlToast());
});
public void OpenUrlExternally(string url, bool forceBypassExternalUrlWarning = false) => waitForReady(() => externalLinkOpener, _ =>
{
bool isTrustedDomain;
@ -1078,7 +1087,7 @@ namespace osu.Game
loadComponentSingleFile(volume = new VolumeOverlay(), leftFloatingOverlayContent.Add, true);
var onScreenDisplay = new OnScreenDisplay();
onScreenDisplay = new OnScreenDisplay();
onScreenDisplay.BeginTracking(this, frameworkConfig);
onScreenDisplay.BeginTracking(this, LocalConfig);

View File

@ -17,7 +17,6 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Framework.Platform;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Collections;
@ -82,10 +81,10 @@ namespace osu.Game.Screens.Select.Carousel
private IBindable<IReadOnlyList<Mod>> mods { get; set; } = null!;
[Resolved]
private Clipboard clipboard { get; set; } = null!;
private IAPIProvider api { get; set; } = null!;
[Resolved]
private IAPIProvider api { get; set; } = null!;
private OsuGame? game { get; set; }
private IBindable<StarDifficulty?> starDifficultyBindable = null!;
private CancellationTokenSource? starDifficultyCancellationSource;
@ -297,7 +296,7 @@ namespace osu.Game.Screens.Select.Carousel
items.Add(new OsuMenuItem("Collections") { Items = collectionItems });
if (beatmapInfo.GetOnlineURL(api) is string url)
items.Add(new OsuMenuItem("Copy link", MenuItemType.Standard, () => clipboard.SetText(url)));
items.Add(new OsuMenuItem("Copy link", MenuItemType.Standard, () => game?.CopyUrlToClipboard(url)));
if (hideRequested != null)
items.Add(new OsuMenuItem(CommonStrings.ButtonsHide.ToSentence(), MenuItemType.Destructive, () => hideRequested(beatmapInfo)));

View File

@ -15,7 +15,6 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Platform;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Collections;
@ -44,10 +43,10 @@ namespace osu.Game.Screens.Select.Carousel
private RealmAccess realm { get; set; } = null!;
[Resolved]
private Clipboard clipboard { get; set; } = null!;
private IAPIProvider api { get; set; } = null!;
[Resolved]
private IAPIProvider api { get; set; } = null!;
private OsuGame? game { get; set; }
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
@ -301,7 +300,7 @@ namespace osu.Game.Screens.Select.Carousel
items.Add(new OsuMenuItem("Restore all hidden", MenuItemType.Standard, () => restoreHiddenRequested(beatmapSet)));
if (beatmapSet.GetOnlineURL(api, ruleset.Value) is string url)
items.Add(new OsuMenuItem("Copy link", MenuItemType.Standard, () => clipboard.SetText(url)));
items.Add(new OsuMenuItem("Copy link", MenuItemType.Standard, () => game?.CopyUrlToClipboard(url)));
if (dialogOverlay != null)
items.Add(new OsuMenuItem("Delete...", MenuItemType.Destructive, () => dialogOverlay.Push(new BeatmapDeleteDialog(beatmapSet))));