From a3541339f541b7d6a2f71a7a96e479d89dff082d Mon Sep 17 00:00:00 2001 From: Lucas A Date: Tue, 30 Apr 2019 21:40:44 +0200 Subject: [PATCH] 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 --- osu.Game/Screens/OsuScreen.cs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/OsuScreen.cs b/osu.Game/Screens/OsuScreen.cs index cf743db9f7..11161dd688 100644 --- a/osu.Game/Screens/OsuScreen.cs +++ b/osu.Game/Screens/OsuScreen.cs @@ -98,8 +98,7 @@ namespace osu.Game.Screens [Resolved(canBeNull: true)] private OsuLogo logo { get; set; } - [Resolved(canBeNull: true)] - private IAPIProvider api { get; set; } + private IAPIProvider api; protected OsuScreen() { @@ -108,9 +107,10 @@ namespace osu.Game.Screens } [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"); + api = provider; } public virtual bool OnPressed(GlobalAction action) @@ -133,14 +133,27 @@ namespace osu.Game.Screens sampleExit?.Play(); applyArrivingDefaults(true); + if (api != null) + api.LocalUser.Value.Status.ValueChanged += userStatusChanged; + setUserStatus(ScreenStatus); base.OnResuming(last); } + private void userStatusChanged(ValueChangedEvent 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) { base.OnSuspending(next); + + if (api != null) + api.LocalUser.Value.Status.ValueChanged -= userStatusChanged; + onSuspendingLogo(); } @@ -150,6 +163,9 @@ namespace osu.Game.Screens backgroundStack?.Push(localBackground = CreateBackground()); + if (api != null) + api.LocalUser.Value.Status.ValueChanged += userStatusChanged; + setUserStatus(ScreenStatus); base.OnEntering(last); @@ -160,6 +176,9 @@ namespace osu.Game.Screens if (ValidForResume && logo != null) onExitingLogo(); + if (api != null) + api.LocalUser.Value.Status.ValueChanged -= userStatusChanged; + if (base.OnExiting(next)) return true;