1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-15 15:27:20 +08:00

Move user dim logic into UserDimContainer instead

This commit is contained in:
David Zhao 2019-02-20 16:53:57 +09:00
parent 87717dcf9e
commit 1bd1b6b099
5 changed files with 53 additions and 42 deletions

View File

@ -144,7 +144,7 @@ namespace osu.Game.Tests.Visual
public void UpdateBindables()
{
DimEnabled = Background.UpdateDim;
DimEnabled = Background.UpdateUserDim;
}
public bool AssertDimmed()

View File

@ -0,0 +1,36 @@
// 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.Game.Configuration;
using osuTK.Graphics;
namespace osu.Game.Graphics.Containers
{
public class UserDimContainer : Container
{
#region User Settings
protected Bindable<double> DimLevel;
#endregion
public Bindable<bool> EnableUserDim = new Bindable<bool>();
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
DimLevel = config.GetBindable<double>(OsuSetting.DimLevel);
EnableUserDim.ValueChanged += _ => updateBackgroundDim();
DimLevel.ValueChanged += _ => updateBackgroundDim();
}
private void updateBackgroundDim()
{
this.FadeColour(EnableUserDim ? OsuColour.Gray(1 - (float)DimLevel) : Color4.White, 800, Easing.OutQuint);
}
}
}

View File

@ -11,6 +11,9 @@ using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Containers;
using osu.Game.Users;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Backgrounds
@ -19,9 +22,10 @@ namespace osu.Game.Screens.Backgrounds
{
private WorkingBeatmap beatmap;
protected Bindable<double> DimLevel;
public Bindable<bool> UpdateDim;
protected Bindable<double> BlurLevel;
public Bindable<bool> EnableUserDim;
protected Container FadeContainer;
protected UserDimContainer FadeContainer;
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
@ -41,7 +45,7 @@ namespace osu.Game.Screens.Backgrounds
Schedule(() =>
{
FadeContainer = new Container { RelativeSizeAxes = Axes.Both };
FadeContainer = new UserDimContainer { RelativeSizeAxes = Axes.Both };
LoadComponentAsync(new BeatmapBackground(beatmap), b => Schedule(() =>
{
float newDepth = 0;
@ -57,38 +61,14 @@ namespace osu.Game.Screens.Backgrounds
Background.BlurSigma = BlurTarget;
}));
InternalChild = FadeContainer;
updateBackgroundDim();
EnableUserDim = FadeContainer.EnableUserDim;
});
}
}
public override void OnEntering(IScreen last)
{
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)
{
return base.OnExiting(last);
}
private void updateBackgroundDim()
{
FadeContainer?.FadeColour(UpdateDim ? OsuColour.Gray(1 - (float)DimLevel) : Color4.White, 800, Easing.OutQuint);
}
public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null)
{
Beatmap = beatmap;
UpdateDim = new Bindable<bool>();
}
public override bool Equals(BackgroundScreen other)

View File

@ -19,7 +19,6 @@ using osu.Framework.Threading;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;
using osu.Game.Online.API;
@ -61,7 +60,6 @@ namespace osu.Game.Screens.Play
public CursorContainer Cursor => RulesetContainer.Cursor;
public bool ProvidingUserCursor => RulesetContainer?.Cursor != null && !RulesetContainer.HasReplayLoaded.Value;
protected float BackgroundOpacity => 1 - (float)DimLevel;
private IAdjustableClock sourceClock;
@ -88,7 +86,7 @@ namespace osu.Game.Screens.Play
private FailOverlay failOverlay;
private DrawableStoryboard storyboard;
private Container storyboardContainer;
private UserDimContainer storyboardContainer;
public bool LoadedBeatmapSuccessfully => RulesetContainer?.Objects.Any() == true;
@ -175,9 +173,9 @@ namespace osu.Game.Screens.Play
OnRetry = Restart,
OnQuit = performUserRequestedExit,
CheckCanPause = () => AllowPause && ValidForResume && !HasFailed && !RulesetContainer.HasReplayLoaded,
Children = new[]
Children = new Container[]
{
storyboardContainer = new Container
storyboardContainer = new UserDimContainer
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
@ -242,6 +240,8 @@ namespace osu.Game.Screens.Play
if (ShowStoryboard)
initializeStoryboard(false);
storyboardContainer.EnableUserDim.Value = true;
// Bind ScoreProcessor to ourselves
ScoreProcessor.AllJudged += onCompletion;
ScoreProcessor.Failed += onFail;
@ -346,7 +346,7 @@ namespace osu.Game.Screens.Play
.Delay(250)
.FadeIn(250);
Background.UpdateDim.Value = true;
Background.EnableUserDim.Value = true;
Task.Run(() =>
{
@ -407,7 +407,7 @@ namespace osu.Game.Screens.Play
{
float fadeOutDuration = instant ? 0 : 250;
this.FadeOut(fadeOutDuration);
Background.UpdateDim.Value = false;
Background.EnableUserDim.Value = false;
}
protected override bool OnScroll(ScrollEvent e) => mouseWheelDisabled.Value && !pauseContainer.IsPaused;
@ -440,9 +440,7 @@ namespace osu.Game.Screens.Play
var beatmap = Beatmap.Value;
var storyboardVisible = ShowStoryboard && beatmap.Storyboard.HasDrawable;
storyboardContainer?
.FadeColour(OsuColour.Gray(BackgroundOpacity), BACKGROUND_FADE_DURATION, Easing.OutQuint)
.FadeTo(storyboardVisible && BackgroundOpacity > 0 ? 1 : 0, BACKGROUND_FADE_DURATION, Easing.OutQuint);
storyboardContainer?.FadeTo(storyboardVisible && 1 - (float)DimLevel > 0 ? 1 : 0, BACKGROUND_FADE_DURATION, Easing.OutQuint);
if (storyboardVisible && beatmap.Storyboard.ReplacesBackground)
Background?.FadeColour(Color4.Black, BACKGROUND_FADE_DURATION, Easing.OutQuint);

View File

@ -243,9 +243,6 @@ namespace osu.Game.Screens.Play
this.FadeOut(150);
cancelLoad();
if (Background != null)
Background.UpdateDim.Value = false;
return base.OnExiting(next);
}