mirror of
https://github.com/ppy/osu.git
synced 2024-09-22 03:27:24 +08:00
Adjust tracker usages to match new API
This commit is contained in:
parent
f59ba799d3
commit
db52255bbe
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -12,7 +13,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
public class TestSceneCreateMultiplayerMatchButton : MultiplayerTestScene
|
public class TestSceneCreateMultiplayerMatchButton : MultiplayerTestScene
|
||||||
{
|
{
|
||||||
[Cached]
|
[Cached]
|
||||||
private OngoingOperationTracker joiningRoomTracker = new OngoingOperationTracker();
|
private OngoingOperationTracker ongoingOperationTracker = new OngoingOperationTracker();
|
||||||
|
|
||||||
private CreateMultiplayerMatchButton button;
|
private CreateMultiplayerMatchButton button;
|
||||||
|
|
||||||
@ -31,12 +32,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestButtonEnableStateChanges()
|
public void TestButtonEnableStateChanges()
|
||||||
{
|
{
|
||||||
|
IDisposable joiningRoomOperation = null;
|
||||||
|
|
||||||
assertButtonEnableState(true);
|
assertButtonEnableState(true);
|
||||||
|
|
||||||
AddStep("begin joining room", () => joiningRoomTracker.BeginOperation());
|
AddStep("begin joining room", () => joiningRoomOperation = ongoingOperationTracker.BeginOperation());
|
||||||
assertButtonEnableState(false);
|
assertButtonEnableState(false);
|
||||||
|
|
||||||
AddStep("end joining room", () => joiningRoomTracker.EndOperation());
|
AddStep("end joining room", () => joiningRoomOperation.Dispose());
|
||||||
assertButtonEnableState(true);
|
assertButtonEnableState(true);
|
||||||
|
|
||||||
AddStep("disconnect client", () => Client.Disconnect());
|
AddStep("disconnect client", () => Client.Disconnect());
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -31,7 +32,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
private RulesetStore rulesets;
|
private RulesetStore rulesets;
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
private OngoingOperationTracker gameplayStartTracker = new OngoingOperationTracker();
|
private OngoingOperationTracker ongoingOperationTracker = new OngoingOperationTracker();
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(GameHost host, AudioManager audio)
|
private void load(GameHost host, AudioManager audio)
|
||||||
@ -167,11 +168,15 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
private void verifyGameplayStartFlow()
|
private void verifyGameplayStartFlow()
|
||||||
{
|
{
|
||||||
|
IDisposable gameplayStartOperation = null;
|
||||||
|
|
||||||
|
AddStep("hook up tracker", () => button.OnReady = () => gameplayStartOperation = ongoingOperationTracker.BeginOperation());
|
||||||
|
|
||||||
addClickButtonStep();
|
addClickButtonStep();
|
||||||
AddAssert("user waiting for load", () => Client.Room?.Users[0].State == MultiplayerUserState.WaitingForLoad);
|
AddAssert("user waiting for load", () => Client.Room?.Users[0].State == MultiplayerUserState.WaitingForLoad);
|
||||||
AddAssert("ready button disabled", () => !button.ChildrenOfType<OsuButton>().Single().Enabled.Value);
|
AddAssert("ready button disabled", () => !button.ChildrenOfType<OsuButton>().Single().Enabled.Value);
|
||||||
|
|
||||||
AddStep("transitioned to gameplay", () => gameplayStartTracker.EndOperation());
|
AddStep("transitioned to gameplay", () => gameplayStartOperation.Dispose());
|
||||||
AddAssert("ready button enabled", () => button.ChildrenOfType<OsuButton>().Single().Enabled.Value);
|
AddAssert("ready button enabled", () => button.ChildrenOfType<OsuButton>().Single().Enabled.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -39,7 +42,10 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
|||||||
private MusicController music { get; set; }
|
private MusicController music { get; set; }
|
||||||
|
|
||||||
[Resolved(CanBeNull = true)]
|
[Resolved(CanBeNull = true)]
|
||||||
private OngoingOperationTracker joiningRoomTracker { get; set; }
|
private OngoingOperationTracker ongoingOperationTracker { get; set; }
|
||||||
|
|
||||||
|
[CanBeNull]
|
||||||
|
private IDisposable joiningRoomOperation { get; set; }
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
@ -102,9 +108,9 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
|||||||
initialRoomsReceived.BindTo(RoomManager.InitialRoomsReceived);
|
initialRoomsReceived.BindTo(RoomManager.InitialRoomsReceived);
|
||||||
initialRoomsReceived.BindValueChanged(_ => updateLoadingLayer());
|
initialRoomsReceived.BindValueChanged(_ => updateLoadingLayer());
|
||||||
|
|
||||||
if (joiningRoomTracker != null)
|
if (ongoingOperationTracker != null)
|
||||||
{
|
{
|
||||||
joiningRoom.BindTo(joiningRoomTracker.InProgress);
|
joiningRoom.BindTo(ongoingOperationTracker.InProgress);
|
||||||
joiningRoom.BindValueChanged(_ => updateLoadingLayer(), true);
|
joiningRoom.BindValueChanged(_ => updateLoadingLayer(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,15 +170,18 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
|||||||
|
|
||||||
private void joinRequested(Room room)
|
private void joinRequested(Room room)
|
||||||
{
|
{
|
||||||
joiningRoomTracker?.BeginOperation();
|
Debug.Assert(joiningRoomOperation == null);
|
||||||
|
joiningRoomOperation = ongoingOperationTracker?.BeginOperation();
|
||||||
|
|
||||||
RoomManager?.JoinRoom(room, r =>
|
RoomManager?.JoinRoom(room, r =>
|
||||||
{
|
{
|
||||||
Open(room);
|
Open(room);
|
||||||
joiningRoomTracker?.EndOperation();
|
joiningRoomOperation?.Dispose();
|
||||||
|
joiningRoomOperation = null;
|
||||||
}, _ =>
|
}, _ =>
|
||||||
{
|
{
|
||||||
joiningRoomTracker?.EndOperation();
|
joiningRoomOperation?.Dispose();
|
||||||
|
joiningRoomOperation = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,13 +11,13 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
public class CreateMultiplayerMatchButton : PurpleTriangleButton
|
public class CreateMultiplayerMatchButton : PurpleTriangleButton
|
||||||
{
|
{
|
||||||
private IBindable<bool> isConnected;
|
private IBindable<bool> isConnected;
|
||||||
private IBindable<bool> joiningRoom;
|
private IBindable<bool> operationInProgress;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private StatefulMultiplayerClient multiplayerClient { get; set; }
|
private StatefulMultiplayerClient multiplayerClient { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OngoingOperationTracker joiningRoomTracker { get; set; }
|
private OngoingOperationTracker ongoingOperationTracker { get; set; }
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
@ -29,10 +29,10 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
isConnected = multiplayerClient.IsConnected.GetBoundCopy();
|
isConnected = multiplayerClient.IsConnected.GetBoundCopy();
|
||||||
isConnected.BindValueChanged(_ => updateState());
|
isConnected.BindValueChanged(_ => updateState());
|
||||||
|
|
||||||
joiningRoom = joiningRoomTracker.InProgress.GetBoundCopy();
|
operationInProgress = ongoingOperationTracker.InProgress.GetBoundCopy();
|
||||||
joiningRoom.BindValueChanged(_ => updateState(), true);
|
operationInProgress.BindValueChanged(_ => updateState(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateState() => Enabled.Value = isConnected.Value && !joiningRoom.Value;
|
private void updateState() => Enabled.Value = isConnected.Value && !operationInProgress.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
@ -68,7 +70,13 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private Bindable<RulesetInfo> ruleset { get; set; }
|
private Bindable<RulesetInfo> ruleset { get; set; }
|
||||||
|
|
||||||
private readonly OngoingOperationTracker applyingSettingsTracker = new OngoingOperationTracker();
|
[Resolved]
|
||||||
|
private OngoingOperationTracker ongoingOperationTracker { get; set; }
|
||||||
|
|
||||||
|
private readonly IBindable<bool> operationInProgress = new BindableBool();
|
||||||
|
|
||||||
|
[CanBeNull]
|
||||||
|
private IDisposable applyingSettingsOperation;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours)
|
||||||
@ -277,7 +285,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
MaxParticipants.BindValueChanged(count => MaxParticipantsField.Text = count.NewValue?.ToString(), true);
|
MaxParticipants.BindValueChanged(count => MaxParticipantsField.Text = count.NewValue?.ToString(), true);
|
||||||
RoomID.BindValueChanged(roomId => initialBeatmapControl.Alpha = roomId.NewValue == null ? 1 : 0, true);
|
RoomID.BindValueChanged(roomId => initialBeatmapControl.Alpha = roomId.NewValue == null ? 1 : 0, true);
|
||||||
|
|
||||||
applyingSettingsTracker.InProgress.BindValueChanged(v =>
|
operationInProgress.BindTo(ongoingOperationTracker.InProgress);
|
||||||
|
operationInProgress.BindValueChanged(v =>
|
||||||
{
|
{
|
||||||
if (v.NewValue)
|
if (v.NewValue)
|
||||||
loadingLayer.Show();
|
loadingLayer.Show();
|
||||||
@ -290,7 +299,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
ApplyButton.Enabled.Value = Playlist.Count > 0 && NameField.Text.Length > 0 && !applyingSettingsTracker.InProgress.Value;
|
ApplyButton.Enabled.Value = Playlist.Count > 0 && NameField.Text.Length > 0 && !operationInProgress.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void apply()
|
private void apply()
|
||||||
@ -299,7 +308,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
hideError();
|
hideError();
|
||||||
applyingSettingsTracker.BeginOperation();
|
|
||||||
|
Debug.Assert(applyingSettingsOperation == null);
|
||||||
|
applyingSettingsOperation = ongoingOperationTracker.BeginOperation();
|
||||||
|
|
||||||
// If the client is already in a room, update via the client.
|
// If the client is already in a room, update via the client.
|
||||||
// Otherwise, update the room directly in preparation for it to be submitted to the API on match creation.
|
// Otherwise, update the room directly in preparation for it to be submitted to the API on match creation.
|
||||||
@ -332,15 +343,23 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
|
|
||||||
private void onSuccess(Room room)
|
private void onSuccess(Room room)
|
||||||
{
|
{
|
||||||
applyingSettingsTracker.EndOperation();
|
Debug.Assert(applyingSettingsOperation != null);
|
||||||
|
|
||||||
SettingsApplied?.Invoke();
|
SettingsApplied?.Invoke();
|
||||||
|
|
||||||
|
applyingSettingsOperation.Dispose();
|
||||||
|
applyingSettingsOperation = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onError(string text)
|
private void onError(string text)
|
||||||
{
|
{
|
||||||
|
Debug.Assert(applyingSettingsOperation != null);
|
||||||
|
|
||||||
ErrorText.Text = text;
|
ErrorText.Text = text;
|
||||||
ErrorText.FadeIn(50);
|
ErrorText.FadeIn(50);
|
||||||
applyingSettingsTracker.EndOperation();
|
|
||||||
|
applyingSettingsOperation.Dispose();
|
||||||
|
applyingSettingsOperation = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,14 +35,14 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
private OsuColour colours { get; set; }
|
private OsuColour colours { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OngoingOperationTracker gameplayStartTracker { get; set; }
|
private OngoingOperationTracker ongoingOperationTracker { get; set; }
|
||||||
|
|
||||||
private SampleChannel sampleReadyCount;
|
private SampleChannel sampleReadyCount;
|
||||||
|
|
||||||
private readonly ButtonWithTrianglesExposed button;
|
private readonly ButtonWithTrianglesExposed button;
|
||||||
|
|
||||||
private int countReady;
|
private int countReady;
|
||||||
private IBindable<bool> gameplayStartInProgress;
|
private IBindable<bool> operationInProgress;
|
||||||
|
|
||||||
public MultiplayerReadyButton()
|
public MultiplayerReadyButton()
|
||||||
{
|
{
|
||||||
@ -59,8 +59,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
{
|
{
|
||||||
sampleReadyCount = audio.Samples.Get(@"SongSelect/select-difficulty");
|
sampleReadyCount = audio.Samples.Get(@"SongSelect/select-difficulty");
|
||||||
|
|
||||||
gameplayStartInProgress = gameplayStartTracker.InProgress.GetBoundCopy();
|
operationInProgress = ongoingOperationTracker.InProgress.GetBoundCopy();
|
||||||
gameplayStartInProgress.BindValueChanged(_ => updateState());
|
operationInProgress.BindValueChanged(_ => updateState());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnRoomUpdated()
|
protected override void OnRoomUpdated()
|
||||||
@ -105,7 +105,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
button.Enabled.Value = Client.Room?.State == MultiplayerRoomState.Open && !gameplayStartInProgress.Value;
|
button.Enabled.Value = Client.Room?.State == MultiplayerRoomState.Open && !operationInProgress.Value;
|
||||||
|
|
||||||
if (newCountReady != countReady)
|
if (newCountReady != countReady)
|
||||||
{
|
{
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -32,13 +34,16 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private StatefulMultiplayerClient client { get; set; }
|
private StatefulMultiplayerClient client { get; set; }
|
||||||
|
|
||||||
[Cached]
|
[Resolved]
|
||||||
private OngoingOperationTracker gameplayStartTracker = new OngoingOperationTracker();
|
private OngoingOperationTracker ongoingOperationTracker { get; set; }
|
||||||
|
|
||||||
private MultiplayerMatchSettingsOverlay settingsOverlay;
|
private MultiplayerMatchSettingsOverlay settingsOverlay;
|
||||||
|
|
||||||
private IBindable<bool> isConnected;
|
private IBindable<bool> isConnected;
|
||||||
|
|
||||||
|
[CanBeNull]
|
||||||
|
private IDisposable gameplayStartOperation;
|
||||||
|
|
||||||
public MultiplayerMatchSubScreen(Room room)
|
public MultiplayerMatchSubScreen(Room room)
|
||||||
{
|
{
|
||||||
Title = room.RoomID.Value == null ? "New room" : room.Name.Value;
|
Title = room.RoomID.Value == null ? "New room" : room.Name.Value;
|
||||||
@ -217,7 +222,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
{
|
{
|
||||||
if (client.Room?.Host?.Equals(localUser) == true)
|
if (client.Room?.Host?.Equals(localUser) == true)
|
||||||
{
|
{
|
||||||
gameplayStartTracker.BeginOperation();
|
Debug.Assert(gameplayStartOperation == null);
|
||||||
|
gameplayStartOperation = ongoingOperationTracker.BeginOperation();
|
||||||
|
|
||||||
client.StartMatch().CatchUnobservedExceptions(true);
|
client.StartMatch().CatchUnobservedExceptions(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -232,7 +239,11 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
int[] userIds = client.CurrentMatchPlayingUserIds.ToArray();
|
int[] userIds = client.CurrentMatchPlayingUserIds.ToArray();
|
||||||
|
|
||||||
StartPlay(() => new MultiplayerPlayer(SelectedItem.Value, userIds));
|
StartPlay(() => new MultiplayerPlayer(SelectedItem.Value, userIds));
|
||||||
gameplayStartTracker.EndOperation();
|
|
||||||
|
Debug.Assert(gameplayStartOperation != null);
|
||||||
|
|
||||||
|
gameplayStartOperation.Dispose();
|
||||||
|
gameplayStartOperation = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
|
@ -53,7 +53,7 @@ namespace osu.Game.Screens.OnlinePlay
|
|||||||
private readonly Bindable<FilterCriteria> currentFilter = new Bindable<FilterCriteria>(new FilterCriteria());
|
private readonly Bindable<FilterCriteria> currentFilter = new Bindable<FilterCriteria>(new FilterCriteria());
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
private readonly OngoingOperationTracker joiningRoomTracker = new OngoingOperationTracker();
|
private readonly OngoingOperationTracker ongoingOperationTracker = new OngoingOperationTracker();
|
||||||
|
|
||||||
[Resolved(CanBeNull = true)]
|
[Resolved(CanBeNull = true)]
|
||||||
private MusicController music { get; set; }
|
private MusicController music { get; set; }
|
||||||
|
Loading…
Reference in New Issue
Block a user