Introduce IdleTracker

This commit is contained in:
Roman Kapustin 2018-09-12 20:34:52 +03:00
parent 761d7629cd
commit 749e89bd25
2 changed files with 41 additions and 4 deletions

View File

@ -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<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>();
@ -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()

View File

@ -0,0 +1,37 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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<PlatformAction>
{
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();
}
}