1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 18:42:56 +08:00

Move volume manipulations to player loader

This commit is contained in:
Bartłomiej Dach 2020-10-24 22:58:13 +02:00
parent 73174961f0
commit e101ba5cba
2 changed files with 21 additions and 20 deletions

View File

@ -2,8 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -18,11 +16,6 @@ namespace osu.Game.Screens.Play
{
public class EpilepsyWarning : VisibilityContainer
{
public const double FADE_DURATION = 500;
private readonly BindableDouble trackVolumeOnEpilepsyWarning = new BindableDouble(1f);
private Track track;
public EpilepsyWarning()
{
@ -77,26 +70,15 @@ namespace osu.Game.Screens.Play
}
}
};
track = beatmap.Value.Track;
track.AddAdjustment(AdjustableProperty.Volume, trackVolumeOnEpilepsyWarning);
}
protected override void PopIn()
{
this.TransformBindableTo(trackVolumeOnEpilepsyWarning, 0.25, FADE_DURATION);
DimmableBackground?.FadeColour(OsuColour.Gray(0.5f), FADE_DURATION, Easing.OutQuint);
this.FadeIn(FADE_DURATION, Easing.OutQuint);
}
protected override void PopOut() => this.FadeOut(FADE_DURATION);
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
track?.RemoveAdjustment(AdjustableProperty.Volume, trackVolumeOnEpilepsyWarning);
}
}
}

View File

@ -104,6 +104,9 @@ namespace osu.Game.Screens.Play
[Resolved]
private AudioManager audioManager { get; set; }
[Resolved]
private MusicController musicController { get; set; }
public PlayerLoader(Func<Player> createPlayer)
{
this.createPlayer = createPlayer;
@ -332,9 +335,17 @@ namespace osu.Game.Screens.Play
const double epilepsy_display_length = 3000;
pushSequence
.Schedule(() => epilepsyWarning.State.Value = Visibility.Visible)
.Schedule(() =>
{
musicController.CurrentTrack.VolumeTo(0.25, EpilepsyWarning.FADE_DURATION, Easing.OutQuint);
epilepsyWarning.State.Value = Visibility.Visible;
})
.Delay(epilepsy_display_length)
.Schedule(() => epilepsyWarning.Hide())
.Schedule(() =>
{
epilepsyWarning.Hide();
epilepsyWarning.Expire();
})
.Delay(EpilepsyWarning.FADE_DURATION);
}
@ -348,6 +359,10 @@ namespace osu.Game.Screens.Play
// Note that this may change if the player we load requested a re-run.
ValidForResume = false;
// restore full volume immediately - there's a usually a period of silence at start of gameplay anyway.
// note that this is delayed slightly to avoid volume spikes just before push.
musicController.CurrentTrack.Delay(50).VolumeTo(1);
if (player.LoadedBeatmapSuccessfully)
this.Push(player);
else
@ -363,6 +378,10 @@ namespace osu.Game.Screens.Play
private void cancelLoad()
{
// in case the epilepsy warning is being displayed, restore full volume.
if (epilepsyWarning?.IsAlive == true)
musicController.CurrentTrack.VolumeTo(1, EpilepsyWarning.FADE_DURATION, Easing.OutQuint);
scheduledPushPlayer?.Cancel();
scheduledPushPlayer = null;
}