From 761d7629cd2c5778669dbaf78656b7e3b090aaeb Mon Sep 17 00:00:00 2001 From: Roman Kapustin Date: Wed, 12 Sep 2018 18:09:19 +0300 Subject: [PATCH 1/7] Return to large logo after idle period --- osu.Game/OsuGame.cs | 6 +++++- osu.Game/Screens/Menu/ButtonSystem.cs | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 6fcb948298..fce11e0a79 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -84,6 +84,9 @@ private Intro intro public float ToolbarOffset => Toolbar.Position.Y + Toolbar.DrawHeight; + private InputManager inputManager; + public double IdleTime => inputManager?.IdleTime ?? 0; + public readonly Bindable OverlayActivationMode = new Bindable(); private OsuScreen screenStack; @@ -113,7 +116,7 @@ public OsuGame(string[] args = null) forwardLoggedErrorsToNotifications(); - RavenLogger = new RavenLogger(this); + RavenLogger = new RavenLogger(this); } public void ToggleSettings() => settings.ToggleVisibility(); @@ -446,6 +449,7 @@ void updateScreenOffset() settings.StateChanged += _ => updateScreenOffset(); notifications.StateChanged += _ => updateScreenOffset(); + inputManager = GetContainingInputManager(); } private void forwardLoggedErrorsToNotifications() diff --git a/osu.Game/Screens/Menu/ButtonSystem.cs b/osu.Game/Screens/Menu/ButtonSystem.cs index b9a799328e..9a21df04d0 100644 --- a/osu.Game/Screens/Menu/ButtonSystem.cs +++ b/osu.Game/Screens/Menu/ButtonSystem.cs @@ -266,8 +266,8 @@ private void updateLogoState(ButtonSystemState lastState = ButtonSystemState.Ini protected override void Update() { - //if (OsuGame.IdleTime > 6000 && State != MenuState.Exit) - // State = MenuState.Initial; + if (game.IdleTime > 6000 && State != ButtonSystemState.Exit) + State = ButtonSystemState.Initial; base.Update(); From 749e89bd2549c3c2f605889433d200d1d87a662d Mon Sep 17 00:00:00 2001 From: Roman Kapustin Date: Wed, 12 Sep 2018 20:34:52 +0300 Subject: [PATCH 2/7] Introduce IdleTracker --- osu.Game/OsuGame.cs | 8 +++--- osu.Game/Screens/Menu/IdleTracker.cs | 37 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 osu.Game/Screens/Menu/IdleTracker.cs diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index fce11e0a79..b14650eca0 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -84,8 +84,8 @@ private Intro intro public float ToolbarOffset => Toolbar.Position.Y + Toolbar.DrawHeight; - private InputManager inputManager; - public double IdleTime => inputManager?.IdleTime ?? 0; + private IdleTracker idleTracker; + public double IdleTime => idleTracker?.IdleTime ?? 0; public readonly Bindable OverlayActivationMode = new Bindable(); @@ -116,7 +116,7 @@ public OsuGame(string[] args = null) forwardLoggedErrorsToNotifications(); - RavenLogger = new RavenLogger(this); + RavenLogger = new RavenLogger(this); } public void ToggleSettings() => settings.ToggleVisibility(); @@ -321,6 +321,7 @@ protected override void LoadComplete() }, mainContent = new Container { RelativeSizeAxes = Axes.Both }, overlayContent = new Container { RelativeSizeAxes = Axes.Both, Depth = float.MinValue }, + idleTracker = new IdleTracker() { RelativeSizeAxes = Axes.Both } }); loadComponentSingleFile(screenStack = new Loader(), d => @@ -449,7 +450,6 @@ void updateScreenOffset() settings.StateChanged += _ => updateScreenOffset(); notifications.StateChanged += _ => updateScreenOffset(); - inputManager = GetContainingInputManager(); } private void forwardLoggedErrorsToNotifications() diff --git a/osu.Game/Screens/Menu/IdleTracker.cs b/osu.Game/Screens/Menu/IdleTracker.cs new file mode 100644 index 0000000000..4a3089a76a --- /dev/null +++ b/osu.Game/Screens/Menu/IdleTracker.cs @@ -0,0 +1,37 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics; +using osu.Framework.Input; +using osu.Framework.Input.Bindings; +using osu.Framework.Input.EventArgs; +using osu.Framework.Input.States; + +namespace osu.Game.Screens.Menu +{ + public class IdleTracker : Component, IKeyBindingHandler + { + private double lastInteractionTime; + public double IdleTime => Clock.CurrentTime - lastInteractionTime; + + private bool updateLastInteractionTime() + { + lastInteractionTime = Clock.CurrentTime; + return false; + } + + public bool OnPressed(PlatformAction action) => updateLastInteractionTime(); + + public bool OnReleased(PlatformAction action) => updateLastInteractionTime(); + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) => updateLastInteractionTime(); + + protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) => updateLastInteractionTime(); + + protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => updateLastInteractionTime(); + + protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) => updateLastInteractionTime(); + + protected override bool OnMouseMove(InputState state) => updateLastInteractionTime(); + } +} From 60c0428979054e5cafca7742a5970a24ba6715c8 Mon Sep 17 00:00:00 2001 From: Roman Kapustin Date: Wed, 12 Sep 2018 20:54:40 +0300 Subject: [PATCH 3/7] Remove redundant empty argument list --- 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 b14650eca0..eb5532800f 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -321,7 +321,7 @@ protected override void LoadComplete() }, mainContent = new Container { RelativeSizeAxes = Axes.Both }, overlayContent = new Container { RelativeSizeAxes = Axes.Both, Depth = float.MinValue }, - idleTracker = new IdleTracker() { RelativeSizeAxes = Axes.Both } + idleTracker = new IdleTracker { RelativeSizeAxes = Axes.Both } }); loadComponentSingleFile(screenStack = new Loader(), d => From 5c741eaa898b5be1d4e339fe61fd94e5e8284167 Mon Sep 17 00:00:00 2001 From: Roman Kapustin Date: Fri, 21 Sep 2018 17:07:46 +0300 Subject: [PATCH 4/7] Fix possible game nullref --- osu.Game/Screens/Menu/ButtonSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Menu/ButtonSystem.cs b/osu.Game/Screens/Menu/ButtonSystem.cs index 9a21df04d0..fa9f6ceb8b 100644 --- a/osu.Game/Screens/Menu/ButtonSystem.cs +++ b/osu.Game/Screens/Menu/ButtonSystem.cs @@ -266,7 +266,7 @@ private void updateLogoState(ButtonSystemState lastState = ButtonSystemState.Ini protected override void Update() { - if (game.IdleTime > 6000 && State != ButtonSystemState.Exit) + if (game?.IdleTime > 6000 && State != ButtonSystemState.Exit) State = ButtonSystemState.Initial; base.Update(); From c7b3fa51d537a8451e8deaad71bc4a1a7b498b18 Mon Sep 17 00:00:00 2001 From: Roman Kapustin Date: Tue, 25 Sep 2018 19:58:50 +0300 Subject: [PATCH 5/7] Inject IdleTracker into ButtonSystem --- osu.Game/OsuGame.cs | 2 +- osu.Game/Screens/Menu/ButtonSystem.cs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index b12d2a3d3a..4e933f57bc 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -85,7 +85,6 @@ private Intro intro public float ToolbarOffset => Toolbar.Position.Y + Toolbar.DrawHeight; private IdleTracker idleTracker; - public double IdleTime => idleTracker?.IdleTime ?? 0; public readonly Bindable OverlayActivationMode = new Bindable(); @@ -378,6 +377,7 @@ protected override void LoadComplete() Depth = -6, }, overlayContent.Add); + dependencies.Cache(idleTracker); dependencies.Cache(settings); dependencies.Cache(onscreenDisplay); dependencies.Cache(social); diff --git a/osu.Game/Screens/Menu/ButtonSystem.cs b/osu.Game/Screens/Menu/ButtonSystem.cs index 015557fa82..8082c7b262 100644 --- a/osu.Game/Screens/Menu/ButtonSystem.cs +++ b/osu.Game/Screens/Menu/ButtonSystem.cs @@ -64,6 +64,8 @@ public void SetOsuLogo(OsuLogo logo) private SampleChannel sampleBack; + private IdleTracker idleTracker; + public ButtonSystem() { RelativeSizeAxes = Axes.Both; @@ -102,9 +104,10 @@ public ButtonSystem() private OsuGame game; [BackgroundDependencyLoader(true)] - private void load(AudioManager audio, OsuGame game) + private void load(AudioManager audio, OsuGame game, IdleTracker idleTracker) { this.game = game; + this.idleTracker = idleTracker; sampleBack = audio.Sample.Get(@"Menu/button-back-select"); } @@ -266,7 +269,7 @@ private void updateLogoState(ButtonSystemState lastState = ButtonSystemState.Ini protected override void Update() { - if (game?.IdleTime > 6000 && State != ButtonSystemState.Exit) + if (idleTracker.IdleTime > 6000 && State != ButtonSystemState.Exit) State = ButtonSystemState.Initial; base.Update(); From bdba22a576ab635d68affcb51563deaaa6e37125 Mon Sep 17 00:00:00 2001 From: Roman Kapustin Date: Tue, 25 Sep 2018 20:11:10 +0300 Subject: [PATCH 6/7] Override Handle(UIEvent e) in IdleTracker --- osu.Game/Screens/Menu/IdleTracker.cs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/osu.Game/Screens/Menu/IdleTracker.cs b/osu.Game/Screens/Menu/IdleTracker.cs index 4a3089a76a..8e7c835823 100644 --- a/osu.Game/Screens/Menu/IdleTracker.cs +++ b/osu.Game/Screens/Menu/IdleTracker.cs @@ -4,8 +4,7 @@ using osu.Framework.Graphics; using osu.Framework.Input; using osu.Framework.Input.Bindings; -using osu.Framework.Input.EventArgs; -using osu.Framework.Input.States; +using osu.Framework.Input.Events; namespace osu.Game.Screens.Menu { @@ -24,14 +23,19 @@ private bool updateLastInteractionTime() public bool OnReleased(PlatformAction action) => updateLastInteractionTime(); - protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) => updateLastInteractionTime(); - - protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) => updateLastInteractionTime(); - - protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => updateLastInteractionTime(); - - protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) => updateLastInteractionTime(); - - protected override bool OnMouseMove(InputState state) => updateLastInteractionTime(); + protected override bool Handle(UIEvent e) + { + switch (e) + { + case KeyDownEvent _: + case KeyUpEvent _: + case MouseDownEvent _: + case MouseUpEvent _: + case MouseMoveEvent _: + return updateLastInteractionTime(); + default: + return base.Handle(e); + } + } } } From baf9e028c30910012c0ca3d5236eb148fbf93c4a Mon Sep 17 00:00:00 2001 From: Roman Kapustin Date: Wed, 26 Sep 2018 19:44:01 +0300 Subject: [PATCH 7/7] Fix possible idleTracker nullref --- osu.Game/{Screens/Menu => Input}/IdleTracker.cs | 2 +- osu.Game/OsuGame.cs | 1 + osu.Game/Screens/Menu/ButtonSystem.cs | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) rename osu.Game/{Screens/Menu => Input}/IdleTracker.cs (97%) diff --git a/osu.Game/Screens/Menu/IdleTracker.cs b/osu.Game/Input/IdleTracker.cs similarity index 97% rename from osu.Game/Screens/Menu/IdleTracker.cs rename to osu.Game/Input/IdleTracker.cs index 8e7c835823..bbc15fe7af 100644 --- a/osu.Game/Screens/Menu/IdleTracker.cs +++ b/osu.Game/Input/IdleTracker.cs @@ -6,7 +6,7 @@ using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; -namespace osu.Game.Screens.Menu +namespace osu.Game.Input { public class IdleTracker : Component, IKeyBindingHandler { diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 4e933f57bc..bb721afec4 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -26,6 +26,7 @@ using osu.Framework.Threading; using osu.Game.Beatmaps; using osu.Game.Graphics; +using osu.Game.Input; using osu.Game.Rulesets.Scoring; using osu.Game.Overlays.Notifications; using osu.Game.Rulesets; diff --git a/osu.Game/Screens/Menu/ButtonSystem.cs b/osu.Game/Screens/Menu/ButtonSystem.cs index 8082c7b262..d86d7529a8 100644 --- a/osu.Game/Screens/Menu/ButtonSystem.cs +++ b/osu.Game/Screens/Menu/ButtonSystem.cs @@ -14,6 +14,7 @@ using osu.Framework.Logging; using osu.Framework.Threading; using osu.Game.Graphics; +using osu.Game.Input; using osu.Game.Input.Bindings; using osu.Game.Overlays; using OpenTK; @@ -269,7 +270,7 @@ private void updateLogoState(ButtonSystemState lastState = ButtonSystemState.Ini protected override void Update() { - if (idleTracker.IdleTime > 6000 && State != ButtonSystemState.Exit) + if (idleTracker?.IdleTime > 6000 && State != ButtonSystemState.Exit) State = ButtonSystemState.Initial; base.Update();