1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-30 17:42:54 +08:00
osu-lazer/osu.Game/Overlays/HoldToConfirmOverlay.cs

70 lines
2.1 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.
2022-06-17 15:37:17 +08:00
#nullable disable
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Containers;
2018-11-20 15:51:59 +08:00
using osuTK.Graphics;
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 16:36:17 +08:00
/// Action is BYO (derived class will need to call <see cref="HoldToConfirmContainer.BeginConfirm"/> and <see cref="HoldToConfirmContainer.AbortConfirm"/> from a user event).
/// </summary>
2018-05-22 15:04:36 +08:00
public abstract class HoldToConfirmOverlay : HoldToConfirmContainer
{
private Box overlay;
private readonly BindableDouble audioVolume = new BindableDouble(1);
[Resolved]
private AudioManager audio { get; set; }
private readonly float finalFillAlpha;
protected HoldToConfirmOverlay(float finalFillAlpha = 1)
{
this.finalFillAlpha = finalFillAlpha;
}
[BackgroundDependencyLoader]
private void load()
{
RelativeSizeAxes = Axes.Both;
AlwaysPresent = true;
Children = new Drawable[]
{
overlay = new Box
{
Alpha = 0,
Colour = Color4.Black,
RelativeSizeAxes = Axes.Both,
}
};
Progress.ValueChanged += p =>
{
double target = p.NewValue * finalFillAlpha;
audioVolume.Value = 1 - target;
overlay.Alpha = (float)target;
};
audio.Tracks.AddAdjustment(AdjustableProperty.Volume, audioVolume);
}
protected override void Dispose(bool isDisposing)
{
audio?.Tracks.RemoveAdjustment(AdjustableProperty.Volume, audioVolume);
base.Dispose(isDisposing);
}
}
}