Skip to content

Commit

Permalink
Better control of show/hide of overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Nov 26, 2024
1 parent d057dc9 commit 672dbe6
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions osu.Game/Overlays/MedalOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ protected override void LoadComplete()
OverlayActivationMode.BindValueChanged(_ => displayIfReady(), true);
}

public override void Hide()
{
// don't allow hiding the overlay via any method other than our own.
}

private void handleMedalMessages(SocketMessage obj)
{
if (obj.Event != @"new")
Expand Down Expand Up @@ -87,64 +92,66 @@ private void handleMedalMessages(SocketMessage obj)

protected override bool OnClick(ClickEvent e)
{
dismissDisplayedMedal();
loadNextMedal();
progressDisplayByUser();
return true;
}

public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
if (e.Action == GlobalAction.Back)
{
dismissDisplayedMedal();
loadNextMedal();
progressDisplayByUser();
return true;
}

return base.OnPressed(e);
}

private void dismissDisplayedMedal()
private void progressDisplayByUser()
{
// For now, we want to make sure that medals are definitely seen by the user.
// So we block exiting the overlay until the load of the active medal completes.
if (currentMedalDisplay?.IsLoaded == false)
return;

currentMedalDisplay?.Dismiss();
currentMedalDisplay = null;

if (!queuedMedals.Any())
{
Logger.Log("All queued medals have been displayed, hiding overlay!");
base.Hide();
return;
}

showNextMedal();
}

private void displayIfReady()
{
if (OverlayActivationMode.Value != OverlayActivation.All)
return;

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

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

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

private void loadNextMedal()
{
if (currentMedalDisplay != null)
return;

if (!queuedMedals.TryDequeue(out currentMedalDisplay))
{
Logger.Log("All queued medals have been displayed!");
Hide();
return;
Show();
LoadComponentAsync(currentMedalDisplay, m => medalContainer.Add(m));
}

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

protected override void Dispose(bool isDisposing)
Expand Down

0 comments on commit 672dbe6

Please sign in to comment.