Use bindable flow for checking idle time

This commit is contained in:
Dean Herbert
2018-11-26 16:32:59 +09:00
parent fe5b043a59
commit 8d65d49126
3 changed files with 42 additions and 8 deletions

View File

@ -8,6 +8,7 @@ using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Bindings;
@ -27,6 +28,8 @@ namespace osu.Game.Screens.Menu
{
public event Action<ButtonSystemState> StateChanged;
private readonly BindableBool isIdle = new BindableBool();
public Action OnEdit;
public Action OnExit;
public Action OnDirect;
@ -65,8 +68,6 @@ namespace osu.Game.Screens.Menu
private SampleChannel sampleBack;
private IdleTracker idleTracker;
public ButtonSystem()
{
RelativeSizeAxes = Axes.Both;
@ -108,10 +109,19 @@ namespace osu.Game.Screens.Menu
private void load(AudioManager audio, OsuGame game, IdleTracker idleTracker)
{
this.game = game;
this.idleTracker = idleTracker;
isIdle.ValueChanged += updateIdleState;
isIdle.BindTo(idleTracker.IsIdle);
sampleBack = audio.Sample.Get(@"Menu/button-back-select");
}
private void updateIdleState(bool isIdle)
{
if (isIdle && State != ButtonSystemState.Exit)
State = ButtonSystemState.Initial;
}
public bool OnPressed(GlobalAction action)
{
switch (action)
@ -270,9 +280,6 @@ namespace osu.Game.Screens.Menu
protected override void Update()
{
if (idleTracker?.IdleTime > 6000 && State != ButtonSystemState.Exit)
State = ButtonSystemState.Initial;
base.Update();
if (logo != null)