2020-12-19 01:37:47 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Testing;
|
2020-12-22 17:25:45 +08:00
|
|
|
using osu.Framework.Utils;
|
2021-02-05 14:52:49 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-01-18 16:10:38 +08:00
|
|
|
using osu.Game.Online;
|
2020-12-25 12:38:11 +08:00
|
|
|
using osu.Game.Online.Multiplayer;
|
2021-01-18 16:10:38 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2021-02-01 16:54:56 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.Osu.Mods;
|
2020-12-25 23:50:00 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Multiplayer.Participants;
|
2020-12-19 01:37:47 +08:00
|
|
|
using osu.Game.Users;
|
|
|
|
using osuTK;
|
|
|
|
|
2020-12-25 12:20:37 +08:00
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
2020-12-25 12:38:11 +08:00
|
|
|
public class TestSceneMultiplayerParticipantsList : MultiplayerTestScene
|
2020-12-19 01:37:47 +08:00
|
|
|
{
|
|
|
|
[SetUp]
|
2021-02-09 14:46:23 +08:00
|
|
|
public new void Setup() => Schedule(createNewParticipantsList);
|
2020-12-19 01:37:47 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAddUser()
|
|
|
|
{
|
|
|
|
AddAssert("one unique panel", () => this.ChildrenOfType<ParticipantPanel>().Select(p => p.User).Distinct().Count() == 1);
|
|
|
|
|
|
|
|
AddStep("add user", () => Client.AddUser(new User
|
|
|
|
{
|
|
|
|
Id = 3,
|
|
|
|
Username = "Second",
|
|
|
|
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
|
|
|
|
}));
|
|
|
|
|
|
|
|
AddAssert("two unique panels", () => this.ChildrenOfType<ParticipantPanel>().Select(p => p.User).Distinct().Count() == 2);
|
2020-12-28 13:56:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAddNullUser()
|
|
|
|
{
|
|
|
|
AddAssert("one unique panel", () => this.ChildrenOfType<ParticipantPanel>().Select(p => p.User).Distinct().Count() == 1);
|
|
|
|
|
|
|
|
AddStep("add non-resolvable user", () => Client.AddNullUser(-3));
|
|
|
|
|
|
|
|
AddUntilStep("two unique panels", () => this.ChildrenOfType<ParticipantPanel>().Select(p => p.User).Distinct().Count() == 2);
|
2020-12-19 01:37:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestRemoveUser()
|
|
|
|
{
|
|
|
|
User secondUser = null;
|
|
|
|
|
|
|
|
AddStep("add a user", () =>
|
|
|
|
{
|
|
|
|
Client.AddUser(secondUser = new User
|
|
|
|
{
|
|
|
|
Id = 3,
|
|
|
|
Username = "Second",
|
|
|
|
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("remove host", () => Client.RemoveUser(API.LocalUser.Value));
|
|
|
|
|
|
|
|
AddAssert("single panel is for second user", () => this.ChildrenOfType<ParticipantPanel>().Single().User.User == secondUser);
|
|
|
|
}
|
|
|
|
|
2021-02-05 14:58:27 +08:00
|
|
|
[Test]
|
|
|
|
public void TestGameStateHasPriorityOverDownloadState()
|
|
|
|
{
|
|
|
|
AddStep("set to downloading map", () => Client.ChangeBeatmapAvailability(BeatmapAvailability.Downloading(0)));
|
|
|
|
checkProgressBarVisibility(true);
|
|
|
|
|
|
|
|
AddStep("make user ready", () => Client.ChangeState(MultiplayerUserState.Results));
|
|
|
|
checkProgressBarVisibility(false);
|
|
|
|
AddUntilStep("ready mark visible", () => this.ChildrenOfType<StateDisplay>().Single().IsPresent);
|
|
|
|
|
|
|
|
AddStep("make user ready", () => Client.ChangeState(MultiplayerUserState.Idle));
|
|
|
|
checkProgressBarVisibility(true);
|
|
|
|
}
|
|
|
|
|
2021-02-09 14:46:23 +08:00
|
|
|
[Test]
|
|
|
|
public void TestCorrectInitialState()
|
|
|
|
{
|
|
|
|
AddStep("set to downloading map", () => Client.ChangeBeatmapAvailability(BeatmapAvailability.Downloading(0)));
|
|
|
|
AddStep("recreate list", createNewParticipantsList);
|
|
|
|
checkProgressBarVisibility(true);
|
|
|
|
}
|
|
|
|
|
2021-01-18 16:10:38 +08:00
|
|
|
[Test]
|
|
|
|
public void TestBeatmapDownloadingStates()
|
|
|
|
{
|
|
|
|
AddStep("set to no map", () => Client.ChangeBeatmapAvailability(BeatmapAvailability.NotDownloaded()));
|
|
|
|
AddStep("set to downloading map", () => Client.ChangeBeatmapAvailability(BeatmapAvailability.Downloading(0)));
|
2021-02-05 14:52:49 +08:00
|
|
|
|
2021-02-05 14:58:27 +08:00
|
|
|
checkProgressBarVisibility(true);
|
2021-02-05 14:52:49 +08:00
|
|
|
|
2021-01-18 16:10:38 +08:00
|
|
|
AddRepeatStep("increment progress", () =>
|
|
|
|
{
|
|
|
|
var progress = this.ChildrenOfType<ParticipantPanel>().Single().User.BeatmapAvailability.DownloadProgress ?? 0;
|
|
|
|
Client.ChangeBeatmapAvailability(BeatmapAvailability.Downloading(progress + RNG.NextSingle(0.1f)));
|
|
|
|
}, 25);
|
2021-02-05 14:52:49 +08:00
|
|
|
|
|
|
|
AddAssert("progress bar increased", () => this.ChildrenOfType<ProgressBar>().Single().Current.Value > 0);
|
|
|
|
|
2021-01-18 16:10:38 +08:00
|
|
|
AddStep("set to importing map", () => Client.ChangeBeatmapAvailability(BeatmapAvailability.Importing()));
|
2021-02-05 14:58:27 +08:00
|
|
|
checkProgressBarVisibility(false);
|
2021-02-05 14:52:49 +08:00
|
|
|
|
2021-01-18 16:10:38 +08:00
|
|
|
AddStep("set to available", () => Client.ChangeBeatmapAvailability(BeatmapAvailability.LocallyAvailable()));
|
|
|
|
}
|
|
|
|
|
2020-12-19 01:37:47 +08:00
|
|
|
[Test]
|
|
|
|
public void TestToggleReadyState()
|
|
|
|
{
|
2020-12-22 17:25:45 +08:00
|
|
|
AddAssert("ready mark invisible", () => !this.ChildrenOfType<StateDisplay>().Single().IsPresent);
|
2020-12-19 01:37:47 +08:00
|
|
|
|
|
|
|
AddStep("make user ready", () => Client.ChangeState(MultiplayerUserState.Ready));
|
2020-12-22 17:25:45 +08:00
|
|
|
AddUntilStep("ready mark visible", () => this.ChildrenOfType<StateDisplay>().Single().IsPresent);
|
2020-12-19 01:37:47 +08:00
|
|
|
|
|
|
|
AddStep("make user idle", () => Client.ChangeState(MultiplayerUserState.Idle));
|
2020-12-22 17:25:45 +08:00
|
|
|
AddUntilStep("ready mark invisible", () => !this.ChildrenOfType<StateDisplay>().Single().IsPresent);
|
2020-12-19 01:37:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestCrownChangesStateWhenHostTransferred()
|
|
|
|
{
|
|
|
|
AddStep("add user", () => Client.AddUser(new User
|
|
|
|
{
|
|
|
|
Id = 3,
|
|
|
|
Username = "Second",
|
|
|
|
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
|
|
|
|
}));
|
|
|
|
|
|
|
|
AddUntilStep("first user crown visible", () => this.ChildrenOfType<ParticipantPanel>().ElementAt(0).ChildrenOfType<SpriteIcon>().First().Alpha == 1);
|
|
|
|
AddUntilStep("second user crown hidden", () => this.ChildrenOfType<ParticipantPanel>().ElementAt(1).ChildrenOfType<SpriteIcon>().First().Alpha == 0);
|
|
|
|
|
|
|
|
AddStep("make second user host", () => Client.TransferHost(3));
|
|
|
|
|
|
|
|
AddUntilStep("first user crown hidden", () => this.ChildrenOfType<ParticipantPanel>().ElementAt(0).ChildrenOfType<SpriteIcon>().First().Alpha == 0);
|
|
|
|
AddUntilStep("second user crown visible", () => this.ChildrenOfType<ParticipantPanel>().ElementAt(1).ChildrenOfType<SpriteIcon>().First().Alpha == 1);
|
|
|
|
}
|
2020-12-19 01:46:16 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestManyUsers()
|
|
|
|
{
|
|
|
|
AddStep("add many users", () =>
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 20; i++)
|
|
|
|
{
|
|
|
|
Client.AddUser(new User
|
|
|
|
{
|
|
|
|
Id = i,
|
|
|
|
Username = $"User {i}",
|
2020-12-22 17:25:45 +08:00
|
|
|
CurrentModeRank = RNG.Next(1, 100000),
|
2020-12-19 01:46:16 +08:00
|
|
|
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
|
|
|
|
});
|
|
|
|
|
2020-12-23 04:16:45 +08:00
|
|
|
Client.ChangeUserState(i, (MultiplayerUserState)RNG.Next(0, (int)MultiplayerUserState.Results + 1));
|
2021-01-18 16:10:38 +08:00
|
|
|
|
|
|
|
if (RNG.NextBool())
|
|
|
|
{
|
|
|
|
var beatmapState = (DownloadState)RNG.Next(0, (int)DownloadState.LocallyAvailable + 1);
|
|
|
|
|
|
|
|
switch (beatmapState)
|
|
|
|
{
|
|
|
|
case DownloadState.NotDownloaded:
|
|
|
|
Client.ChangeUserBeatmapAvailability(i, BeatmapAvailability.NotDownloaded());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DownloadState.Downloading:
|
|
|
|
Client.ChangeUserBeatmapAvailability(i, BeatmapAvailability.Downloading(RNG.NextSingle()));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DownloadState.Importing:
|
|
|
|
Client.ChangeUserBeatmapAvailability(i, BeatmapAvailability.Importing());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-12-19 01:46:16 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-02-01 16:54:56 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestUserWithMods()
|
|
|
|
{
|
|
|
|
AddStep("add user", () =>
|
|
|
|
{
|
|
|
|
Client.AddUser(new User
|
|
|
|
{
|
|
|
|
Id = 0,
|
2021-02-03 13:53:13 +08:00
|
|
|
Username = "User 0",
|
2021-02-01 16:54:56 +08:00
|
|
|
CurrentModeRank = RNG.Next(1, 100000),
|
|
|
|
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
|
|
|
|
});
|
|
|
|
|
2021-02-01 16:57:32 +08:00
|
|
|
Client.ChangeUserMods(0, new Mod[]
|
2021-02-01 16:54:56 +08:00
|
|
|
{
|
|
|
|
new OsuModHardRock(),
|
|
|
|
new OsuModDifficultyAdjust { ApproachRate = { Value = 1 } }
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-02-01 17:25:09 +08:00
|
|
|
for (var i = MultiplayerUserState.Idle; i < MultiplayerUserState.Results; i++)
|
|
|
|
{
|
|
|
|
var state = i;
|
|
|
|
AddStep($"set state: {state}", () => Client.ChangeUserState(0, state));
|
|
|
|
}
|
2021-02-01 16:54:56 +08:00
|
|
|
}
|
2021-02-05 14:58:27 +08:00
|
|
|
|
2021-02-09 14:46:23 +08:00
|
|
|
private void createNewParticipantsList()
|
|
|
|
{
|
|
|
|
Child = new ParticipantsList { Anchor = Anchor.Centre, Origin = Anchor.Centre, RelativeSizeAxes = Axes.Y, Size = new Vector2(380, 0.7f) };
|
|
|
|
}
|
|
|
|
|
2021-02-05 14:58:27 +08:00
|
|
|
private void checkProgressBarVisibility(bool visible) =>
|
|
|
|
AddUntilStep($"progress bar {(visible ? "is" : "is not")}visible", () =>
|
|
|
|
this.ChildrenOfType<ProgressBar>().Single().IsPresent == visible);
|
2020-12-19 01:37:47 +08:00
|
|
|
}
|
|
|
|
}
|