OsuScreens can now set a per screen user status

which defaults to UserStatusOnline
This commit is contained in:
Lucas A 2019-04-12 22:36:01 +02:00
parent 67a03bbc90
commit 69dda0ffd4
1 changed files with 23 additions and 0 deletions

View File

@ -14,6 +14,8 @@
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 @@ public abstract class OsuScreen : Screen, IOsuScreen, IKeyBindingHandler<GlobalA
protected new OsuGameBase Game => base.Game as OsuGameBase;
/// <summary>
/// The <see cref="UserStatus"/> 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 :
/// <para>- <see cref="ScreenStatus"/> is overriden and returns null</para>
/// <para>- The current <see cref="UserStatus"/> is <see cref="UserStatusDoNotDisturb"/> or <see cref="UserStatusOffline"/></para>
/// </summary>
protected virtual UserStatus ScreenStatus => new UserStatusOnline();
/// <summary>
/// Whether to disallow changes to game-wise Beatmap/Ruleset bindables for this screen (and all children).
/// </summary>
@ -83,6 +93,9 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
[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 @@ public override void OnResuming(IScreen last)
sampleExit?.Play();
applyArrivingDefaults(true);
setUserStatus(ScreenStatus);
base.OnResuming(last);
}
@ -130,6 +145,8 @@ public override void OnEntering(IScreen last)
backgroundStack?.Push(localBackground = CreateBackground());
setUserStatus(ScreenStatus);
base.OnEntering(last);
}
@ -147,6 +164,12 @@ public override bool OnExiting(IScreen next)
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
}
/// <summary>
/// Fired when this screen was entered or resumed and the logo state is required to be adjusted.
/// </summary>