Skip to content

Commit

Permalink
Change point of queueing to avoid loading-from-in-queue
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Nov 26, 2024
1 parent 98044c1 commit 71294c3
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions osu.Game/Overlays/MedalOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected override void LoadComplete()
{
base.LoadComplete();

OverlayActivationMode.BindValueChanged(_ => displayIfReady(), true);
OverlayActivationMode.BindValueChanged(_ => showNextMedal(), true);
}

public override void Hide()
Expand Down Expand Up @@ -84,10 +84,13 @@ private void handleMedalMessages(SocketMessage obj)

var medalAnimation = new MedalAnimation(medal);

queuedMedals.Enqueue(medalAnimation);
Logger.Log($"Queueing medal unlock for \"{medal.Name}\" ({queuedMedals.Count} to display)");

Schedule(displayIfReady);
LoadComponentAsync(medalAnimation, m =>
{
queuedMedals.Enqueue(m);
showNextMedal();
});
}

protected override bool OnClick(ClickEvent e)
Expand Down Expand Up @@ -130,30 +133,21 @@ private void progressDisplayByUser()
showNextMedal();
}

private void displayIfReady()
private void showNextMedal()
{
if (OverlayActivationMode.Value != OverlayActivation.All)
// If already displayed, keep displaying medals regardless of activation mode changes.
if (OverlayActivationMode.Value != OverlayActivation.All && State.Value == Visibility.Hidden)
return;

if (currentMedalDisplay != null || queuedMedals.Any())
showNextMedal();
}

private void showNextMedal()
{
// A medal is already loading / loaded, so just ensure the overlay is visible.
// A medal is already displaying.
if (currentMedalDisplay != null)
{
Show();
return;
}

if (queuedMedals.TryDequeue(out currentMedalDisplay))
{
Logger.Log($"Preparing to display \"{currentMedalDisplay.Medal.Name}\"");

Logger.Log($"Displaying \"{currentMedalDisplay.Medal.Name}\"");
medalContainer.Add(currentMedalDisplay);
Show();
LoadComponentAsync(currentMedalDisplay, m => medalContainer.Add(m));
}
}

Expand Down

0 comments on commit 71294c3

Please sign in to comment.