Merge pull request #5733 from peppy/reduce-hold-to-confirm-delay

Reduce delay for hold-to-confirm controls
This commit is contained in:
Dan Balasescu 2019-08-16 14:10:57 +09:00 committed by GitHub
commit 8a5410eced
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 3 deletions

View File

@ -17,6 +17,8 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
private bool exitAction; private bool exitAction;
protected override double TimePerAction => 100; // required for the early exit test, since hold-to-confirm delay is 200ms
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Menu; using osu.Game.Screens.Menu;
@ -12,7 +13,13 @@ namespace osu.Game.Tests.Visual.UserInterface
{ {
public class TestSceneHoldToConfirmOverlay : OsuTestScene public class TestSceneHoldToConfirmOverlay : OsuTestScene
{ {
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(ExitConfirmOverlay) }; protected override double TimePerAction => 100; // required for the early exit test, since hold-to-confirm delay is 200ms
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(ExitConfirmOverlay),
typeof(HoldToConfirmContainer),
};
public TestSceneHoldToConfirmOverlay() public TestSceneHoldToConfirmOverlay()
{ {

View File

@ -12,9 +12,11 @@ namespace osu.Game.Graphics.Containers
{ {
public Action Action; public Action Action;
private const int activate_delay = 400; private const int default_activation_delay = 200;
private const int fadeout_delay = 200; private const int fadeout_delay = 200;
private readonly double activationDelay;
private bool fired; private bool fired;
private bool confirming; private bool confirming;
@ -25,13 +27,22 @@ namespace osu.Game.Graphics.Containers
public Bindable<double> Progress = new BindableDouble(); public Bindable<double> Progress = new BindableDouble();
/// <summary>
/// Create a new instance.
/// </summary>
/// <param name="activationDelay">The time requried before an action is confirmed.</param>
protected HoldToConfirmContainer(double activationDelay = default_activation_delay)
{
this.activationDelay = activationDelay;
}
protected void BeginConfirm() protected void BeginConfirm()
{ {
if (confirming || (!AllowMultipleFires && fired)) return; if (confirming || (!AllowMultipleFires && fired)) return;
confirming = true; confirming = true;
this.TransformBindableTo(Progress, 1, activate_delay * (1 - Progress.Value), Easing.Out).OnComplete(_ => Confirm()); this.TransformBindableTo(Progress, 1, activationDelay * (1 - Progress.Value), Easing.Out).OnComplete(_ => Confirm());
} }
protected virtual void Confirm() protected virtual void Confirm()