mirror of
https://github.com/ppy/osu
synced 2025-02-22 13:37:08 +00: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)
|
||||
{
|
||||
case LinkAction.OpenBeatmap:
|
||||
// todo: replace this with overlay.ShowBeatmap(id) once an appropriate API call is implemented.
|
||||
if (int.TryParse(linkArgument, out int beatmapId))
|
||||
Process.Start($"https://osu.ppy.sh/b/{beatmapId}");
|
||||
// TODO: proper query params handling
|
||||
if (int.TryParse(linkArgument.Contains('?') ? linkArgument.Split('?')[0] : linkArgument, out int beatmapId))
|
||||
game?.ShowBeatmap(beatmapId);
|
||||
break;
|
||||
case LinkAction.OpenBeatmapSet:
|
||||
if (int.TryParse(linkArgument, out int setId))
|
||||
|
@ -5,13 +5,21 @@ namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
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>
|
||||
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)
|
||||
{
|
||||
scoreLoad?.Cancel();
|
||||
|
@ -17,6 +17,7 @@ using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Overlays.BeatmapSet;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Overlays.BeatmapSet.Scores;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
@ -139,6 +140,23 @@ namespace osu.Game.Overlays
|
||||
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)
|
||||
{
|
||||
// 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