mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 11:07:52 +08:00
Extract UserActivity logic to OsuGame.
This commit is contained in:
parent
567cf932f1
commit
790a2ca97d
@ -51,6 +51,7 @@ using osu.Game.Screens.Select;
|
||||
using osu.Game.Updater;
|
||||
using osu.Game.Utils;
|
||||
using LogLevel = osu.Framework.Logging.LogLevel;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game
|
||||
{
|
||||
@ -961,11 +962,15 @@ namespace osu.Game
|
||||
LocalUserPlaying.Value = false;
|
||||
|
||||
if (current is IOsuScreen currentOsuScreen)
|
||||
{
|
||||
OverlayActivationMode.UnbindFrom(currentOsuScreen.OverlayActivationMode);
|
||||
API.Activity.UnbindFrom(currentOsuScreen.Activity);
|
||||
}
|
||||
|
||||
if (newScreen is IOsuScreen newOsuScreen)
|
||||
{
|
||||
OverlayActivationMode.BindTo(newOsuScreen.OverlayActivationMode);
|
||||
((IBindable<UserActivity>)API.Activity).BindTo(newOsuScreen.Activity);
|
||||
|
||||
MusicController.AllowRateAdjustments = newOsuScreen.AllowRateAdjustments;
|
||||
|
||||
|
@ -6,6 +6,7 @@ using osu.Framework.Screens;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Screens
|
||||
{
|
||||
@ -43,6 +44,11 @@ namespace osu.Game.Screens
|
||||
/// </summary>
|
||||
IBindable<OverlayActivation> OverlayActivationMode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The current <see cref="UserActivity"/> for this screen.
|
||||
/// </summary>
|
||||
IBindable<UserActivity> Activity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The amount of parallax to be applied while this screen is displayed.
|
||||
/// </summary>
|
||||
|
@ -14,7 +14,6 @@ using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.Menu;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Users;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
|
||||
namespace osu.Game.Screens
|
||||
@ -63,22 +62,12 @@ namespace osu.Game.Screens
|
||||
/// </summary>
|
||||
protected virtual UserActivity InitialActivity => null;
|
||||
|
||||
private UserActivity activity;
|
||||
|
||||
/// <summary>
|
||||
/// The current <see cref="UserActivity"/> for this screen.
|
||||
/// </summary>
|
||||
protected UserActivity Activity
|
||||
{
|
||||
get => activity;
|
||||
set
|
||||
{
|
||||
if (value == activity) return;
|
||||
protected readonly Bindable<UserActivity> Activity;
|
||||
|
||||
activity = value;
|
||||
updateActivity();
|
||||
}
|
||||
}
|
||||
IBindable<UserActivity> IOsuScreen.Activity => Activity;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to disallow changes to game-wise Beatmap/Ruleset bindables for this screen (and all children).
|
||||
@ -135,15 +124,13 @@ 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;
|
||||
Origin = Anchor.Centre;
|
||||
|
||||
OverlayActivationMode = new Bindable<OverlayActivation>(InitialOverlayActivationMode);
|
||||
Activity = new Bindable<UserActivity>();
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
@ -158,8 +145,6 @@ namespace osu.Game.Screens
|
||||
sampleExit?.Play();
|
||||
applyArrivingDefaults(true);
|
||||
|
||||
updateActivity();
|
||||
|
||||
base.OnResuming(last);
|
||||
}
|
||||
|
||||
@ -176,8 +161,8 @@ namespace osu.Game.Screens
|
||||
|
||||
backgroundStack?.Push(localBackground = CreateBackground());
|
||||
|
||||
if (activity == null)
|
||||
Activity = InitialActivity;
|
||||
if (Activity.Value == null)
|
||||
Activity.Value = InitialActivity;
|
||||
|
||||
base.OnEntering(last);
|
||||
}
|
||||
@ -196,12 +181,6 @@ namespace osu.Game.Screens
|
||||
return false;
|
||||
}
|
||||
|
||||
private void updateActivity()
|
||||
{
|
||||
if (api != null)
|
||||
api.Activity.Value = activity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fired when this screen was entered or resumed and the logo state is required to be adjusted.
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user