mirror of
https://github.com/ppy/osu.git
synced 2025-03-03 21:03:21 +08:00
Make LinkFlowContainer handle beatmap id lookup in game.
This commit is contained in:
parent
25524bf24f
commit
c304c1eecf
@ -71,9 +71,9 @@ namespace osu.Game.Graphics.Containers
|
|||||||
switch (linkType)
|
switch (linkType)
|
||||||
{
|
{
|
||||||
case LinkAction.OpenBeatmap:
|
case LinkAction.OpenBeatmap:
|
||||||
// todo: replace this with overlay.ShowBeatmap(id) once an appropriate API call is implemented.
|
// TODO: proper query params handling
|
||||||
if (int.TryParse(linkArgument, out int beatmapId))
|
if (int.TryParse(linkArgument.Contains('?') ? linkArgument.Split('?')[0] : linkArgument, out int beatmapId))
|
||||||
Process.Start($"https://osu.ppy.sh/b/{beatmapId}");
|
game?.ShowBeatmap(beatmapId);
|
||||||
break;
|
break;
|
||||||
case LinkAction.OpenBeatmapSet:
|
case LinkAction.OpenBeatmapSet:
|
||||||
if (int.TryParse(linkArgument, out int setId))
|
if (int.TryParse(linkArgument, out int setId))
|
||||||
|
@ -5,13 +5,21 @@ namespace osu.Game.Online.API.Requests
|
|||||||
{
|
{
|
||||||
public class GetBeatmapSetRequest : APIRequest<APIResponseBeatmapSet>
|
public class GetBeatmapSetRequest : APIRequest<APIResponseBeatmapSet>
|
||||||
{
|
{
|
||||||
private readonly int beatmapSetId;
|
private readonly int id;
|
||||||
|
private readonly BeatmapSetLookupType type;
|
||||||
|
|
||||||
public GetBeatmapSetRequest(int beatmapSetId)
|
public GetBeatmapSetRequest(int id, BeatmapSetLookupType type = BeatmapSetLookupType.SetId)
|
||||||
{
|
{
|
||||||
this.beatmapSetId = beatmapSetId;
|
this.id = id;
|
||||||
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Target => $@"beatmapsets/{beatmapSetId}";
|
protected override string Target => type == BeatmapSetLookupType.SetId ? $@"beatmapsets/{id}" : $@"beatmapsets/lookup?beatmap_id={id}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum BeatmapSetLookupType
|
||||||
|
{
|
||||||
|
SetId,
|
||||||
|
BeatmapId,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,6 +160,12 @@ namespace osu.Game
|
|||||||
/// <param name="userId">The user to display.</param>
|
/// <param name="userId">The user to display.</param>
|
||||||
public void ShowUser(long userId) => userProfile.ShowUser(userId);
|
public void ShowUser(long userId) => userProfile.ShowUser(userId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Show a beatmap's set as an overlay, displaying the given beatmap.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="beatmapId">The beatmap to show.</param>
|
||||||
|
public void ShowBeatmap(int beatmapId) => beatmapSetOverlay.ShowBeatmap(beatmapId);
|
||||||
|
|
||||||
protected void LoadScore(Score s)
|
protected void LoadScore(Score s)
|
||||||
{
|
{
|
||||||
scoreLoad?.Cancel();
|
scoreLoad?.Cancel();
|
||||||
|
@ -17,6 +17,7 @@ using osu.Game.Online.API.Requests;
|
|||||||
using osu.Game.Overlays.BeatmapSet;
|
using osu.Game.Overlays.BeatmapSet;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Overlays.BeatmapSet.Scores;
|
using osu.Game.Overlays.BeatmapSet.Scores;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
{
|
{
|
||||||
@ -139,6 +140,23 @@ namespace osu.Game.Overlays
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ShowBeatmap(int beatmapId)
|
||||||
|
{
|
||||||
|
var req = new GetBeatmapSetRequest(beatmapId, BeatmapSetLookupType.BeatmapId);
|
||||||
|
req.Success += res =>
|
||||||
|
{
|
||||||
|
ShowBeatmapSet(res.ToBeatmapSet(rulesets));
|
||||||
|
header.Picker.Beatmap.Value = header.BeatmapSet.Beatmaps.First(b => b.OnlineBeatmapID == beatmapId);
|
||||||
|
};
|
||||||
|
api.Queue(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowBeatmap(BeatmapInfo beatmap)
|
||||||
|
{
|
||||||
|
ShowBeatmapSet(beatmap.BeatmapSet);
|
||||||
|
header.Picker.Beatmap.Value = beatmap;
|
||||||
|
}
|
||||||
|
|
||||||
public void ShowBeatmapSet(int beatmapSetId)
|
public void ShowBeatmapSet(int beatmapSetId)
|
||||||
{
|
{
|
||||||
// todo: display the overlay while we are loading here. we need to support setting BeatmapSet to null for this to work.
|
// todo: display the overlay while we are loading here. we need to support setting BeatmapSet to null for this to work.
|
||||||
|
Loading…
Reference in New Issue
Block a user