2019-01-24 08:43:03 +00:00
|
|
|
|
// 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.
|
2018-05-21 16:44:06 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
2019-09-19 05:04:51 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-05-21 16:44:06 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-09-19 05:04:51 +00:00
|
|
|
|
using osu.Game.Configuration;
|
2018-05-21 16:44:06 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Containers
|
|
|
|
|
{
|
2018-05-22 07:04:36 +00:00
|
|
|
|
public abstract class HoldToConfirmContainer : Container
|
2018-05-21 16:44:06 +00:00
|
|
|
|
{
|
2022-05-06 05:34:31 +00:00
|
|
|
|
public const double DANGEROUS_HOLD_ACTIVATION_DELAY = 500;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the associated action is considered dangerous, warranting a longer hold.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsDangerousAction { get; }
|
|
|
|
|
|
2018-05-21 16:44:06 +00:00
|
|
|
|
public Action Action;
|
|
|
|
|
|
|
|
|
|
private const int fadeout_delay = 200;
|
|
|
|
|
|
2019-09-19 11:17:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether currently in a fired state (and the confirm <see cref="Action"/> has been sent).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool Fired { get; private set; }
|
|
|
|
|
|
2018-05-21 16:44:06 +00:00
|
|
|
|
private bool confirming;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the overlay should be allowed to return from a fired state.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual bool AllowMultipleFires => false;
|
|
|
|
|
|
2022-03-21 07:07:26 +00:00
|
|
|
|
/// <summary>
|
2022-05-06 05:34:31 +00:00
|
|
|
|
/// The current activation delay for this control.
|
2022-03-21 07:07:26 +00:00
|
|
|
|
/// </summary>
|
2022-05-06 05:34:31 +00:00
|
|
|
|
protected IBindable<double> HoldActivationDelay => holdActivationDelay;
|
2022-03-21 07:07:26 +00:00
|
|
|
|
|
2018-05-21 16:44:06 +00:00
|
|
|
|
public Bindable<double> Progress = new BindableDouble();
|
|
|
|
|
|
2022-03-04 03:21:05 +00:00
|
|
|
|
private Bindable<double> holdActivationDelay;
|
2019-09-19 05:04:51 +00:00
|
|
|
|
|
2022-05-03 07:06:04 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuConfigManager config { get; set; }
|
|
|
|
|
|
2022-05-06 05:34:31 +00:00
|
|
|
|
protected HoldToConfirmContainer(bool isDangerousAction = false)
|
|
|
|
|
{
|
|
|
|
|
IsDangerousAction = isDangerousAction;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-03 07:06:04 +00:00
|
|
|
|
protected override void LoadComplete()
|
2019-08-16 04:21:41 +00:00
|
|
|
|
{
|
2022-05-03 07:06:04 +00:00
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2022-05-06 05:34:31 +00:00
|
|
|
|
if (IsDangerousAction)
|
|
|
|
|
{
|
|
|
|
|
holdActivationDelay.Value = DANGEROUS_HOLD_ACTIVATION_DELAY;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
holdActivationDelay = HoldActivationDelay != null
|
|
|
|
|
? new Bindable<double>(HoldActivationDelay.Value)
|
|
|
|
|
: config.GetBindable<double>(OsuSetting.UIHoldActivationDelay);
|
|
|
|
|
}
|
2019-08-16 04:21:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-21 16:44:06 +00:00
|
|
|
|
protected void BeginConfirm()
|
|
|
|
|
{
|
2019-09-19 11:17:58 +00:00
|
|
|
|
if (confirming || (!AllowMultipleFires && Fired)) return;
|
2018-05-21 16:44:06 +00:00
|
|
|
|
|
|
|
|
|
confirming = true;
|
|
|
|
|
|
2019-09-19 05:04:51 +00:00
|
|
|
|
this.TransformBindableTo(Progress, 1, holdActivationDelay.Value * (1 - Progress.Value), Easing.Out).OnComplete(_ => Confirm());
|
2018-05-21 16:44:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void Confirm()
|
|
|
|
|
{
|
|
|
|
|
Action?.Invoke();
|
2019-09-19 11:17:58 +00:00
|
|
|
|
Fired = true;
|
2018-05-21 16:44:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void AbortConfirm()
|
|
|
|
|
{
|
2019-09-19 11:17:58 +00:00
|
|
|
|
if (!AllowMultipleFires && Fired) return;
|
2018-05-21 16:44:06 +00:00
|
|
|
|
|
|
|
|
|
confirming = false;
|
2019-09-19 11:17:58 +00:00
|
|
|
|
Fired = false;
|
2018-05-21 16:44:06 +00:00
|
|
|
|
|
2022-04-14 03:33:59 +00:00
|
|
|
|
this
|
|
|
|
|
.TransformBindableTo(Progress, Progress.Value)
|
|
|
|
|
.Delay(200)
|
|
|
|
|
.TransformBindableTo(Progress, 0, fadeout_delay, Easing.InSine);
|
2018-05-21 16:44:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|