mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 03:25:11 +08:00
Introduce IdleTracker
This commit is contained in:
parent
761d7629cd
commit
749e89bd25
@ -84,8 +84,8 @@ namespace osu.Game
|
||||
|
||||
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 @@ namespace osu.Game
|
||||
|
||||
forwardLoggedErrorsToNotifications();
|
||||
|
||||
RavenLogger = new RavenLogger(this);
|
||||
RavenLogger = new RavenLogger(this);
|
||||
}
|
||||
|
||||
public void ToggleSettings() => settings.ToggleVisibility();
|
||||
@ -321,6 +321,7 @@ namespace osu.Game
|
||||
},
|
||||
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 @@ namespace osu.Game
|
||||
|
||||
settings.StateChanged += _ => updateScreenOffset();
|
||||
notifications.StateChanged += _ => updateScreenOffset();
|
||||
inputManager = GetContainingInputManager();
|
||||
}
|
||||
|
||||
private void forwardLoggedErrorsToNotifications()
|
||||
|
37
osu.Game/Screens/Menu/IdleTracker.cs
Normal file
37
osu.Game/Screens/Menu/IdleTracker.cs
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user