From 152f3b1da3ee2e82216e16c35be3677e5ec7c039 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 26 Dec 2018 21:10:31 +0900 Subject: [PATCH] Add processing overlay to lounge screen --- .../Visual/TestCaseLoungeRoomsContainer.cs | 8 +-- .../Visual/TestCaseMatchSettingsOverlay.cs | 8 ++- osu.Game/Screens/Multi/IRoomManager.cs | 11 ++-- .../Screens/Multi/Lounge/LoungeSubScreen.cs | 51 ++++++++++--------- .../Match/Components/MatchSettingsOverlay.cs | 2 +- osu.Game/Screens/Multi/RoomManager.cs | 16 +++--- 6 files changed, 49 insertions(+), 47 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseLoungeRoomsContainer.cs b/osu.Game.Tests/Visual/TestCaseLoungeRoomsContainer.cs index 5ecd09e885..e9dfb0f041 100644 --- a/osu.Game.Tests/Visual/TestCaseLoungeRoomsContainer.cs +++ b/osu.Game.Tests/Visual/TestCaseLoungeRoomsContainer.cs @@ -71,14 +71,14 @@ namespace osu.Game.Tests.Visual private class TestRoomManager : IRoomManager { - public event Action RoomJoined; - public readonly BindableCollection Rooms = new BindableCollection(); IBindableCollection IRoomManager.Rooms => Rooms; - public void CreateRoom(Room room, Action onSuccess = null, Action onError = null) => Rooms.Add(room); + public void CreateRoom(Room room, Action onSuccess = null, Action onError = null) => Rooms.Add(room); - public void JoinRoom(Room room) => RoomJoined?.Invoke(room); + public void JoinRoom(Room room, Action onSuccess = null, Action onError = null) + { + } public void PartRoom() { diff --git a/osu.Game.Tests/Visual/TestCaseMatchSettingsOverlay.cs b/osu.Game.Tests/Visual/TestCaseMatchSettingsOverlay.cs index 086e6fbefe..afce8999b4 100644 --- a/osu.Game.Tests/Visual/TestCaseMatchSettingsOverlay.cs +++ b/osu.Game.Tests/Visual/TestCaseMatchSettingsOverlay.cs @@ -136,11 +136,9 @@ namespace osu.Game.Tests.Visual public Func CreateRequested; - public event Action RoomJoined; - public IBindableCollection Rooms { get; } = null; - public void CreateRoom(Room room, Action onSuccess = null, Action onError = null) + public void CreateRoom(Room room, Action onSuccess = null, Action onError = null) { if (CreateRequested == null) return; @@ -148,10 +146,10 @@ namespace osu.Game.Tests.Visual if (!CreateRequested.Invoke(room)) onError?.Invoke(FAILED_TEXT); else - onSuccess?.Invoke(); + onSuccess?.Invoke(room); } - public void JoinRoom(Room room) => throw new NotImplementedException(); + public void JoinRoom(Room room, Action onSuccess = null, Action onError = null) => throw new NotImplementedException(); public void PartRoom() => throw new NotImplementedException(); diff --git a/osu.Game/Screens/Multi/IRoomManager.cs b/osu.Game/Screens/Multi/IRoomManager.cs index 0e051802e3..a929e1a0f7 100644 --- a/osu.Game/Screens/Multi/IRoomManager.cs +++ b/osu.Game/Screens/Multi/IRoomManager.cs @@ -10,11 +10,6 @@ namespace osu.Game.Screens.Multi { public interface IRoomManager { - /// - /// Invoked when a room is joined. - /// - event Action RoomJoined; - /// /// All the active s. /// @@ -26,13 +21,15 @@ namespace osu.Game.Screens.Multi /// The to create. /// An action to be invoked if the creation succeeds. /// An action to be invoked if an error occurred. - void CreateRoom(Room room, Action onSuccess = null, Action onError = null); + void CreateRoom(Room room, Action onSuccess = null, Action onError = null); /// /// Joins a . /// /// The to join. must be populated. - void JoinRoom(Room room); + /// + /// + void JoinRoom(Room room, Action onSuccess = null, Action onError = null); /// /// Parts the currently-joined . diff --git a/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs b/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs index aef8265130..83f91536d3 100644 --- a/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs +++ b/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs @@ -7,6 +7,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Input.Events; using osu.Framework.Screens; +using osu.Game.Graphics.UserInterface; using osu.Game.Online.Multiplayer; using osu.Game.Overlays.SearchableList; using osu.Game.Screens.Multi.Lounge.Components; @@ -21,6 +22,7 @@ namespace osu.Game.Screens.Multi.Lounge private readonly Container content; private readonly RoomsContainer rooms; private readonly Action pushGameplayScreen; + private readonly ProcessingOverlay processingOverlay; [Resolved(CanBeNull = true)] private IRoomManager roomManager { get; set; } @@ -43,18 +45,26 @@ namespace osu.Game.Screens.Multi.Lounge RelativeSizeAxes = Axes.Both, Children = new Drawable[] { - new ScrollContainer + new Container { RelativeSizeAxes = Axes.Both, Width = 0.55f, - ScrollbarOverlapsContent = false, - Padding = new MarginPadding(10), - Child = new SearchContainer + Children = new Drawable[] { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Child = rooms = new RoomsContainer { JoinRequested = r => roomManager?.JoinRoom(r) } - }, + new ScrollContainer + { + RelativeSizeAxes = Axes.Both, + ScrollbarOverlapsContent = false, + Padding = new MarginPadding(10), + Child = new SearchContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Child = rooms = new RoomsContainer { JoinRequested = joinRequested } + }, + }, + processingOverlay = new ProcessingOverlay { Alpha = 0 } + } }, inspector = new RoomInspector { @@ -74,13 +84,6 @@ namespace osu.Game.Screens.Multi.Lounge Filter.Search.Exit += Exit; } - [BackgroundDependencyLoader] - private void load() - { - if (roomManager != null) - roomManager.RoomJoined += Push; - } - protected override void UpdateAfterChildren() { base.UpdateAfterChildren(); @@ -123,6 +126,16 @@ namespace osu.Game.Screens.Multi.Lounge roomManager?.Filter(Filter.CreateCriteria()); } + private void joinRequested(Room room) + { + processingOverlay.Show(); + roomManager?.JoinRoom(room, r => + { + Open(room); + processingOverlay.Hide(); + }, _ => processingOverlay.Hide()); + } + /// /// Push a room as a new subscreen. /// @@ -134,13 +147,5 @@ namespace osu.Game.Screens.Multi.Lounge Push(new MatchSubScreen(room, s => pushGameplayScreen?.Invoke(s))); } - - protected override void Dispose(bool isDisposing) - { - base.Dispose(isDisposing); - - if (roomManager != null) - roomManager.RoomJoined -= Push; - } } } diff --git a/osu.Game/Screens/Multi/Match/Components/MatchSettingsOverlay.cs b/osu.Game/Screens/Multi/Match/Components/MatchSettingsOverlay.cs index 916a21fb71..1210b9379f 100644 --- a/osu.Game/Screens/Multi/Match/Components/MatchSettingsOverlay.cs +++ b/osu.Game/Screens/Multi/Match/Components/MatchSettingsOverlay.cs @@ -301,7 +301,7 @@ namespace osu.Game.Screens.Multi.Match.Components private void hideError() => ErrorText.FadeOut(50); - private void onSuccess() => processingOverlay.Hide(); + private void onSuccess(Room room) => processingOverlay.Hide(); private void onError(string text) { diff --git a/osu.Game/Screens/Multi/RoomManager.cs b/osu.Game/Screens/Multi/RoomManager.cs index 642084547c..6ddfd0fab1 100644 --- a/osu.Game/Screens/Multi/RoomManager.cs +++ b/osu.Game/Screens/Multi/RoomManager.cs @@ -19,8 +19,6 @@ namespace osu.Game.Screens.Multi { public class RoomManager : PollingComponent, IRoomManager { - public event Action RoomJoined; - private readonly BindableCollection rooms = new BindableCollection(); public IBindableCollection Rooms => rooms; @@ -48,7 +46,7 @@ namespace osu.Game.Screens.Multi PartRoom(); } - public void CreateRoom(Room room, Action onSuccess = null, Action onError = null) + public void CreateRoom(Room room, Action onSuccess = null, Action onError = null) { room.Host.Value = api.LocalUser; @@ -58,7 +56,7 @@ namespace osu.Game.Screens.Multi update(room, result); addRoom(room); - onSuccess?.Invoke(); + onSuccess?.Invoke(room); }; req.Failure += exception => @@ -74,7 +72,7 @@ namespace osu.Game.Screens.Multi private JoinRoomRequest currentJoinRoomRequest; - public void JoinRoom(Room room) + public void JoinRoom(Room room, Action onSuccess = null, Action onError = null) { currentJoinRoomRequest?.Cancel(); currentJoinRoomRequest = null; @@ -83,10 +81,14 @@ namespace osu.Game.Screens.Multi currentJoinRoomRequest.Success += () => { currentRoom = room; - RoomJoined?.Invoke(room); + onSuccess?.Invoke(room); }; - currentJoinRoomRequest.Failure += exception => Logger.Log($"Failed to join room: {exception}", level: LogLevel.Important); + currentJoinRoomRequest.Failure += exception => + { + Logger.Log($"Failed to join room: {exception}", level: LogLevel.Important); + onError?.Invoke(exception.ToString()); + }; api.Queue(currentJoinRoomRequest); }