1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 17:52:56 +08:00

Move user dimming logic into its own container

This commit is contained in:
David Zhao 2019-02-14 17:47:53 +09:00
parent e174fa2d3e
commit e2a312a663
5 changed files with 76 additions and 8 deletions

View File

@ -0,0 +1 @@
osu

View File

@ -2,18 +2,24 @@
// 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.Graphics.Textures;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
using osuTK;
namespace osu.Game.Screens.Backgrounds
{
public class BackgroundScreenBeatmap : BlurrableBackgroundScreen
{
private WorkingBeatmap beatmap;
protected WorkingBeatmap beatmap;
public WorkingBeatmap Beatmap
public virtual WorkingBeatmap Beatmap
{
get { return beatmap; }
set
@ -37,13 +43,18 @@ namespace osu.Game.Screens.Backgrounds
}
b.Depth = newDepth;
AddInternal(Background = b);
AddBackground(Background = b);
Background.BlurSigma = BlurTarget;
}));
});
}
}
protected virtual void AddBackground(Drawable d)
{
AddInternal(d);
}
public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null)
{
Beatmap = beatmap;
@ -57,7 +68,7 @@ namespace osu.Game.Screens.Backgrounds
return base.Equals(other) && beatmap == otherBeatmapBackground.Beatmap;
}
private class BeatmapBackground : Background
protected class BeatmapBackground : Background
{
private readonly WorkingBeatmap beatmap;

View File

@ -0,0 +1,57 @@
// 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

@ -29,6 +29,7 @@ using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
using osu.Game.Scoring;
using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Ranking;
using osu.Game.Skinning;
using osu.Game.Storyboards.Drawables;

View File

@ -14,9 +14,9 @@ namespace osu.Game.Screens.Play
{
public abstract class ScreenWithBeatmapBackground : OsuScreen
{
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap.Value);
protected override BackgroundScreen CreateBackground() => new UserDimmableBackgroundScreenBeatmap(Beatmap.Value);
protected new BackgroundScreenBeatmap Background => base.Background as BackgroundScreenBeatmap;
protected new UserDimmableBackgroundScreenBeatmap Background => base.Background as UserDimmableBackgroundScreenBeatmap;
public override bool AllowBeatmapRulesetChange => false;
@ -43,7 +43,6 @@ namespace osu.Game.Screens.Play
public override void OnEntering(IScreen last)
{
base.OnEntering(last);
DimLevel.ValueChanged += _ => UpdateBackgroundElements();
BlurLevel.ValueChanged += _ => UpdateBackgroundElements();
ShowStoryboard.ValueChanged += _ => UpdateBackgroundElements();
InitializeBackgroundElements();
@ -68,7 +67,6 @@ namespace osu.Game.Screens.Play
{
if (!this.IsCurrentScreen()) return;
Background?.FadeColour(OsuColour.Gray(BackgroundOpacity), BACKGROUND_FADE_DURATION, Easing.OutQuint);
Background?.BlurTo(new Vector2((float)BlurLevel.Value * 25), BACKGROUND_FADE_DURATION, Easing.OutQuint);
}
}