1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 08:43:20 +08:00

Make test cases more compact, add two way toggles

This commit is contained in:
David Zhao 2019-02-28 20:01:15 +09:00
parent 19d529c1c8
commit e3338e94d1
4 changed files with 66 additions and 94 deletions

View File

@ -91,7 +91,7 @@ namespace osu.Game.Tests.Visual
}
/// <summary>
/// Check if PlayerLoader properly triggers background dim previews when a user hovers over the visual settings panel.
/// Check if <see cref="PlayerLoader"/> properly triggers background dim previews when a user hovers over the visual settings panel.
/// </summary>
[Test]
public void PlayerLoaderSettingsHoverTest()
@ -105,9 +105,11 @@ namespace osu.Game.Tests.Visual
InputManager.MoveMouseTo(playerLoader.ScreenPos);
InputManager.MoveMouseTo(playerLoader.VisualSettingsPos);
});
waitForDim();
AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed());
AddStep("Stop background preview", () => InputManager.MoveMouseTo(playerLoader.ScreenPos));
waitForDim();
AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed());
}
/// <summary>
@ -118,20 +120,11 @@ namespace osu.Game.Tests.Visual
[Test]
public void PlayerLoaderTransitionTest()
{
setupUserSettings();
AddStep("Start player loader", () => { songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer())); });
AddUntilStep(() => playerLoader?.IsLoaded ?? false, "Wait for Player Loader to load");
AddStep("Allow beatmap to load", () =>
{
player.Ready = true;
InputManager.MoveMouseTo(playerLoader.ScreenPos);
});
AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load");
performFullSetup();
AddStep("Trigger hover event", () => playerLoader.TriggerOnHover());
AddAssert("Background retained from song select", () => songSelect.IsBackgroundCurrent());
waitForDim();
AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed());
AddAssert("Screen is unblurred", () => songSelect.IsBackgroundUnblurred());
AddAssert("Screen is dimmed and unblurred", () => songSelect.IsBackgroundDimmed() && songSelect.IsBackgroundUnblurred());
}
/// <summary>
@ -142,9 +135,14 @@ namespace osu.Game.Tests.Visual
{
performFullSetup();
createFakeStoryboard();
AddStep("Storyboard Enabled", () =>
{
player.ReplacesBackground.Value = true;
player.StoryboardEnabled.Value = true;
});
waitForDim();
AddAssert("Background is invisible, storyboard is visible", () => songSelect.IsBackgroundInvisible() && player.IsStoryboardVisible());
AddStep("Disable storyboard", () =>
AddStep("Storyboard Disabled", () =>
{
player.ReplacesBackground.Value = false;
player.StoryboardEnabled.Value = false;
@ -161,37 +159,24 @@ namespace osu.Game.Tests.Visual
{
performFullSetup();
createFakeStoryboard();
AddUntilStep(() =>
{
if (songSelect.IsCurrentScreen()) return true;
songSelect.MakeCurrent();
return false;
}, "Wait for song select is current");
AddStep("Exit to song select", () => player.Exit());
waitForDim();
AddAssert("Background is visible", () => songSelect.IsBackgroundVisible());
}
/// <summary>
/// Check if the fade container is properly being reset when screen dim is disabled.
/// Check if the <see cref="UserDimContainer"/> is properly accepting user dim changes at all.
/// </summary>
[Test]
public void DisableUserDimTest()
{
performFullSetup();
AddStep("Test User Undimming", () => songSelect.DimEnabled.Value = false);
waitForDim();
AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed());
AddStep("EnableUserDim disabled", () => songSelect.DimEnabled.Value = false);
waitForDim();
AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed());
}
/// <summary>
/// Check if the fade container is properly being faded when screen dim is enabled.
/// </summary>
[Test]
public void EnableUserDimTest()
{
performFullSetup();
AddStep("Test User Dimming", () => songSelect.DimEnabled.Value = true);
AddStep("EnableUserDim enabled", () => songSelect.DimEnabled.Value = true);
waitForDim();
AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed());
}
@ -203,55 +188,44 @@ namespace osu.Game.Tests.Visual
public void PauseTest()
{
performFullSetup(true);
AddStep("Transition to Pause", () =>
{
if (!player.IsPaused.Value)
player.Exit();
});
AddStep("Pause", () => player.CurrentPauseContainer.Pause());
waitForDim();
AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed());
AddStep("Unpause", () => player.CurrentPauseContainer.Resume());
waitForDim();
AddAssert("Screen is dimmed", () => songSelect.IsBackgroundDimmed());
}
/// <summary>
/// Check if the fade container removes user dim when suspending player for results
/// Check if the fade container removes user dim when suspending <see cref="Player"/> for <see cref="SoloResults"/>
/// </summary>
[Test]
public void TransitionTest()
{
performFullSetup();
AddStep("Transition to Results", () => player.Push(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" } })));
AddStep("Transition to Results", () => player.Push(new FadeAccessibleResults(new ScoreInfo { User = new User { Username = "osu!" } })));
waitForDim();
AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed());
AddAssert("Background retained from song select", () => songSelect.IsBackgroundCurrent());
AddAssert("Screen is undimmed and is original background", () => songSelect.IsBackgroundUndimmed() && songSelect.IsBackgroundCurrent());
}
/// <summary>
/// Check if background gets undimmed when leaving the player for the previous screen
/// Check if background gets undimmed when leaving <see cref="Player"/> for <see cref="PlaySongSelect"/>
/// </summary>
[Test]
public void TransitionOutTest()
{
performFullSetup();
AddUntilStep(() =>
{
if (!songSelect.IsCurrentScreen())
{
songSelect.MakeCurrent();
return false;
}
return true;
}, "Wait for song select is current");
AddStep("Exit to song select", () => player.Exit());
waitForDim();
AddAssert("Screen is undimmed", () => songSelect.IsBackgroundUndimmed());
}
private void waitForDim() => AddWaitStep(5, "Wait for dim");
private void createFakeStoryboard() => AddStep("Enable storyboard", () =>
private void createFakeStoryboard() => AddStep("Create storyboard", () =>
{
player.ReplacesBackground.Value = true;
player.StoryboardEnabled.Value = true;
player.StoryboardEnabled.Value = false;
player.ReplacesBackground.Value = false;
player.CurrentStoryboardContainer.Add(new SpriteText
{
Size = new Vector2(250, 50),
@ -271,8 +245,6 @@ namespace osu.Game.Tests.Visual
{
songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer
{
AllowLeadIn = false,
AllowResults = false,
AllowPause = allowPause,
Ready = true,
}));
@ -332,9 +304,9 @@ namespace osu.Game.Tests.Visual
public bool IsBackgroundCurrent() => ((FadeAccessibleBackground)Background).IsCurrentScreen();
}
private class FadeAccesibleResults : SoloResults
private class FadeAccessibleResults : SoloResults
{
public FadeAccesibleResults(ScoreInfo score)
public FadeAccessibleResults(ScoreInfo score)
: base(score)
{
}
@ -356,6 +328,8 @@ namespace osu.Game.Tests.Visual
};
}
public PauseContainer CurrentPauseContainer => PauseContainer;
public UserDimContainer CurrentStoryboardContainer => StoryboardContainer;
// Whether or not the player should be allowed to load.
@ -404,23 +378,22 @@ namespace osu.Game.Tests.Visual
{
}
public void TriggerOnHover()
{
OnHover(new HoverEvent(new InputState()));
}
public void TriggerOnHover() => OnHover(new HoverEvent(new InputState()));
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(Beatmap.Value);
}
private class FadeAccessibleBackground : BackgroundScreenBeatmap
{
protected override UserDimContainer CreateFadeContainer() => new TestUserDimContainer { RelativeSizeAxes = Axes.Both };
protected override UserDimContainer CreateFadeContainer() => fadeContainer = new TestUserDimContainer { RelativeSizeAxes = Axes.Both };
public Color4 CurrentColour => ((TestUserDimContainer)FadeContainer).CurrentColour;
public float CurrentAlpha => ((TestUserDimContainer)FadeContainer).CurrentAlpha;
public Color4 CurrentColour => fadeContainer.CurrentColour;
public float CurrentAlpha => fadeContainer.CurrentAlpha;
public Vector2 CurrentBlur => Background.BlurSigma;
private TestUserDimContainer fadeContainer;
public FadeAccessibleBackground(WorkingBeatmap beatmap)
: base(beatmap)
{
@ -429,13 +402,13 @@ namespace osu.Game.Tests.Visual
private class TestUserDimContainer : UserDimContainer
{
public Color4 CurrentColour => DimContainer.Colour;
public float CurrentAlpha => DimContainer.Alpha;
public TestUserDimContainer(bool isStoryboard = false)
: base(isStoryboard)
{
}
public Color4 CurrentColour => DimContainer.Colour;
public float CurrentAlpha => DimContainer.Alpha;
}
}
}

View File

@ -16,6 +16,8 @@ namespace osu.Game.Graphics.Containers
/// </summary>
public class UserDimContainer : Container
{
private const float background_fade_duration = 800;
protected Bindable<double> DimLevel { get; private set; }
protected Bindable<bool> ShowStoryboard { get; private set; }
@ -30,14 +32,12 @@ namespace osu.Game.Graphics.Containers
/// </summary>
public readonly Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>();
protected Container DimContainer { get; private set; }
protected Container DimContainer { get; }
protected override Container<Drawable> Content => DimContainer;
private readonly bool isStoryboard;
private const float background_fade_duration = 800;
/// <summary>
/// Creates a new <see cref="UserDimContainer" />.
/// </summary>
@ -48,9 +48,8 @@ namespace osu.Game.Graphics.Containers
/// </param>
public UserDimContainer(bool isStoryboard = false)
{
DimContainer = new Container { RelativeSizeAxes = Axes.Both };
this.isStoryboard = isStoryboard;
AddInternal(DimContainer);
AddInternal(DimContainer = new Container { RelativeSizeAxes = Axes.Both });
}
[BackgroundDependencyLoader]

View File

@ -8,6 +8,7 @@ using osu.Framework.Graphics.Textures;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Containers;
using osu.Game.Users;
namespace osu.Game.Screens.Backgrounds
{
@ -22,7 +23,7 @@ namespace osu.Game.Screens.Backgrounds
public readonly Bindable<bool> StoryboardReplacesBackground = new Bindable<bool>();
protected UserDimContainer FadeContainer { get; private set; }
private readonly UserDimContainer fadeContainer;
protected virtual UserDimContainer CreateFadeContainer() => new UserDimContainer { RelativeSizeAxes = Axes.Both };
@ -50,9 +51,9 @@ namespace osu.Game.Screens.Backgrounds
}
b.Depth = newDepth;
FadeContainer.Add(Background = b);
fadeContainer.Add(Background = b);
Background.BlurSigma = BlurTarget;
FadeContainer.StoryboardReplacesBackground.BindTo(StoryboardReplacesBackground);
StoryboardReplacesBackground.BindTo(fadeContainer.StoryboardReplacesBackground);
}));
});
}
@ -60,10 +61,9 @@ namespace osu.Game.Screens.Backgrounds
public BackgroundScreenBeatmap(WorkingBeatmap beatmap = null)
{
FadeContainer = CreateFadeContainer();
InternalChild = FadeContainer;
EnableUserDim.BindTo(FadeContainer.EnableUserDim);
Beatmap = beatmap;
InternalChild = fadeContainer = CreateFadeContainer();
fadeContainer.EnableUserDim.BindTo(EnableUserDim);
}
public override bool Equals(BackgroundScreen other)

View File

@ -72,7 +72,7 @@ namespace osu.Game.Screens.Play
[Resolved]
private ScoreManager scoreManager { get; set; }
private PauseContainer pauseContainer;
protected PauseContainer PauseContainer { get; private set; }
private RulesetInfo ruleset;
@ -80,10 +80,10 @@ namespace osu.Game.Screens.Play
private SampleChannel sampleRestart;
protected ScoreProcessor ScoreProcessor;
protected RulesetContainer RulesetContainer;
protected ScoreProcessor ScoreProcessor { get; private set; }
protected RulesetContainer RulesetContainer { get; private set; }
protected HUDOverlay HUDOverlay;
protected HUDOverlay HUDOverlay { get; private set; }
private FailOverlay failOverlay;
private DrawableStoryboard storyboard;
@ -175,7 +175,7 @@ namespace osu.Game.Screens.Play
InternalChildren = new Drawable[]
{
pauseContainer = new PauseContainer(offsetClock, adjustableClock)
PauseContainer = new PauseContainer(offsetClock, adjustableClock)
{
Retries = RestartCount,
OnRetry = Restart,
@ -239,7 +239,7 @@ namespace osu.Game.Screens.Play
HUDOverlay.HoldToQuit.Action = performUserRequestedExit;
HUDOverlay.KeyCounter.Visible.BindTo(RulesetContainer.HasReplayLoaded);
RulesetContainer.IsPaused.BindTo(pauseContainer.IsPaused);
RulesetContainer.IsPaused.BindTo(PauseContainer.IsPaused);
if (ShowStoryboard.Value)
initializeStoryboard(false);
@ -357,7 +357,7 @@ namespace osu.Game.Screens.Play
Background.EnableUserDim.Value = true;
storyboardReplacesBackground.BindTo(Background.StoryboardReplacesBackground);
Background.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground);
StoryboardContainer.StoryboardReplacesBackground.BindTo(storyboardReplacesBackground);
storyboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable;
@ -372,7 +372,7 @@ namespace osu.Game.Screens.Play
this.Delay(750).Schedule(() =>
{
if (!pauseContainer.IsPaused.Value)
if (!PauseContainer.IsPaused.Value)
{
adjustableClock.Start();
}
@ -380,8 +380,8 @@ namespace osu.Game.Screens.Play
});
});
pauseContainer.Alpha = 0;
pauseContainer.FadeIn(750, Easing.OutQuint);
PauseContainer.Alpha = 0;
PauseContainer.FadeIn(750, Easing.OutQuint);
}
public override void OnSuspending(IScreen next)
@ -399,7 +399,7 @@ namespace osu.Game.Screens.Play
return true;
}
if ((!AllowPause || HasFailed || !ValidForResume || pauseContainer?.IsPaused.Value != false || RulesetContainer?.HasReplayLoaded.Value != false) && (!pauseContainer?.IsResuming ?? true))
if ((!AllowPause || HasFailed || !ValidForResume || PauseContainer?.IsPaused.Value != false || RulesetContainer?.HasReplayLoaded.Value != false) && (!PauseContainer?.IsResuming ?? true))
{
// In the case of replays, we may have changed the playback rate.
applyRateFromMods();
@ -408,7 +408,7 @@ namespace osu.Game.Screens.Play
}
if (LoadedBeatmapSuccessfully)
pauseContainer?.Pause();
PauseContainer?.Pause();
return true;
}
@ -421,7 +421,7 @@ namespace osu.Game.Screens.Play
storyboardReplacesBackground.Value = false;
}
protected override bool OnScroll(ScrollEvent e) => mouseWheelDisabled.Value && !pauseContainer.IsPaused.Value;
protected override bool OnScroll(ScrollEvent e) => mouseWheelDisabled.Value && !PauseContainer.IsPaused.Value;
private void initializeStoryboard(bool asyncLoad)
{