1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 07:27:25 +08:00

Merge pull request #10591 from bdach/epilepsy-warning-volume-restoration

Fix epilepsy warning not restoring track volume
This commit is contained in:
Dean Herbert 2020-10-25 22:59:56 +09:00 committed by GitHub
commit bab8c7480d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 27 deletions

View File

@ -265,6 +265,26 @@ namespace osu.Game.Tests.Visual.Gameplay
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
AddAssert($"epilepsy warning {(warning ? "present" : "absent")}", () => this.ChildrenOfType<EpilepsyWarning>().Any() == warning);
if (warning)
{
AddUntilStep("sound volume decreased", () => Beatmap.Value.Track.AggregateVolume.Value == 0.25);
AddUntilStep("sound volume restored", () => Beatmap.Value.Track.AggregateVolume.Value == 1);
}
}
[Test]
public void TestEpilepsyWarningEarlyExit()
{
AddStep("set epilepsy warning", () => epilepsyWarning = true);
AddStep("load dummy beatmap", () => ResetPlayer(false));
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
AddUntilStep("wait for epilepsy warning", () => loader.ChildrenOfType<EpilepsyWarning>().Single().Alpha > 0);
AddStep("exit early", () => loader.Exit());
AddUntilStep("sound volume restored", () => Beatmap.Value.Track.AggregateVolume.Value == 1);
}
private class TestPlayerLoaderContainer : Container

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,7 @@ 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 const double FADE_DURATION = 250;
public EpilepsyWarning()
{
@ -77,26 +71,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

@ -55,6 +55,8 @@ namespace osu.Game.Screens.Play
private bool backgroundBrightnessReduction;
private readonly BindableDouble volumeAdjustment = new BindableDouble(1);
protected bool BackgroundBrightnessReduction
{
set
@ -169,6 +171,7 @@ namespace osu.Game.Screens.Play
if (epilepsyWarning != null)
epilepsyWarning.DimmableBackground = Background;
Beatmap.Value.Track.AddAdjustment(AdjustableProperty.Volume, volumeAdjustment);
content.ScaleTo(0.7f);
Background?.FadeColour(Color4.White, 800, Easing.OutQuint);
@ -197,6 +200,11 @@ namespace osu.Game.Screens.Play
cancelLoad();
BackgroundBrightnessReduction = false;
// we're moving to player, so a period of silence is upcoming.
// stop the track before removing adjustment to avoid a volume spike.
Beatmap.Value.Track.Stop();
Beatmap.Value.Track.RemoveAdjustment(AdjustableProperty.Volume, volumeAdjustment);
}
public override bool OnExiting(IScreen next)
@ -208,6 +216,7 @@ namespace osu.Game.Screens.Play
Background.EnableUserDim.Value = false;
BackgroundBrightnessReduction = false;
Beatmap.Value.Track.RemoveAdjustment(AdjustableProperty.Volume, volumeAdjustment);
return base.OnExiting(next);
}
@ -331,18 +340,16 @@ namespace osu.Game.Screens.Play
{
const double epilepsy_display_length = 3000;
pushSequence.Schedule(() =>
{
epilepsyWarning.State.Value = Visibility.Visible;
this.Delay(epilepsy_display_length).Schedule(() =>
pushSequence
.Schedule(() => epilepsyWarning.State.Value = Visibility.Visible)
.TransformBindableTo(volumeAdjustment, 0.25, EpilepsyWarning.FADE_DURATION, Easing.OutQuint)
.Delay(epilepsy_display_length)
.Schedule(() =>
{
epilepsyWarning.Hide();
epilepsyWarning.Expire();
});
});
pushSequence.Delay(epilepsy_display_length);
})
.Delay(EpilepsyWarning.FADE_DURATION);
}
pushSequence.Schedule(() =>