From 7d23973ef8aa53c77b09201b829800060c61f401 Mon Sep 17 00:00:00 2001 From: jvyden Date: Fri, 16 Apr 2021 05:01:58 -0400 Subject: [PATCH] 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[] {