mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 08:22:56 +08:00
Better encapsulate exposed bindables of HoldToConfirmContainer
This commit is contained in:
parent
be960eb092
commit
a11771c11b
@ -14,15 +14,18 @@ namespace osu.Game.Graphics.Containers
|
|||||||
{
|
{
|
||||||
public const double DANGEROUS_HOLD_ACTIVATION_DELAY = 500;
|
public const double DANGEROUS_HOLD_ACTIVATION_DELAY = 500;
|
||||||
|
|
||||||
|
private const int fadeout_delay = 200;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the associated action is considered dangerous, warranting a longer hold.
|
/// Whether the associated action is considered dangerous, warranting a longer hold.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsDangerousAction { get; }
|
public bool IsDangerousAction { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The action to perform when a hold successfully completes.
|
||||||
|
/// </summary>
|
||||||
public Action Action;
|
public Action Action;
|
||||||
|
|
||||||
private const int fadeout_delay = 200;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether currently in a fired state (and the confirm <see cref="Action"/> has been sent).
|
/// Whether currently in a fired state (and the confirm <see cref="Action"/> has been sent).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -30,19 +33,24 @@ namespace osu.Game.Graphics.Containers
|
|||||||
|
|
||||||
private bool confirming;
|
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>
|
/// <summary>
|
||||||
/// Whether the overlay should be allowed to return from a fired state.
|
/// Whether the overlay should be allowed to return from a fired state.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual bool AllowMultipleFires => false;
|
protected virtual bool AllowMultipleFires => false;
|
||||||
|
|
||||||
/// <summary>
|
private readonly Bindable<double> progress = new BindableDouble();
|
||||||
/// The current activation delay for this control.
|
|
||||||
/// </summary>
|
|
||||||
protected IBindable<double> HoldActivationDelay => holdActivationDelay;
|
|
||||||
|
|
||||||
public Bindable<double> Progress = new BindableDouble();
|
private readonly Bindable<double> holdActivationDelay = new Bindable<double>();
|
||||||
|
|
||||||
private Bindable<double> holdActivationDelay;
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuConfigManager config { get; set; }
|
private OsuConfigManager config { get; set; }
|
||||||
@ -57,15 +65,9 @@ namespace osu.Game.Graphics.Containers
|
|||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
if (IsDangerousAction)
|
if (IsDangerousAction)
|
||||||
{
|
|
||||||
holdActivationDelay.Value = DANGEROUS_HOLD_ACTIVATION_DELAY;
|
holdActivationDelay.Value = DANGEROUS_HOLD_ACTIVATION_DELAY;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
config.BindWith(OsuSetting.UIHoldActivationDelay, holdActivationDelay);
|
||||||
holdActivationDelay = HoldActivationDelay != null
|
|
||||||
? new Bindable<double>(HoldActivationDelay.Value)
|
|
||||||
: config.GetBindable<double>(OsuSetting.UIHoldActivationDelay);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void BeginConfirm()
|
protected void BeginConfirm()
|
||||||
@ -74,7 +76,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
|
|
||||||
confirming = true;
|
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()
|
protected virtual void Confirm()
|
||||||
@ -91,9 +93,9 @@ namespace osu.Game.Graphics.Containers
|
|||||||
Fired = false;
|
Fired = false;
|
||||||
|
|
||||||
this
|
this
|
||||||
.TransformBindableTo(Progress, Progress.Value)
|
.TransformBindableTo(progress, progress.Value)
|
||||||
.Delay(200)
|
.Delay(200)
|
||||||
.TransformBindableTo(Progress, 0, fadeout_delay, Easing.InSine);
|
.TransformBindableTo(progress, 0, fadeout_delay, Easing.InSine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
|
|
||||||
private void bind()
|
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);
|
Progress.ValueChanged += progress => icon.Scale = new Vector2(1 + (float)progress.NewValue * 0.2f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user