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:
commit
ac96744671
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user