1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 16:52:54 +08:00

Merge pull request #14654 from peppy/improve-background-screen-ownership-code-quality

Improve code around background screen handling to read better
This commit is contained in:
Dan Balasescu 2021-09-07 17:06:18 +09:00 committed by GitHub
commit ac96744671
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 9 deletions

View File

@ -17,15 +17,21 @@ namespace osu.Game.Screens
Origin = Anchor.Centre;
}
public void Push(BackgroundScreen screen)
/// <summary>
/// Attempt to push a new background screen to this stack.
/// </summary>
/// <param name="screen">The screen to attempt to push.</param>
/// <returns>Whether the push succeeded. For example, if the existing screen was already of the correct type this will return <c>false</c>.</returns>
public bool Push(BackgroundScreen screen)
{
if (screen == null)
return;
return false;
if (EqualityComparer<BackgroundScreen>.Default.Equals((BackgroundScreen)CurrentScreen, screen))
return;
return false;
base.Push(screen);
return true;
}
}
}

View File

@ -186,17 +186,14 @@ namespace osu.Game.Screens
{
applyArrivingDefaults(false);
backgroundStack?.Push(ownedBackground = CreateBackground());
background = backgroundStack?.CurrentScreen as BackgroundScreen;
if (background != ownedBackground)
if (backgroundStack?.Push(ownedBackground = CreateBackground()) != true)
{
// background may have not been replaced, at which point we don't want to track the background lifetime.
// If the constructed instance was not actually pushed to the background stack, we don't want to track it unnecessarily.
ownedBackground?.Dispose();
ownedBackground = null;
}
background = backgroundStack?.CurrentScreen as BackgroundScreen;
base.OnEntering(last);
}