mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 17:52:56 +08:00
Put user dim logic in yet another container inside UserDimContainer
This commit is contained in:
parent
a4162a69fb
commit
76de39a344
@ -12,6 +12,7 @@ using osu.Framework.Screens;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Screens;
|
||||
@ -32,18 +33,38 @@ namespace osu.Game.Tests.Visual
|
||||
{
|
||||
typeof(ScreenWithBeatmapBackground),
|
||||
typeof(PlayerLoader),
|
||||
typeof(Player)
|
||||
typeof(Player),
|
||||
typeof(UserDimContainer)
|
||||
};
|
||||
|
||||
private DummySongSelect songSelect;
|
||||
private DimAccessiblePlayerLoader playerLoader;
|
||||
private DimAccessiblePlayer player;
|
||||
private readonly ScreenStack screen;
|
||||
|
||||
[Cached]
|
||||
private BackgroundScreenStack backgroundStack;
|
||||
|
||||
private void createSongSelect()
|
||||
{
|
||||
AddStep("Create song select if required", () =>
|
||||
{
|
||||
if (songSelect == null)
|
||||
{
|
||||
LoadComponentAsync(new DummySongSelect(), p =>
|
||||
{
|
||||
songSelect = p;
|
||||
screen.Push(p);
|
||||
songSelect.UpdateBindables();
|
||||
});
|
||||
}
|
||||
});
|
||||
AddUntilStep(() => songSelect?.IsLoaded ?? false, "Wait for song select to load");
|
||||
}
|
||||
|
||||
private void performSetup()
|
||||
{
|
||||
createSongSelect();
|
||||
AddUntilStep(() =>
|
||||
{
|
||||
if (!songSelect.IsCurrentScreen())
|
||||
@ -53,31 +74,17 @@ namespace osu.Game.Tests.Visual
|
||||
}
|
||||
return true;
|
||||
}, "Wait for song select is current");
|
||||
|
||||
AddStep("Load new player to song select", () => songSelect.Push(player = new DimAccessiblePlayer { Ready = true }));
|
||||
AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load");
|
||||
}
|
||||
|
||||
public TestCaseBackgroundScreenBeatmap()
|
||||
{
|
||||
ScreenStack screen;
|
||||
|
||||
InputManager.Add(backgroundStack = new BackgroundScreenStack {RelativeSizeAxes = Axes.Both});
|
||||
InputManager.Add(screen = new ScreenStack { RelativeSizeAxes = Axes.Both });
|
||||
|
||||
AddStep("Load Song Select", () =>
|
||||
{
|
||||
songSelect?.MakeCurrent();
|
||||
songSelect?.Exit();
|
||||
|
||||
LoadComponentAsync(new DummySongSelect(), p =>
|
||||
{
|
||||
songSelect = p;
|
||||
screen.Push(p);
|
||||
songSelect.UpdateBindables();
|
||||
});
|
||||
});
|
||||
|
||||
AddUntilStep(() => songSelect?.IsLoaded ?? false, "Wait for song select to load");
|
||||
createSongSelect();
|
||||
AddStep("Create beatmap", () =>
|
||||
{
|
||||
Beatmap.Value = new TestWorkingBeatmap(new Beatmap<OsuHitObject>
|
||||
@ -301,32 +308,40 @@ namespace osu.Game.Tests.Visual
|
||||
|
||||
private class FadeAccessibleBackground : BackgroundScreenBeatmap
|
||||
{
|
||||
private Bindable<float> dimLevel;
|
||||
private readonly Bindable<double> dimLevel = new Bindable<double>();
|
||||
|
||||
protected override UserDimContainer CreateFadeContainer() => new TestUserDimContainer { RelativeSizeAxes = Axes.Both };
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuConfigManager config)
|
||||
{
|
||||
dimLevel = config.GetBindable<float>(OsuSetting.DimLevel);
|
||||
config.BindWith(OsuSetting.DimLevel, dimLevel);
|
||||
}
|
||||
|
||||
public bool AssertDimmed()
|
||||
{
|
||||
return FadeContainer.Colour == OsuColour.Gray(1 - dimLevel);
|
||||
return ((TestUserDimContainer)FadeContainer).CurrentColour == OsuColour.Gray(1 - (float)dimLevel);
|
||||
}
|
||||
|
||||
public bool AssertUndimmed()
|
||||
{
|
||||
return FadeContainer.Colour == Color4.White;
|
||||
return ((TestUserDimContainer)FadeContainer).CurrentColour == Color4.White;
|
||||
}
|
||||
|
||||
public bool AssertInvisible()
|
||||
{
|
||||
return FadeContainer.Alpha == 0;
|
||||
return ((TestUserDimContainer)FadeContainer).CurrentAlpha == 0;
|
||||
}
|
||||
|
||||
public bool AssertVisible()
|
||||
{
|
||||
return FadeContainer.Alpha == 1;
|
||||
return ((TestUserDimContainer)FadeContainer).CurrentAlpha == 1;
|
||||
}
|
||||
|
||||
private class TestUserDimContainer : UserDimContainer
|
||||
{
|
||||
public Color4 CurrentColour => DimContainer.Colour;
|
||||
public float CurrentAlpha => DimContainer.Alpha;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ namespace osu.Game.Graphics.Containers
|
||||
protected Bindable<bool> ShowStoryboard;
|
||||
public Bindable<bool> EnableUserDim = new Bindable<bool>();
|
||||
public Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>();
|
||||
protected Container DimContainer;
|
||||
protected override Container<Drawable> Content => DimContainer;
|
||||
|
||||
private readonly bool isStoryboard;
|
||||
|
||||
@ -23,7 +25,9 @@ namespace osu.Game.Graphics.Containers
|
||||
|
||||
public UserDimContainer(bool isStoryboard = false)
|
||||
{
|
||||
DimContainer = new Container { RelativeSizeAxes = Axes.Both };
|
||||
this.isStoryboard = isStoryboard;
|
||||
AddInternal(DimContainer);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -41,15 +45,15 @@ namespace osu.Game.Graphics.Containers
|
||||
{
|
||||
if (isStoryboard)
|
||||
{
|
||||
this.FadeTo(!ShowStoryboard || DimLevel == 1 ? 0 : 1, background_fade_duration, Easing.OutQuint);
|
||||
DimContainer.FadeTo(!ShowStoryboard || DimLevel == 1 ? 0 : 1, background_fade_duration, Easing.OutQuint);
|
||||
}
|
||||
else
|
||||
{
|
||||
// The background needs to be hidden in the case of it being replaced
|
||||
this.FadeTo(ShowStoryboard && StoryboardReplacesBackground ? 0 : 1, background_fade_duration, Easing.OutQuint);
|
||||
DimContainer.FadeTo(ShowStoryboard && StoryboardReplacesBackground ? 0 : 1, background_fade_duration, Easing.OutQuint);
|
||||
}
|
||||
|
||||
this.FadeColour(EnableUserDim ? OsuColour.Gray(1 - (float)DimLevel) : Color4.White, background_fade_duration, Easing.OutQuint);
|
||||
DimContainer.FadeColour(EnableUserDim ? OsuColour.Gray(1 - (float)DimLevel) : Color4.White, background_fade_duration, Easing.OutQuint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ namespace osu.Game.Screens.Backgrounds
|
||||
public Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>();
|
||||
|
||||
protected UserDimContainer FadeContainer;
|
||||
protected virtual UserDimContainer CreateFadeContainer() => new UserDimContainer { RelativeSizeAxes = Axes.Both };
|
||||
|
||||
public virtual WorkingBeatmap Beatmap
|
||||
{
|
||||
@ -29,7 +30,7 @@ namespace osu.Game.Screens.Backgrounds
|
||||
|
||||
beatmap = value;
|
||||
|
||||
FadeContainer = new UserDimContainer { RelativeSizeAxes = Axes.Both };
|
||||
FadeContainer = CreateFadeContainer();
|
||||
InternalChild = FadeContainer;
|
||||
EnableUserDim.BindTo(FadeContainer.EnableUserDim);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user