diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneHoldToConfirmOverlay.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneHoldToConfirmOverlay.cs
index f787754aa4..feef1dae6b 100644
--- a/osu.Game.Tests/Visual/UserInterface/TestSceneHoldToConfirmOverlay.cs
+++ b/osu.Game.Tests/Visual/UserInterface/TestSceneHoldToConfirmOverlay.cs
@@ -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();
}
}
}
diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs
index 4cbf2b4d94..64b1f2d7bc 100644
--- a/osu.Game/Configuration/OsuConfigManager.cs
+++ b/osu.Game/Configuration/OsuConfigManager.cs
@@ -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
}
}
diff --git a/osu.Game/Graphics/Containers/HoldToConfirmContainer.cs b/osu.Game/Graphics/Containers/HoldToConfirmContainer.cs
index 773265d19b..5d549ba217 100644
--- a/osu.Game/Graphics/Containers/HoldToConfirmContainer.cs
+++ b/osu.Game/Graphics/Containers/HoldToConfirmContainer.cs
@@ -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;
+ ///
+ /// Whether currently in a fired state (and the confirm has been sent).
+ ///
+ public bool Fired { get; private set; }
- private bool fired;
private bool confirming;
///
@@ -27,35 +30,35 @@ namespace osu.Game.Graphics.Containers
public Bindable Progress = new BindableDouble();
- ///
- /// Create a new instance.
- ///
- /// The time requried before an action is confirmed.
- protected HoldToConfirmContainer(double activationDelay = default_activation_delay)
+ private Bindable holdActivationDelay;
+
+ [BackgroundDependencyLoader]
+ private void load(OsuConfigManager config)
{
- this.activationDelay = activationDelay;
+ holdActivationDelay = config.GetBindable(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);
}
diff --git a/osu.Game/Overlays/DialogOverlay.cs b/osu.Game/Overlays/DialogOverlay.cs
index 6aaeff8554..59d748bc5d 100644
--- a/osu.Game/Overlays/DialogOverlay.cs
+++ b/osu.Game/Overlays/DialogOverlay.cs
@@ -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().FirstOrDefault()?.Click();
+ CurrentDialog?.Buttons.OfType().FirstOrDefault()?.Click();
return true;
}
diff --git a/osu.Game/Overlays/HoldToConfirmOverlay.cs b/osu.Game/Overlays/HoldToConfirmOverlay.cs
index fdc6f096bc..eb325d8dd3 100644
--- a/osu.Game/Overlays/HoldToConfirmOverlay.cs
+++ b/osu.Game/Overlays/HoldToConfirmOverlay.cs
@@ -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);
}
}
diff --git a/osu.Game/Overlays/Settings/Sections/Graphics/UserInterfaceSettings.cs b/osu.Game/Overlays/Settings/Sections/Graphics/UserInterfaceSettings.cs
index dd822fedb6..a6956b7d9a 100644
--- a/osu.Game/Overlays/Settings/Sections/Graphics/UserInterfaceSettings.cs
+++ b/osu.Game/Overlays/Settings/Sections/Graphics/UserInterfaceSettings.cs
@@ -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(OsuSetting.MenuParallax)
},
+ new SettingsSlider
+ {
+ LabelText = "Hold-to-confirm activation time",
+ Bindable = config.GetBindable(OsuSetting.UIHoldActivationDelay),
+ KeyboardStep = 50
+ },
};
}
+
+ private class TimeSlider : OsuSliderBar
+ {
+ public override string TooltipText => Current.Value.ToString("N0") + "ms";
+ }
}
}
diff --git a/osu.Game/Screens/Menu/ExitConfirmOverlay.cs b/osu.Game/Screens/Menu/ExitConfirmOverlay.cs
index 519834859d..aaa3a77e74 100644
--- a/osu.Game/Screens/Menu/ExitConfirmOverlay.cs
+++ b/osu.Game/Screens/Menu/ExitConfirmOverlay.cs
@@ -9,6 +9,10 @@ namespace osu.Game.Screens.Menu
{
public class ExitConfirmOverlay : HoldToConfirmOverlay, IKeyBindingHandler
{
+ 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;
}
diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs
index a006877082..0274973161 100644
--- a/osu.Game/Screens/Menu/MainMenu.cs
+++ b/osu.Game/Screens/Menu/MainMenu.cs
@@ -1,18 +1,22 @@
// Copyright (c) ppy Pty Ltd . 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 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(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
+ },
+ };
+ }
+ }
}
}