Esempio n. 1
0
        public override void Start()
        {
            Plugin.Log?.Info("Installing Interface");

            HostLobbySetupViewController hostViewController = Container.Resolve <HostLobbySetupViewController>();

            Container.InstantiateComponent <HostLobbySetupPanel>(hostViewController.gameObject);

            ClientLobbySetupViewController clientViewController = Container.Resolve <ClientLobbySetupViewController>();

            Container.InstantiateComponent <ClientLobbySetupPanel>(clientViewController.gameObject);

            CenterStageScreenController centerScreenController = Container.Resolve <CenterStageScreenController>();

            Container.InstantiateComponent <CenterScreenLoadingPanel>(centerScreenController.gameObject);

            ServerPlayerListController playerListController = Container.Resolve <ServerPlayerListController>();
            GameServerPlayersTableView playersTableView     = playerListController.GetField <GameServerPlayersTableView, ServerPlayerListController>("_gameServerPlayersTableView");
            GameServerPlayerTableCell  playerTableCell      = playersTableView.GetField <GameServerPlayerTableCell, GameServerPlayersTableView>("_gameServerPlayerCellPrefab");
            GameServerPlayerTableCell  newPlayerTableCell   = GameObject.Instantiate(playerTableCell);

            newPlayerTableCell.gameObject.SetActive(false);
            PlayerTableCellStub playerTableCellStub = newPlayerTableCell.gameObject.AddComponent <PlayerTableCellStub>();

            playerTableCellStub.Construct(newPlayerTableCell);
            Destroy(newPlayerTableCell.GetComponent <GameServerPlayerTableCell>());
            playersTableView.SetField <GameServerPlayersTableView, GameServerPlayerTableCell>("_gameServerPlayerCellPrefab", playerTableCellStub);
        }
        static void Postfix(List <IConnectedPlayer> sortedPlayers, ILobbyPlayersDataModel lobbyPlayersDataModel, GameServerPlayersTableView __instance)
        {
            IPreviewBeatmapLevel hostBeatmap = lobbyPlayersDataModel.GetPlayerBeatmapLevel(lobbyPlayersDataModel.hostUserId);

            if (hostBeatmap != null && hostBeatmap is PreviewBeatmapStub hostBeatmapStub)
            {
                TableView tableView = __instance.GetField <TableView, GameServerPlayersTableView>("_tableView");
                foreach (TableCell cell in tableView.visibleCells)
                {
                    if (cell is GameServerPlayerTableCell playerCell)
                    {
                        Image             background      = playerCell.GetField <Image, GameServerPlayerTableCell>("_localPlayerBackgroundImage");
                        CurvedTextMeshPro emptySuggestion = playerCell.GetField <CurvedTextMeshPro, GameServerPlayerTableCell>("_emptySuggestedLevelText");
                        CurvedTextMeshPro suggestion      = playerCell.GetField <CurvedTextMeshPro, GameServerPlayerTableCell>("_suggestedLevelText");
                        IConnectedPlayer  player          = sortedPlayers[playerCell.idx];
                        Color             backgroundColor = new Color();

                        if (player.isConnectionOwner)
                        {
                            suggestion.gameObject.SetActive(false);
                            emptySuggestion.gameObject.SetActive(true);
                            emptySuggestion.text = "Loading...";
                            hostBeatmapStub.isDownloadable.ContinueWith(r =>
                            {
                                HMMainThreadDispatcher.instance.Enqueue(() =>
                                {
                                    suggestion.gameObject.SetActive(true);
                                    emptySuggestion.gameObject.SetActive(false);
                                });
                            });
                        }
                        // TODO: check merge
                        background.enabled = true;
                        if (player.HasState("beatmap_downloaded") || player.HasState("start_primed"))
                        {
                            backgroundColor   = green;
                            backgroundColor.a = player.isMe ? 0.4f : 0.1f;
                            background.color  = backgroundColor;
                        }
                        else
                        {
                            hostBeatmapStub.isDownloadable.ContinueWith(r =>
                            {
                                bool downloadable = r.Result;
                                backgroundColor   = downloadable ? yellow : red;
                                backgroundColor.a = player.isMe ? 0.4f : 0.1f;
                                HMMainThreadDispatcher.instance.Enqueue(() =>
                                {
                                    background.color = backgroundColor;
                                });
                            });
                        }
                    }
                }
            }
        }