Fix logo sample always playing in main menu when initially logged out

This commit is contained in:
Bartłomiej Dach 2021-11-10 14:03:29 +01:00
parent b1e13e2d63
commit 30efc589d1
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
1 changed files with 10 additions and 3 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -214,10 +215,16 @@ protected override void LogoArriving(OsuLogo logo, bool resuming)
}
else if (!api.IsLoggedIn)
{
logo.Action += displayLogin;
// copy out old action to avoid accidentally capturing logo.Action in closure, causing a self-reference loop.
var previousAction = logo.Action;
// we want to hook into logo.Action to display the login overlay, but also preserve the return value of the old action.
// therefore pass the old action to displayLogin, so that it can return that value.
// this ensures that the OsuLogo sample does not play when it is not desired.
logo.Action = () => displayLogin(previousAction);
}
bool displayLogin()
bool displayLogin(Func<bool> originalAction)
{
if (!loginDisplayed.Value)
{
@ -225,7 +232,7 @@ bool displayLogin()
loginDisplayed.Value = true;
}
return true;
return originalAction.Invoke();
}
}