1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +08:00

Add setting to adjust hold-to-confirm activation time (#6166)

Add setting to adjust hold-to-confirm activation time
This commit is contained in:
Dean Herbert 2019-09-19 22:51:20 +09:00 committed by GitHub
commit fc78284765
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 116 additions and 33 deletions

View File

@ -52,19 +52,23 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("start confirming", () => overlay.Begin());
AddStep("abort confirming", () => overlay.Abort());
AddAssert("ensure not fired internally", () => !overlay.Fired);
AddAssert("ensure aborted", () => !fired);
AddStep("start confirming", () => overlay.Begin());
AddUntilStep("wait until confirmed", () => fired);
AddAssert("ensure fired internally", () => overlay.Fired);
AddStep("abort after fire", () => overlay.Abort());
AddAssert("ensure not fired internally", () => !overlay.Fired);
AddStep("start confirming", () => overlay.Begin());
AddUntilStep("wait until fired again", () => overlay.Fired);
}
private class TestHoldToConfirmOverlay : ExitConfirmOverlay
{
protected override bool AllowMultipleFires => true;
public void Begin() => BeginConfirm();
public void Abort() => AbortConfirm();
}
}
}

View File

@ -114,6 +114,8 @@ namespace osu.Game.Configuration
Set(OsuSetting.UIScale, 1f, 0.8f, 1.6f, 0.01f);
Set(OsuSetting.UIHoldActivationDelay, 200, 0, 500);
Set(OsuSetting.IntroSequence, IntroSequence.Triangles);
}
@ -183,6 +185,7 @@ namespace osu.Game.Configuration
ScalingSizeY,
UIScale,
IntroSequence,
UIHoldActivationDelay,
HitLighting
}
}

View File

@ -2,9 +2,11 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Configuration;
namespace osu.Game.Graphics.Containers
{
@ -12,12 +14,13 @@ namespace osu.Game.Graphics.Containers
{
public Action Action;
private const int default_activation_delay = 200;
private const int fadeout_delay = 200;
private readonly double activationDelay;
/// <summary>
/// Whether currently in a fired state (and the confirm <see cref="Action"/> has been sent).
/// </summary>
public bool Fired { get; private set; }
private bool fired;
private bool confirming;
/// <summary>
@ -27,35 +30,35 @@ namespace osu.Game.Graphics.Containers
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)
private Bindable<int> holdActivationDelay;
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
this.activationDelay = activationDelay;
holdActivationDelay = config.GetBindable<int>(OsuSetting.UIHoldActivationDelay);
}
protected void BeginConfirm()
{
if (confirming || (!AllowMultipleFires && fired)) return;
if (confirming || (!AllowMultipleFires && Fired)) return;
confirming = true;
this.TransformBindableTo(Progress, 1, activationDelay * (1 - Progress.Value), Easing.Out).OnComplete(_ => Confirm());
this.TransformBindableTo(Progress, 1, holdActivationDelay.Value * (1 - Progress.Value), Easing.Out).OnComplete(_ => Confirm());
}
protected virtual void Confirm()
{
Action?.Invoke();
fired = true;
Fired = true;
}
protected void AbortConfirm()
{
if (!AllowMultipleFires && fired) return;
if (!AllowMultipleFires && Fired) return;
confirming = false;
Fired = false;
this.TransformBindableTo(Progress, 0, fadeout_delay, Easing.Out);
}

View File

@ -13,7 +13,8 @@ namespace osu.Game.Overlays
public class DialogOverlay : OsuFocusedOverlayContainer
{
private readonly Container dialogContainer;
private PopupDialog currentDialog;
public PopupDialog CurrentDialog { get; private set; }
public DialogOverlay()
{
@ -31,15 +32,15 @@ namespace osu.Game.Overlays
public void Push(PopupDialog dialog)
{
if (dialog == currentDialog) return;
if (dialog == CurrentDialog) return;
currentDialog?.Hide();
currentDialog = dialog;
CurrentDialog?.Hide();
CurrentDialog = dialog;
dialogContainer.Add(currentDialog);
dialogContainer.Add(CurrentDialog);
currentDialog.Show();
currentDialog.State.ValueChanged += state => onDialogOnStateChanged(dialog, state.NewValue);
CurrentDialog.Show();
CurrentDialog.State.ValueChanged += state => onDialogOnStateChanged(dialog, state.NewValue);
Show();
}
@ -52,8 +53,11 @@ namespace osu.Game.Overlays
//handle the dialog being dismissed.
dialog.Delay(PopupDialog.EXIT_DURATION).Expire();
if (dialog == currentDialog)
if (dialog == CurrentDialog)
{
Hide();
CurrentDialog = null;
}
}
protected override void PopIn()
@ -66,9 +70,9 @@ namespace osu.Game.Overlays
{
base.PopOut();
if (currentDialog?.State.Value == Visibility.Visible)
if (CurrentDialog?.State.Value == Visibility.Visible)
{
currentDialog.Hide();
CurrentDialog.Hide();
return;
}
@ -80,7 +84,7 @@ namespace osu.Game.Overlays
switch (action)
{
case GlobalAction.Select:
currentDialog?.Buttons.OfType<PopupDialogOkButton>().FirstOrDefault()?.Click();
CurrentDialog?.Buttons.OfType<PopupDialogOkButton>().FirstOrDefault()?.Click();
return true;
}

View File

@ -51,7 +51,7 @@ namespace osu.Game.Overlays
protected override void Dispose(bool isDisposing)
{
audio.Tracks.RemoveAdjustment(AdjustableProperty.Volume, audioVolume);
audio?.Tracks.RemoveAdjustment(AdjustableProperty.Volume, audioVolume);
base.Dispose(isDisposing);
}
}

View File

@ -2,7 +2,9 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays.Settings.Sections.Graphics
{
@ -13,7 +15,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
Children = new[]
Children = new Drawable[]
{
new SettingsCheckbox
{
@ -25,7 +27,18 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
LabelText = "Parallax",
Bindable = config.GetBindable<bool>(OsuSetting.MenuParallax)
},
new SettingsSlider<int, TimeSlider>
{
LabelText = "Hold-to-confirm activation time",
Bindable = config.GetBindable<int>(OsuSetting.UIHoldActivationDelay),
KeyboardStep = 50
},
};
}
private class TimeSlider : OsuSliderBar<int>
{
public override string TooltipText => Current.Value.ToString("N0") + "ms";
}
}
}

View File

@ -9,6 +9,10 @@ namespace osu.Game.Screens.Menu
{
public class ExitConfirmOverlay : HoldToConfirmOverlay, IKeyBindingHandler<GlobalAction>
{
protected override bool AllowMultipleFires => true;
public void Abort() => AbortConfirm();
public bool OnPressed(GlobalAction action)
{
if (action == GlobalAction.Back)
@ -24,7 +28,8 @@ namespace osu.Game.Screens.Menu
{
if (action == GlobalAction.Back)
{
AbortConfirm();
if (!Fired)
AbortConfirm();
return true;
}

View File

@ -1,18 +1,22 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osuTK;
using osuTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Platform;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API;
using osu.Game.Overlays;
using osu.Game.Overlays.Dialog;
using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Charts;
using osu.Game.Screens.Edit;
@ -51,15 +55,24 @@ namespace osu.Game.Screens.Menu
[Resolved]
private IAPIProvider api { get; set; }
[Resolved(canBeNull: true)]
private DialogOverlay dialogOverlay { get; set; }
private BackgroundScreenDefault background;
protected override BackgroundScreen CreateBackground() => background;
private Bindable<int> holdDelay;
private ExitConfirmOverlay exitConfirmOverlay;
[BackgroundDependencyLoader(true)]
private void load(DirectOverlay direct, SettingsOverlay settings)
private void load(DirectOverlay direct, SettingsOverlay settings, OsuConfigManager config)
{
if (host.CanExit)
AddInternal(new ExitConfirmOverlay { Action = this.Exit });
AddInternal(exitConfirmOverlay = new ExitConfirmOverlay { Action = this.Exit });
holdDelay = config.GetBindable<int>(OsuSetting.UIHoldActivationDelay);
AddRangeInternal(new Drawable[]
{
@ -74,7 +87,7 @@ namespace osu.Game.Screens.Menu
OnEdit = delegate { this.Push(new Editor()); },
OnSolo = onSolo,
OnMulti = delegate { this.Push(new Multiplayer()); },
OnExit = this.Exit,
OnExit = confirmAndExit,
}
}
},
@ -103,6 +116,12 @@ namespace osu.Game.Screens.Menu
preloadSongSelect();
}
private void confirmAndExit()
{
exitConfirmed = true;
this.Exit();
}
private void preloadSongSelect()
{
if (songSelect == null)
@ -141,6 +160,7 @@ namespace osu.Game.Screens.Menu
}
private bool loginDisplayed;
private bool exitConfirmed;
protected override void LogoArriving(OsuLogo logo, bool resuming)
{
@ -221,9 +241,40 @@ namespace osu.Game.Screens.Menu
public override bool OnExiting(IScreen next)
{
if (holdDelay.Value == 0 && !exitConfirmed && dialogOverlay != null && !(dialogOverlay.CurrentDialog is ConfirmExitDialog))
{
dialogOverlay.Push(new ConfirmExitDialog(confirmAndExit, () => exitConfirmOverlay.Abort()));
return true;
}
buttons.State = ButtonSystemState.Exit;
this.FadeOut(3000);
return base.OnExiting(next);
}
private class ConfirmExitDialog : PopupDialog
{
public ConfirmExitDialog(Action confirm, Action cancel)
{
HeaderText = "Are you sure you want to exit?";
BodyText = "Last chance to back out.";
Icon = FontAwesome.Solid.ExclamationTriangle;
Buttons = new PopupDialogButton[]
{
new PopupDialogOkButton
{
Text = @"Good bye",
Action = confirm
},
new PopupDialogCancelButton
{
Text = @"Just a little more",
Action = cancel
},
};
}
}
}
}