Handle the restoring of the screen status when the user status is changed back to online after having being set to DND / offline via the login overlay

This commit is contained in:
Lucas A 2019-04-30 21:40:44 +02:00
parent 7e42068a14
commit a3541339f5

View File

@ -98,8 +98,7 @@ namespace osu.Game.Screens
[Resolved(canBeNull: true)] [Resolved(canBeNull: true)]
private OsuLogo logo { get; set; } private OsuLogo logo { get; set; }
[Resolved(canBeNull: true)] private IAPIProvider api;
private IAPIProvider api { get; set; }
protected OsuScreen() protected OsuScreen()
{ {
@ -108,9 +107,10 @@ namespace osu.Game.Screens
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(OsuGame osu, AudioManager audio) private void load(OsuGame osu, AudioManager audio, IAPIProvider provider)
{ {
sampleExit = audio.Sample.Get(@"UI/screen-back"); sampleExit = audio.Sample.Get(@"UI/screen-back");
api = provider;
} }
public virtual bool OnPressed(GlobalAction action) public virtual bool OnPressed(GlobalAction action)
@ -133,14 +133,27 @@ namespace osu.Game.Screens
sampleExit?.Play(); sampleExit?.Play();
applyArrivingDefaults(true); applyArrivingDefaults(true);
if (api != null)
api.LocalUser.Value.Status.ValueChanged += userStatusChanged;
setUserStatus(ScreenStatus); setUserStatus(ScreenStatus);
base.OnResuming(last); base.OnResuming(last);
} }
private void userStatusChanged(ValueChangedEvent<UserStatus> obj)
{
if (obj.NewValue?.GetType() != ScreenStatus?.GetType()) //restore the status back to this screen's status when the user status is changed back to online after having being set to DND / offline
setUserStatus(ScreenStatus);
}
public override void OnSuspending(IScreen next) public override void OnSuspending(IScreen next)
{ {
base.OnSuspending(next); base.OnSuspending(next);
if (api != null)
api.LocalUser.Value.Status.ValueChanged -= userStatusChanged;
onSuspendingLogo(); onSuspendingLogo();
} }
@ -150,6 +163,9 @@ namespace osu.Game.Screens
backgroundStack?.Push(localBackground = CreateBackground()); backgroundStack?.Push(localBackground = CreateBackground());
if (api != null)
api.LocalUser.Value.Status.ValueChanged += userStatusChanged;
setUserStatus(ScreenStatus); setUserStatus(ScreenStatus);
base.OnEntering(last); base.OnEntering(last);
@ -160,6 +176,9 @@ namespace osu.Game.Screens
if (ValidForResume && logo != null) if (ValidForResume && logo != null)
onExitingLogo(); onExitingLogo();
if (api != null)
api.LocalUser.Value.Status.ValueChanged -= userStatusChanged;
if (base.OnExiting(next)) if (base.OnExiting(next))
return true; return true;