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(); + } +}