1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 22:22:54 +08:00

Implement copy url in beatmap and beatmap set carousel

This commit is contained in:
jkh675 2024-08-20 22:48:11 +08:00
parent 3b94d1f8eb
commit 8e273709f1
2 changed files with 18 additions and 2 deletions

View File

@ -17,6 +17,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Platform;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables; using osu.Game.Beatmaps.Drawables;
using osu.Game.Collections; using osu.Game.Collections;
@ -25,6 +26,7 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Resources.Localisation.Web; using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets; using osu.Game.Rulesets;
@ -53,6 +55,7 @@ namespace osu.Game.Screens.Select.Carousel
private Action<BeatmapInfo>? selectRequested; private Action<BeatmapInfo>? selectRequested;
private Action<BeatmapInfo>? hideRequested; private Action<BeatmapInfo>? hideRequested;
private Action? copyBeatmapSetUrl;
private Triangles triangles = null!; private Triangles triangles = null!;
@ -89,7 +92,7 @@ namespace osu.Game.Screens.Select.Carousel
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(BeatmapManager? manager, SongSelect? songSelect) private void load(BeatmapManager? manager, SongSelect? songSelect, Clipboard clipboard, IAPIProvider api)
{ {
Header.Height = height; Header.Height = height;
@ -102,6 +105,8 @@ namespace osu.Game.Screens.Select.Carousel
if (manager != null) if (manager != null)
hideRequested = manager.Hide; hideRequested = manager.Hide;
copyBeatmapSetUrl += () => clipboard.SetText($@"{api.WebsiteRootUrl}/beatmapsets/{beatmapInfo.BeatmapSet.OnlineID}#{beatmapInfo.Ruleset.ShortName}/{beatmapInfo.OnlineID}");
Header.Children = new Drawable[] Header.Children = new Drawable[]
{ {
background = new Box background = new Box
@ -288,6 +293,8 @@ namespace osu.Game.Screens.Select.Carousel
items.Add(new OsuMenuItem("Collections") { Items = collectionItems }); items.Add(new OsuMenuItem("Collections") { Items = collectionItems });
items.Add(new OsuMenuItem("Copy URL", MenuItemType.Standard, () => copyBeatmapSetUrl?.Invoke()));
if (hideRequested != null) if (hideRequested != null)
items.Add(new OsuMenuItem(CommonStrings.ButtonsHide.ToSentence(), MenuItemType.Destructive, () => hideRequested(beatmapInfo))); items.Add(new OsuMenuItem(CommonStrings.ButtonsHide.ToSentence(), MenuItemType.Destructive, () => hideRequested(beatmapInfo)));

View File

@ -8,18 +8,22 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Platform;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Collections; using osu.Game.Collections;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Rulesets;
namespace osu.Game.Screens.Select.Carousel namespace osu.Game.Screens.Select.Carousel
{ {
@ -29,6 +33,7 @@ namespace osu.Game.Screens.Select.Carousel
private Action<BeatmapSetInfo> restoreHiddenRequested = null!; private Action<BeatmapSetInfo> restoreHiddenRequested = null!;
private Action<int>? viewDetails; private Action<int>? viewDetails;
private Action? copyBeatmapSetUrl;
[Resolved] [Resolved]
private IDialogOverlay? dialogOverlay { get; set; } private IDialogOverlay? dialogOverlay { get; set; }
@ -65,7 +70,7 @@ namespace osu.Game.Screens.Select.Carousel
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(BeatmapSetOverlay? beatmapOverlay, SongSelect? songSelect) private void load(BeatmapSetOverlay? beatmapOverlay, SongSelect? songSelect, Clipboard clipboard, IBindable<RulesetInfo> ruleset, IAPIProvider api)
{ {
if (songSelect != null) if (songSelect != null)
mainMenuItems = songSelect.CreateForwardNavigationMenuItemsForBeatmap(() => (((CarouselBeatmapSet)Item!).GetNextToSelect() as CarouselBeatmap)!.BeatmapInfo); mainMenuItems = songSelect.CreateForwardNavigationMenuItemsForBeatmap(() => (((CarouselBeatmapSet)Item!).GetNextToSelect() as CarouselBeatmap)!.BeatmapInfo);
@ -78,6 +83,8 @@ namespace osu.Game.Screens.Select.Carousel
if (beatmapOverlay != null) if (beatmapOverlay != null)
viewDetails = beatmapOverlay.FetchAndShowBeatmapSet; viewDetails = beatmapOverlay.FetchAndShowBeatmapSet;
copyBeatmapSetUrl += () => clipboard.SetText($@"{api.WebsiteRootUrl}/beatmapsets/{beatmapSet.OnlineID}#{ruleset.Value.ShortName}");
} }
protected override void Update() protected override void Update()
@ -287,6 +294,8 @@ namespace osu.Game.Screens.Select.Carousel
if (beatmapSet.Beatmaps.Any(b => b.Hidden)) if (beatmapSet.Beatmaps.Any(b => b.Hidden))
items.Add(new OsuMenuItem("Restore all hidden", MenuItemType.Standard, () => restoreHiddenRequested(beatmapSet))); items.Add(new OsuMenuItem("Restore all hidden", MenuItemType.Standard, () => restoreHiddenRequested(beatmapSet)));
items.Add(new OsuMenuItem("Copy URL", MenuItemType.Standard, () => copyBeatmapSetUrl?.Invoke()));
if (dialogOverlay != null) if (dialogOverlay != null)
items.Add(new OsuMenuItem("Delete...", MenuItemType.Destructive, () => dialogOverlay.Push(new BeatmapDeleteDialog(beatmapSet)))); items.Add(new OsuMenuItem("Delete...", MenuItemType.Destructive, () => dialogOverlay.Push(new BeatmapDeleteDialog(beatmapSet))));
return items.ToArray(); return items.ToArray();