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() { _leaderboardTableViewScroller.PageScrollUp(); _leaderboardTableView.RefreshScrollButtons(); }); _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() { _leaderboardTableViewScroller.PageScrollDown(); _leaderboardTableView.RefreshScrollButtons(); }); _pageDownButton.interactable = false; _playNowButton = this.CreateUIButton("CancelButton", 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); var tableGameObject = new GameObject("CustomTableView"); tableGameObject.SetActive(false); _leaderboardTableView = tableGameObject.AddComponent <TableView>(); _leaderboardTableView.gameObject.AddComponent <RectMask2D>(); _leaderboardTableView.transform.SetParent(container, 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); _leaderboardTableView.SetPrivateField("_isInitialized", false); _leaderboardTableView.SetPrivateField("_preallocatedCells", new TableView.CellsGroup[0]); RectTransform viewport = new GameObject("Viewport").AddComponent <RectTransform>(); //Make a Viewport RectTransform viewport.SetParent(_leaderboardTableView.transform as RectTransform, false); //It expects one from a ScrollRect, so we have to make one ourselves. viewport.sizeDelta = new Vector2(0f, 56f); _leaderboardTableView.Init(); _leaderboardTableView.SetPrivateField("_scrollRectTransform", viewport); RectMask2D viewportMask = Instantiate(Resources.FindObjectsOfTypeAll <RectMask2D>().First(x => x.name != "CustomTableView"), _leaderboardTableView.transform, false); viewportMask.transform.DetachChildren(); _leaderboardTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Content").transform.SetParent(viewportMask.rectTransform, false); ReflectionUtil.SetPrivateField(_leaderboardTableView, "_pageUpButton", _pageUpButton); ReflectionUtil.SetPrivateField(_leaderboardTableView, "_pageDownButton", _pageDownButton); _leaderboardTableView.dataSource = this; tableGameObject.SetActive(true); _leaderboardTableViewScroller = _leaderboardTableView.GetPrivateField <TableViewScroller>("_scroller"); _timerText = BeatSaberUI.CreateText(rectTransform, "", new Vector2(0f, 34f)); _timerText.fontSize = 8f; _timerText.alignment = TextAlignmentOptions.Center; _timerText.rectTransform.sizeDelta = new Vector2(30f, 6f); _lastHighscoreText = BeatSaberUI.CreateText(rectTransform, "Last Highscore", new Vector2(45f, -35f)); _lastHighscoreText.alignment = TextAlignmentOptions.Right; _lastHighscoreText.color = Color.white; _lastHighscoreText.fontSize = 5f; _lastHighscoreText.gameObject.SetActive(false); } }
IEnumerator WaitForControllers() { #if DEBUG Plugin.log.Info("Waiting for game controllers..."); #endif yield return(new WaitUntil(delegate() { return FindObjectOfType <ScoreController>() != null; })); #if DEBUG Plugin.log.Info("Game controllers found!"); #endif _gameManager = Resources.FindObjectsOfTypeAll <StandardLevelGameplayManager>().First(); if (_gameManager != null) { try { if (ReflectionUtil.GetPrivateField <IPauseTrigger>(_gameManager, "_pauseTrigger") != null) { ReflectionUtil.GetPrivateField <IPauseTrigger>(_gameManager, "_pauseTrigger").pauseTriggeredEvent -= _gameManager.HandlePauseTriggered; ReflectionUtil.GetPrivateField <IPauseTrigger>(_gameManager, "_pauseTrigger").pauseTriggeredEvent += ShowMenu; } if (ReflectionUtil.GetPrivateField <VRPlatformHelper>(_gameManager, "_vrPlatformHelper") != null) { ReflectionUtil.GetPrivateField <VRPlatformHelper>(_gameManager, "_vrPlatformHelper").inputFocusWasCapturedEvent -= _gameManager.HandleInputFocusWasCaptured; ReflectionUtil.GetPrivateField <VRPlatformHelper>(_gameManager, "_vrPlatformHelper").inputFocusWasCapturedEvent += ShowMenu; } } catch (Exception e) { Plugin.log.Critical(e); } } #if DEBUG Plugin.log.Info("Disabled pause button!"); #endif _scoreController = FindObjectOfType <ScoreController>(); if (_scoreController != null) { _scoreController.scoreDidChangeEvent += ScoreChanged; _scoreController.noteWasCutEvent += NoteWasCutEvent; _scoreController.comboDidChangeEvent += ComboDidChangeEvent; _scoreController.noteWasMissedEvent += NoteWasMissedEvent; } #if DEBUG Plugin.log.Info("Found score controller"); #endif _energyController = FindObjectOfType <GameEnergyCounter>(); if (_energyController != null) { _energyController.gameEnergyDidChangeEvent += EnergyDidChangeEvent; } #if DEBUG Plugin.log.Info("Found energy controller"); #endif audioTimeSync = Resources.FindObjectsOfTypeAll <AudioTimeSyncController>().FirstOrDefault(); _pauseMenuManager = FindObjectsOfType <PauseMenuManager>().First(); if (_pauseMenuManager != null) { _pauseMenuManager.GetPrivateField <Button>("_restartButton").interactable = false; } #if DEBUG Plugin.log.Info("Found pause manager"); #endif _loaded = true; }
protected override void DidActivate(bool firstActivation, ActivationType type) { ui = BSMultiplayerUI._instance; _parentMasterViewController = transform.parent.GetComponent <MultiplayerServerHubViewController>(); _serverTableCellInstance = Resources.FindObjectsOfTypeAll <StandardLevelListTableCell>().First(x => (x.name == "StandardLevelListTableCell")); 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() { _serverTableView.PageScrollUp(); }); _pageUpButton.interactable = false; } 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() { _serverTableView.PageScrollDown(); }); _pageDownButton.interactable = false; } if (_serverTableView == null) { _serverTableView = new GameObject().AddComponent <TableView>(); _serverTableView.transform.SetParent(rectTransform, false); Mask viewportMask = Instantiate(Resources.FindObjectsOfTypeAll <Mask>().First(), _serverTableView.transform, false); viewportMask.transform.DetachChildren(); _serverTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Content").transform.SetParent(viewportMask.rectTransform, false); (_serverTableView.transform as RectTransform).anchorMin = new Vector2(0f, 0.5f); (_serverTableView.transform as RectTransform).anchorMax = new Vector2(1f, 0.5f); (_serverTableView.transform as RectTransform).sizeDelta = new Vector2(0f, 60f); (_serverTableView.transform as RectTransform).position = new Vector3(0f, 0f, 2.4f); (_serverTableView.transform as RectTransform).anchoredPosition = new Vector3(0f, -3f); ReflectionUtil.SetPrivateField(_serverTableView, "_pageUpButton", _pageUpButton); ReflectionUtil.SetPrivateField(_serverTableView, "_pageDownButton", _pageDownButton); _serverTableView.didSelectRowEvent += ServerTableView_DidSelectRow; _serverTableView.dataSource = this; } else { _serverTableView.ReloadData(); } }