mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 08:52:55 +08:00
Create IRoomManager interface, add test for RoomsContainer
This commit is contained in:
parent
f79aa07d02
commit
6712a68797
86
osu.Game.Tests/Visual/TestCaseLoungeRoomsContainer.cs
Normal file
86
osu.Game.Tests/Visual/TestCaseLoungeRoomsContainer.cs
Normal file
@ -0,0 +1,86 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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
|
||||
{
|
||||
public class TestCaseLoungeRoomsContainer : OsuTestCase
|
||||
{
|
||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||
{
|
||||
typeof(RoomsContainer),
|
||||
typeof(DrawableRoom)
|
||||
};
|
||||
|
||||
[Cached(Type = typeof(IRoomManager))]
|
||||
private TestRoomManager roomManager = new TestRoomManager();
|
||||
|
||||
public TestCaseLoungeRoomsContainer()
|
||||
{
|
||||
RoomsContainer rooms;
|
||||
|
||||
Child = rooms = new RoomsContainer
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Width = 0.5f,
|
||||
JoinRequested = joinRequested
|
||||
};
|
||||
|
||||
int roomId = 0;
|
||||
|
||||
AddStep("Add room", () => roomManager.Rooms.Add(new Room
|
||||
{
|
||||
Name = { Value = $"Room {++roomId}"},
|
||||
Host = { Value = new User { Username = "Host" } },
|
||||
EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) }
|
||||
}));
|
||||
|
||||
AddStep("Remove selected", () =>
|
||||
{
|
||||
if (rooms.SelectedRoom.Value != null)
|
||||
roomManager.Rooms.Remove(rooms.SelectedRoom.Value);
|
||||
});
|
||||
}
|
||||
|
||||
private void joinRequested(Room room) => room.Status.Value = new JoinedRoomStatus();
|
||||
|
||||
private class TestRoomManager : IRoomManager
|
||||
{
|
||||
public event Action<Room> OpenRequested;
|
||||
|
||||
public readonly BindableCollection<Room> Rooms = new BindableCollection<Room>();
|
||||
IBindableCollection<Room> IRoomManager.Rooms => Rooms;
|
||||
|
||||
public void CreateRoom(Room room) => Rooms.Add(room);
|
||||
|
||||
public void JoinRoom(Room room) => OpenRequested?.Invoke(room);
|
||||
|
||||
public void PartRoom()
|
||||
{
|
||||
}
|
||||
|
||||
public void Filter(FilterCriteria criteria)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private class JoinedRoomStatus : RoomStatus
|
||||
{
|
||||
public override string Message => "Joined";
|
||||
|
||||
public override Color4 GetAppropriateColour(OsuColour colours) => colours.Yellow;
|
||||
}
|
||||
}
|
||||
}
|
46
osu.Game/Screens/Multi/IRoomManager.cs
Normal file
46
osu.Game/Screens/Multi/IRoomManager.cs
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Screens.Multi.Lounge.Components;
|
||||
|
||||
namespace osu.Game.Screens.Multi
|
||||
{
|
||||
public interface IRoomManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Invoked when this <see cref="IRoomManager"/> requests a <see cref="Room"/> to be opened.
|
||||
/// </summary>
|
||||
event Action<Room> OpenRequested;
|
||||
|
||||
/// <summary>
|
||||
/// All the active <see cref="Room"/>s.
|
||||
/// </summary>
|
||||
IBindableCollection<Room> Rooms { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Room"/>.
|
||||
/// </summary>
|
||||
/// <param name="room">The <see cref="Room"/> to create.</param>
|
||||
void CreateRoom(Room room);
|
||||
|
||||
/// <summary>
|
||||
/// Joins a <see cref="Room"/>.
|
||||
/// </summary>
|
||||
/// <param name="room">The <see cref="Room"/> to join. <see cref="Room.RoomID"/> must be populated.</param>
|
||||
void JoinRoom(Room room);
|
||||
|
||||
/// <summary>
|
||||
/// Parts the currently-joined <see cref="Room"/>.
|
||||
/// </summary>
|
||||
void PartRoom();
|
||||
|
||||
/// <summary>
|
||||
/// Queries for <see cref="Room"/>s matching a new <see cref="FilterCriteria"/>.
|
||||
/// </summary>
|
||||
/// <param name="criteria">The <see cref="FilterCriteria"/> to match.</param>
|
||||
void Filter(FilterCriteria criteria);
|
||||
}
|
||||
}
|
@ -27,7 +27,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
private readonly FillFlowContainer<DrawableRoom> roomFlow;
|
||||
|
||||
[Resolved]
|
||||
private RoomManager manager { get; set; }
|
||||
private IRoomManager roomManager { get; set; }
|
||||
|
||||
public RoomsContainer()
|
||||
{
|
||||
@ -46,7 +46,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
rooms.BindTo(manager.Rooms);
|
||||
rooms.BindTo(roomManager.Rooms);
|
||||
|
||||
rooms.ItemsAdded += addRooms;
|
||||
rooms.ItemsRemoved += removeRooms;
|
||||
|
@ -23,7 +23,7 @@ namespace osu.Game.Screens.Multi.Lounge
|
||||
private readonly Action<Screen> pushGameplayScreen;
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private RoomManager roomManager { get; set; }
|
||||
private IRoomManager roomManager { get; set; }
|
||||
|
||||
public override string Title => "Lounge";
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
private readonly Room room;
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private RoomManager manager { get; set; }
|
||||
private IRoomManager manager { get; set; }
|
||||
|
||||
public RoomSettingsOverlay(Room room)
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ namespace osu.Game.Screens.Multi.Match
|
||||
private OsuGame game { get; set; }
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private RoomManager manager { get; set; }
|
||||
private IRoomManager manager { get; set; }
|
||||
|
||||
public MatchScreen(Room room, Action<Screen> pushGameplayScreen)
|
||||
{
|
||||
|
@ -31,7 +31,7 @@ namespace osu.Game.Screens.Multi
|
||||
|
||||
private OsuScreen currentScreen;
|
||||
|
||||
[Cached]
|
||||
[Cached(Type = typeof(IRoomManager))]
|
||||
private RoomManager roomManager;
|
||||
|
||||
public Multiplayer()
|
||||
|
@ -17,12 +17,12 @@ using osu.Game.Screens.Multi.Lounge.Components;
|
||||
|
||||
namespace osu.Game.Screens.Multi
|
||||
{
|
||||
public class RoomManager : PollingComponent
|
||||
public class RoomManager : PollingComponent, IRoomManager
|
||||
{
|
||||
public event Action<Room> OpenRequested;
|
||||
|
||||
public IBindableCollection<Room> Rooms => rooms;
|
||||
private readonly BindableCollection<Room> rooms = new BindableCollection<Room>();
|
||||
public IBindableCollection<Room> Rooms => rooms;
|
||||
|
||||
private Room currentRoom;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user