mirror of
https://github.com/ppy/osu
synced 2025-03-04 02:19:45 +00:00
Prepare classes for player loader test scene
This commit is contained in:
parent
220fdd0a04
commit
c3221e1a36
@ -3,14 +3,20 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.MathUtils;
|
using osu.Framework.MathUtils;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
|
using osu.Game.Graphics.Containers;
|
||||||
|
using osu.Game.Overlays;
|
||||||
|
using osu.Game.Overlays.Notifications;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Rulesets.Osu;
|
using osu.Game.Rulesets.Osu;
|
||||||
using osu.Game.Rulesets.Scoring;
|
using osu.Game.Rulesets.Scoring;
|
||||||
@ -24,19 +30,35 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
public class TestScenePlayerLoader : ManualInputManagerTestScene
|
public class TestScenePlayerLoader : ManualInputManagerTestScene
|
||||||
{
|
{
|
||||||
private TestPlayerLoader loader;
|
private TestPlayerLoader loader;
|
||||||
private OsuScreenStack stack;
|
private TestPlayerLoaderContainer container;
|
||||||
|
private TestPlayer player;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private AudioManager audioManager { get; set; }
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup() => Schedule(() =>
|
public void Setup() => Schedule(() =>
|
||||||
{
|
{
|
||||||
InputManager.Child = stack = new OsuScreenStack { RelativeSizeAxes = Axes.Both };
|
ResetPlayer(false);
|
||||||
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the input manager child to a new test player loader container instance.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="interactive">If the test player should behave like the production one.</param>
|
||||||
|
public void ResetPlayer(bool interactive)
|
||||||
|
{
|
||||||
|
player = new TestPlayer(interactive, interactive);
|
||||||
|
loader = new TestPlayerLoader(() => player);
|
||||||
|
container = new TestPlayerLoaderContainer(loader);
|
||||||
|
InputManager.Child = container;
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestBlockLoadViaMouseMovement()
|
public void TestBlockLoadViaMouseMovement()
|
||||||
{
|
{
|
||||||
AddStep("load dummy beatmap", () => stack.Push(loader = new TestPlayerLoader(() => new TestPlayer(false, false))));
|
AddStep("load dummy beatmap", () => ResetPlayer(false));
|
||||||
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
|
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
|
||||||
AddRepeatStep("move mouse", () => InputManager.MoveMouseTo(loader.VisualSettings.ScreenSpaceDrawQuad.TopLeft + (loader.VisualSettings.ScreenSpaceDrawQuad.BottomRight - loader.VisualSettings.ScreenSpaceDrawQuad.TopLeft) * RNG.NextSingle()), 20);
|
AddRepeatStep("move mouse", () => InputManager.MoveMouseTo(loader.VisualSettings.ScreenSpaceDrawQuad.TopLeft + (loader.VisualSettings.ScreenSpaceDrawQuad.BottomRight - loader.VisualSettings.ScreenSpaceDrawQuad.TopLeft) * RNG.NextSingle()), 20);
|
||||||
AddAssert("loader still active", () => loader.IsCurrentScreen());
|
AddAssert("loader still active", () => loader.IsCurrentScreen());
|
||||||
@ -49,13 +71,13 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
Player player = null;
|
Player player = null;
|
||||||
SlowLoadPlayer slowPlayer = null;
|
SlowLoadPlayer slowPlayer = null;
|
||||||
|
|
||||||
AddStep("load dummy beatmap", () => stack.Push(loader = new TestPlayerLoader(() => player = new TestPlayer(false, false))));
|
AddStep("load dummy beatmap", () => ResetPlayer(false));
|
||||||
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
|
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
|
||||||
AddStep("mouse in centre", () => InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre));
|
AddStep("mouse in centre", () => InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre));
|
||||||
AddUntilStep("wait for player to be current", () => player.IsCurrentScreen());
|
AddUntilStep("wait for player to be current", () => player.IsCurrentScreen());
|
||||||
AddStep("load slow dummy beatmap", () =>
|
AddStep("load slow dummy beatmap", () =>
|
||||||
{
|
{
|
||||||
stack.Push(loader = new TestPlayerLoader(() => slowPlayer = new SlowLoadPlayer(false, false)));
|
InputManager.Children = container = new TestPlayerLoaderContainer(loader = new TestPlayerLoader(() => slowPlayer = new SlowLoadPlayer(false, false)));
|
||||||
Scheduler.AddDelayed(() => slowPlayer.AllowLoad.Set(), 5000);
|
Scheduler.AddDelayed(() => slowPlayer.AllowLoad.Set(), 5000);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -65,7 +87,6 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestModReinstantiation()
|
public void TestModReinstantiation()
|
||||||
{
|
{
|
||||||
TestPlayer player = null;
|
|
||||||
TestMod gameMod = null;
|
TestMod gameMod = null;
|
||||||
TestMod playerMod1 = null;
|
TestMod playerMod1 = null;
|
||||||
TestMod playerMod2 = null;
|
TestMod playerMod2 = null;
|
||||||
@ -73,7 +94,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
AddStep("load player", () =>
|
AddStep("load player", () =>
|
||||||
{
|
{
|
||||||
Mods.Value = new[] { gameMod = new TestMod() };
|
Mods.Value = new[] { gameMod = new TestMod() };
|
||||||
stack.Push(loader = new TestPlayerLoader(() => player = new TestPlayer()));
|
ResetPlayer(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddUntilStep("wait for loader to become current", () => loader.IsCurrentScreen());
|
AddUntilStep("wait for loader to become current", () => loader.IsCurrentScreen());
|
||||||
@ -97,6 +118,61 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
AddAssert("player mods applied", () => playerMod2.Applied);
|
AddAssert("player mods applied", () => playerMod2.Applied);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestMutedNotification()
|
||||||
|
{
|
||||||
|
AddStep("set master volume to 0%", () => audioManager.Volume.Value = 0);
|
||||||
|
AddStep("reset notification lock", () => PlayerLoader.ResetNotificationLock());
|
||||||
|
//AddStep("reset notification overlay", () => notificationOverlay);
|
||||||
|
AddStep("load player", () => ResetPlayer(false));
|
||||||
|
AddUntilStep("wait for player", () => player.IsLoaded);
|
||||||
|
|
||||||
|
AddAssert("check for notification", () => container.NotificationOverlay.UnreadCount.Value == 1);
|
||||||
|
AddAssert("click notification", () =>
|
||||||
|
{
|
||||||
|
var scrollContainer = container.NotificationOverlay.Children.Last() as OsuScrollContainer;
|
||||||
|
var flowContainer = scrollContainer.Children.First() as FillFlowContainer<NotificationSection>;
|
||||||
|
return flowContainer.Children.First().First().Click();
|
||||||
|
});
|
||||||
|
AddAssert("check master volume", () => audioManager.Volume.IsDefault);
|
||||||
|
|
||||||
|
AddStep("restart player", () =>
|
||||||
|
{
|
||||||
|
var lastPlayer = player;
|
||||||
|
player = null;
|
||||||
|
lastPlayer.Restart();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestPlayerLoaderContainer : Container
|
||||||
|
{
|
||||||
|
private TestPlayerLoader loader;
|
||||||
|
|
||||||
|
[Cached]
|
||||||
|
public NotificationOverlay NotificationOverlay { get; } = new NotificationOverlay
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopRight,
|
||||||
|
Origin = Anchor.TopRight,
|
||||||
|
};
|
||||||
|
|
||||||
|
[Cached]
|
||||||
|
public VolumeOverlay VolumeOverlay { get; } = new VolumeOverlay
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopLeft,
|
||||||
|
Origin = Anchor.TopLeft,
|
||||||
|
};
|
||||||
|
|
||||||
|
public TestPlayerLoaderContainer(TestPlayerLoader testPlayerLoader)
|
||||||
|
{
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
loader = testPlayerLoader,
|
||||||
|
NotificationOverlay,
|
||||||
|
VolumeOverlay
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class TestPlayerLoader : PlayerLoader
|
private class TestPlayerLoader : PlayerLoader
|
||||||
{
|
{
|
||||||
public new VisualSettings VisualSettings => base.VisualSettings;
|
public new VisualSettings VisualSettings => base.VisualSettings;
|
||||||
|
@ -65,6 +65,9 @@ namespace osu.Game.Screens.Play
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private VolumeOverlay volumeOverlay { get; set; }
|
private VolumeOverlay volumeOverlay { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private AudioManager audioManager { get; set; }
|
||||||
|
|
||||||
private static bool muteWarningShownOnce;
|
private static bool muteWarningShownOnce;
|
||||||
|
|
||||||
public PlayerLoader(Func<Player> createPlayer)
|
public PlayerLoader(Func<Player> createPlayer)
|
||||||
@ -79,7 +82,7 @@ namespace osu.Game.Screens.Play
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(AudioManager audioManager, NotificationOverlay notificationOverlay)
|
private void load()
|
||||||
{
|
{
|
||||||
InternalChild = (content = new LogoTrackingContainer
|
InternalChild = (content = new LogoTrackingContainer
|
||||||
{
|
{
|
||||||
@ -112,8 +115,6 @@ namespace osu.Game.Screens.Play
|
|||||||
});
|
});
|
||||||
|
|
||||||
loadNewPlayer();
|
loadNewPlayer();
|
||||||
|
|
||||||
checkVolume(audioManager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void playerLoaded(Player player) => info.Loading = false;
|
private void playerLoaded(Player player) => info.Loading = false;
|
||||||
@ -212,6 +213,7 @@ namespace osu.Game.Screens.Play
|
|||||||
{
|
{
|
||||||
inputManager = GetContainingInputManager();
|
inputManager = GetContainingInputManager();
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
checkVolume(audioManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScheduledDelegate pushDebounce;
|
private ScheduledDelegate pushDebounce;
|
||||||
@ -526,5 +528,13 @@ namespace osu.Game.Screens.Play
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets <see cref="muteWarningShownOnce"/> to <see cref="false"/>, reserved for testing.
|
||||||
|
/// </summary>
|
||||||
|
public static void ResetNotificationLock()
|
||||||
|
{
|
||||||
|
muteWarningShownOnce = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user