1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 09:02:55 +08:00

Better encapsulate exposed bindables of HoldToConfirmContainer

This commit is contained in:
Dean Herbert 2022-05-06 14:37:50 +09:00
parent be960eb092
commit a11771c11b
2 changed files with 22 additions and 20 deletions

View File

@ -14,15 +14,18 @@ namespace osu.Game.Graphics.Containers
{
public const double DANGEROUS_HOLD_ACTIVATION_DELAY = 500;
private const int fadeout_delay = 200;
/// <summary>
/// Whether the associated action is considered dangerous, warranting a longer hold.
/// </summary>
public bool IsDangerousAction { get; }
/// <summary>
/// The action to perform when a hold successfully completes.
/// </summary>
public Action Action;
private const int fadeout_delay = 200;
/// <summary>
/// Whether currently in a fired state (and the confirm <see cref="Action"/> has been sent).
/// </summary>
@ -30,19 +33,24 @@ namespace osu.Game.Graphics.Containers
private bool confirming;
/// <summary>
/// The current activation delay for this control.
/// </summary>
public IBindable<double> HoldActivationDelay => holdActivationDelay;
/// <summary>
/// The progress of any ongoing hold operation. 0 means no hold has started; 1 means a hold has been completed.
/// </summary>
public IBindable<double> Progress => progress;
/// <summary>
/// Whether the overlay should be allowed to return from a fired state.
/// </summary>
protected virtual bool AllowMultipleFires => false;
/// <summary>
/// The current activation delay for this control.
/// </summary>
protected IBindable<double> HoldActivationDelay => holdActivationDelay;
private readonly Bindable<double> progress = new BindableDouble();
public Bindable<double> Progress = new BindableDouble();
private Bindable<double> holdActivationDelay;
private readonly Bindable<double> holdActivationDelay = new Bindable<double>();
[Resolved]
private OsuConfigManager config { get; set; }
@ -57,15 +65,9 @@ namespace osu.Game.Graphics.Containers
base.LoadComplete();
if (IsDangerousAction)
{
holdActivationDelay.Value = DANGEROUS_HOLD_ACTIVATION_DELAY;
}
else
{
holdActivationDelay = HoldActivationDelay != null
? new Bindable<double>(HoldActivationDelay.Value)
: config.GetBindable<double>(OsuSetting.UIHoldActivationDelay);
}
config.BindWith(OsuSetting.UIHoldActivationDelay, holdActivationDelay);
}
protected void BeginConfirm()
@ -74,7 +76,7 @@ namespace osu.Game.Graphics.Containers
confirming = true;
this.TransformBindableTo(Progress, 1, holdActivationDelay.Value * (1 - Progress.Value), Easing.Out).OnComplete(_ => Confirm());
this.TransformBindableTo(progress, 1, holdActivationDelay.Value * (1 - progress.Value), Easing.Out).OnComplete(_ => Confirm());
}
protected virtual void Confirm()
@ -91,9 +93,9 @@ namespace osu.Game.Graphics.Containers
Fired = false;
this
.TransformBindableTo(Progress, Progress.Value)
.TransformBindableTo(progress, progress.Value)
.Delay(200)
.TransformBindableTo(Progress, 0, fadeout_delay, Easing.InSine);
.TransformBindableTo(progress, 0, fadeout_delay, Easing.InSine);
}
}
}

View File

@ -164,7 +164,7 @@ namespace osu.Game.Screens.Play.HUD
private void bind()
{
circularProgress.Current.BindTo(Progress);
((IBindable<double>)circularProgress.Current).BindTo(Progress);
Progress.ValueChanged += progress => icon.Scale = new Vector2(1 + (float)progress.NewValue * 0.2f);
}