2019-01-24 16:43:03 +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.
|
2018-12-25 10:45:50 +08:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2018-12-25 10:59:08 +08:00
|
|
|
using System.Linq;
|
2018-12-25 10:45:50 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Online.Multiplayer;
|
|
|
|
using osu.Game.Screens.Multi;
|
|
|
|
using osu.Game.Screens.Multi.Lounge.Components;
|
|
|
|
using osu.Game.Users;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
{
|
2019-02-08 15:02:14 +08:00
|
|
|
public class TestCaseLoungeRoomsContainer : MultiplayerTestCase
|
2018-12-25 10:45:50 +08:00
|
|
|
{
|
|
|
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
|
|
|
{
|
|
|
|
typeof(RoomsContainer),
|
|
|
|
typeof(DrawableRoom)
|
|
|
|
};
|
|
|
|
|
|
|
|
[Cached(Type = typeof(IRoomManager))]
|
|
|
|
private TestRoomManager roomManager = new TestRoomManager();
|
|
|
|
|
|
|
|
public TestCaseLoungeRoomsContainer()
|
|
|
|
{
|
2018-12-25 10:59:08 +08:00
|
|
|
RoomsContainer container;
|
2018-12-25 10:45:50 +08:00
|
|
|
|
2018-12-25 10:59:08 +08:00
|
|
|
Child = container = new RoomsContainer
|
2018-12-25 10:45:50 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Width = 0.5f,
|
|
|
|
JoinRequested = joinRequested
|
|
|
|
};
|
|
|
|
|
2018-12-25 10:59:08 +08:00
|
|
|
AddStep("clear rooms", () => roomManager.Rooms.Clear());
|
2018-12-25 10:45:50 +08:00
|
|
|
|
2018-12-25 10:59:08 +08:00
|
|
|
AddStep("add rooms", () =>
|
2018-12-25 10:45:50 +08:00
|
|
|
{
|
2018-12-25 10:59:08 +08:00
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
roomManager.Rooms.Add(new Room
|
|
|
|
{
|
|
|
|
RoomID = { Value = i },
|
|
|
|
Name = { Value = $"Room {i}" },
|
|
|
|
Host = { Value = new User { Username = "Host" } },
|
|
|
|
EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) }
|
|
|
|
});
|
|
|
|
}
|
2018-12-25 10:45:50 +08:00
|
|
|
});
|
2018-12-25 10:59:08 +08:00
|
|
|
|
|
|
|
AddAssert("has 2 rooms", () => container.Rooms.Count == 3);
|
|
|
|
AddStep("remove first room", () => roomManager.Rooms.Remove(roomManager.Rooms.FirstOrDefault()));
|
|
|
|
AddAssert("has 2 rooms", () => container.Rooms.Count == 2);
|
|
|
|
AddAssert("first room removed", () => container.Rooms.All(r => r.Room.RoomID.Value != 0));
|
|
|
|
|
|
|
|
AddStep("select first room", () => container.Rooms.First().Action?.Invoke());
|
2019-02-08 15:02:14 +08:00
|
|
|
AddAssert("first room selected", () => Room == roomManager.Rooms.First());
|
2018-12-25 10:59:08 +08:00
|
|
|
|
|
|
|
AddStep("join first room", () => container.Rooms.First().Action?.Invoke());
|
|
|
|
AddAssert("first room joined", () => roomManager.Rooms.First().Status.Value is JoinedRoomStatus);
|
2018-12-25 10:45:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void joinRequested(Room room) => room.Status.Value = new JoinedRoomStatus();
|
|
|
|
|
|
|
|
private class TestRoomManager : IRoomManager
|
|
|
|
{
|
2019-02-08 15:02:00 +08:00
|
|
|
public event Action RoomsUpdated
|
|
|
|
{
|
2019-02-08 15:02:14 +08:00
|
|
|
add { }
|
|
|
|
remove { }
|
2019-02-08 15:02:00 +08:00
|
|
|
}
|
2018-12-28 00:45:19 +08:00
|
|
|
|
2019-01-07 17:50:27 +08:00
|
|
|
public readonly BindableList<Room> Rooms = new BindableList<Room>();
|
|
|
|
IBindableList<Room> IRoomManager.Rooms => Rooms;
|
2018-12-25 10:45:50 +08:00
|
|
|
|
2018-12-26 20:10:31 +08:00
|
|
|
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) => Rooms.Add(room);
|
2018-12-25 10:45:50 +08:00
|
|
|
|
2018-12-26 20:10:31 +08:00
|
|
|
public void JoinRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
|
|
|
|
{
|
|
|
|
}
|
2018-12-25 10:45:50 +08:00
|
|
|
|
|
|
|
public void PartRoom()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class JoinedRoomStatus : RoomStatus
|
|
|
|
{
|
|
|
|
public override string Message => "Joined";
|
|
|
|
|
|
|
|
public override Color4 GetAppropriateColour(OsuColour colours) => colours.Yellow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|