2019-05-31 05:40:53 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 08:43:03 +00:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-20 08:30:27 +00:00
|
|
|
|
2019-05-07 04:02:19 +00:00
|
|
|
using System;
|
2019-05-10 09:21:07 +00:00
|
|
|
using System.Collections.Generic;
|
2019-04-09 06:05:03 +00:00
|
|
|
using System.Linq;
|
2018-08-02 10:47:50 +00:00
|
|
|
using System.Threading;
|
2019-12-06 04:47:34 +00:00
|
|
|
using System.Threading.Tasks;
|
2019-04-09 04:50:54 +00:00
|
|
|
using NUnit.Framework;
|
2018-04-20 08:30:27 +00:00
|
|
|
using osu.Framework.Allocation;
|
2019-09-25 10:24:05 +00:00
|
|
|
using osu.Framework.Audio;
|
2019-02-12 10:53:08 +00:00
|
|
|
using osu.Framework.Graphics;
|
2019-09-25 10:24:05 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-01-09 04:43:44 +00:00
|
|
|
using osu.Framework.Utils;
|
2019-01-23 11:52:00 +00:00
|
|
|
using osu.Framework.Screens;
|
2019-10-01 16:15:40 +00:00
|
|
|
using osu.Game.Configuration;
|
2019-09-25 10:24:05 +00:00
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osu.Game.Overlays.Notifications;
|
2019-04-09 06:05:03 +00:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2019-04-19 10:45:17 +00:00
|
|
|
using osu.Game.Rulesets.Osu;
|
2019-12-06 04:47:34 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Mods;
|
2019-04-09 06:05:03 +00:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
2019-04-25 10:56:57 +00:00
|
|
|
using osu.Game.Scoring;
|
2019-02-25 13:05:49 +00:00
|
|
|
using osu.Game.Screens;
|
2018-04-20 08:30:27 +00:00
|
|
|
using osu.Game.Screens.Play;
|
2019-07-05 06:50:31 +00:00
|
|
|
using osu.Game.Screens.Play.PlayerSettings;
|
2019-09-25 10:24:05 +00:00
|
|
|
using osuTK.Input;
|
2018-04-20 08:30:27 +00:00
|
|
|
|
2019-03-24 16:02:36 +00:00
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
2018-04-20 08:30:27 +00:00
|
|
|
{
|
2020-03-23 01:01:33 +00:00
|
|
|
public class TestScenePlayerLoader : OsuManualInputManagerTestScene
|
2018-04-20 08:30:27 +00:00
|
|
|
{
|
2019-07-05 06:50:31 +00:00
|
|
|
private TestPlayerLoader loader;
|
2019-09-25 10:24:05 +00:00
|
|
|
private TestPlayerLoaderContainer container;
|
|
|
|
private TestPlayer player;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private AudioManager audioManager { get; set; }
|
|
|
|
|
2019-10-01 16:15:40 +00:00
|
|
|
[Resolved]
|
|
|
|
private SessionStatics sessionStatics { get; set; }
|
|
|
|
|
2019-09-25 10:24:05 +00:00
|
|
|
/// <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>
|
|
|
|
/// <param name="beforeLoadAction">An action to run before player load but after bindable leases are returned.</param>
|
2019-09-26 12:05:43 +00:00
|
|
|
/// <param name="afterLoadAction">An action to run after container load.</param>
|
|
|
|
public void ResetPlayer(bool interactive, Action beforeLoadAction = null, Action afterLoadAction = null)
|
2019-02-25 13:05:49 +00:00
|
|
|
{
|
2019-09-25 10:24:05 +00:00
|
|
|
audioManager.Volume.SetDefault();
|
|
|
|
|
|
|
|
InputManager.Clear();
|
|
|
|
|
|
|
|
beforeLoadAction?.Invoke();
|
2019-05-31 05:40:53 +00:00
|
|
|
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
2019-09-25 10:24:05 +00:00
|
|
|
|
2019-12-13 12:45:38 +00:00
|
|
|
foreach (var mod in SelectedMods.Value.OfType<IApplicableToTrack>())
|
2019-12-09 08:34:04 +00:00
|
|
|
mod.ApplyToTrack(Beatmap.Value.Track);
|
2019-12-06 04:47:34 +00:00
|
|
|
|
2019-09-25 10:24:05 +00:00
|
|
|
InputManager.Child = container = new TestPlayerLoaderContainer(
|
2019-09-26 12:05:43 +00:00
|
|
|
loader = new TestPlayerLoader(() =>
|
|
|
|
{
|
|
|
|
afterLoadAction?.Invoke();
|
|
|
|
return player = new TestPlayer(interactive, interactive);
|
|
|
|
}));
|
2019-09-25 10:24:05 +00:00
|
|
|
}
|
2019-02-25 13:05:49 +00:00
|
|
|
|
2019-12-06 04:47:34 +00:00
|
|
|
/// <summary>
|
|
|
|
/// When <see cref="PlayerLoader"/> exits early, it has to wait for the player load task
|
|
|
|
/// to complete before running disposal on player. This previously caused an issue where mod
|
|
|
|
/// speed adjustments were undone too late, causing cross-screen pollution.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TestEarlyExit()
|
|
|
|
{
|
2019-12-13 12:45:38 +00:00
|
|
|
AddStep("load dummy beatmap", () => ResetPlayer(false, () => SelectedMods.Value = new[] { new OsuModNightcore() }));
|
2019-12-06 04:47:34 +00:00
|
|
|
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
|
|
|
|
AddAssert("mod rate applied", () => Beatmap.Value.Track.Rate != 1);
|
|
|
|
AddStep("exit loader", () => loader.Exit());
|
|
|
|
AddUntilStep("wait for not current", () => !loader.IsCurrentScreen());
|
|
|
|
AddAssert("player did not load", () => !player.IsLoaded);
|
|
|
|
AddUntilStep("player disposed", () => loader.DisposalTask?.IsCompleted == true);
|
|
|
|
AddAssert("mod rate still applied", () => Beatmap.Value.Track.Rate != 1);
|
|
|
|
}
|
|
|
|
|
2019-07-05 06:50:31 +00:00
|
|
|
[Test]
|
|
|
|
public void TestBlockLoadViaMouseMovement()
|
|
|
|
{
|
2019-09-25 10:24:05 +00:00
|
|
|
AddStep("load dummy beatmap", () => ResetPlayer(false));
|
2019-07-06 06:25:53 +00:00
|
|
|
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
|
2020-02-14 10:02:11 +00:00
|
|
|
|
|
|
|
AddUntilStep("wait for load ready", () =>
|
|
|
|
{
|
|
|
|
moveMouse();
|
|
|
|
return player.LoadState == LoadState.Ready;
|
|
|
|
});
|
|
|
|
AddRepeatStep("move mouse", moveMouse, 20);
|
|
|
|
|
|
|
|
AddAssert("loader still active", () => loader.IsCurrentScreen());
|
|
|
|
AddUntilStep("loads after idle", () => !loader.IsCurrentScreen());
|
|
|
|
|
|
|
|
void moveMouse()
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(
|
|
|
|
loader.VisualSettings.ScreenSpaceDrawQuad.TopLeft
|
|
|
|
+ (loader.VisualSettings.ScreenSpaceDrawQuad.BottomRight - loader.VisualSettings.ScreenSpaceDrawQuad.TopLeft)
|
|
|
|
* RNG.NextSingle());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestBlockLoadViaFocus()
|
|
|
|
{
|
|
|
|
OsuFocusedOverlayContainer overlay = null;
|
|
|
|
|
|
|
|
AddStep("load dummy beatmap", () => ResetPlayer(false));
|
|
|
|
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
|
|
|
|
|
|
|
|
AddStep("show focused overlay", () => { container.Add(overlay = new ChangelogOverlay { State = { Value = Visibility.Visible } }); });
|
|
|
|
AddUntilStep("overlay visible", () => overlay.IsPresent);
|
|
|
|
|
|
|
|
AddUntilStep("wait for load ready", () => player.LoadState == LoadState.Ready);
|
|
|
|
AddRepeatStep("twiddle thumbs", () => { }, 20);
|
|
|
|
|
2019-07-05 06:50:31 +00:00
|
|
|
AddAssert("loader still active", () => loader.IsCurrentScreen());
|
2020-02-14 10:02:11 +00:00
|
|
|
|
|
|
|
AddStep("hide overlay", () => overlay.Hide());
|
2019-07-05 06:50:31 +00:00
|
|
|
AddUntilStep("loads after idle", () => !loader.IsCurrentScreen());
|
|
|
|
}
|
|
|
|
|
2019-04-09 04:50:54 +00:00
|
|
|
[Test]
|
|
|
|
public void TestLoadContinuation()
|
2018-04-20 08:30:27 +00:00
|
|
|
{
|
2019-05-07 04:02:19 +00:00
|
|
|
SlowLoadPlayer slowPlayer = null;
|
|
|
|
|
2019-09-25 10:24:05 +00:00
|
|
|
AddStep("load dummy beatmap", () => ResetPlayer(false));
|
2019-03-19 08:24:26 +00:00
|
|
|
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
|
2018-08-02 10:47:50 +00:00
|
|
|
AddStep("mouse in centre", () => InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre));
|
2019-05-07 04:02:19 +00:00
|
|
|
AddUntilStep("wait for player to be current", () => player.IsCurrentScreen());
|
2018-08-02 10:47:50 +00:00
|
|
|
AddStep("load slow dummy beatmap", () =>
|
|
|
|
{
|
2019-09-25 10:24:05 +00:00
|
|
|
InputManager.Child = container = new TestPlayerLoaderContainer(
|
|
|
|
loader = new TestPlayerLoader(() => slowPlayer = new SlowLoadPlayer(false, false)));
|
|
|
|
|
2019-05-07 04:02:19 +00:00
|
|
|
Scheduler.AddDelayed(() => slowPlayer.AllowLoad.Set(), 5000);
|
2018-08-02 10:47:50 +00:00
|
|
|
});
|
|
|
|
|
2019-05-07 04:02:19 +00:00
|
|
|
AddUntilStep("wait for player to be current", () => slowPlayer.IsCurrentScreen());
|
2018-08-02 10:47:50 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 06:05:03 +00:00
|
|
|
[Test]
|
|
|
|
public void TestModReinstantiation()
|
|
|
|
{
|
|
|
|
TestMod gameMod = null;
|
|
|
|
TestMod playerMod1 = null;
|
|
|
|
TestMod playerMod2 = null;
|
|
|
|
|
2019-12-13 12:45:38 +00:00
|
|
|
AddStep("load player", () => { ResetPlayer(true, () => SelectedMods.Value = new[] { gameMod = new TestMod() }); });
|
2019-04-09 06:05:03 +00:00
|
|
|
|
2019-04-19 10:45:17 +00:00
|
|
|
AddUntilStep("wait for loader to become current", () => loader.IsCurrentScreen());
|
|
|
|
AddStep("mouse in centre", () => InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre));
|
|
|
|
AddUntilStep("wait for player to be current", () => player.IsCurrentScreen());
|
|
|
|
AddStep("retrieve mods", () => playerMod1 = (TestMod)player.Mods.Value.Single());
|
2019-04-09 06:05:03 +00:00
|
|
|
AddAssert("game mods not applied", () => gameMod.Applied == false);
|
|
|
|
AddAssert("player mods applied", () => playerMod1.Applied);
|
|
|
|
|
|
|
|
AddStep("restart player", () =>
|
|
|
|
{
|
2019-04-19 10:45:17 +00:00
|
|
|
var lastPlayer = player;
|
2019-04-09 06:05:03 +00:00
|
|
|
player = null;
|
2019-04-19 10:45:17 +00:00
|
|
|
lastPlayer.Restart();
|
2019-04-09 06:05:03 +00:00
|
|
|
});
|
|
|
|
|
2019-04-19 10:45:17 +00:00
|
|
|
AddUntilStep("wait for player to be current", () => player.IsCurrentScreen());
|
|
|
|
AddStep("retrieve mods", () => playerMod2 = (TestMod)player.Mods.Value.Single());
|
2019-04-09 06:05:03 +00:00
|
|
|
AddAssert("game mods not applied", () => gameMod.Applied == false);
|
|
|
|
AddAssert("player has different mods", () => playerMod1 != playerMod2);
|
|
|
|
AddAssert("player mods applied", () => playerMod2.Applied);
|
|
|
|
}
|
|
|
|
|
2020-01-08 18:55:35 +00:00
|
|
|
[Test]
|
|
|
|
public void TestModDisplayChanges()
|
|
|
|
{
|
|
|
|
var testMod = new TestMod();
|
|
|
|
|
|
|
|
AddStep("load player", () => ResetPlayer(true));
|
|
|
|
|
|
|
|
AddUntilStep("wait for loader to become current", () => loader.IsCurrentScreen());
|
|
|
|
AddStep("set test mod in loader", () => loader.Mods.Value = new[] { testMod });
|
|
|
|
AddAssert("test mod is displayed", () => (TestMod)loader.DisplayedMods.Single() == testMod);
|
|
|
|
}
|
|
|
|
|
2019-09-25 10:24:05 +00:00
|
|
|
[Test]
|
2020-02-14 10:27:32 +00:00
|
|
|
public void TestMutedNotificationMasterVolume()
|
|
|
|
{
|
|
|
|
addVolumeSteps("master volume", () => audioManager.Volume.Value = 0, null, () => audioManager.Volume.IsDefault);
|
|
|
|
}
|
2019-09-26 12:05:43 +00:00
|
|
|
|
|
|
|
[Test]
|
2020-02-14 10:27:32 +00:00
|
|
|
public void TestMutedNotificationTrackVolume()
|
|
|
|
{
|
|
|
|
addVolumeSteps("music volume", () => audioManager.VolumeTrack.Value = 0, null, () => audioManager.VolumeTrack.IsDefault);
|
|
|
|
}
|
2019-09-26 12:05:43 +00:00
|
|
|
|
|
|
|
[Test]
|
2020-02-14 10:27:32 +00:00
|
|
|
public void TestMutedNotificationMuteButton()
|
|
|
|
{
|
|
|
|
addVolumeSteps("mute button", null, () => container.VolumeOverlay.IsMuted.Value = true, () => !container.VolumeOverlay.IsMuted.Value);
|
|
|
|
}
|
2019-09-26 12:05:43 +00:00
|
|
|
|
|
|
|
/// <remarks>
|
|
|
|
/// Created for avoiding copy pasting code for the same steps.
|
|
|
|
/// </remarks>
|
|
|
|
/// <param name="volumeName">What part of the volume system is checked</param>
|
|
|
|
/// <param name="beforeLoad">The action to be invoked to set the volume before loading</param>
|
|
|
|
/// <param name="afterLoad">The action to be invoked to set the volume after loading</param>
|
|
|
|
/// <param name="assert">The function to be invoked and checked</param>
|
|
|
|
private void addVolumeSteps(string volumeName, Action beforeLoad, Action afterLoad, Func<bool> assert)
|
2019-09-25 10:24:05 +00:00
|
|
|
{
|
2019-10-01 16:15:40 +00:00
|
|
|
AddStep("reset notification lock", () => sessionStatics.GetBindable<bool>(Static.MutedAudioNotificationShownOnce).Value = false);
|
2019-09-25 10:24:05 +00:00
|
|
|
|
2019-09-26 12:05:43 +00:00
|
|
|
AddStep("load player", () => ResetPlayer(false, beforeLoad, afterLoad));
|
2020-02-14 10:27:32 +00:00
|
|
|
AddUntilStep("wait for player", () => player.LoadState == LoadState.Ready);
|
2019-09-25 10:24:05 +00:00
|
|
|
|
|
|
|
AddAssert("check for notification", () => container.NotificationOverlay.UnreadCount.Value == 1);
|
|
|
|
AddStep("click notification", () =>
|
|
|
|
{
|
|
|
|
var scrollContainer = (OsuScrollContainer)container.NotificationOverlay.Children.Last();
|
|
|
|
var flowContainer = scrollContainer.Children.OfType<FillFlowContainer<NotificationSection>>().First();
|
|
|
|
var notification = flowContainer.First();
|
|
|
|
|
|
|
|
InputManager.MoveMouseTo(notification);
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
|
2019-09-26 12:05:43 +00:00
|
|
|
AddAssert("check " + volumeName, assert);
|
2020-02-14 10:27:32 +00:00
|
|
|
|
|
|
|
AddUntilStep("wait for player load", () => player.IsLoaded);
|
2019-09-25 10:24:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private class TestPlayerLoaderContainer : Container
|
|
|
|
{
|
|
|
|
[Cached]
|
|
|
|
public readonly NotificationOverlay NotificationOverlay;
|
|
|
|
|
|
|
|
[Cached]
|
|
|
|
public readonly VolumeOverlay VolumeOverlay;
|
|
|
|
|
|
|
|
public TestPlayerLoaderContainer(IScreen screen)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
2020-01-31 10:10:44 +00:00
|
|
|
OsuScreenStack stack;
|
|
|
|
|
2019-09-25 10:24:05 +00:00
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2020-01-31 10:10:44 +00:00
|
|
|
stack = new OsuScreenStack
|
2019-09-25 10:24:05 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
NotificationOverlay = new NotificationOverlay
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
},
|
|
|
|
VolumeOverlay = new VolumeOverlay
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
}
|
|
|
|
};
|
2020-01-31 10:10:44 +00:00
|
|
|
|
|
|
|
stack.Push(screen);
|
2019-09-25 10:24:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-05 06:50:31 +00:00
|
|
|
private class TestPlayerLoader : PlayerLoader
|
|
|
|
{
|
|
|
|
public new VisualSettings VisualSettings => base.VisualSettings;
|
|
|
|
|
2019-12-06 04:47:34 +00:00
|
|
|
public new Task DisposalTask => base.DisposalTask;
|
|
|
|
|
2020-01-08 19:10:43 +00:00
|
|
|
public IReadOnlyList<Mod> DisplayedMods => MetadataInfo.Mods.Value;
|
2020-01-08 18:55:35 +00:00
|
|
|
|
2019-07-05 06:50:31 +00:00
|
|
|
public TestPlayerLoader(Func<Player> createPlayer)
|
|
|
|
: base(createPlayer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-09 06:05:03 +00:00
|
|
|
private class TestMod : Mod, IApplicableToScoreProcessor
|
|
|
|
{
|
|
|
|
public override string Name => string.Empty;
|
|
|
|
public override string Acronym => string.Empty;
|
|
|
|
public override double ScoreMultiplier => 1;
|
|
|
|
|
|
|
|
public bool Applied { get; private set; }
|
|
|
|
|
|
|
|
public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor)
|
|
|
|
{
|
|
|
|
Applied = true;
|
|
|
|
}
|
2019-04-25 10:56:57 +00:00
|
|
|
|
|
|
|
public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank;
|
2019-04-09 06:05:03 +00:00
|
|
|
}
|
|
|
|
|
2020-03-05 02:25:07 +00:00
|
|
|
protected class SlowLoadPlayer : TestPlayer
|
2018-08-02 10:47:50 +00:00
|
|
|
{
|
2019-05-07 04:02:19 +00:00
|
|
|
public readonly ManualResetEventSlim AllowLoad = new ManualResetEventSlim(false);
|
2018-08-02 10:47:50 +00:00
|
|
|
|
2019-03-26 07:53:44 +00:00
|
|
|
public SlowLoadPlayer(bool allowPause = true, bool showResults = true)
|
|
|
|
: base(allowPause, showResults)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-08-02 10:47:50 +00:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2019-05-07 04:02:19 +00:00
|
|
|
if (!AllowLoad.Wait(TimeSpan.FromSeconds(10)))
|
|
|
|
throw new TimeoutException();
|
2018-08-02 10:47:50 +00:00
|
|
|
}
|
2018-04-20 08:30:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|