From 5d4aa5a12e669e77edb03ef14be284cf23741fc2 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Thu, 2 May 2019 20:51:19 +0200 Subject: [PATCH] Add ScreenStatus property to change the OsuScreen's status + Renamed old ScreenStatus property to InitialScreenStatus --- .../TestCaseBackgroundScreenBeatmap.cs | 8 +++-- .../Visual/Gameplay/TestCasePause.cs | 2 +- osu.Game/Screens/Edit/Editor.cs | 2 +- osu.Game/Screens/OsuScreen.cs | 33 +++++++++++++++---- osu.Game/Screens/Play/Player.cs | 2 +- osu.Game/Screens/Play/PlayerLoader.cs | 2 +- osu.Game/Screens/Select/PlaySongSelect.cs | 2 +- 7 files changed, 36 insertions(+), 15 deletions(-) diff --git a/osu.Game.Tests/Visual/Background/TestCaseBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/Background/TestCaseBackgroundScreenBeatmap.cs index d4e563220b..58404d307f 100644 --- a/osu.Game.Tests/Visual/Background/TestCaseBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/Background/TestCaseBackgroundScreenBeatmap.cs @@ -275,6 +275,8 @@ namespace osu.Game.Tests.Visual.Background private class DummySongSelect : PlaySongSelect { + protected override UserStatusOnline InitialScreenStatus => null; + protected override BackgroundScreen CreateBackground() { FadeAccessibleBackground background = new FadeAccessibleBackground(Beatmap.Value); @@ -318,7 +320,7 @@ namespace osu.Game.Tests.Visual.Background private class FadeAccessibleResults : SoloResults { - protected override UserStatus ScreenStatus => null; + protected override UserStatusOnline InitialScreenStatus => null; public FadeAccessibleResults(ScoreInfo score) : base(score) @@ -332,7 +334,7 @@ namespace osu.Game.Tests.Visual.Background private class TestPlayer : Player { - protected override UserStatus ScreenStatus => null; + protected override UserStatusOnline InitialScreenStatus => null; protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(Beatmap.Value); @@ -381,7 +383,7 @@ namespace osu.Game.Tests.Visual.Background public VisualSettings VisualSettingsPos => VisualSettings; public BackgroundScreen ScreenPos => Background; - protected override UserStatus ScreenStatus => null; + protected override UserStatusOnline InitialScreenStatus => null; public TestPlayerLoader(Player player) : base(() => player) diff --git a/osu.Game.Tests/Visual/Gameplay/TestCasePause.cs b/osu.Game.Tests/Visual/Gameplay/TestCasePause.cs index eb84fe6316..ae7faf318f 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestCasePause.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestCasePause.cs @@ -193,7 +193,7 @@ namespace osu.Game.Tests.Visual.Gameplay public new HUDOverlay HUDOverlay => base.HUDOverlay; - protected override UserStatus ScreenStatus => null; + protected override UserStatusOnline InitialScreenStatus => null; public bool FailOverlayVisible => FailOverlay.State == Visibility.Visible; diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 6cbbc90ada..a04124082c 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -48,7 +48,7 @@ namespace osu.Game.Screens.Edit private DependencyContainer dependencies; private GameHost host; - protected override UserStatus ScreenStatus => new UserStatusEditing(Beatmap.Value.BeatmapInfo); + protected override UserStatusOnline InitialScreenStatus => new UserStatusEditing(Beatmap.Value.BeatmapInfo); protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) => dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); diff --git a/osu.Game/Screens/OsuScreen.cs b/osu.Game/Screens/OsuScreen.cs index f00d18271d..17b8ca60dc 100644 --- a/osu.Game/Screens/OsuScreen.cs +++ b/osu.Game/Screens/OsuScreen.cs @@ -55,12 +55,29 @@ 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 + /// The to set the user's status automatically to when this screen is entered /// - protected virtual UserStatus ScreenStatus => new UserStatusOnline(); + protected virtual UserStatusOnline InitialScreenStatus => new UserStatusOnline(); + + /// + /// The for this screen. + /// Note that the status won't be updated for the user if : + /// - The is set to null + /// - The current of the user is or + /// + protected UserStatusOnline ScreenStatus + { + set + { + if (value == null) return; + + status = value; + setUserStatus(value); + } + get => status; + } + + private UserStatusOnline status; /// /// Whether to disallow changes to game-wise Beatmap/Ruleset bindables for this screen (and all children). @@ -104,6 +121,8 @@ namespace osu.Game.Screens { Anchor = Anchor.Centre; Origin = Anchor.Centre; + + status = null; } [BackgroundDependencyLoader(true)] @@ -136,7 +155,7 @@ namespace osu.Game.Screens if (api != null) api.LocalUser.Value.Status.ValueChanged += userStatusChanged; - setUserStatus(ScreenStatus); + ScreenStatus = ScreenStatus; base.OnResuming(last); } @@ -167,7 +186,7 @@ namespace osu.Game.Screens if (api != null) api.LocalUser.Value.Status.ValueChanged += userStatusChanged; - setUserStatus(ScreenStatus); + ScreenStatus = InitialScreenStatus; base.OnEntering(last); } diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 3a3bac8070..883e96b316 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -35,7 +35,7 @@ namespace osu.Game.Screens.Play { protected override bool AllowBackButton => false; // handled by HoldForMenuButton - protected override UserStatus ScreenStatus => new UserStatusSoloGame(Beatmap.Value.BeatmapInfo, Ruleset.Value); + protected override UserStatusOnline InitialScreenStatus => new UserStatusSoloGame(Beatmap.Value.BeatmapInfo, Ruleset.Value); public override float BackgroundParallaxAmount => 0.1f; diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 1099fbdcfd..8c4bf079ea 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -43,7 +43,7 @@ namespace osu.Game.Screens.Play private bool hideOverlays; public override bool HideOverlaysOnEnter => hideOverlays; - protected override UserStatus ScreenStatus => null; //shows the previous screen status + protected override UserStatusOnline InitialScreenStatus => null; //shows the previous screen status public override bool DisallowExternalBeatmapRulesetChanges => true; diff --git a/osu.Game/Screens/Select/PlaySongSelect.cs b/osu.Game/Screens/Select/PlaySongSelect.cs index 8c6872846e..58b8ef3d28 100644 --- a/osu.Game/Screens/Select/PlaySongSelect.cs +++ b/osu.Game/Screens/Select/PlaySongSelect.cs @@ -19,7 +19,7 @@ namespace osu.Game.Screens.Select public override bool AllowExternalScreenChange => true; - protected override UserStatus ScreenStatus => new UserStatusChoosingBeatmap(); + protected override UserStatusOnline InitialScreenStatus => new UserStatusChoosingBeatmap(); [BackgroundDependencyLoader] private void load(OsuColour colours)