Add documentation and move storyboard init logic

This commit is contained in:
David Zhao 2019-02-24 20:03:24 +09:00
parent 3a9835fcdd
commit 24f5bc7a75
4 changed files with 43 additions and 7 deletions

View File

@ -284,7 +284,7 @@ namespace osu.Game.Tests.Visual
/// <summary> /// <summary>
/// Make sure every time a screen gets pushed, the background doesn't get replaced /// Make sure every time a screen gets pushed, the background doesn't get replaced
/// </summary> /// </summary>
/// <returns>Whether or not the original background is still the current background</returns> /// <returns>Whether or not the original background (The one created in DummySongSelect) is still the current background</returns>
public bool AssertBackgroundCurrent() public bool AssertBackgroundCurrent()
{ {
return ((FadeAccessibleBackground)Background).IsCurrentScreen(); return ((FadeAccessibleBackground)Background).IsCurrentScreen();

View File

@ -10,19 +10,41 @@ using osuTK.Graphics;
namespace osu.Game.Graphics.Containers namespace osu.Game.Graphics.Containers
{ {
/// <summary>
/// A container that applies user-configured dim levels to its contents.
/// This container specifies behavior that applies to both Storyboards and Backgrounds.
/// </summary>
public class UserDimContainer : Container public class UserDimContainer : Container
{ {
protected Bindable<double> DimLevel; protected Bindable<double> DimLevel;
protected Bindable<bool> ShowStoryboard; protected Bindable<bool> ShowStoryboard;
public Bindable<bool> EnableUserDim = new Bindable<bool>();
/// <summary>
/// Whether or not user-configured dim levels should be applied to the container.
/// </summary>
public readonly Bindable<bool> EnableUserDim = new Bindable<bool>();
/// <summary>
/// Whether or not the storyboard loaded should completely hide the background behind it.
/// </summary>
public Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>(); public Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>();
protected Container DimContainer; protected Container DimContainer;
protected override Container<Drawable> Content => DimContainer; protected override Container<Drawable> Content => DimContainer;
private readonly bool isStoryboard; private readonly bool isStoryboard;
private const float background_fade_duration = 800; private const float background_fade_duration = 800;
/// <summary>
/// </summary>
/// <param name="isStoryboard">
/// Whether or not this instance of UserDimContainer contains a storyboard.
/// While both backgrounds and storyboards allow user dim levels to be applied, storyboards can be toggled via <see cref="ShowStoryboard"/>
/// and can cause backgrounds to become hidden via <see cref="StoryboardReplacesBackground"/>.
/// </param>
public UserDimContainer(bool isStoryboard = false) public UserDimContainer(bool isStoryboard = false)
{ {
DimContainer = new Container { RelativeSizeAxes = Axes.Both }; DimContainer = new Container { RelativeSizeAxes = Axes.Both };
@ -41,6 +63,12 @@ namespace osu.Game.Graphics.Containers
StoryboardReplacesBackground.ValueChanged += _ => updateBackgroundDim(); StoryboardReplacesBackground.ValueChanged += _ => updateBackgroundDim();
} }
protected override void LoadComplete()
{
base.LoadComplete();
updateBackgroundDim();
}
private void updateBackgroundDim() private void updateBackgroundDim()
{ {
if (isStoryboard) if (isStoryboard)
@ -49,7 +77,7 @@ namespace osu.Game.Graphics.Containers
} }
else else
{ {
// The background needs to be hidden in the case of it being replaced // The background needs to be hidden in the case of it being replaced by the storyboard
DimContainer.FadeTo(ShowStoryboard.Value && StoryboardReplacesBackground.Value ? 0 : 1, background_fade_duration, Easing.OutQuint); DimContainer.FadeTo(ShowStoryboard.Value && StoryboardReplacesBackground.Value ? 0 : 1, background_fade_duration, Easing.OutQuint);
} }

View File

@ -14,10 +14,16 @@ namespace osu.Game.Screens.Backgrounds
public class BackgroundScreenBeatmap : BlurrableBackgroundScreen public class BackgroundScreenBeatmap : BlurrableBackgroundScreen
{ {
private WorkingBeatmap beatmap; private WorkingBeatmap beatmap;
/// <summary>
/// Whether or not user dim settings should be applied to this Background.
/// </summary>
public Bindable<bool> EnableUserDim = new Bindable<bool>(); public Bindable<bool> EnableUserDim = new Bindable<bool>();
public Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>(); public Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>();
protected UserDimContainer FadeContainer; protected UserDimContainer FadeContainer;
protected virtual UserDimContainer CreateFadeContainer() => new UserDimContainer { RelativeSizeAxes = Axes.Both }; protected virtual UserDimContainer CreateFadeContainer() => new UserDimContainer { RelativeSizeAxes = Axes.Both };
public virtual WorkingBeatmap Beatmap public virtual WorkingBeatmap Beatmap

View File

@ -345,7 +345,12 @@ namespace osu.Game.Screens.Play
.Delay(250) .Delay(250)
.FadeIn(250); .FadeIn(250);
ShowStoryboard.ValueChanged += _ => UpdateBackgroundElements(); ShowStoryboard.ValueChanged += _ =>
{
if (ShowStoryboard.Value && storyboard == null)
initializeStoryboard(true);
};
Background.EnableUserDim.Value = true; Background.EnableUserDim.Value = true;
storyboardContainer.StoryboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable; storyboardContainer.StoryboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable;
storyboardContainer.StoryboardReplacesBackground.BindTo(Background?.StoryboardReplacesBackground); storyboardContainer.StoryboardReplacesBackground.BindTo(Background?.StoryboardReplacesBackground);
@ -433,9 +438,6 @@ namespace osu.Game.Screens.Play
if (!this.IsCurrentScreen()) return; if (!this.IsCurrentScreen()) return;
base.UpdateBackgroundElements(); base.UpdateBackgroundElements();
if (ShowStoryboard.Value && storyboard == null)
initializeStoryboard(true);
} }
protected virtual Results CreateResults(ScoreInfo score) => new SoloResults(score); protected virtual Results CreateResults(ScoreInfo score) => new SoloResults(score);