mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 22:22:55 +08:00
Disable create room button after triggering join
This commit is contained in:
parent
47ab7c9fd6
commit
af66e45311
@ -0,0 +1,52 @@
|
||||
// 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 NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Screens.OnlinePlay;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneCreateMultiplayerMatchButton : MultiplayerTestScene
|
||||
{
|
||||
[Cached]
|
||||
private OngoingOperationTracker joiningRoomTracker = new OngoingOperationTracker();
|
||||
|
||||
private CreateMultiplayerMatchButton button;
|
||||
|
||||
public override void SetUpSteps()
|
||||
{
|
||||
base.SetUpSteps();
|
||||
AddStep("create button", () => Child = button = new CreateMultiplayerMatchButton
|
||||
{
|
||||
Width = 200,
|
||||
Height = 100,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestButtonEnableStateChanges()
|
||||
{
|
||||
assertButtonEnableState(true);
|
||||
|
||||
AddStep("begin joining room", () => joiningRoomTracker.BeginOperation());
|
||||
assertButtonEnableState(false);
|
||||
|
||||
AddStep("end joining room", () => joiningRoomTracker.EndOperation());
|
||||
assertButtonEnableState(true);
|
||||
|
||||
AddStep("disconnect client", () => Client.Disconnect());
|
||||
assertButtonEnableState(false);
|
||||
|
||||
AddStep("re-connect client", () => Client.Connect());
|
||||
assertButtonEnableState(true);
|
||||
}
|
||||
|
||||
private void assertButtonEnableState(bool enabled)
|
||||
=> AddAssert($"button {(enabled ? "enabled" : "disabled")}", () => button.Enabled.Value == enabled);
|
||||
}
|
||||
}
|
@ -26,6 +26,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
protected override UserActivity InitialActivity => new UserActivity.SearchingForLobby();
|
||||
|
||||
private readonly IBindable<bool> initialRoomsReceived = new Bindable<bool>();
|
||||
private readonly IBindable<bool> joiningRoom = new Bindable<bool>();
|
||||
|
||||
private FilterControl filter;
|
||||
private Container content;
|
||||
@ -37,7 +38,8 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
[Resolved]
|
||||
private MusicController music { get; set; }
|
||||
|
||||
private bool joiningRoom;
|
||||
[Resolved]
|
||||
private OngoingOperationTracker joiningRoomTracker { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
@ -98,7 +100,10 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
base.LoadComplete();
|
||||
|
||||
initialRoomsReceived.BindTo(RoomManager.InitialRoomsReceived);
|
||||
initialRoomsReceived.BindValueChanged(onInitialRoomsReceivedChanged, true);
|
||||
initialRoomsReceived.BindValueChanged(_ => updateLoadingLayer());
|
||||
|
||||
joiningRoom.BindTo(joiningRoomTracker.InProgress);
|
||||
joiningRoom.BindValueChanged(_ => updateLoadingLayer(), true);
|
||||
}
|
||||
|
||||
protected override void UpdateAfterChildren()
|
||||
@ -156,26 +161,21 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
|
||||
private void joinRequested(Room room)
|
||||
{
|
||||
joiningRoom = true;
|
||||
updateLoadingLayer();
|
||||
joiningRoomTracker.BeginOperation();
|
||||
|
||||
RoomManager?.JoinRoom(room, r =>
|
||||
{
|
||||
Open(room);
|
||||
joiningRoom = false;
|
||||
updateLoadingLayer();
|
||||
joiningRoomTracker.EndOperation();
|
||||
}, _ =>
|
||||
{
|
||||
joiningRoom = false;
|
||||
updateLoadingLayer();
|
||||
joiningRoomTracker.EndOperation();
|
||||
});
|
||||
}
|
||||
|
||||
private void onInitialRoomsReceivedChanged(ValueChangedEvent<bool> received) => updateLoadingLayer();
|
||||
|
||||
private void updateLoadingLayer()
|
||||
{
|
||||
if (joiningRoom || !initialRoomsReceived.Value)
|
||||
if (joiningRoom.Value || !initialRoomsReceived.Value)
|
||||
loadingLayer.Show();
|
||||
else
|
||||
loadingLayer.Hide();
|
||||
|
@ -10,14 +10,29 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
{
|
||||
public class CreateMultiplayerMatchButton : PurpleTriangleButton
|
||||
{
|
||||
private IBindable<bool> isConnected;
|
||||
private IBindable<bool> joiningRoom;
|
||||
|
||||
[Resolved]
|
||||
private StatefulMultiplayerClient multiplayerClient { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private OngoingOperationTracker joiningRoomTracker { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(StatefulMultiplayerClient multiplayerClient)
|
||||
private void load()
|
||||
{
|
||||
Triangles.TriangleScale = 1.5f;
|
||||
|
||||
Text = "Create room";
|
||||
|
||||
((IBindable<bool>)Enabled).BindTo(multiplayerClient.IsConnected);
|
||||
isConnected = multiplayerClient.IsConnected.GetBoundCopy();
|
||||
isConnected.BindValueChanged(_ => updateState());
|
||||
|
||||
joiningRoom = joiningRoomTracker.InProgress.GetBoundCopy();
|
||||
joiningRoom.BindValueChanged(_ => updateState(), true);
|
||||
}
|
||||
|
||||
private void updateState() => Enabled.Value = isConnected.Value && !joiningRoom.Value;
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,9 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
[Cached]
|
||||
private readonly Bindable<FilterCriteria> currentFilter = new Bindable<FilterCriteria>(new FilterCriteria());
|
||||
|
||||
[Cached]
|
||||
private readonly OngoingOperationTracker joiningRoomTracker = new OngoingOperationTracker();
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private MusicController music { get; set; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user