1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:57:36 +08:00

Merge pull request #2705 from peppy/fix-beatmap-info-wedge-async

Fix incorrect async logic in BeatmapInfoWedge
This commit is contained in:
Dan Balasescu 2018-06-04 20:42:55 +09:00 committed by GitHub
commit 69e75bfa09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 32 deletions

View File

@ -53,7 +53,7 @@ namespace osu.Game.Tests.Visual
AddStep("show", () => AddStep("show", () =>
{ {
infoWedge.State = Visibility.Visible; infoWedge.State = Visibility.Visible;
infoWedge.UpdateBeatmap(beatmap); infoWedge.Beatmap = beatmap;
}); });
// select part is redundant, but wait for load isn't // select part is redundant, but wait for load isn't
@ -133,7 +133,7 @@ namespace osu.Game.Tests.Visual
AddStep($"select {b.Metadata.Title} beatmap", () => AddStep($"select {b.Metadata.Title} beatmap", () =>
{ {
infoBefore = infoWedge.Info; infoBefore = infoWedge.Info;
infoWedge.UpdateBeatmap(beatmap.Value = new TestWorkingBeatmap(b)); infoWedge.Beatmap = beatmap.Value = new TestWorkingBeatmap(b);
}); });
AddUntilStep(() => infoWedge.Info != infoBefore, "wait for async load"); AddUntilStep(() => infoWedge.Info != infoBefore, "wait for async load");
@ -144,7 +144,7 @@ namespace osu.Game.Tests.Visual
AddStep("select null beatmap", () => AddStep("select null beatmap", () =>
{ {
beatmap.Value = beatmap.Default; beatmap.Value = beatmap.Default;
infoWedge.UpdateBeatmap(beatmap); infoWedge.Beatmap = beatmap;
}); });
} }

View File

@ -57,7 +57,7 @@ namespace osu.Game.Screens.Select
{ {
if (osuGame != null) if (osuGame != null)
ruleset.BindTo(osuGame.Ruleset); ruleset.BindTo(osuGame.Ruleset);
ruleset.ValueChanged += updateRuleset; ruleset.ValueChanged += _ => updateDisplay();
} }
protected override bool BlockPassThroughMouse => false; protected override bool BlockPassThroughMouse => false;
@ -78,66 +78,76 @@ namespace osu.Game.Screens.Select
private WorkingBeatmap beatmap; private WorkingBeatmap beatmap;
public void UpdateBeatmap(WorkingBeatmap beatmap) public WorkingBeatmap Beatmap
{ {
this.beatmap = beatmap; get => beatmap;
loadBeatmap(); set
{
if (beatmap == value) return;
beatmap = value;
updateDisplay();
}
} }
private void updateRuleset(RulesetInfo ruleset) => loadBeatmap(); private BufferedWedgeInfo loadingInfo;
private void loadBeatmap() private void updateDisplay()
{ {
void updateState() void removeOldInfo()
{ {
State = beatmap == null ? Visibility.Hidden : Visibility.Visible; State = beatmap == null ? Visibility.Hidden : Visibility.Visible;
Info?.FadeOut(250); Info?.FadeOut(250);
Info?.Expire(); Info?.Expire();
Info = null;
} }
if (beatmap == null) if (beatmap == null)
{ {
updateState(); removeOldInfo();
return; return;
} }
LoadComponentAsync(new BufferedWedgeInfo(beatmap, ruleset.Value) LoadComponentAsync(loadingInfo = new BufferedWedgeInfo(beatmap, ruleset.Value)
{ {
Shear = -Shear, Shear = -Shear,
Depth = Info?.Depth + 1 ?? 0, Depth = Info?.Depth + 1 ?? 0
}, newInfo => }, loaded =>
{ {
updateState(); // ensure we are the most recent loaded wedge.
Add(Info = newInfo); if (loaded != loadingInfo) return;
removeOldInfo();
Add(Info = loaded);
}); });
} }
public class BufferedWedgeInfo : BufferedContainer public class BufferedWedgeInfo : BufferedContainer
{ {
private readonly WorkingBeatmap working;
public OsuSpriteText VersionLabel { get; private set; } public OsuSpriteText VersionLabel { get; private set; }
public OsuSpriteText TitleLabel { get; private set; } public OsuSpriteText TitleLabel { get; private set; }
public OsuSpriteText ArtistLabel { get; private set; } public OsuSpriteText ArtistLabel { get; private set; }
public FillFlowContainer MapperContainer { get; private set; } public FillFlowContainer MapperContainer { get; private set; }
public FillFlowContainer InfoLabelContainer { get; private set; } public FillFlowContainer InfoLabelContainer { get; private set; }
private UnicodeBindableString titleBinding; private UnicodeBindableString titleBinding;
private UnicodeBindableString artistBinding; private UnicodeBindableString artistBinding;
private readonly WorkingBeatmap beatmap;
private readonly RulesetInfo ruleset; private readonly RulesetInfo ruleset;
public BufferedWedgeInfo(WorkingBeatmap working, RulesetInfo userRuleset) public BufferedWedgeInfo(WorkingBeatmap beatmap, RulesetInfo userRuleset)
{ {
this.working = working; this.beatmap = beatmap;
ruleset = userRuleset ?? beatmap.BeatmapInfo.Ruleset;
ruleset = userRuleset ?? working.BeatmapInfo.Ruleset;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(LocalisationEngine localisation) private void load(LocalisationEngine localisation)
{ {
var beatmapInfo = working.BeatmapInfo; var beatmapInfo = beatmap.BeatmapInfo;
var metadata = beatmapInfo.Metadata ?? working.BeatmapSetInfo?.Metadata ?? new BeatmapMetadata(); var metadata = beatmapInfo.Metadata ?? beatmap.BeatmapSetInfo?.Metadata ?? new BeatmapMetadata();
PixelSnapping = true; PixelSnapping = true;
CacheDrawnFrameBuffer = true; CacheDrawnFrameBuffer = true;
@ -165,7 +175,7 @@ namespace osu.Game.Screens.Select
Children = new[] Children = new[]
{ {
// Zoomed-in and cropped beatmap background // Zoomed-in and cropped beatmap background
new BeatmapBackgroundSprite(working) new BeatmapBackgroundSprite(beatmap)
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
@ -248,27 +258,27 @@ namespace osu.Game.Screens.Select
private InfoLabel[] getInfoLabels() private InfoLabel[] getInfoLabels()
{ {
var beatmap = working.Beatmap; var b = beatmap.Beatmap;
List<InfoLabel> labels = new List<InfoLabel>(); List<InfoLabel> labels = new List<InfoLabel>();
if (beatmap?.HitObjects?.Any() == true) if (b?.HitObjects?.Any() == true)
{ {
HitObject lastObject = beatmap.HitObjects.LastOrDefault(); HitObject lastObject = b.HitObjects.LastOrDefault();
double endTime = (lastObject as IHasEndTime)?.EndTime ?? lastObject?.StartTime ?? 0; double endTime = (lastObject as IHasEndTime)?.EndTime ?? lastObject?.StartTime ?? 0;
labels.Add(new InfoLabel(new BeatmapStatistic labels.Add(new InfoLabel(new BeatmapStatistic
{ {
Name = "Length", Name = "Length",
Icon = FontAwesome.fa_clock_o, Icon = FontAwesome.fa_clock_o,
Content = TimeSpan.FromMilliseconds(endTime - beatmap.HitObjects.First().StartTime).ToString(@"m\:ss"), Content = TimeSpan.FromMilliseconds(endTime - b.HitObjects.First().StartTime).ToString(@"m\:ss"),
})); }));
labels.Add(new InfoLabel(new BeatmapStatistic labels.Add(new InfoLabel(new BeatmapStatistic
{ {
Name = "BPM", Name = "BPM",
Icon = FontAwesome.fa_circle, Icon = FontAwesome.fa_circle,
Content = getBPMRange(beatmap), Content = getBPMRange(b),
})); }));
IBeatmap playableBeatmap; IBeatmap playableBeatmap;
@ -276,12 +286,12 @@ namespace osu.Game.Screens.Select
try try
{ {
// Try to get the beatmap with the user's ruleset // Try to get the beatmap with the user's ruleset
playableBeatmap = working.GetPlayableBeatmap(ruleset); playableBeatmap = beatmap.GetPlayableBeatmap(ruleset);
} }
catch (BeatmapInvalidForRulesetException) catch (BeatmapInvalidForRulesetException)
{ {
// Can't be converted to the user's ruleset, so use the beatmap's own ruleset // Can't be converted to the user's ruleset, so use the beatmap's own ruleset
playableBeatmap = working.GetPlayableBeatmap(working.BeatmapInfo.Ruleset); playableBeatmap = beatmap.GetPlayableBeatmap(beatmap.BeatmapInfo.Ruleset);
} }
labels.AddRange(playableBeatmap.GetStatistics().Select(s => new InfoLabel(s))); labels.AddRange(playableBeatmap.GetStatistics().Select(s => new InfoLabel(s)));

View File

@ -430,7 +430,7 @@ namespace osu.Game.Screens.Select
backgroundModeBeatmap.FadeTo(1, 250); backgroundModeBeatmap.FadeTo(1, 250);
} }
beatmapInfoWedge.UpdateBeatmap(beatmap); beatmapInfoWedge.Beatmap = beatmap;
} }
private void ensurePlayingSelected(bool preview = false) private void ensurePlayingSelected(bool preview = false)