diff --git a/osu.Game/Screens/OsuScreen.cs b/osu.Game/Screens/OsuScreen.cs index e0a25deecf..d54936ffda 100644 --- a/osu.Game/Screens/OsuScreen.cs +++ b/osu.Game/Screens/OsuScreen.cs @@ -14,6 +14,8 @@ using osu.Game.Input.Bindings; using osu.Game.Rulesets; using osu.Game.Screens.Menu; using osu.Game.Overlays; +using osu.Game.Users; +using osu.Game.Online.API; namespace osu.Game.Screens { @@ -50,6 +52,14 @@ namespace osu.Game.Screens protected new OsuGameBase Game => base.Game as OsuGameBase; + /// + /// The to set the user's status automatically to when this screen is entered / resumed. + /// Note that the user status won't be automatically set if : + /// - is overriden and returns null + /// - The current is or + /// + protected virtual UserStatus ScreenStatus => new UserStatusOnline(); + /// /// Whether to disallow changes to game-wise Beatmap/Ruleset bindables for this screen (and all children). /// @@ -83,6 +93,9 @@ namespace osu.Game.Screens [Resolved(canBeNull: true)] private OsuLogo logo { get; set; } + [Resolved(canBeNull: true)] + private IAPIProvider api { get; set; } + protected OsuScreen() { Anchor = Anchor.Centre; @@ -115,6 +128,8 @@ namespace osu.Game.Screens sampleExit?.Play(); applyArrivingDefaults(true); + setUserStatus(ScreenStatus); + base.OnResuming(last); } @@ -130,6 +145,8 @@ namespace osu.Game.Screens backgroundStack?.Push(localBackground = CreateBackground()); + setUserStatus(ScreenStatus); + base.OnEntering(last); } @@ -147,6 +164,12 @@ namespace osu.Game.Screens return false; } + private void setUserStatus(UserStatus status) + { + if (api != null && status != null && !(api.LocalUser.Value.Status.Value is UserStatusDoNotDisturb) && !(api.LocalUser.Value.Status.Value is UserStatusOffline)) //only sets the user's status to the given one if + api.LocalUser.Value.Status.Value = status; //status is not null and the current status isn't either UserStatusDoNotDisturb or UserStatusOffline + } + /// /// Fired when this screen was entered or resumed and the logo state is required to be adjusted. ///