mirror of
https://github.com/osukey/osukey.git
synced 2025-08-06 16:13:57 +09:00
Rework OsuScreen user activity logic
This commit is contained in:
@ -55,29 +55,27 @@ namespace osu.Game.Screens
|
|||||||
protected new OsuGameBase Game => base.Game as OsuGameBase;
|
protected new OsuGameBase Game => base.Game as OsuGameBase;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The <see cref="UserStatusOnline"/> to set the user's status automatically to when this screen is entered
|
/// The <see cref="UserActivity"/> to set the user's activity automatically to when this screen is entered
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual UserStatusOnline InitialScreenStatus => new UserStatusOnline();
|
protected virtual UserActivity InitialScreenActivity => null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The <see cref="UserStatusOnline"/> for this screen.
|
/// The <see cref="UserActivity"/> for this screen.
|
||||||
/// Note that the status won't be updated for the user if :
|
|
||||||
/// <para>- The <see cref="ScreenStatus"/> is set to null</para>
|
|
||||||
/// <para>- The current <see cref="UserStatus"/> of the user is <see cref="UserStatusDoNotDisturb"/> or <see cref="UserStatusOffline"/></para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected UserStatusOnline ScreenStatus
|
protected UserActivity ScreenActivity
|
||||||
{
|
{
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value == null) return;
|
if (value == null) return;
|
||||||
|
if (api == null) return;
|
||||||
|
|
||||||
status = value;
|
activity = value;
|
||||||
setUserStatus(value);
|
api.LocalUser.Value.Activity.Value = activity;
|
||||||
}
|
}
|
||||||
get => status;
|
get => activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private UserStatusOnline status;
|
private UserActivity activity;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether to disallow changes to game-wise Beatmap/Ruleset bindables for this screen (and all children).
|
/// Whether to disallow changes to game-wise Beatmap/Ruleset bindables for this screen (and all children).
|
||||||
@ -122,7 +120,7 @@ namespace osu.Game.Screens
|
|||||||
Anchor = Anchor.Centre;
|
Anchor = Anchor.Centre;
|
||||||
Origin = Anchor.Centre;
|
Origin = Anchor.Centre;
|
||||||
|
|
||||||
status = null;
|
activity = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader(true)]
|
[BackgroundDependencyLoader(true)]
|
||||||
@ -152,28 +150,15 @@ namespace osu.Game.Screens
|
|||||||
sampleExit?.Play();
|
sampleExit?.Play();
|
||||||
applyArrivingDefaults(true);
|
applyArrivingDefaults(true);
|
||||||
|
|
||||||
if (api != null)
|
|
||||||
api.LocalUser.Value.Status.ValueChanged += userStatusChanged;
|
|
||||||
|
|
||||||
ScreenStatus = ScreenStatus;
|
ScreenStatus = ScreenStatus;
|
||||||
|
|
||||||
base.OnResuming(last);
|
base.OnResuming(last);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void userStatusChanged(ValueChangedEvent<UserStatus> obj)
|
|
||||||
{
|
|
||||||
if (obj.NewValue?.GetType() == ScreenStatus?.GetType()) return; //don't update the user's status if the current status is of the same type as the given one
|
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,10 +168,7 @@ namespace osu.Game.Screens
|
|||||||
|
|
||||||
backgroundStack?.Push(localBackground = CreateBackground());
|
backgroundStack?.Push(localBackground = CreateBackground());
|
||||||
|
|
||||||
if (api != null)
|
ScreenStatus = InitialScreenActivity;
|
||||||
api.LocalUser.Value.Status.ValueChanged += userStatusChanged;
|
|
||||||
|
|
||||||
ScreenStatus = InitialScreenStatus;
|
|
||||||
|
|
||||||
base.OnEntering(last);
|
base.OnEntering(last);
|
||||||
}
|
}
|
||||||
@ -196,9 +178,6 @@ 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;
|
||||||
|
|
||||||
@ -208,16 +187,6 @@ namespace osu.Game.Screens
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUserStatus(UserStatus status)
|
|
||||||
{
|
|
||||||
if (api == null) return;
|
|
||||||
if (status == null) return;
|
|
||||||
|
|
||||||
if (!(api.LocalUser.Value.Status.Value is UserStatusOnline)) return; //don't update the user's status if the current status doesn't allow to be modified by screens (eg: DND / Offline)
|
|
||||||
|
|
||||||
api.LocalUser.Value.Status.Value = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fired when this screen was entered or resumed and the logo state is required to be adjusted.
|
/// Fired when this screen was entered or resumed and the logo state is required to be adjusted.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Reference in New Issue
Block a user