mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 04:13:00 +08:00
BeatmapSetOverlay
fetch on login state change
This commit is contained in:
parent
c7151ad69b
commit
44de24f153
@ -10,6 +10,7 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Overlays.BeatmapSet;
|
using osu.Game.Overlays.BeatmapSet;
|
||||||
@ -30,6 +31,14 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
private readonly Bindable<APIBeatmapSet> beatmapSet = new Bindable<APIBeatmapSet>();
|
private readonly Bindable<APIBeatmapSet> beatmapSet = new Bindable<APIBeatmapSet>();
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private IAPIProvider api { get; set; }
|
||||||
|
|
||||||
|
private IBindable<APIUser> apiUser;
|
||||||
|
|
||||||
|
private int? lastRequestedBeatmapId;
|
||||||
|
private BeatmapSetLookupType? lastBeatmapSetLookupType;
|
||||||
|
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Isolates the beatmap set overlay from the game-wide selected mods bindable
|
/// Isolates the beatmap set overlay from the game-wide selected mods bindable
|
||||||
/// to avoid affecting the beatmap details section (i.e. <see cref="AdvancedStats.StatisticRow"/>).
|
/// to avoid affecting the beatmap details section (i.e. <see cref="AdvancedStats.StatisticRow"/>).
|
||||||
@ -72,6 +81,17 @@ namespace osu.Game.Overlays
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
apiUser = api.LocalUser.GetBoundCopy();
|
||||||
|
apiUser.BindValueChanged(_ => Schedule(() =>
|
||||||
|
{
|
||||||
|
if (api.IsLoggedIn)
|
||||||
|
fetchAndSetLastRequestedBeatmap();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
protected override BeatmapSetHeader CreateHeader() => new BeatmapSetHeader();
|
protected override BeatmapSetHeader CreateHeader() => new BeatmapSetHeader();
|
||||||
|
|
||||||
protected override Color4 BackgroundColour => ColourProvider.Background6;
|
protected override Color4 BackgroundColour => ColourProvider.Background6;
|
||||||
@ -84,26 +104,24 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
public void FetchAndShowBeatmap(int beatmapId)
|
public void FetchAndShowBeatmap(int beatmapId)
|
||||||
{
|
{
|
||||||
|
lastRequestedBeatmapId = beatmapId;
|
||||||
|
lastBeatmapSetLookupType = BeatmapSetLookupType.BeatmapId;
|
||||||
|
|
||||||
beatmapSet.Value = null;
|
beatmapSet.Value = null;
|
||||||
|
|
||||||
var req = new GetBeatmapSetRequest(beatmapId, BeatmapSetLookupType.BeatmapId);
|
fetchAndSetBeatmap(beatmapId);
|
||||||
req.Success += res =>
|
|
||||||
{
|
|
||||||
beatmapSet.Value = res;
|
|
||||||
Header.HeaderContent.Picker.Beatmap.Value = Header.BeatmapSet.Value.Beatmaps.First(b => b.OnlineID == beatmapId);
|
|
||||||
};
|
|
||||||
API.Queue(req);
|
|
||||||
|
|
||||||
Show();
|
Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FetchAndShowBeatmapSet(int beatmapSetId)
|
public void FetchAndShowBeatmapSet(int beatmapSetId)
|
||||||
{
|
{
|
||||||
|
lastRequestedBeatmapId = beatmapSetId;
|
||||||
|
lastBeatmapSetLookupType = BeatmapSetLookupType.SetId;
|
||||||
|
|
||||||
beatmapSet.Value = null;
|
beatmapSet.Value = null;
|
||||||
|
|
||||||
var req = new GetBeatmapSetRequest(beatmapSetId);
|
fetchAndSetBeatmapSet(beatmapSetId);
|
||||||
req.Success += res => beatmapSet.Value = res;
|
|
||||||
API.Queue(req);
|
|
||||||
|
|
||||||
Show();
|
Show();
|
||||||
}
|
}
|
||||||
@ -118,6 +136,47 @@ namespace osu.Game.Overlays
|
|||||||
Show();
|
Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fetchAndSetBeatmap(int beatmapId)
|
||||||
|
{
|
||||||
|
if (!api.IsLoggedIn)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var req = new GetBeatmapSetRequest(beatmapId, BeatmapSetLookupType.BeatmapId);
|
||||||
|
req.Success += res =>
|
||||||
|
{
|
||||||
|
beatmapSet.Value = res;
|
||||||
|
Header.HeaderContent.Picker.Beatmap.Value = Header.BeatmapSet.Value.Beatmaps.First(b => b.OnlineID == beatmapId);
|
||||||
|
};
|
||||||
|
API.Queue(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fetchAndSetBeatmapSet(int beatmapSetId)
|
||||||
|
{
|
||||||
|
if (!api.IsLoggedIn)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var req = new GetBeatmapSetRequest(beatmapSetId);
|
||||||
|
req.Success += res => beatmapSet.Value = res;
|
||||||
|
API.Queue(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fetchAndSetLastRequestedBeatmap()
|
||||||
|
{
|
||||||
|
if (lastRequestedBeatmapId == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (lastBeatmapSetLookupType)
|
||||||
|
{
|
||||||
|
case BeatmapSetLookupType.SetId:
|
||||||
|
fetchAndSetBeatmapSet(lastRequestedBeatmapId.Value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BeatmapSetLookupType.BeatmapId:
|
||||||
|
fetchAndSetBeatmap(lastRequestedBeatmapId.Value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private partial class CommentsSection : BeatmapSetLayoutSection
|
private partial class CommentsSection : BeatmapSetLayoutSection
|
||||||
{
|
{
|
||||||
public readonly Bindable<APIBeatmapSet> BeatmapSet = new Bindable<APIBeatmapSet>();
|
public readonly Bindable<APIBeatmapSet> BeatmapSet = new Bindable<APIBeatmapSet>();
|
||||||
|
Loading…
Reference in New Issue
Block a user