mirror of
https://github.com/ppy/osu
synced 2025-01-24 14:53:18 +00:00
Update "exit" flow when pressing back on Android
This commit is contained in:
parent
8d70b85e41
commit
3eee505aa2
@ -3,6 +3,7 @@
|
||||
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Overlays;
|
||||
|
||||
@ -42,4 +43,26 @@ namespace osu.Game.Screens.Menu
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="ExitConfirmOverlay"/> that behaves as if the <see cref="OsuSetting.UIHoldActivationDelay"/> is always <c>0</c>.
|
||||
/// </summary>
|
||||
/// <remarks>This is useful for mobile devices using gesture navigation, where holding to confirm is not possible.</remarks>
|
||||
public class NoHoldExitConfirmOverlay : ExitConfirmOverlay, IKeyBindingHandler<GlobalAction>
|
||||
{
|
||||
public new bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
||||
{
|
||||
if (e.Repeat)
|
||||
return false;
|
||||
|
||||
if (e.Action == GlobalAction.Back)
|
||||
{
|
||||
Progress.Value = 1;
|
||||
Confirm();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Platform;
|
||||
@ -89,6 +90,14 @@ namespace osu.Game.Screens.Menu
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (host.CanSuspendToBackground)
|
||||
{
|
||||
AddInternal(exitConfirmOverlay = new NoHoldExitConfirmOverlay
|
||||
{
|
||||
// treat as if the UIHoldActivationDelay is always 0. see NoHoldExitConfirmOverlay xmldoc for more info.
|
||||
Action = this.Exit
|
||||
});
|
||||
}
|
||||
|
||||
AddRangeInternal(new[]
|
||||
{
|
||||
@ -148,6 +157,24 @@ namespace osu.Game.Screens.Menu
|
||||
|
||||
private void confirmAndExit()
|
||||
{
|
||||
if (host.CanSuspendToBackground)
|
||||
{
|
||||
// cancel the overlay as we're not actually exiting.
|
||||
// this is the same action as 'onCancel' in `ConfirmExitDialog`.
|
||||
exitConfirmOverlay.Abort();
|
||||
|
||||
// fade the track so the Bass.Pause() on suspend isn't as jarring.
|
||||
const double fade_time = 500;
|
||||
musicController.CurrentTrack
|
||||
.VolumeTo(0, fade_time, Easing.Out).Then()
|
||||
.VolumeTo(1, fade_time, Easing.In);
|
||||
|
||||
host.SuspendToBackground();
|
||||
|
||||
// on hosts that can only suspend, we don't ever want to exit the game.
|
||||
return;
|
||||
}
|
||||
|
||||
if (exitConfirmed) return;
|
||||
|
||||
exitConfirmed = true;
|
||||
|
Loading…
Reference in New Issue
Block a user