mirror of https://github.com/ppy/osu
Improve code around background screen handling to read better
This commit is contained in:
parent
c7abda8f58
commit
93da531d13
|
@ -17,15 +17,21 @@ public BackgroundScreenStack()
|
|||
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 @@ public override void OnEntering(IScreen last)
|
|||
{
|
||||
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