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-10 08:07:19 +00:00
2022-06-17 07:37:17 +00:00
#nullable disable
2018-05-10 08:07:19 +00:00
using osu.Framework.Allocation ;
2019-06-04 09:37:26 +00:00
using osu.Framework.Audio ;
using osu.Framework.Bindables ;
2018-05-10 08:07:19 +00:00
using osu.Framework.Graphics ;
using osu.Framework.Graphics.Shapes ;
2018-05-21 16:44:06 +00:00
using osu.Game.Graphics.Containers ;
2018-11-20 07:51:59 +00:00
using osuTK.Graphics ;
2018-05-10 08:07:19 +00:00
namespace osu.Game.Overlays
{
/// <summary>
/// An overlay which will display a black screen that dims over a period before confirming an exit action.
2019-04-25 08:36:17 +00:00
/// Action is BYO (derived class will need to call <see cref="HoldToConfirmContainer.BeginConfirm"/> and <see cref="HoldToConfirmContainer.AbortConfirm"/> from a user event).
2018-05-10 08:07:19 +00:00
/// </summary>
2022-11-24 05:32:20 +00:00
public abstract partial class HoldToConfirmOverlay : HoldToConfirmContainer
2018-05-10 08:07:19 +00:00
{
private Box overlay ;
2019-06-04 09:37:26 +00:00
private readonly BindableDouble audioVolume = new BindableDouble ( 1 ) ;
[Resolved]
private AudioManager audio { get ; set ; }
2021-01-18 09:22:21 +00:00
private readonly float finalFillAlpha ;
protected HoldToConfirmOverlay ( float finalFillAlpha = 1 )
{
this . finalFillAlpha = finalFillAlpha ;
}
2018-05-10 08:07:19 +00:00
[BackgroundDependencyLoader]
private void load ( )
{
RelativeSizeAxes = Axes . Both ;
AlwaysPresent = true ;
Children = new Drawable [ ]
{
overlay = new Box
{
Alpha = 0 ,
Colour = Color4 . Black ,
RelativeSizeAxes = Axes . Both ,
}
} ;
2019-06-04 09:37:26 +00:00
Progress . ValueChanged + = p = >
{
2021-10-27 04:04:41 +00:00
double target = p . NewValue * finalFillAlpha ;
2021-01-18 09:22:21 +00:00
audioVolume . Value = 1 - target ;
overlay . Alpha = ( float ) target ;
2019-06-04 09:37:26 +00:00
} ;
audio . Tracks . AddAdjustment ( AdjustableProperty . Volume , audioVolume ) ;
}
protected override void Dispose ( bool isDisposing )
{
2019-09-19 05:04:51 +00:00
audio ? . Tracks . RemoveAdjustment ( AdjustableProperty . Volume , audioVolume ) ;
2019-06-04 09:37:26 +00:00
base . Dispose ( isDisposing ) ;
2018-05-10 08:07:19 +00:00
}
}
}