1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:07:44 +08:00

Fix regression with background dim

This commit is contained in:
David Zhao 2019-02-15 16:17:01 +09:00
parent 3a74ad678a
commit 6da9f94ae3
6 changed files with 116 additions and 64 deletions

View File

@ -0,0 +1,65 @@
// 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.
using System;
using NUnit.Framework.Internal;
using osu.Framework.Allocation;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Rulesets;
using osu.Game.Screens;
using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Play;
namespace osu.Game.Tests.Visual
{
public class TestCaseBackgroundScreenBeatmap : TestCasePlayer
{
[BackgroundDependencyLoader]
private void load(OsuConfigManager manager)
{
LoadScreen(new DimAccessiblePlayer());
}
[Test]
public void EnableUserDimTest()
{
AddStep("Test User Dimming", () => ((DimAccessiblePlayer)Player).EnableScreenDim());
AddAssert("Check screen dim", () => ((DimAccessiblePlayer)Player).AssertDimState());
}
protected override Player CreatePlayer(Ruleset ruleset) => new DimAccessiblePlayer();
private class DimAccessiblePlayer : Player
{
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground();
public void EnableScreenDim()
{
Background.UpdateDim.Value = true;
}
public void DisableScreenDim()
{
Background.UpdateDim.Value = false;
}
public bool AssertDimState()
{
return ((FadeAccessibleBackground)Background).AssertDimState();
}
private class FadeAccessibleBackground : BackgroundScreenBeatmap
{
public bool AssertDimState()
{
return FadeContainer.Colour == OsuColour.Gray(BackgroundOpacity);
}
}
}
}
internal class SetupAttribute : Attribute
{
}
}

View File

@ -170,6 +170,6 @@ namespace osu.Game.Configuration
ScalingPositionY,
ScalingSizeX,
ScalingSizeY,
UIScale
UIScale,
}
}

View File

@ -18,6 +18,17 @@ namespace osu.Game.Screens.Backgrounds
public class BackgroundScreenBeatmap : BlurrableBackgroundScreen
{
protected WorkingBeatmap beatmap;
protected Bindable<double> DimLevel;
public Bindable<bool> UpdateDim;
protected float BackgroundOpacity => 1 - (float)DimLevel;
protected Container FadeContainer;
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
DimLevel = config.GetBindable<double>(OsuSetting.DimLevel);
}
public virtual WorkingBeatmap Beatmap
{
@ -31,6 +42,7 @@ namespace osu.Game.Screens.Backgrounds
Schedule(() =>
{
FadeContainer = new Container { RelativeSizeAxes = Axes.Both };
LoadComponentAsync(new BeatmapBackground(beatmap), b => Schedule(() =>
{
float newDepth = 0;
@ -41,23 +53,51 @@ namespace osu.Game.Screens.Backgrounds
Background.FadeOut(250);
Background.Expire();
}
b.Depth = newDepth;
AddBackground(Background = b);
FadeContainer.Child = Background = b;
InternalChild = FadeContainer;
Background.BlurSigma = BlurTarget;
}));
});
}
}
protected virtual void AddBackground(Drawable d)
public override void OnEntering(IScreen last)
{
AddInternal(d);
base.OnEntering(last);
DimLevel.ValueChanged += _ => updateBackgroundDim();
UpdateDim.ValueChanged += _ => updateBackgroundDim();
updateBackgroundDim();
}
public override void OnResuming(IScreen last)
{
base.OnResuming(last);
updateBackgroundDim();
}
public override bool OnExiting(IScreen last)
{
UpdateDim.Value = false;
return base.OnExiting(last);
}
private void updateBackgroundDim()
{
if (UpdateDim)
FadeContainer?.FadeColour(OsuColour.Gray(BackgroundOpacity), 800, Easing.OutQuint);
else
FadeContainer?.FadeColour(OsuColour.Gray(1.0f), 800, Easing.InQuint);
}
public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null)
{
Beatmap = beatmap;
UpdateDim = new Bindable<bool>();
}
public void EnableUserDim()
{
UpdateDim.Value = true;
}
public override bool Equals(BackgroundScreen other)

View File

@ -1,57 +0,0 @@
// 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.
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osuTK;
namespace osu.Game.Screens.Backgrounds
{
public class UserDimmableBackgroundScreenBeatmap : BackgroundScreenBeatmap
{
protected Bindable<double> DimLevel;
protected float BackgroundOpacity => 1 - (float)DimLevel;
private Container fadeContainer;
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
DimLevel = config.GetBindable<double>(OsuSetting.DimLevel);
fadeContainer = new Container { RelativeSizeAxes = Axes.Both};
}
protected override void AddBackground(Drawable d)
{
fadeContainer.Child = d;
InternalChild = fadeContainer;
}
public override void OnEntering(IScreen last)
{
base.OnEntering(last);
DimLevel.ValueChanged += _ => updateBackgroundDim();
updateBackgroundDim();
}
public override void OnResuming(IScreen last)
{
base.OnResuming(last);
updateBackgroundDim();
}
public UserDimmableBackgroundScreenBeatmap(WorkingBeatmap beatmap = null)
:base(beatmap)
{
}
private void updateBackgroundDim()
{
fadeContainer?.FadeColour(OsuColour.Gray(BackgroundOpacity), 800, Easing.OutQuint);
}
}
}

View File

@ -247,6 +247,8 @@ namespace osu.Game.Screens.Play
foreach (var mod in Beatmap.Value.Mods.Value.OfType<IApplicableToScoreProcessor>())
mod.ApplyToScoreProcessor(ScoreProcessor);
Background?.EnableUserDim();
}
private void applyRateFromMods()
@ -395,6 +397,8 @@ namespace osu.Game.Screens.Play
if (LoadedBeatmapSuccessfully)
pauseContainer?.Pause();
Background.UpdateDim.Value = false;
return true;
}

View File

@ -13,9 +13,9 @@ namespace osu.Game.Screens.Play
{
public abstract class ScreenWithBeatmapBackground : OsuScreen
{
protected override BackgroundScreen CreateBackground() => new UserDimmableBackgroundScreenBeatmap(Beatmap.Value);
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap.Value);
protected new UserDimmableBackgroundScreenBeatmap Background => base.Background as UserDimmableBackgroundScreenBeatmap;
protected new BackgroundScreenBeatmap Background => base.Background as BackgroundScreenBeatmap;
public override bool AllowBeatmapRulesetChange => false;