1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 09:52:55 +08:00
osu-lazer/osu.Game/Graphics/Containers/HoldToConfirmContainer.cs

67 lines
1.9 KiB
C#
Raw Normal View History

// 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 osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Configuration;
namespace osu.Game.Graphics.Containers
{
2018-05-22 15:04:36 +08:00
public abstract class HoldToConfirmContainer : Container
{
public Action Action;
private const int fadeout_delay = 200;
2019-09-19 19:17:58 +08:00
/// <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 confirming;
/// <summary>
/// Whether the overlay should be allowed to return from a fired state.
/// </summary>
protected virtual bool AllowMultipleFires => false;
public Bindable<double> Progress = new BindableDouble();
2019-10-02 12:26:46 +08:00
private Bindable<float> holdActivationDelay;
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
2019-08-16 12:21:41 +08:00
{
2019-10-02 12:26:46 +08:00
holdActivationDelay = config.GetBindable<float>(OsuSetting.UIHoldActivationDelay);
2019-08-16 12:21:41 +08:00
}
protected void BeginConfirm()
{
2019-09-19 19:17:58 +08:00
if (confirming || (!AllowMultipleFires && Fired)) return;
confirming = true;
this.TransformBindableTo(Progress, 1, holdActivationDelay.Value * (1 - Progress.Value), Easing.Out).OnComplete(_ => Confirm());
}
protected virtual void Confirm()
{
Action?.Invoke();
2019-09-19 19:17:58 +08:00
Fired = true;
}
protected void AbortConfirm()
{
2019-09-19 19:17:58 +08:00
if (!AllowMultipleFires && Fired) return;
confirming = false;
2019-09-19 19:17:58 +08:00
Fired = false;
this.TransformBindableTo(Progress, 0, fadeout_delay, Easing.Out);
}
}
}