Skip to content

Commit

Permalink
Merge pull request #30496 from bdach/copy-link-to-score
Browse files Browse the repository at this point in the history
 Add context menu option to copy link to an online score
  • Loading branch information
peppy authored Nov 5, 2024
2 parents fcc6319 + 6a1893f commit f21d2de
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 10 deletions.
3 changes: 2 additions & 1 deletion osu.Game/Graphics/UserInterface/ExternalLinkButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Localisation;
using osuTK;
using osuTK.Graphics;

Expand Down Expand Up @@ -77,7 +78,7 @@ public MenuItem[] ContextMenuItems
if (Link != null)
{
items.Add(new OsuMenuItem("Open", MenuItemType.Highlighted, () => game?.OpenUrlExternally(Link)));
items.Add(new OsuMenuItem("Copy link", MenuItemType.Standard, copyUrl));
items.Add(new OsuMenuItem(CommonStrings.CopyLink, MenuItemType.Standard, copyUrl));
}

return items.ToArray();
Expand Down
7 changes: 6 additions & 1 deletion osu.Game/Localisation/CommonStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ public static class CommonStrings
/// </summary>
public static LocalisableString General => new TranslatableString(getKey(@"general"), @"General");

/// <summary>
/// "Copy link"
/// </summary>
public static LocalisableString CopyLink => new TranslatableString(getKey(@"copy_link"), @"Copy link");

private static string getKey(string key) => $@"{prefix}:{key}";
}
}
}
6 changes: 3 additions & 3 deletions osu.Game/Online/Chat/ExternalLinkOpener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using osu.Game.Localisation;
using osu.Game.Overlays;
using osu.Game.Overlays.Dialog;
using CommonStrings = osu.Game.Resources.Localisation.Web.CommonStrings;
using WebCommonStrings = osu.Game.Resources.Localisation.Web.CommonStrings;

namespace osu.Game.Online.Chat
{
Expand Down Expand Up @@ -60,12 +60,12 @@ public ExternalLinkDialog(string url, Action openExternalLinkAction, Action copy
},
new PopupDialogCancelButton
{
Text = @"Copy link",
Text = CommonStrings.CopyLink,
Action = copyExternalLinkAction
},
new PopupDialogCancelButton
{
Text = CommonStrings.ButtonsCancel,
Text = WebCommonStrings.ButtonsCancel,
},
};
}
Expand Down
16 changes: 14 additions & 2 deletions osu.Game/Online/Leaderboards/LeaderboardScore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Framework.Platform;
using osu.Game.Extensions;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
Expand All @@ -33,6 +34,8 @@
using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets.Mods;
using osu.Game.Utils;
using CommonStrings = osu.Game.Localisation.CommonStrings;
using WebCommonStrings = osu.Game.Resources.Localisation.Web.CommonStrings;

namespace osu.Game.Online.Leaderboards
{
Expand Down Expand Up @@ -71,6 +74,12 @@ public partial class LeaderboardScore : OsuClickableContainer, IHasContextMenu,
[Resolved(canBeNull: true)]
private SongSelect songSelect { get; set; }

[Resolved(canBeNull: true)]
private Clipboard clipboard { get; set; }

[Resolved]
private IAPIProvider api { get; set; }

public ITooltip<ScoreInfo> GetCustomTooltip() => new LeaderboardScoreTooltip();
public virtual ScoreInfo TooltipContent => Score;

Expand Down Expand Up @@ -423,10 +432,13 @@ public MenuItem[] ContextMenuItems
if (Score.Mods.Length > 0 && songSelect != null)
items.Add(new OsuMenuItem("Use these mods", MenuItemType.Highlighted, () => songSelect.Mods.Value = Score.Mods));

if (Score.OnlineID > 0)
items.Add(new OsuMenuItem(CommonStrings.CopyLink, MenuItemType.Standard, () => clipboard?.SetText($@"{api.WebsiteRootUrl}/scores/{Score.OnlineID}")));

if (Score.Files.Count > 0)
{
items.Add(new OsuMenuItem(Localisation.CommonStrings.Export, MenuItemType.Standard, () => scoreManager.Export(Score)));
items.Add(new OsuMenuItem(CommonStrings.ButtonsDelete, MenuItemType.Destructive, () => dialogOverlay?.Push(new LocalScoreDeleteDialog(Score))));
items.Add(new OsuMenuItem(CommonStrings.Export, MenuItemType.Standard, () => scoreManager.Export(Score)));
items.Add(new OsuMenuItem(WebCommonStrings.ButtonsDelete, MenuItemType.Destructive, () => dialogOverlay?.Push(new LocalScoreDeleteDialog(Score))));
}

return items.ToArray();
Expand Down
6 changes: 4 additions & 2 deletions osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
using osu.Game.Rulesets.Mods;
using osuTK;
using osuTK.Graphics;
using CommonStrings = osu.Game.Localisation.CommonStrings;
using WebCommonStrings = osu.Game.Resources.Localisation.Web.CommonStrings;

namespace osu.Game.Screens.Select.Carousel
{
Expand Down Expand Up @@ -296,10 +298,10 @@ public MenuItem[] ContextMenuItems
items.Add(new OsuMenuItem("Collections") { Items = collectionItems });

if (beatmapInfo.GetOnlineURL(api, ruleset.Value) is string url)
items.Add(new OsuMenuItem("Copy link", MenuItemType.Standard, () => game?.CopyUrlToClipboard(url)));
items.Add(new OsuMenuItem(CommonStrings.CopyLink, MenuItemType.Standard, () => game?.CopyUrlToClipboard(url)));

if (hideRequested != null)
items.Add(new OsuMenuItem(CommonStrings.ButtonsHide.ToSentence(), MenuItemType.Destructive, () => hideRequested(beatmapInfo)));
items.Add(new OsuMenuItem(WebCommonStrings.ButtonsHide.ToSentence(), MenuItemType.Destructive, () => hideRequested(beatmapInfo)));

return items.ToArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using osu.Game.Collections;
using osu.Game.Database;
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
using osu.Game.Online.API;
using osu.Game.Overlays;
using osu.Game.Rulesets;
Expand Down Expand Up @@ -300,7 +301,7 @@ public MenuItem[] ContextMenuItems
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, () => game?.CopyUrlToClipboard(url)));
items.Add(new OsuMenuItem(CommonStrings.CopyLink, MenuItemType.Standard, () => game?.CopyUrlToClipboard(url)));

if (dialogOverlay != null)
items.Add(new OsuMenuItem("Delete...", MenuItemType.Destructive, () => dialogOverlay.Push(new BeatmapDeleteDialog(beatmapSet))));
Expand Down
11 changes: 11 additions & 0 deletions osu.Game/Screens/SelectV2/Leaderboards/LeaderboardScoreV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Framework.Platform;
using osu.Game.Configuration;
using osu.Game.Extensions;
using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Leaderboards;
using osu.Game.Overlays;
Expand Down Expand Up @@ -82,6 +84,12 @@ public partial class LeaderboardScoreV2 : OsuClickableContainer, IHasContextMenu
[Resolved]
private ScoreManager scoreManager { get; set; } = null!;

[Resolved]
private Clipboard? clipboard { get; set; }

[Resolved]
private IAPIProvider api { get; set; } = null!;

private Container content = null!;
private Box background = null!;
private Box foreground = null!;
Expand Down Expand Up @@ -769,6 +777,9 @@ public MenuItem[] ContextMenuItems
if (score.Mods.Length > 0)
items.Add(new OsuMenuItem("Use these mods", MenuItemType.Highlighted, () => SelectedMods.Value = score.Mods.Where(m => IsValidMod.Invoke(m)).ToArray()));

if (score.OnlineID > 0)
items.Add(new OsuMenuItem(CommonStrings.CopyLink, MenuItemType.Standard, () => clipboard?.SetText($@"{api.WebsiteRootUrl}/scores/{score.OnlineID}")));

if (score.Files.Count <= 0) return items.ToArray();

items.Add(new OsuMenuItem(CommonStrings.Export, MenuItemType.Standard, () => scoreManager.Export(score)));
Expand Down

0 comments on commit f21d2de

Please sign in to comment.