From 692f5c289d363b0d1fa227675b634f24fb55fbdf Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 26 Dec 2018 20:12:51 +0900 Subject: [PATCH 01/10] Move PartRoom calls --- osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs | 9 --------- osu.Game/Screens/Multi/RoomManager.cs | 6 ++++++ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs b/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs index c49cfc6b9c..7ec04087de 100644 --- a/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs +++ b/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs @@ -106,20 +106,11 @@ namespace osu.Game.Screens.Multi.Lounge protected override bool OnExiting(Screen next) { - roomManager?.PartRoom(); - Filter.Search.HoldFocus = false; // no base call; don't animate return false; } - protected override void OnResuming(Screen last) - { - roomManager?.PartRoom(); - - base.OnResuming(last); - } - protected override void OnSuspending(Screen next) { base.OnSuspending(next); diff --git a/osu.Game/Screens/Multi/RoomManager.cs b/osu.Game/Screens/Multi/RoomManager.cs index 68a11c0ba8..0af96c2e1b 100644 --- a/osu.Game/Screens/Multi/RoomManager.cs +++ b/osu.Game/Screens/Multi/RoomManager.cs @@ -42,6 +42,12 @@ namespace osu.Game.Screens.Multi TimeBetweenPolls = 5000; } + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + PartRoom(); + } + public void CreateRoom(Room room) { room.Host.Value = api.LocalUser; From 869081ce9cbe99c5c89c842009ac8de6b88252b9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 26 Dec 2018 20:21:30 +0900 Subject: [PATCH 02/10] Open -> Push --- osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs | 9 ++++++--- osu.Game/Screens/Multi/Multiplayer.cs | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs b/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs index 7ec04087de..aef8265130 100644 --- a/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs +++ b/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs @@ -78,7 +78,7 @@ namespace osu.Game.Screens.Multi.Lounge private void load() { if (roomManager != null) - roomManager.RoomJoined += Open; + roomManager.RoomJoined += Push; } protected override void UpdateAfterChildren() @@ -123,7 +123,10 @@ namespace osu.Game.Screens.Multi.Lounge roomManager?.Filter(Filter.CreateCriteria()); } - public void Open(Room room) + /// + /// Push a room as a new subscreen. + /// + public void Push(Room room) { // Handles the case where a room is clicked 3 times in quick succession if (!IsCurrentScreen) @@ -137,7 +140,7 @@ namespace osu.Game.Screens.Multi.Lounge base.Dispose(isDisposing); if (roomManager != null) - roomManager.RoomJoined -= Open; + roomManager.RoomJoined -= Push; } } } diff --git a/osu.Game/Screens/Multi/Multiplayer.cs b/osu.Game/Screens/Multi/Multiplayer.cs index b105024a24..40f66811f7 100644 --- a/osu.Game/Screens/Multi/Multiplayer.cs +++ b/osu.Game/Screens/Multi/Multiplayer.cs @@ -86,7 +86,7 @@ namespace osu.Game.Screens.Multi Right = 10, }, Text = "Create room", - Action = () => loungeSubScreen.Open(new Room + Action = () => loungeSubScreen.Push(new Room { Name = { Value = $"{api.LocalUser}'s awesome room" } }), From 7a431ed87f322320eacda6fc73023ea223701fe8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 26 Dec 2018 20:31:04 +0900 Subject: [PATCH 03/10] Update ParticipantInfo --- .../Lounge/Components/ParticipantInfo.cs | 47 ++++--------------- .../Multi/Lounge/Components/RoomInspector.cs | 2 +- 2 files changed, 11 insertions(+), 38 deletions(-) diff --git a/osu.Game/Screens/Multi/Lounge/Components/ParticipantInfo.cs b/osu.Game/Screens/Multi/Lounge/Components/ParticipantInfo.cs index b0ce800d4b..1bc6d5aec0 100644 --- a/osu.Game/Screens/Multi/Lounge/Components/ParticipantInfo.cs +++ b/osu.Game/Screens/Multi/Lounge/Components/ParticipantInfo.cs @@ -2,12 +2,10 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; -using System.Linq; using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; @@ -19,12 +17,12 @@ namespace osu.Game.Screens.Multi.Lounge.Components { public class ParticipantInfo : Container { - private readonly FillFlowContainer levelRangeContainer; + private readonly FillFlowContainer summaryContainer; public readonly IBindable Host = new Bindable(); public readonly IBindable> Participants = new Bindable>(); - public ParticipantInfo(string rankPrefix = null) + public ParticipantInfo() { RelativeSizeAxes = Axes.X; Height = 15f; @@ -49,7 +47,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components Width = 22f, RelativeSizeAxes = Axes.Y, }, - new Container //todo: team banners + /*new Container //todo: team banners { Width = 38f, RelativeSizeAxes = Axes.Y, @@ -63,7 +61,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components Colour = OsuColour.FromHex(@"ad387e"), }, }, - }, + },*/ hostText = new LinkFlowContainer { Anchor = Anchor.CentreLeft, @@ -72,7 +70,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components } }, }, - levelRangeContainer = new FillFlowContainer + summaryContainer = new FillFlowContainer { Anchor = Anchor.CentreRight, Origin = Anchor.CentreRight, @@ -82,34 +80,9 @@ namespace osu.Game.Screens.Multi.Lounge.Components { new OsuSpriteText { - Text = rankPrefix, + Text = "0 participants", TextSize = 14, - }, - new OsuSpriteText - { - Text = "#", - TextSize = 14, - }, - levelRangeLower = new OsuSpriteText - { - TextSize = 14, - Font = @"Exo2.0-Bold", - }, - new OsuSpriteText - { - Text = " - ", - TextSize = 14, - }, - new OsuSpriteText - { - Text = "#", - TextSize = 14, - }, - levelRangeHigher = new OsuSpriteText - { - TextSize = 14, - Font = @"Exo2.0-Bold", - }, + } }, }, }; @@ -123,18 +96,18 @@ namespace osu.Game.Screens.Multi.Lounge.Components flagContainer.Child = new DrawableFlag(v.Country) { RelativeSizeAxes = Axes.Both }; }); - Participants.BindValueChanged(v => + /*Participants.BindValueChanged(v => { var ranks = v.Select(u => u.Statistics.Ranks.Global); levelRangeLower.Text = ranks.Min().ToString(); levelRangeHigher.Text = ranks.Max().ToString(); - }); + });*/ } [BackgroundDependencyLoader] private void load(OsuColour colours) { - levelRangeContainer.Colour = colours.Gray9; + summaryContainer.Colour = colours.Gray9; } } } diff --git a/osu.Game/Screens/Multi/Lounge/Components/RoomInspector.cs b/osu.Game/Screens/Multi/Lounge/Components/RoomInspector.cs index 08beace4ca..be16d89255 100644 --- a/osu.Game/Screens/Multi/Lounge/Components/RoomInspector.cs +++ b/osu.Game/Screens/Multi/Lounge/Components/RoomInspector.cs @@ -142,7 +142,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components Padding = contentPadding, Children = new Drawable[] { - participantInfo = new ParticipantInfo(@"Rank Range "), + participantInfo = new ParticipantInfo(), }, }, }, From 9901b116000ecbc16c06498198edd229a1586d72 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 26 Dec 2018 17:44:36 +0900 Subject: [PATCH 04/10] Display room join errors as notifications --- osu.Game/Screens/Multi/RoomManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Multi/RoomManager.cs b/osu.Game/Screens/Multi/RoomManager.cs index 0af96c2e1b..1947909438 100644 --- a/osu.Game/Screens/Multi/RoomManager.cs +++ b/osu.Game/Screens/Multi/RoomManager.cs @@ -73,7 +73,7 @@ namespace osu.Game.Screens.Multi RoomJoined?.Invoke(room); }; - currentJoinRoomRequest.Failure += exception => Logger.Log($"Failed to join room: {exception}"); + currentJoinRoomRequest.Failure += exception => Logger.Log($"Failed to join room: {exception}", level: LogLevel.Important); api.Queue(currentJoinRoomRequest); } From 940d4a16bbbdedfc616f0a33e45e4e3d792d2100 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 26 Dec 2018 18:38:58 +0900 Subject: [PATCH 05/10] Add error message when creation fails --- .../Visual/TestCaseLoungeRoomsContainer.cs | 2 +- .../Visual/TestCaseMatchSettingsOverlay.cs | 49 +++++++++++++++++-- .../Online/API/Requests/CreateRoomRequest.cs | 3 +- .../API/Requests/Responses/APICreatedRoom.cs | 14 ++++++ osu.Game/Screens/Multi/IRoomManager.cs | 3 +- .../Match/Components/MatchSettingsOverlay.cs | 44 ++++++++++++++--- osu.Game/Screens/Multi/RoomManager.cs | 10 +++- 7 files changed, 109 insertions(+), 16 deletions(-) create mode 100644 osu.Game/Online/API/Requests/Responses/APICreatedRoom.cs diff --git a/osu.Game.Tests/Visual/TestCaseLoungeRoomsContainer.cs b/osu.Game.Tests/Visual/TestCaseLoungeRoomsContainer.cs index dd7e8f7fac..e42781849d 100644 --- a/osu.Game.Tests/Visual/TestCaseLoungeRoomsContainer.cs +++ b/osu.Game.Tests/Visual/TestCaseLoungeRoomsContainer.cs @@ -76,7 +76,7 @@ namespace osu.Game.Tests.Visual public readonly BindableCollection Rooms = new BindableCollection(); IBindableCollection IRoomManager.Rooms => Rooms; - public void CreateRoom(Room room) => Rooms.Add(room); + public void CreateRoom(Room room, Action onError = null) => Rooms.Add(room); public void JoinRoom(Room room) => RoomJoined?.Invoke(room); diff --git a/osu.Game.Tests/Visual/TestCaseMatchSettingsOverlay.cs b/osu.Game.Tests/Visual/TestCaseMatchSettingsOverlay.cs index 3c41fd6920..a31b91cc2a 100644 --- a/osu.Game.Tests/Visual/TestCaseMatchSettingsOverlay.cs +++ b/osu.Game.Tests/Visual/TestCaseMatchSettingsOverlay.cs @@ -9,6 +9,7 @@ using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; +using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; using osu.Game.Online.Multiplayer; using osu.Game.Screens.Multi; @@ -77,7 +78,11 @@ namespace osu.Game.Tests.Visual settings.NameField.Current.Value = expected_name; settings.DurationField.Current.Value = expectedDuration; - roomManager.CreateRequested = r => createdRoom = r; + roomManager.CreateRequested = r => + { + createdRoom = r; + return true; + }; }); AddStep("create room", () => settings.ApplyButton.Action.Invoke()); @@ -85,13 +90,40 @@ namespace osu.Game.Tests.Visual AddAssert("has correct duration", () => createdRoom.Duration.Value == expectedDuration); } - private class TestRoomSettings : MatchSettingsOverlay + [Test] + public void TestCreationFailureDisplaysError() + { + bool fail; + + AddStep("setup", () => + { + fail = true; + roomManager.CreateRequested = _ => !fail; + }); + AddAssert("error not displayed", () => !settings.ErrorText.IsPresent); + + AddStep("create room", () => settings.ApplyButton.Action.Invoke()); + AddAssert("error displayed", () => settings.ErrorText.IsPresent); + AddAssert("error has correct text", () => settings.ErrorText.Text == TestRoomManager.FAILED_TEXT); + + AddStep("create room no fail", () => + { + fail = false; + settings.ApplyButton.Action.Invoke(); + }); + + AddUntilStep(() => !settings.ErrorText.IsPresent, "error not displayed"); + } + + private class TestRoomSettings : RoomSettingsOverlay { public new TriangleButton ApplyButton => base.ApplyButton; public new OsuTextBox NameField => base.NameField; public new OsuDropdown DurationField => base.DurationField; + public new OsuSpriteText ErrorText => base.ErrorText; + public TestRoomSettings(Room room) : base(room) { @@ -100,13 +132,22 @@ namespace osu.Game.Tests.Visual private class TestRoomManager : IRoomManager { - public Action CreateRequested; + public const string FAILED_TEXT = "failed"; + + public Func CreateRequested; public event Action RoomJoined; public IBindableCollection Rooms { get; } = null; - public void CreateRoom(Room room) => CreateRequested?.Invoke(room); + public void CreateRoom(Room room, Action onError = null) + { + if (CreateRequested == null) + return; + + if (!CreateRequested.Invoke(room)) + onError?.Invoke(FAILED_TEXT); + } public void JoinRoom(Room room) => throw new NotImplementedException(); diff --git a/osu.Game/Online/API/Requests/CreateRoomRequest.cs b/osu.Game/Online/API/Requests/CreateRoomRequest.cs index 7ce289b65a..fc401be5f1 100644 --- a/osu.Game/Online/API/Requests/CreateRoomRequest.cs +++ b/osu.Game/Online/API/Requests/CreateRoomRequest.cs @@ -4,11 +4,12 @@ using System.Net.Http; using Newtonsoft.Json; using osu.Framework.IO.Network; +using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Multiplayer; namespace osu.Game.Online.API.Requests { - public class CreateRoomRequest : APIRequest + public class CreateRoomRequest : APIRequest { private readonly Room room; diff --git a/osu.Game/Online/API/Requests/Responses/APICreatedRoom.cs b/osu.Game/Online/API/Requests/Responses/APICreatedRoom.cs new file mode 100644 index 0000000000..ca0daa04b6 --- /dev/null +++ b/osu.Game/Online/API/Requests/Responses/APICreatedRoom.cs @@ -0,0 +1,14 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using Newtonsoft.Json; +using osu.Game.Online.Multiplayer; + +namespace osu.Game.Online.API.Requests.Responses +{ + public class APICreatedRoom : Room + { + [JsonProperty("error")] + public string Error { get; set; } + } +} diff --git a/osu.Game/Screens/Multi/IRoomManager.cs b/osu.Game/Screens/Multi/IRoomManager.cs index b94df93581..bb996f0b5c 100644 --- a/osu.Game/Screens/Multi/IRoomManager.cs +++ b/osu.Game/Screens/Multi/IRoomManager.cs @@ -24,7 +24,8 @@ namespace osu.Game.Screens.Multi /// Creates a new . /// /// The to create. - void CreateRoom(Room room); + /// An action to be invoked if an error occurred. + void CreateRoom(Room room, Action onError = null); /// /// Joins a . diff --git a/osu.Game/Screens/Multi/Match/Components/MatchSettingsOverlay.cs b/osu.Game/Screens/Multi/Match/Components/MatchSettingsOverlay.cs index 6de2bed938..d6228b106b 100644 --- a/osu.Game/Screens/Multi/Match/Components/MatchSettingsOverlay.cs +++ b/osu.Game/Screens/Multi/Match/Components/MatchSettingsOverlay.cs @@ -37,6 +37,8 @@ namespace osu.Game.Screens.Multi.Match.Components protected readonly TriangleButton ApplyButton; protected readonly OsuPasswordTextBox PasswordField; + protected readonly OsuSpriteText ErrorText; + private readonly Room room; [Resolved(CanBeNull = true)] @@ -200,14 +202,31 @@ namespace osu.Game.Screens.Multi.Match.Components RelativeSizeAxes = Axes.Both, Colour = OsuColour.FromHex(@"28242d").Darken(0.5f).Opacity(1f), }, - ApplyButton = new CreateRoomButton + new FillFlowContainer { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 20), Margin = new MarginPadding { Vertical = 20 }, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = new Vector2(230, 55), - Action = apply, - }, + Children = new Drawable[] + { + ApplyButton = new CreateRoomButton + { + Anchor = Anchor.BottomCentre, + Origin = Anchor.BottomCentre, + Size = new Vector2(230, 55), + Action = apply, + }, + ErrorText = new OsuSpriteText + { + Anchor = Anchor.BottomCentre, + Origin = Anchor.BottomCentre, + Alpha = 0, + Depth = 1 + } + } + } } } } @@ -229,6 +248,7 @@ namespace osu.Game.Screens.Multi.Match.Components private void load(OsuColour colours) { typeLabel.Colour = colours.Yellow; + ErrorText.Colour = colours.RedDark; MaxParticipantsField.ReadOnly = true; PasswordField.ReadOnly = true; @@ -258,6 +278,8 @@ namespace osu.Game.Screens.Multi.Match.Components private void apply() { + hideError(); + bindings.Name.Value = NameField.Text; bindings.Availability.Value = AvailabilityPicker.Current.Value; bindings.Type.Value = TypePicker.Current.Value; @@ -269,7 +291,15 @@ namespace osu.Game.Screens.Multi.Match.Components bindings.Duration.Value = DurationField.Current.Value; - manager?.CreateRoom(room); + manager?.CreateRoom(room, showError); + } + + private void hideError() => ErrorText.FadeOut(50); + + private void showError(string text) + { + ErrorText.Text = text; + ErrorText.FadeIn(50); } private class SettingsTextBox : OsuTextBox diff --git a/osu.Game/Screens/Multi/RoomManager.cs b/osu.Game/Screens/Multi/RoomManager.cs index 1947909438..08458bf4e9 100644 --- a/osu.Game/Screens/Multi/RoomManager.cs +++ b/osu.Game/Screens/Multi/RoomManager.cs @@ -48,13 +48,19 @@ namespace osu.Game.Screens.Multi PartRoom(); } - public void CreateRoom(Room room) + public void CreateRoom(Room room, Action onError = null) { room.Host.Value = api.LocalUser; var req = new CreateRoomRequest(room); req.Success += result => addRoom(room, result); - req.Failure += exception => Logger.Log($"Failed to create room: {exception}"); + req.Failure += exception => + { + if (req.Result != null) + onError?.Invoke(req.Result.Error); + else + Logger.Log($"Failed to create the room: {exception}", level: LogLevel.Important); + }; api.Queue(req); } From 5af29f838480b35ba4c9a5c3dd8af7aadcb55871 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 26 Dec 2018 20:32:01 +0900 Subject: [PATCH 06/10] Reduce code duplication --- osu.Game/Screens/Multi/RoomManager.cs | 45 ++++++++++++++++----------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/osu.Game/Screens/Multi/RoomManager.cs b/osu.Game/Screens/Multi/RoomManager.cs index 08458bf4e9..d91c05f79f 100644 --- a/osu.Game/Screens/Multi/RoomManager.cs +++ b/osu.Game/Screens/Multi/RoomManager.cs @@ -53,7 +53,12 @@ namespace osu.Game.Screens.Multi room.Host.Value = api.LocalUser; var req = new CreateRoomRequest(room); - req.Success += result => addRoom(room, result); + req.Success += result => + { + update(room, result); + addRoom(room); + }; + req.Failure += exception => { if (req.Result != null) @@ -120,13 +125,8 @@ namespace osu.Game.Screens.Multi // Add new matches, or update existing foreach (var r in result) { - processPlaylist(r); - - var existing = rooms.FirstOrDefault(e => e.RoomID.Value == r.RoomID.Value); - if (existing == null) - rooms.Add(r); - else - existing.CopyFrom(r); + update(r, r); + addRoom(r); } tcs.SetResult(true); @@ -139,22 +139,29 @@ namespace osu.Game.Screens.Multi return tcs.Task; } - private void addRoom(Room local, Room remote) + /// + /// Updates a local with a remote copy. + /// + /// The local to update. + /// The remote to update with. + private void update(Room local, Room remote) { - processPlaylist(remote); - + foreach (var pi in remote.Playlist) + pi.MapObjects(beatmaps, rulesets); local.CopyFrom(remote); - - var existing = rooms.FirstOrDefault(e => e.RoomID.Value == local.RoomID.Value); - if (existing != null) - rooms.Remove(existing); - rooms.Add(local); } - private void processPlaylist(Room room) + /// + /// Adds a to the list of available rooms. + /// + /// The to add.< + private void addRoom(Room room) { - foreach (var pi in room.Playlist) - pi.MapObjects(beatmaps, rulesets); + var existing = rooms.FirstOrDefault(e => e.RoomID.Value == room.RoomID.Value); + if (existing == null) + rooms.Add(room); + else + existing.CopyFrom(room); } } } From 2e5cd8b4e3c845b46a9fdb321b1458da36137f09 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 26 Dec 2018 20:33:49 +0900 Subject: [PATCH 07/10] Fix post-rebase errors --- osu.Game.Tests/Visual/TestCaseMatchSettingsOverlay.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/TestCaseMatchSettingsOverlay.cs b/osu.Game.Tests/Visual/TestCaseMatchSettingsOverlay.cs index a31b91cc2a..f93d1b3069 100644 --- a/osu.Game.Tests/Visual/TestCaseMatchSettingsOverlay.cs +++ b/osu.Game.Tests/Visual/TestCaseMatchSettingsOverlay.cs @@ -115,7 +115,7 @@ namespace osu.Game.Tests.Visual AddUntilStep(() => !settings.ErrorText.IsPresent, "error not displayed"); } - private class TestRoomSettings : RoomSettingsOverlay + private class TestRoomSettings : MatchSettingsOverlay { public new TriangleButton ApplyButton => base.ApplyButton; From 0c384417f152d52b62f4aff2119a008fa2203f8b Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 26 Dec 2018 20:45:56 +0900 Subject: [PATCH 08/10] Add processing overlay to room creation process --- .../Visual/TestCaseLoungeRoomsContainer.cs | 2 +- .../Visual/TestCaseMatchSettingsOverlay.cs | 4 +++- osu.Game/Screens/Multi/IRoomManager.cs | 3 ++- .../Match/Components/MatchSettingsOverlay.cs | 17 +++++++++++++---- osu.Game/Screens/Multi/RoomManager.cs | 4 +++- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseLoungeRoomsContainer.cs b/osu.Game.Tests/Visual/TestCaseLoungeRoomsContainer.cs index e42781849d..5ecd09e885 100644 --- a/osu.Game.Tests/Visual/TestCaseLoungeRoomsContainer.cs +++ b/osu.Game.Tests/Visual/TestCaseLoungeRoomsContainer.cs @@ -76,7 +76,7 @@ namespace osu.Game.Tests.Visual public readonly BindableCollection Rooms = new BindableCollection(); IBindableCollection IRoomManager.Rooms => Rooms; - public void CreateRoom(Room room, 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); diff --git a/osu.Game.Tests/Visual/TestCaseMatchSettingsOverlay.cs b/osu.Game.Tests/Visual/TestCaseMatchSettingsOverlay.cs index f93d1b3069..086e6fbefe 100644 --- a/osu.Game.Tests/Visual/TestCaseMatchSettingsOverlay.cs +++ b/osu.Game.Tests/Visual/TestCaseMatchSettingsOverlay.cs @@ -140,13 +140,15 @@ namespace osu.Game.Tests.Visual public IBindableCollection Rooms { get; } = null; - public void CreateRoom(Room room, Action onError = null) + public void CreateRoom(Room room, Action onSuccess = null, Action onError = null) { if (CreateRequested == null) return; if (!CreateRequested.Invoke(room)) onError?.Invoke(FAILED_TEXT); + else + onSuccess?.Invoke(); } public void JoinRoom(Room room) => throw new NotImplementedException(); diff --git a/osu.Game/Screens/Multi/IRoomManager.cs b/osu.Game/Screens/Multi/IRoomManager.cs index bb996f0b5c..0e051802e3 100644 --- a/osu.Game/Screens/Multi/IRoomManager.cs +++ b/osu.Game/Screens/Multi/IRoomManager.cs @@ -24,8 +24,9 @@ namespace osu.Game.Screens.Multi /// Creates a new . /// /// 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 onError = null); + void CreateRoom(Room room, Action onSuccess = null, Action onError = null); /// /// Joins a . diff --git a/osu.Game/Screens/Multi/Match/Components/MatchSettingsOverlay.cs b/osu.Game/Screens/Multi/Match/Components/MatchSettingsOverlay.cs index d6228b106b..916a21fb71 100644 --- a/osu.Game/Screens/Multi/Match/Components/MatchSettingsOverlay.cs +++ b/osu.Game/Screens/Multi/Match/Components/MatchSettingsOverlay.cs @@ -39,6 +39,8 @@ namespace osu.Game.Screens.Multi.Match.Components protected readonly OsuSpriteText ErrorText; + private readonly ProcessingOverlay processingOverlay; + private readonly Room room; [Resolved(CanBeNull = true)] @@ -231,7 +233,8 @@ namespace osu.Game.Screens.Multi.Match.Components } } } - } + }, + processingOverlay = new ProcessingOverlay { Alpha = 0 } }, }; @@ -264,7 +267,7 @@ namespace osu.Game.Screens.Multi.Match.Components ApplyButton.Enabled.Value = hasValidSettings; } - private bool hasValidSettings => NameField.Text.Length > 0 && bindings.Playlist.Count > 0; + private bool hasValidSettings => bindings.Room.RoomID.Value == null && NameField.Text.Length > 0 && bindings.Playlist.Count > 0; protected override void PopIn() { @@ -291,15 +294,21 @@ namespace osu.Game.Screens.Multi.Match.Components bindings.Duration.Value = DurationField.Current.Value; - manager?.CreateRoom(room, showError); + manager?.CreateRoom(room, onSuccess, onError); + + processingOverlay.Show(); } private void hideError() => ErrorText.FadeOut(50); - private void showError(string text) + private void onSuccess() => processingOverlay.Hide(); + + private void onError(string text) { ErrorText.Text = text; ErrorText.FadeIn(50); + + processingOverlay.Hide(); } private class SettingsTextBox : OsuTextBox diff --git a/osu.Game/Screens/Multi/RoomManager.cs b/osu.Game/Screens/Multi/RoomManager.cs index d91c05f79f..642084547c 100644 --- a/osu.Game/Screens/Multi/RoomManager.cs +++ b/osu.Game/Screens/Multi/RoomManager.cs @@ -48,7 +48,7 @@ namespace osu.Game.Screens.Multi PartRoom(); } - public void CreateRoom(Room room, Action onError = null) + public void CreateRoom(Room room, Action onSuccess = null, Action onError = null) { room.Host.Value = api.LocalUser; @@ -57,6 +57,8 @@ namespace osu.Game.Screens.Multi { update(room, result); addRoom(room); + + onSuccess?.Invoke(); }; req.Failure += exception => From 152f3b1da3ee2e82216e16c35be3677e5ec7c039 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 26 Dec 2018 21:10:31 +0900 Subject: [PATCH 09/10] 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); } From 2d19436456a1fa177fd07339c839a3fac5451b9d Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 26 Dec 2018 21:21:26 +0900 Subject: [PATCH 10/10] Open -> Push --- osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs b/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs index 83f91536d3..d9633218eb 100644 --- a/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs +++ b/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs @@ -131,7 +131,7 @@ namespace osu.Game.Screens.Multi.Lounge processingOverlay.Show(); roomManager?.JoinRoom(room, r => { - Open(room); + Push(room); processingOverlay.Hide(); }, _ => processingOverlay.Hide()); }