From 7d23973ef8aa53c77b09201b829800060c61f401 Mon Sep 17 00:00:00 2001 From: jvyden Date: Fri, 16 Apr 2021 05:01:58 -0400 Subject: [PATCH 01/15] Reset SessionStatics on activity Closes #12424 --- .../Visual/Components/TestSceneIdleTracker.cs | 39 +++++++++++++++---- osu.Game/Configuration/SessionStatics.cs | 8 ++++ osu.Game/Input/GameIdleTracker.cs | 11 +++++- osu.Game/OsuGame.cs | 2 +- 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs index 4d64c7d35d..794f6ae83f 100644 --- a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs +++ b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs @@ -5,6 +5,7 @@ using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Game.Configuration; using osu.Game.Input; using osuTK; using osuTK.Graphics; @@ -21,14 +22,17 @@ namespace osu.Game.Tests.Visual.Components private IdleTrackingBox[] boxes; + public SessionStatics sessionStatics; + [SetUp] public void SetUp() => Schedule(() => { + sessionStatics = new SessionStatics(); InputManager.MoveMouseTo(Vector2.Zero); Children = boxes = new[] { - box1 = new IdleTrackingBox(2000) + box1 = new IdleTrackingBox(2000, sessionStatics) { Name = "TopLeft", RelativeSizeAxes = Axes.Both, @@ -36,7 +40,7 @@ namespace osu.Game.Tests.Visual.Components Anchor = Anchor.TopLeft, Origin = Anchor.TopLeft, }, - box2 = new IdleTrackingBox(4000) + box2 = new IdleTrackingBox(4000, sessionStatics) { Name = "TopRight", RelativeSizeAxes = Axes.Both, @@ -44,7 +48,7 @@ namespace osu.Game.Tests.Visual.Components Anchor = Anchor.TopRight, Origin = Anchor.TopRight, }, - box3 = new IdleTrackingBox(6000) + box3 = new IdleTrackingBox(6000, sessionStatics) { Name = "BottomLeft", RelativeSizeAxes = Axes.Both, @@ -52,7 +56,7 @@ namespace osu.Game.Tests.Visual.Components Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, }, - box4 = new IdleTrackingBox(8000) + box4 = new IdleTrackingBox(8000, sessionStatics) { Name = "BottomRight", RelativeSizeAxes = Axes.Both, @@ -61,6 +65,7 @@ namespace osu.Game.Tests.Visual.Components Origin = Anchor.BottomRight, }, }; + }); [Test] @@ -133,6 +138,26 @@ namespace osu.Game.Tests.Visual.Components waitForAllIdle(); } + [Test] + public void TestSessionStaticsReset() + { + AddStep("move to top left", () => InputManager.MoveMouseTo(box1)); + AddStep("set session statics", () => + { + sessionStatics.SetValue(Static.LoginOverlayDisplayed, true); + sessionStatics.SetValue(Static.MutedAudioNotificationShownOnce, true); + sessionStatics.SetValue(Static.LowBatteryNotificationShownOnce, true); + sessionStatics.SetValue(Static.LastHoverSoundPlaybackTime, (double?)1d); + }); + + AddStep("move away from box1", () => InputManager.MoveMouseTo(box4)); + AddUntilStep("Wait for idle", () => box1.IsIdle); + AddAssert("LoginOverlayDisplayed is default", () => sessionStatics.Get(Static.LoginOverlayDisplayed) == false); + AddAssert("MutedAudioNotificationShownOnce is default", () => sessionStatics.Get(Static.MutedAudioNotificationShownOnce) == false); + AddAssert("LowBatteryNotificationShownOnce is default", () => sessionStatics.Get(Static.LowBatteryNotificationShownOnce) == false); + AddAssert("LastHoverSoundPlaybackTime is default", () => sessionStatics.Get(Static.LastHoverSoundPlaybackTime) == null); + } + private void checkIdleStatus(int box, bool expectedIdle) { AddAssert($"box {box} is {(expectedIdle ? "idle" : "active")}", () => boxes[box - 1].IsIdle == expectedIdle); @@ -140,7 +165,7 @@ namespace osu.Game.Tests.Visual.Components private void waitForAllIdle() { - AddUntilStep("Wait for all idle", () => box1.IsIdle && box2.IsIdle && box3.IsIdle && box4.IsIdle); + AddUntilStep("wait for all idle", () => box1.IsIdle && box2.IsIdle && box3.IsIdle && box4.IsIdle); } private class IdleTrackingBox : CompositeDrawable @@ -149,7 +174,7 @@ namespace osu.Game.Tests.Visual.Components public bool IsIdle => idleTracker.IsIdle.Value; - public IdleTrackingBox(double timeToIdle) + public IdleTrackingBox(int timeToIdle, SessionStatics statics) { Box box; @@ -158,7 +183,7 @@ namespace osu.Game.Tests.Visual.Components InternalChildren = new Drawable[] { - idleTracker = new IdleTracker(timeToIdle), + idleTracker = new GameIdleTracker(timeToIdle, statics), box = new Box { Colour = Color4.White, diff --git a/osu.Game/Configuration/SessionStatics.cs b/osu.Game/Configuration/SessionStatics.cs index 71e1a1efcc..c960409de8 100644 --- a/osu.Game/Configuration/SessionStatics.cs +++ b/osu.Game/Configuration/SessionStatics.cs @@ -20,6 +20,14 @@ namespace osu.Game.Configuration SetDefault(Static.LastHoverSoundPlaybackTime, (double?)null); SetDefault(Static.SeasonalBackgrounds, null); } + + public void ResetValues() + { + SetValue(Static.LoginOverlayDisplayed, false); + SetValue(Static.MutedAudioNotificationShownOnce, false); + SetValue(Static.LowBatteryNotificationShownOnce, false); + SetValue(Static.LastHoverSoundPlaybackTime, (double?)null); + } } public enum Static diff --git a/osu.Game/Input/GameIdleTracker.cs b/osu.Game/Input/GameIdleTracker.cs index 260be7e5c9..53dab0c07b 100644 --- a/osu.Game/Input/GameIdleTracker.cs +++ b/osu.Game/Input/GameIdleTracker.cs @@ -1,7 +1,9 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using osu.Framework.Bindables; using osu.Framework.Input; +using osu.Game.Configuration; namespace osu.Game.Input { @@ -9,9 +11,16 @@ namespace osu.Game.Input { private InputManager inputManager; - public GameIdleTracker(int time) + public GameIdleTracker(int time, SessionStatics statics) : base(time) { + IsIdle.ValueChanged += _ => UpdateStatics(_, statics); + } + + protected static void UpdateStatics(ValueChangedEvent e, SessionStatics statics) + { + if (e.OldValue != e.NewValue && e.NewValue) + statics.ResetValues(); } protected override void LoadComplete() diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 809e5d3c1b..97d4011607 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -575,7 +575,7 @@ namespace osu.Game Container logoContainer; BackButton.Receptor receptor; - dependencies.CacheAs(idleTracker = new GameIdleTracker(6000)); + dependencies.CacheAs(idleTracker = new GameIdleTracker(6000, Dependencies.Get())); AddRange(new Drawable[] { From 43e6e5e049a99ef85678cc4953a3f08335a6afdf Mon Sep 17 00:00:00 2001 From: jvyden Date: Fri, 16 Apr 2021 05:15:58 -0400 Subject: [PATCH 02/15] increase GameIdleTracker time to 5 minutes --- osu.Game/OsuGame.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 97d4011607..3930db01b9 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -575,7 +575,7 @@ namespace osu.Game Container logoContainer; BackButton.Receptor receptor; - dependencies.CacheAs(idleTracker = new GameIdleTracker(6000, Dependencies.Get())); + dependencies.CacheAs(idleTracker = new GameIdleTracker(300_000, Dependencies.Get())); AddRange(new Drawable[] { From d760e81a9130e5e9ea484e9a77225e743d4c900f Mon Sep 17 00:00:00 2001 From: jvyden Date: Fri, 16 Apr 2021 05:22:41 -0400 Subject: [PATCH 03/15] Fix lint --- osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs index 794f6ae83f..61efc61537 100644 --- a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs +++ b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs @@ -65,7 +65,6 @@ namespace osu.Game.Tests.Visual.Components Origin = Anchor.BottomRight, }, }; - }); [Test] From ec0211809f145e203408523de7b7f94f0d4ca6fd Mon Sep 17 00:00:00 2001 From: jvyden Date: Fri, 16 Apr 2021 05:53:27 -0400 Subject: [PATCH 04/15] Apply peppy's suggestions --- .../Visual/Components/TestSceneIdleTracker.cs | 11 ++++++++--- osu.Game/Configuration/SessionStatics.cs | 6 ++---- osu.Game/Input/GameIdleTracker.cs | 11 +---------- osu.Game/OsuGame.cs | 11 ++++++++++- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs index 61efc61537..be8e50d649 100644 --- a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs +++ b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs @@ -22,7 +22,7 @@ namespace osu.Game.Tests.Visual.Components private IdleTrackingBox[] boxes; - public SessionStatics sessionStatics; + private SessionStatics sessionStatics; [SetUp] public void SetUp() => Schedule(() => @@ -175,6 +175,7 @@ namespace osu.Game.Tests.Visual.Components public IdleTrackingBox(int timeToIdle, SessionStatics statics) { + Box box; Alpha = 0.6f; @@ -182,7 +183,7 @@ namespace osu.Game.Tests.Visual.Components InternalChildren = new Drawable[] { - idleTracker = new GameIdleTracker(timeToIdle, statics), + idleTracker = new GameIdleTracker(timeToIdle), box = new Box { Colour = Color4.White, @@ -190,7 +191,11 @@ namespace osu.Game.Tests.Visual.Components }, }; - idleTracker.IsIdle.BindValueChanged(idle => box.Colour = idle.NewValue ? Color4.White : Color4.Black, true); + idleTracker.IsIdle.BindValueChanged(idle => + { + box.Colour = idle.NewValue ? Color4.White : Color4.Black; + if (idle.NewValue) statics.ResetValues(); + }, true); } } } diff --git a/osu.Game/Configuration/SessionStatics.cs b/osu.Game/Configuration/SessionStatics.cs index c960409de8..99089dd076 100644 --- a/osu.Game/Configuration/SessionStatics.cs +++ b/osu.Game/Configuration/SessionStatics.cs @@ -23,10 +23,8 @@ namespace osu.Game.Configuration public void ResetValues() { - SetValue(Static.LoginOverlayDisplayed, false); - SetValue(Static.MutedAudioNotificationShownOnce, false); - SetValue(Static.LowBatteryNotificationShownOnce, false); - SetValue(Static.LastHoverSoundPlaybackTime, (double?)null); + ConfigStore.Clear(); + InitialiseDefaults(); } } diff --git a/osu.Game/Input/GameIdleTracker.cs b/osu.Game/Input/GameIdleTracker.cs index 53dab0c07b..260be7e5c9 100644 --- a/osu.Game/Input/GameIdleTracker.cs +++ b/osu.Game/Input/GameIdleTracker.cs @@ -1,9 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Bindables; using osu.Framework.Input; -using osu.Game.Configuration; namespace osu.Game.Input { @@ -11,16 +9,9 @@ namespace osu.Game.Input { private InputManager inputManager; - public GameIdleTracker(int time, SessionStatics statics) + public GameIdleTracker(int time) : base(time) { - IsIdle.ValueChanged += _ => UpdateStatics(_, statics); - } - - protected static void UpdateStatics(ValueChangedEvent e, SessionStatics statics) - { - if (e.OldValue != e.NewValue && e.NewValue) - statics.ResetValues(); } protected override void LoadComplete() diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 3930db01b9..0abb0373fa 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -575,7 +575,16 @@ namespace osu.Game Container logoContainer; BackButton.Receptor receptor; - dependencies.CacheAs(idleTracker = new GameIdleTracker(300_000, Dependencies.Get())); + dependencies.CacheAs(idleTracker = new GameIdleTracker(6000)); + + GameIdleTracker sessionIdleTracker = new GameIdleTracker(300_000); + Add(sessionIdleTracker); + + sessionIdleTracker.IsIdle.BindValueChanged((e) => + { + if (e.NewValue) + Dependencies.Get().ResetValues(); + }); AddRange(new Drawable[] { From 8d6c30c73bb39b5383a9119ea351a760e3b48722 Mon Sep 17 00:00:00 2001 From: jvyden Date: Fri, 16 Apr 2021 05:57:36 -0400 Subject: [PATCH 05/15] Fix lint --- osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs index be8e50d649..0bc0fbf5d4 100644 --- a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs +++ b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs @@ -175,7 +175,6 @@ namespace osu.Game.Tests.Visual.Components public IdleTrackingBox(int timeToIdle, SessionStatics statics) { - Box box; Alpha = 0.6f; From 9c6914d29ded9af216b56e6bcacb19ec2c71f88e Mon Sep 17 00:00:00 2001 From: jvyden Date: Fri, 16 Apr 2021 06:26:45 -0400 Subject: [PATCH 06/15] Fix redundant lambda parentheses --- osu.Game/OsuGame.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 0abb0373fa..898a2baccf 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -580,7 +580,7 @@ namespace osu.Game GameIdleTracker sessionIdleTracker = new GameIdleTracker(300_000); Add(sessionIdleTracker); - sessionIdleTracker.IsIdle.BindValueChanged((e) => + sessionIdleTracker.IsIdle.BindValueChanged(e => { if (e.NewValue) Dependencies.Get().ResetValues(); From a4e3e53a63788fdd09029836c779b94ff7389fd3 Mon Sep 17 00:00:00 2001 From: jvyden Date: Fri, 16 Apr 2021 06:34:57 -0400 Subject: [PATCH 07/15] Revert back to hardcoded SessionStatics reset values --- osu.Game/Configuration/SessionStatics.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/osu.Game/Configuration/SessionStatics.cs b/osu.Game/Configuration/SessionStatics.cs index 99089dd076..872a910837 100644 --- a/osu.Game/Configuration/SessionStatics.cs +++ b/osu.Game/Configuration/SessionStatics.cs @@ -23,8 +23,11 @@ namespace osu.Game.Configuration public void ResetValues() { - ConfigStore.Clear(); - InitialiseDefaults(); + SetValue(Static.LoginOverlayDisplayed, false); + SetValue(Static.MutedAudioNotificationShownOnce, false); + SetValue(Static.LowBatteryNotificationShownOnce, false); + SetValue(Static.LastHoverSoundPlaybackTime, (double?)null); + SetValue(Static.SeasonalBackgrounds, null); } } From 6773162f17bab34cb88272d915d07b19bfab7f47 Mon Sep 17 00:00:00 2001 From: jvyden Date: Sat, 17 Apr 2021 08:47:27 -0400 Subject: [PATCH 08/15] Implicitly set defaults when resetting values --- osu.Game/Configuration/SessionStatics.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game/Configuration/SessionStatics.cs b/osu.Game/Configuration/SessionStatics.cs index 872a910837..e57b1c2fdf 100644 --- a/osu.Game/Configuration/SessionStatics.cs +++ b/osu.Game/Configuration/SessionStatics.cs @@ -23,11 +23,11 @@ namespace osu.Game.Configuration public void ResetValues() { - SetValue(Static.LoginOverlayDisplayed, false); - SetValue(Static.MutedAudioNotificationShownOnce, false); - SetValue(Static.LowBatteryNotificationShownOnce, false); - SetValue(Static.LastHoverSoundPlaybackTime, (double?)null); - SetValue(Static.SeasonalBackgrounds, null); + GetOriginalBindable(Static.LoginOverlayDisplayed).SetDefault(); + GetOriginalBindable(Static.MutedAudioNotificationShownOnce).SetDefault(); + GetOriginalBindable(Static.LowBatteryNotificationShownOnce).SetDefault(); + GetOriginalBindable(Static.LastHoverSoundPlaybackTime).SetDefault(); + GetOriginalBindable(Static.SeasonalBackgrounds).SetDefault(); } } From 2b6caf9b650fd5cfc5af4e168d1d794322ceb4a8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 19 Apr 2021 11:25:43 +0900 Subject: [PATCH 09/15] Fix duplicate code in setting default logic --- osu.Game/Configuration/SessionStatics.cs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/osu.Game/Configuration/SessionStatics.cs b/osu.Game/Configuration/SessionStatics.cs index e57b1c2fdf..ac94c39bd2 100644 --- a/osu.Game/Configuration/SessionStatics.cs +++ b/osu.Game/Configuration/SessionStatics.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using osu.Framework.Bindables; using osu.Game.Graphics.UserInterface; using osu.Game.Online.API.Requests.Responses; using osu.Game.Overlays; @@ -12,23 +13,18 @@ namespace osu.Game.Configuration /// public class SessionStatics : InMemoryConfigManager { - protected override void InitialiseDefaults() - { - SetDefault(Static.LoginOverlayDisplayed, false); - SetDefault(Static.MutedAudioNotificationShownOnce, false); - SetDefault(Static.LowBatteryNotificationShownOnce, false); - SetDefault(Static.LastHoverSoundPlaybackTime, (double?)null); - SetDefault(Static.SeasonalBackgrounds, null); - } + protected override void InitialiseDefaults() => ResetValues(); public void ResetValues() { - GetOriginalBindable(Static.LoginOverlayDisplayed).SetDefault(); - GetOriginalBindable(Static.MutedAudioNotificationShownOnce).SetDefault(); - GetOriginalBindable(Static.LowBatteryNotificationShownOnce).SetDefault(); - GetOriginalBindable(Static.LastHoverSoundPlaybackTime).SetDefault(); - GetOriginalBindable(Static.SeasonalBackgrounds).SetDefault(); + ensureDefault(SetDefault(Static.LoginOverlayDisplayed, false)); + ensureDefault(SetDefault(Static.MutedAudioNotificationShownOnce, false)); + ensureDefault(SetDefault(Static.LowBatteryNotificationShownOnce, false)); + ensureDefault(SetDefault(Static.LastHoverSoundPlaybackTime, (double?)null)); + ensureDefault(SetDefault(Static.SeasonalBackgrounds, null)); } + + private void ensureDefault(Bindable bindable) => bindable.SetDefault(); } public enum Static From dbb8f7f4a95523e7770391f9a6c8578d39eae84a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 19 Apr 2021 11:30:55 +0900 Subject: [PATCH 10/15] Tidy up initialisation code and avoid using DI on inherited class --- osu.Game/OsuGame.cs | 12 ++++++------ osu.Game/OsuGameBase.cs | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 898a2baccf..1a2555f3f1 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -577,15 +577,15 @@ namespace osu.Game dependencies.CacheAs(idleTracker = new GameIdleTracker(6000)); - GameIdleTracker sessionIdleTracker = new GameIdleTracker(300_000); - Add(sessionIdleTracker); - - sessionIdleTracker.IsIdle.BindValueChanged(e => + var sessionIdleTracker = new GameIdleTracker(300000); + sessionIdleTracker.IsIdle.BindValueChanged(idle => { - if (e.NewValue) - Dependencies.Get().ResetValues(); + if (idle.NewValue) + SessionStatics.ResetValues(); }); + Add(new GameIdleTracker(300000)); + AddRange(new Drawable[] { new VolumeControlReceptor diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 406819cbd2..fbe4022cc1 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -61,6 +61,8 @@ namespace osu.Game protected OsuConfigManager LocalConfig; + protected SessionStatics SessionStatics { get; private set; } + protected BeatmapManager BeatmapManager; protected ScoreManager ScoreManager; @@ -289,7 +291,7 @@ namespace osu.Game if (powerStatus != null) dependencies.CacheAs(powerStatus); - dependencies.Cache(new SessionStatics()); + dependencies.Cache(SessionStatics = new SessionStatics()); dependencies.Cache(new OsuColour()); RegisterImportHandler(BeatmapManager); From b727faace38e51a056c4131443fbf3a5356fbd71 Mon Sep 17 00:00:00 2001 From: jvyden Date: Sun, 18 Apr 2021 23:03:43 -0400 Subject: [PATCH 11/15] Revert changes to IdleTracker --- .../Visual/Components/TestSceneIdleTracker.cs | 41 +++---------------- 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs index c3ea63ea65..d888f6a01e 100644 --- a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs +++ b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs @@ -5,7 +5,6 @@ using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; -using osu.Game.Configuration; using osu.Game.Input; using osuTK; using osuTK.Graphics; @@ -22,17 +21,14 @@ namespace osu.Game.Tests.Visual.Components private IdleTrackingBox[] boxes; - private SessionStatics sessionStatics; - [SetUp] public void SetUp() => Schedule(() => { - sessionStatics = new SessionStatics(); InputManager.MoveMouseTo(Vector2.Zero); Children = boxes = new[] { - box1 = new IdleTrackingBox(2000, sessionStatics) + box1 = new IdleTrackingBox(2000) { Name = "TopLeft", RelativeSizeAxes = Axes.Both, @@ -40,7 +36,7 @@ namespace osu.Game.Tests.Visual.Components Anchor = Anchor.TopLeft, Origin = Anchor.TopLeft, }, - box2 = new IdleTrackingBox(4000, sessionStatics) + box2 = new IdleTrackingBox(4000) { Name = "TopRight", RelativeSizeAxes = Axes.Both, @@ -48,7 +44,7 @@ namespace osu.Game.Tests.Visual.Components Anchor = Anchor.TopRight, Origin = Anchor.TopRight, }, - box3 = new IdleTrackingBox(6000, sessionStatics) + box3 = new IdleTrackingBox(6000) { Name = "BottomLeft", RelativeSizeAxes = Axes.Both, @@ -56,7 +52,7 @@ namespace osu.Game.Tests.Visual.Components Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, }, - box4 = new IdleTrackingBox(8000, sessionStatics) + box4 = new IdleTrackingBox(8000) { Name = "BottomRight", RelativeSizeAxes = Axes.Both, @@ -145,27 +141,6 @@ namespace osu.Game.Tests.Visual.Components waitForAllIdle(); } - - [Test] - public void TestSessionStaticsReset() - { - AddStep("move to top left", () => InputManager.MoveMouseTo(box1)); - AddStep("set session statics", () => - { - sessionStatics.SetValue(Static.LoginOverlayDisplayed, true); - sessionStatics.SetValue(Static.MutedAudioNotificationShownOnce, true); - sessionStatics.SetValue(Static.LowBatteryNotificationShownOnce, true); - sessionStatics.SetValue(Static.LastHoverSoundPlaybackTime, (double?)1d); - }); - - AddStep("move away from box1", () => InputManager.MoveMouseTo(box4)); - AddUntilStep("Wait for idle", () => box1.IsIdle); - AddAssert("LoginOverlayDisplayed is default", () => sessionStatics.Get(Static.LoginOverlayDisplayed) == false); - AddAssert("MutedAudioNotificationShownOnce is default", () => sessionStatics.Get(Static.MutedAudioNotificationShownOnce) == false); - AddAssert("LowBatteryNotificationShownOnce is default", () => sessionStatics.Get(Static.LowBatteryNotificationShownOnce) == false); - AddAssert("LastHoverSoundPlaybackTime is default", () => sessionStatics.Get(Static.LastHoverSoundPlaybackTime) == null); - } - private void checkIdleStatus(int box, bool expectedIdle) { AddAssert($"box {box} is {(expectedIdle ? "idle" : "active")}", () => boxes[box - 1].IsIdle == expectedIdle); @@ -182,7 +157,7 @@ namespace osu.Game.Tests.Visual.Components public bool IsIdle => idleTracker.IsIdle.Value; - public IdleTrackingBox(int timeToIdle, SessionStatics statics) + public IdleTrackingBox(int timeToIdle) { Box box; @@ -198,12 +173,6 @@ namespace osu.Game.Tests.Visual.Components RelativeSizeAxes = Axes.Both, }, }; - - idleTracker.IsIdle.BindValueChanged(idle => - { - box.Colour = idle.NewValue ? Color4.White : Color4.Black; - if (idle.NewValue) statics.ResetValues(); - }, true); } } } From c39ab2c69219ff8d47337993597d56fc51fd01ab Mon Sep 17 00:00:00 2001 From: jvyden Date: Sun, 18 Apr 2021 23:04:28 -0400 Subject: [PATCH 12/15] Add SessionStaticsTest --- .../NonVisual/SessionStaticsTest.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 osu.Game.Tests/NonVisual/SessionStaticsTest.cs diff --git a/osu.Game.Tests/NonVisual/SessionStaticsTest.cs b/osu.Game.Tests/NonVisual/SessionStaticsTest.cs new file mode 100644 index 0000000000..d5fd803986 --- /dev/null +++ b/osu.Game.Tests/NonVisual/SessionStaticsTest.cs @@ -0,0 +1,47 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Game.Configuration; +using osu.Game.Input; + +namespace osu.Game.Tests.NonVisual +{ + [TestFixture] + public class SessionStaticsTest + { + private SessionStatics sessionStatics; + private IdleTracker sessionIdleTracker; + + [SetUp] + public void SetUp() + { + sessionStatics = new SessionStatics(); + sessionIdleTracker = new GameIdleTracker(1000); + + sessionStatics.SetValue(Static.LoginOverlayDisplayed, true); + sessionStatics.SetValue(Static.MutedAudioNotificationShownOnce, true); + sessionStatics.SetValue(Static.LowBatteryNotificationShownOnce, true); + sessionStatics.SetValue(Static.LastHoverSoundPlaybackTime, (double?)1d); + + sessionIdleTracker.IsIdle.BindValueChanged(e => + { + if (e.NewValue) + sessionStatics.ResetValues(); + }); + } + + [Test] + [Timeout(2000)] + public void TestSessionStaticsReset() + { + sessionIdleTracker.IsIdle.BindValueChanged(e => + { + Assert.IsTrue(sessionStatics.GetBindable(Static.LoginOverlayDisplayed).IsDefault); + Assert.IsTrue(sessionStatics.GetBindable(Static.MutedAudioNotificationShownOnce).IsDefault); + Assert.IsTrue(sessionStatics.GetBindable(Static.LowBatteryNotificationShownOnce).IsDefault); + Assert.IsTrue(sessionStatics.GetBindable(Static.LastHoverSoundPlaybackTime).IsDefault); + }); + } + } +} From 999f2d810caba2e15d720aebcfdc1e2e47fcdf8b Mon Sep 17 00:00:00 2001 From: jvyden Date: Sun, 18 Apr 2021 23:30:07 -0400 Subject: [PATCH 13/15] Fix accidentally removed code --- osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs index d888f6a01e..77eadc14be 100644 --- a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs +++ b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs @@ -173,6 +173,8 @@ namespace osu.Game.Tests.Visual.Components RelativeSizeAxes = Axes.Both, }, }; + + idleTracker.IsIdle.BindValueChanged(idle => box.Colour = idle.NewValue ? Color4.White : Color4.Black, true); } } } From a854ce429a8a30f042d98521248a0b7b99456f19 Mon Sep 17 00:00:00 2001 From: jvyden Date: Sun, 18 Apr 2021 23:49:13 -0400 Subject: [PATCH 14/15] add blank line between method --- osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs index 77eadc14be..86a9d555a3 100644 --- a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs +++ b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs @@ -141,6 +141,7 @@ namespace osu.Game.Tests.Visual.Components waitForAllIdle(); } + private void checkIdleStatus(int box, bool expectedIdle) { AddAssert($"box {box} is {(expectedIdle ? "idle" : "active")}", () => boxes[box - 1].IsIdle == expectedIdle); From ffc1e841e045270e0d28c670778b516264f7db08 Mon Sep 17 00:00:00 2001 From: jvyden Date: Mon, 19 Apr 2021 01:06:26 -0400 Subject: [PATCH 15/15] Fix sessionIdleTracker not being properly added to OsuGame --- osu.Game/OsuGame.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 1a2555f3f1..28f32ba455 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -584,7 +584,7 @@ namespace osu.Game SessionStatics.ResetValues(); }); - Add(new GameIdleTracker(300000)); + Add(sessionIdleTracker); AddRange(new Drawable[] {