Exemple #1
0
        protected override void DidActivate(bool firstActivation, ActivationType type)
        {
            if (_pageUpButton == null)
            {
                _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageUpButton")), rectTransform, false);
                (_pageUpButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchoredPosition = new Vector2(0f, -14f);
                _pageUpButton.interactable = true;
                _pageUpButton.onClick.AddListener(delegate()
                {
                    _songsTableView.PageScrollUp();
                });
            }

            if (_pageDownButton == null)
            {
                _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), rectTransform, false);
                (_pageDownButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchoredPosition = new Vector2(0f, 8f);
                _pageDownButton.interactable = true;
                _pageDownButton.onClick.AddListener(delegate()
                {
                    _songsTableView.PageScrollDown();
                });
            }

            _songListTableCellInstance = Resources.FindObjectsOfTypeAll <StandardLevelListTableCell>().First(x => (x.name == "StandardLevelListTableCell"));

            if (_songsTableView == null)
            {
                _songsTableView = new GameObject().AddComponent <TableView>();

                _songsTableView.transform.SetParent(rectTransform, false);

                Mask viewportMask = Instantiate(Resources.FindObjectsOfTypeAll <Mask>().First(), _songsTableView.transform, false);
                viewportMask.transform.DetachChildren();

                _songsTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Content").transform.SetParent(viewportMask.rectTransform, false);

                (_songsTableView.transform as RectTransform).anchorMin        = new Vector2(0f, 0.5f);
                (_songsTableView.transform as RectTransform).anchorMax        = new Vector2(1f, 0.5f);
                (_songsTableView.transform as RectTransform).sizeDelta        = new Vector2(0f, 60f);
                (_songsTableView.transform as RectTransform).position         = new Vector3(0f, 0f, 2.4f);
                (_songsTableView.transform as RectTransform).anchoredPosition = new Vector3(0f, -3f);

                ReflectionUtil.SetPrivateField(_songsTableView, "_pageUpButton", _pageUpButton);
                ReflectionUtil.SetPrivateField(_songsTableView, "_pageDownButton", _pageDownButton);

                _songsTableView.didSelectRowEvent += _songsTableView_DidSelectRowEvent;
            }
        }
        protected override void DidActivate(bool firstActivation, ActivationType type)
        {
            if (firstActivation && type == ActivationType.AddedToHierarchy)
            {
                _songTableCell = Instantiate(Resources.FindObjectsOfTypeAll <LevelListTableCell>().First(x => (x.name == "LevelListTableCell")), rectTransform);
                (_songTableCell.transform as RectTransform).anchoredPosition = new Vector2(100f, -1.5f);
                _songTableCell.SetPrivateField("_beatmapCharacteristicAlphas", new float[0]);
                _songTableCell.SetPrivateField("_beatmapCharacteristicImages", new UnityEngine.UI.Image[0]);
                _songTableCell.SetPrivateField("_bought", true);
                foreach (var icon in _songTableCell.GetComponentsInChildren <UnityEngine.UI.Image>().Where(x => x.name.StartsWith("LevelTypeIcon")))
                {
                    Destroy(icon.gameObject);
                }

                _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().Last(x => (x.name == "PageUpButton")), rectTransform, false);
                (_pageUpButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchoredPosition = new Vector2(0f, -12.5f);
                (_pageUpButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 6f);
                _pageUpButton.interactable = true;
                _pageUpButton.onClick.AddListener(delegate()
                {
                    _leaderboardTableView.PageScrollUp();
                });
                _pageUpButton.interactable = false;

                _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), rectTransform, false);
                (_pageDownButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchoredPosition = new Vector2(0f, 7f);
                (_pageDownButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 6f);
                _pageDownButton.interactable = true;
                _pageDownButton.onClick.AddListener(delegate()
                {
                    _leaderboardTableView.PageScrollDown();
                });
                _pageDownButton.interactable = false;

                _playNowButton = this.CreateUIButton("QuitButton", new Vector2(-39f, 34.5f), new Vector2(28f, 8.8f), () => { playNowButtonPressed?.Invoke(); }, "Play now");
                _playNowButton.ToggleWordWrapping(false);
                _progressText = BeatSaberUI.CreateText(rectTransform, "0.0%", new Vector2(8f, 32f));
                _progressText.gameObject.SetActive(false);

                _leaderboardTableCellInstance = Resources.FindObjectsOfTypeAll <LeaderboardTableCell>().First(x => (x.name == "LeaderboardTableCell"));

                RectTransform container = new GameObject("Content", typeof(RectTransform)).transform as RectTransform;
                container.SetParent(rectTransform, false);
                container.anchorMin        = new Vector2(0.15f, 0.5f);
                container.anchorMax        = new Vector2(0.85f, 0.5f);
                container.sizeDelta        = new Vector2(0f, 56f);
                container.anchoredPosition = new Vector2(0f, -3f);

                _leaderboardTableView = new GameObject("CustomTableView").AddComponent <TableView>();
                _leaderboardTableView.gameObject.AddComponent <RectMask2D>();
                _leaderboardTableView.transform.SetParent(container, false);

                _leaderboardTableView.SetPrivateField("_isInitialized", false);
                _leaderboardTableView.SetPrivateField("_preallocatedCells", new TableView.CellsGroup[0]);
                _leaderboardTableView.Init();

                RectMask2D viewportMask = Instantiate(Resources.FindObjectsOfTypeAll <RectMask2D>().First(), _leaderboardTableView.transform, false);
                viewportMask.transform.DetachChildren();
                _leaderboardTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Content").transform.SetParent(viewportMask.rectTransform, false);

                (_leaderboardTableView.transform as RectTransform).anchorMin        = new Vector2(0f, 0f);
                (_leaderboardTableView.transform as RectTransform).anchorMax        = new Vector2(1f, 1f);
                (_leaderboardTableView.transform as RectTransform).sizeDelta        = new Vector2(0f, 0f);
                (_leaderboardTableView.transform as RectTransform).anchoredPosition = new Vector3(0f, 0f);

                ReflectionUtil.SetPrivateField(_leaderboardTableView, "_pageUpButton", _pageUpButton);
                ReflectionUtil.SetPrivateField(_leaderboardTableView, "_pageDownButton", _pageDownButton);

                _leaderboardTableView.dataSource = this;

                _timerText           = BeatSaberUI.CreateText(rectTransform, "", new Vector2(0f, 34f));
                _timerText.fontSize  = 8f;
                _timerText.alignment = TextAlignmentOptions.Center;
                _timerText.rectTransform.sizeDelta = new Vector2(30f, 6f);
            }
        }
        protected override void DidActivate(bool firstActivation, ActivationType type)
        {
            if (firstActivation && type == ActivationType.AddedToHierarchy)
            {
                _songTableCell = Instantiate(Resources.FindObjectsOfTypeAll <LevelListTableCell>().First(x => (x.name == "LevelListTableCell")));
                (_songTableCell.transform as RectTransform).anchoredPosition = new Vector2(18f, 39f);

                _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageUpButton")), rectTransform, false);
                (_pageUpButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 1f);
                (_pageUpButton.transform as RectTransform).anchoredPosition = new Vector2(0f, -12f);
                (_pageUpButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 6f);
                _pageUpButton.interactable = true;
                _pageUpButton.onClick.AddListener(delegate()
                {
                    _leaderboardTableView.PageScrollUp();
                });
                _pageUpButton.interactable = false;

                _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), rectTransform, false);
                (_pageDownButton.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0f);
                (_pageDownButton.transform as RectTransform).anchoredPosition = new Vector2(0f, 6f);
                (_pageDownButton.transform as RectTransform).sizeDelta        = new Vector2(40f, 6f);
                _pageDownButton.interactable = true;
                _pageDownButton.onClick.AddListener(delegate()
                {
                    _leaderboardTableView.PageScrollDown();
                });
                _pageDownButton.interactable = false;

                _leaderboardTableCellInstance = Resources.FindObjectsOfTypeAll <LeaderboardTableCell>().First(x => (x.name == "LeaderboardTableCell"));

                RectTransform container = new GameObject("Content", typeof(RectTransform)).transform as RectTransform;
                container.SetParent(rectTransform, false);
                container.anchorMin        = new Vector2(0.15f, 0.5f);
                container.anchorMax        = new Vector2(0.85f, 0.5f);
                container.sizeDelta        = new Vector2(0f, 56f);
                container.anchoredPosition = new Vector2(0f, -3f);

                _leaderboardTableView = new GameObject("CustomTableView").AddComponent <TableView>();
                _leaderboardTableView.gameObject.AddComponent <RectMask2D>();
                _leaderboardTableView.transform.SetParent(container, false);

                _leaderboardTableView.SetPrivateField("_isInitialized", false);
                _leaderboardTableView.SetPrivateField("_preallocatedCells", new TableView.CellsGroup[0]);
                _leaderboardTableView.Init();

                RectMask2D viewportMask = Instantiate(Resources.FindObjectsOfTypeAll <RectMask2D>().First(), _leaderboardTableView.transform, false);
                viewportMask.transform.DetachChildren();
                _leaderboardTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Content").transform.SetParent(viewportMask.rectTransform, false);

                (_leaderboardTableView.transform as RectTransform).anchorMin        = new Vector2(0f, 0f);
                (_leaderboardTableView.transform as RectTransform).anchorMax        = new Vector2(1f, 1f);
                (_leaderboardTableView.transform as RectTransform).sizeDelta        = new Vector2(0f, 0f);
                (_leaderboardTableView.transform as RectTransform).anchoredPosition = new Vector3(0f, 0f);

                ReflectionUtil.SetPrivateField(_leaderboardTableView, "_pageUpButton", _pageUpButton);
                ReflectionUtil.SetPrivateField(_leaderboardTableView, "_pageDownButton", _pageDownButton);

                _leaderboardTableView.dataSource = this;

                _timerText           = BeatSaberUI.CreateText(rectTransform, "", new Vector2(0f, 34f));
                _timerText.fontSize  = 8f;
                _timerText.alignment = TextAlignmentOptions.Center;
                _timerText.rectTransform.sizeDelta = new Vector2(30f, 6f);
            }
        }
Exemple #4
0
        private void ReceivedFromServer(string[] _data)
        {
            lastCommands.Clear();
            foreach (string data in _data)
            {
                try
                {
                    ServerCommand command = JsonUtility.FromJson <ServerCommand>(data);
                    lastCommands.Add(command);

                    if (command.commandType == ServerCommandType.SetPlayerInfos)
                    {
                        if (command.scoreboardScoreFormat != null)
                        {
                            scoreboardScoreFormat = command.scoreboardScoreFormat;
                        }

                        _playerInfos.Clear();
                        foreach (string playerStr in command.playerInfos)
                        {
                            PlayerInfo player = JsonUtility.FromJson <PlayerInfo>(playerStr);
                            if (!String.IsNullOrEmpty(player.playerAvatar) && Config.Instance.ShowAvatarsInGame)
                            {
                                byte[] avatar = Convert.FromBase64String(player.playerAvatar);

                                player.rightHandPos = Serialization.ToVector3(avatar.Take(12).ToArray());
                                player.leftHandPos  = Serialization.ToVector3(avatar.Skip(12).Take(12).ToArray());
                                player.headPos      = Serialization.ToVector3(avatar.Skip(24).Take(12).ToArray());

                                player.rightHandRot = Serialization.ToQuaternion(avatar.Skip(36).Take(16).ToArray());
                                player.leftHandRot  = Serialization.ToQuaternion(avatar.Skip(52).Take(16).ToArray());
                                player.headRot      = Serialization.ToQuaternion(avatar.Skip(68).Take(16).ToArray());
                            }
                            _playerInfos.Add(player);
                        }

                        localPlayerIndex = FindIndexInList(_playerInfos, localPlayerInfo);

                        if (Config.Instance.ShowAvatarsInGame)
                        {
                            try
                            {
                                if (_avatars.Count > _playerInfos.Count)
                                {
                                    List <AvatarController> avatarsToRemove = new List <AvatarController>();
                                    for (int i = _playerInfos.Count; i < _avatars.Count; i++)
                                    {
                                        avatarsToRemove.Add(_avatars[i]);
                                    }
                                    foreach (AvatarController avatar in avatarsToRemove)
                                    {
                                        _avatars.Remove(avatar);
                                        Destroy(avatar.gameObject);
                                    }
                                }
                                else if (_avatars.Count < _playerInfos.Count)
                                {
                                    for (int i = 0; i < (_playerInfos.Count - _avatars.Count); i++)
                                    {
                                        _avatars.Add(new GameObject("Avatar").AddComponent <AvatarController>());
                                    }
                                }

                                List <PlayerInfo> _playerInfosByID = _playerInfos.OrderBy(x => x.playerId).ToList();
                                for (int i = 0; i < _playerInfos.Count; i++)
                                {
                                    _avatars[i].SetPlayerInfo(_playerInfosByID[i], (i - FindIndexInList(_playerInfosByID, localPlayerInfo)) * 3f, localPlayerInfo.Equals(_playerInfosByID[i]));
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine($"AVATARS EXCEPTION: {e}");
                            }
                        }


                        if (_playerInfos.Count <= 5)
                        {
                            for (int i = 0; i < _playerInfos.Count; i++)
                            {
                                scoreDisplays[i].UpdatePlayerInfo(_playerInfos[i], FindIndexInList(_playerInfos, _playerInfos[i]));
                            }
                            for (int i = _playerInfos.Count; i < scoreDisplays.Count; i++)
                            {
                                scoreDisplays[i].UpdatePlayerInfo(null, 0);
                            }
                        }
                        else
                        {
                            if (localPlayerIndex < 3)
                            {
                                for (int i = 0; i < 5; i++)
                                {
                                    scoreDisplays[i].UpdatePlayerInfo(_playerInfos[i], FindIndexInList(_playerInfos, _playerInfos[i]));
                                }
                            }
                            else if (localPlayerIndex > _playerInfos.Count - 3)
                            {
                                for (int i = _playerInfos.Count - 5; i < _playerInfos.Count; i++)
                                {
                                    scoreDisplays[i - (_playerInfos.Count - 5)].UpdatePlayerInfo(_playerInfos[i], FindIndexInList(_playerInfos, _playerInfos[i]));
                                }
                            }
                            else
                            {
                                for (int i = localPlayerIndex - 2; i < localPlayerIndex + 3; i++)
                                {
                                    scoreDisplays[i - (localPlayerIndex - 2)].UpdatePlayerInfo(_playerInfos[i], FindIndexInList(_playerInfos, _playerInfos[i]));
                                }
                            }
                        }

                        if (PlayerInfosReceived != null)
                        {
                            PlayerInfosReceived.Invoke(_playerInfos);
                        }
                    }
                    else if (command.commandType == ServerCommandType.Kicked)
                    {
                        Console.WriteLine($"You were kicked! Reason: {command.kickReason}");
                        GameSongController controller = Resources.FindObjectsOfTypeAll <GameSongController>().FirstOrDefault();
                        ReflectionUtil.SetPrivateField(controller, "_songDidFinish", true);
                        controller.SendSongDidFinishEvent();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("EXCEPTION ON RECEIVED: " + e);
                }
            }

            StartCoroutine(ReceiveFromServerCoroutine());
        }