Exemplo n.º 1
0
        public new void Setup() => Schedule(() =>
        {
            importedSet        = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First();
            Beatmap.Value      = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First());
            selectedItem.Value = new PlaylistItem
            {
                Beatmap = { Value = Beatmap.Value.BeatmapInfo },
                Ruleset = { Value = Beatmap.Value.BeatmapInfo.Ruleset },
            };

            if (button != null)
            {
                Remove(button);
            }

            Add(button = new MultiplayerReadyButton
            {
                Anchor       = Anchor.Centre,
                Origin       = Anchor.Centre,
                Size         = new Vector2(200, 50),
                OnReadyClick = async() =>
                {
                    readyClickOperation = OngoingOperationTracker.BeginOperation();

                    if (Client.IsHost && Client.LocalUser?.State == MultiplayerUserState.Ready)
                    {
                        await Client.StartMatch();
                        return;
                    }

                    await Client.ToggleReady();
                    readyClickOperation.Dispose();
                }
            });
        });
        public new void Setup() => Schedule(() =>
        {
            AvailabilityTracker.SelectedItem.BindTo(selectedItem);

            importedSet        = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First();
            Beatmap.Value      = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First());
            selectedItem.Value = new PlaylistItem
            {
                Beatmap = { Value = Beatmap.Value.BeatmapInfo },
                Ruleset = { Value = Beatmap.Value.BeatmapInfo.Ruleset },
            };

            Child = new FillFlowContainer
            {
                AutoSizeAxes = Axes.Both,
                Direction    = FillDirection.Vertical,
                Children     = new Drawable[]
                {
                    spectateButton = new MultiplayerSpectateButton
                    {
                        Anchor          = Anchor.Centre,
                        Origin          = Anchor.Centre,
                        Size            = new Vector2(200, 50),
                        OnSpectateClick = () =>
                        {
                            readyClickOperation = OngoingOperationTracker.BeginOperation();

                            Task.Run(async() =>
                            {
                                await Client.ToggleSpectate();
                                readyClickOperation.Dispose();
                            });
                        }
                    },
                    readyButton = new MultiplayerReadyButton
                    {
                        Anchor       = Anchor.Centre,
                        Origin       = Anchor.Centre,
                        Size         = new Vector2(200, 50),
                        OnReadyClick = () =>
                        {
                            readyClickOperation = OngoingOperationTracker.BeginOperation();

                            Task.Run(async() =>
                            {
                                if (Client.IsHost && Client.LocalUser?.State == MultiplayerUserState.Ready)
                                {
                                    await Client.StartMatch();
                                    return;
                                }

                                await Client.ToggleReady();

                                readyClickOperation.Dispose();
                            });
                        }
                    }
                }
            };
        });
Exemplo n.º 3
0
        private void load()
        {
            Dependencies.CacheAs(multiplayerClient.Object);
            Dependencies.CacheAs(ongoingOperationTracker = new OngoingOperationTracker());
            Dependencies.CacheAs(availabilityTracker.Object);

            availabilityTracker.SetupGet(a => a.Availability).Returns(beatmapAvailability);

            multiplayerClient.SetupGet(m => m.LocalUser).Returns(() => localUser);
            multiplayerClient.SetupGet(m => m.Room).Returns(() => multiplayerRoom);

            // By default, the local user is to be the host.
            multiplayerClient.SetupGet(m => m.IsHost).Returns(() => ReferenceEquals(multiplayerRoom.Host, localUser));

            // Assume all state changes are accepted by the server.
            multiplayerClient.Setup(m => m.ChangeState(It.IsAny <MultiplayerUserState>()))
            .Callback((MultiplayerUserState r) =>
            {
                Logger.Log($"Changing local user state from {localUser.State} to {r}");
                localUser.State = r;
                raiseRoomUpdated();
            });

            multiplayerClient.Setup(m => m.StartMatch())
            .Callback(() =>
            {
                multiplayerClient.Raise(m => m.LoadRequested -= null);

                // immediately "end" gameplay, as we don't care about that part of the process.
                changeUserState(localUser.UserID, MultiplayerUserState.Idle);
            });

            multiplayerClient.Setup(m => m.SendMatchRequest(It.IsAny <MatchUserRequest>()))
            .Callback((MatchUserRequest request) =>
            {
                switch (request)
                {
                case StartMatchCountdownRequest countdownStart:
                    setRoomCountdown(countdownStart.Duration);
                    break;

                case StopCountdownRequest _:
                    multiplayerRoom.Countdown = null;
                    raiseRoomUpdated();
                    break;
                }
            });

            Children = new Drawable[]
            {
                ongoingOperationTracker,
                content = new PopoverContainer {
                    RelativeSizeAxes = Axes.Both
                }
            };
        }
Exemplo n.º 4
0
        protected MultiplayerTestScene(bool joinRoom = true)
        {
            this.joinRoom            = joinRoom;
            base.Content.Add(content = new TestMultiplayerRoomContainer {
                RelativeSizeAxes = Axes.Both
            });

            Client                  = content.Client;
            RoomManager             = content.RoomManager;
            Filter                  = content.Filter;
            OngoingOperationTracker = content.OngoingOperationTracker;
        }
Exemplo n.º 5
0
        public TestMultiplayerRoomContainer()
        {
            RelativeSizeAxes = Axes.Both;

            RoomManager             = new TestMultiplayerRoomManager();
            Client                  = new TestMultiplayerClient(RoomManager);
            OngoingOperationTracker = new OngoingOperationTracker();

            AddRangeInternal(new Drawable[]
            {
                Client,
                RoomManager,
                OngoingOperationTracker,
                content = new Container {
                    RelativeSizeAxes = Axes.Both
                }
            });
        }
Exemplo n.º 6
0
        public void TestButtonEnableStateChanges()
        {
            IDisposable joiningRoomOperation = null;

            assertButtonEnableState(true);

            AddStep("begin joining room", () => joiningRoomOperation = OngoingOperationTracker.BeginOperation());
            assertButtonEnableState(false);

            AddStep("end joining room", () => joiningRoomOperation.Dispose());
            assertButtonEnableState(true);

            AddStep("disconnect client", () => MultiplayerClient.Disconnect());
            assertButtonEnableState(false);

            AddStep("re-connect client", () => MultiplayerClient.Connect());
            assertButtonEnableState(true);
        }
Exemplo n.º 7
0
        public OnlinePlayTestSceneDependencies()
        {
            SelectedRoom            = new Bindable <Room>();
            RoomManager             = CreateRoomManager();
            OngoingOperationTracker = new OngoingOperationTracker();
            AvailabilityTracker     = new OnlinePlayBeatmapAvailabilityTracker();

            dependencies = new DependencyContainer(new CachedModelDependencyContainer <Room>(null)
            {
                Model = { BindTarget = SelectedRoom }
            });

            CacheAs(SelectedRoom);
            CacheAs(RoomManager);
            CacheAs(OngoingOperationTracker);
            CacheAs(AvailabilityTracker);
            CacheAs(new OverlayColourProvider(OverlayColourScheme.Plum));
        }
Exemplo n.º 8
0
        public OnlinePlayTestSceneDependencies()
        {
            SelectedRoom            = new Bindable <Room>();
            RoomManager             = CreateRoomManager();
            Filter                  = new Bindable <FilterCriteria>(new FilterCriteria());
            OngoingOperationTracker = new OngoingOperationTracker();
            AvailabilityTracker     = new OnlinePlayBeatmapAvailabilityTracker();

            dependencies = new DependencyContainer(new CachedModelDependencyContainer <Room>(null)
            {
                Model = { BindTarget = SelectedRoom }
            });

            CacheAs(SelectedRoom);
            CacheAs(RoomManager);
            CacheAs(Filter);
            CacheAs(OngoingOperationTracker);
            CacheAs(AvailabilityTracker);
        }
        public new void Setup() => Schedule(() =>
        {
            AvailabilityTracker.SelectedItem.BindTo(selectedItem);

            beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
            importedSet   = beatmaps.GetAllUsableBeatmapSets().First();
            Beatmap.Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First());

            selectedItem.Value = new PlaylistItem(Beatmap.Value.BeatmapInfo)
            {
                RulesetID = Beatmap.Value.BeatmapInfo.Ruleset.OnlineID
            };

            if (button != null)
            {
                Remove(button);
            }

            Add(button = new MultiplayerReadyButton
            {
                Anchor       = Anchor.Centre,
                Origin       = Anchor.Centre,
                Size         = new Vector2(200, 50),
                OnReadyClick = () =>
                {
                    readyClickOperation = OngoingOperationTracker.BeginOperation();

                    Task.Run(async() =>
                    {
                        if (MultiplayerClient.IsHost && MultiplayerClient.LocalUser?.State == MultiplayerUserState.Ready)
                        {
                            await MultiplayerClient.StartMatch();
                            return;
                        }

                        await MultiplayerClient.ToggleReady();

                        readyClickOperation.Dispose();
                    });
                }
            });
        });
Exemplo n.º 10
0
 public void SetUp()
 {
     AddStep("create tracker", () => Child = tracker = new OngoingOperationTracker());
     AddStep("bind to operation status", () => operationInProgress = tracker.InProgress.GetBoundCopy());
 }
Exemplo n.º 11
0
 private void load()
 {
     InternalChild = OngoingOperationTracker = new OngoingOperationTracker();
 }