private void SetupUI() { if (initialized) { return; } _beatmapCharacteristics = Resources.FindObjectsOfTypeAll <BeatmapCharacteristicSO>(); _lastCharacteristic = _beatmapCharacteristics.First(x => x.characteristicName == "Standard"); Resources.FindObjectsOfTypeAll <BeatmapCharacteristicSelectionViewController>().First().didSelectBeatmapCharacteristicEvent += (BeatmapCharacteristicSelectionViewController sender, BeatmapCharacteristicSO selected) => { _lastCharacteristic = selected; }; if (SongLoader.AreSongsLoaded) { _levelCollection = SongLoader.CustomLevelCollectionSO; } else { SongLoader.SongsLoadedEvent += (SongLoader sender, List <CustomLevel> levels) => { _levelCollection = SongLoader.CustomLevelCollectionSO; }; } _levelListViewController = Resources.FindObjectsOfTypeAll <LevelListViewController>().FirstOrDefault(); RectTransform _tableViewRectTransform = _levelListViewController.GetComponentsInChildren <RectTransform>().First(x => x.name == "TableViewContainer"); _tableViewRectTransform.sizeDelta = new Vector2(0f, -35f); //_tableViewRectTransform.anchoredPosition = new Vector2(0f, -2.5f); RectTransform _pageUp = _tableViewRectTransform.GetComponentsInChildren <RectTransform>(true).First(x => x.name == "PageUpButton"); _pageUp.anchoredPosition = new Vector2(0f, -1f); RectTransform _pageDown = _tableViewRectTransform.GetComponentsInChildren <RectTransform>(true).First(x => x.name == "PageDownButton"); _pageDown.anchoredPosition = new Vector2(0f, 1f); _requestButton = _levelListViewController.CreateUIButton("CreditsButton", new Vector2(0, 30.25f), new Vector2(20f, 6f), RequestsButtonPressed, "Requests"); _requestButton.SetButtonTextSize(3f); _requestButton.ToggleWordWrapping(false); _detailViewController = Resources.FindObjectsOfTypeAll <StandardLevelDetailViewController>().First(x => x.name == "StandardLevelDetailViewController"); //based on https://github.com/halsafar/BeatSaberSongBrowser/blob/master/SongBrowserPlugin/UI/Browser/SongBrowserUI.cs#L192 var statsPanel = _detailViewController.GetComponentsInChildren <CanvasRenderer>(true).First(x => x.name == "LevelParamsPanel"); var statTransforms = statsPanel.GetComponentsInChildren <RectTransform>(); var valueTexts = statsPanel.GetComponentsInChildren <TextMeshProUGUI>().Where(x => x.name == "ValueText").ToList(); foreach (RectTransform r in statTransforms) { if (r.name == "Separator") { continue; } r.sizeDelta = new Vector2(r.sizeDelta.x * 0.85f, r.sizeDelta.y * 0.85f); } _levelListViewController.didSelectLevelEvent += _levelListViewController_didSelectLevelEvent; initialized = true; }
/// <summary> /// Constructor. Acquire all necessary BeatSaberUi elements. /// </summary> /// <param name="flowCoordinator"></param> public BeatSaberUIController(FlowCoordinator flowCoordinator) { Logger.Debug("Collecting all BeatSaberUI Elements..."); LevelSelectionFlowCoordinator = flowCoordinator; // gather flow coordinator elements LevelSelectionNavigationController = LevelSelectionFlowCoordinator.GetPrivateField <LevelSelectionNavigationController>("levelSelectionNavigationController"); Logger.Debug("Acquired LevelSelectionNavigationController [{0}]", LevelSelectionNavigationController.GetInstanceID()); LevelFilteringNavigationController = LevelSelectionNavigationController.GetPrivateField <LevelFilteringNavigationController>("_levelFilteringNavigationController"); Logger.Debug("Acquired LevelFilteringNavigationController [{0}]", LevelFilteringNavigationController.GetInstanceID()); LevelCollectionNavigationController = LevelSelectionNavigationController.GetPrivateField <LevelCollectionNavigationController>("_levelCollectionNavigationController"); Logger.Debug("Acquired LevelCollectionNavigationController [{0}]", LevelCollectionNavigationController.GetInstanceID()); LevelCollectionViewController = LevelCollectionNavigationController.GetPrivateField <LevelCollectionViewController>("_levelCollectionViewController"); Logger.Debug("Acquired LevelPackLevelsViewController [{0}]", LevelCollectionViewController.GetInstanceID()); LevelDetailViewController = LevelCollectionNavigationController.GetPrivateField <StandardLevelDetailViewController>("_levelDetailViewController"); Logger.Debug("Acquired StandardLevelDetailViewController [{0}]", LevelDetailViewController.GetInstanceID()); LevelCollectionTableView = this.LevelCollectionViewController.GetPrivateField <LevelCollectionTableView>("_levelCollectionTableView"); Logger.Debug("Acquired LevelPackLevelsTableView [{0}]", LevelCollectionTableView.GetInstanceID()); StandardLevelDetailView = LevelDetailViewController.GetPrivateField <StandardLevelDetailView>("_standardLevelDetailView"); Logger.Debug("Acquired StandardLevelDetailView [{0}]", StandardLevelDetailView.GetInstanceID()); BeatmapCharacteristicSelectionViewController = LevelDetailViewController.GetComponentInChildren <BeatmapCharacteristicSegmentedControlController>(); Logger.Debug("Acquired BeatmapCharacteristicSegmentedControlController [{0}]", BeatmapCharacteristicSelectionViewController.GetInstanceID()); LevelDifficultyViewController = StandardLevelDetailView.GetPrivateField <BeatmapDifficultySegmentedControlController>("_beatmapDifficultySegmentedControlController"); Logger.Debug("Acquired BeatmapDifficultySegmentedControlController [{0}]", LevelDifficultyViewController.GetInstanceID()); LevelCollectionTableViewTransform = LevelCollectionTableView.transform as RectTransform; Logger.Debug("Acquired TableViewRectTransform from LevelPackLevelsTableView [{0}]", LevelCollectionTableViewTransform.GetInstanceID()); AnnotatedBeatmapLevelCollectionsViewController = LevelFilteringNavigationController.GetPrivateField <AnnotatedBeatmapLevelCollectionsViewController>("_annotatedBeatmapLevelCollectionsViewController"); Logger.Debug("Acquired AnnotatedBeatmapLevelCollectionsViewController from LevelFilteringNavigationController [{0}]", AnnotatedBeatmapLevelCollectionsViewController.GetInstanceID()); TableView tableView = LevelCollectionTableView.GetPrivateField <TableView>("_tableView"); TableViewPageUpButton = tableView.GetPrivateField <Button>("_pageUpButton"); TableViewPageDownButton = tableView.GetPrivateField <Button>("_pageDownButton"); Logger.Debug("Acquired Page Up and Down buttons..."); ActionButtons = LevelDetailViewController.GetComponentsInChildren <RectTransform>().First(x => x.name == "ActionButtons"); Logger.Debug("Acquired ActionButtons [{0}]", ActionButtons.GetInstanceID()); ScreenSystem = Resources.FindObjectsOfTypeAll <ScreenSystem>().Last(); Logger.Debug("Acquired ScreenSystem [{0}]", ScreenSystem.GetInstanceID()); SimpleDialogPromptViewControllerPrefab = Resources.FindObjectsOfTypeAll <SimpleDialogPromptViewController>().Last(); Logger.Debug("Acquired SimpleDialogPromptViewControllerPrefab [{0}]", SimpleDialogPromptViewControllerPrefab.GetInstanceID()); BeatmapLevelsModel = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().Last(); Logger.Debug("Acquired BeatmapLevelsModel [{0}]", BeatmapLevelsModel); }
private void SetupTweaks() { if (initialized || PluginConfig.disableSongListTweaks) { return; } Logger.Log("Setting up song list tweaks..."); _playlistsFlowCoordinator = (new GameObject("PlaylistsFlowCoordinator")).AddComponent <PlaylistsFlowCoordinator>(); _playlistsFlowCoordinator.didFinishEvent += _playlistsFlowCoordinator_didFinishEvent; _beatmapCharacteristics = Resources.FindObjectsOfTypeAll <BeatmapCharacteristicSO>(); _lastCharacteristic = _beatmapCharacteristics.First(x => x.characteristicName == "Standard"); Resources.FindObjectsOfTypeAll <BeatmapCharacteristicSelectionViewController>().First().didSelectBeatmapCharacteristicEvent += (BeatmapCharacteristicSelectionViewController sender, BeatmapCharacteristicSO selected) => { _lastCharacteristic = selected; }; if (SongLoader.AreSongsLoaded) { _levelCollection = SongLoader.CustomLevelCollectionSO; } else { SongLoader.SongsLoadedEvent += (SongLoader sender, List <CustomLevel> levels) => { _levelCollection = SongLoader.CustomLevelCollectionSO; }; } _mainFlowCoordinator = Resources.FindObjectsOfTypeAll <MainFlowCoordinator>().FirstOrDefault(); _mainFlowCoordinator.GetPrivateField <MainMenuViewController>("_mainMenuViewController").didFinishEvent += SongListTweaks_didFinishEvent; _simpleDialog = ReflectionUtil.GetPrivateField <SimpleDialogPromptViewController>(_mainFlowCoordinator, "_simpleDialogPromptViewController"); _simpleDialog = Instantiate(_simpleDialog.gameObject, _simpleDialog.transform.parent).GetComponent <SimpleDialogPromptViewController>(); _difficultyViewController = Resources.FindObjectsOfTypeAll <BeatmapDifficultyViewController>().FirstOrDefault(); _difficultyViewController.didSelectDifficultyEvent += _difficultyViewController_didSelectDifficultyEvent; _levelListViewController = Resources.FindObjectsOfTypeAll <LevelListViewController>().FirstOrDefault(); _levelListViewController.didSelectLevelEvent += _levelListViewController_didSelectLevelEvent;; RectTransform _tableViewRectTransform = _levelListViewController.GetComponentsInChildren <RectTransform>().First(x => x.name == "TableViewContainer"); _tableViewRectTransform.sizeDelta = new Vector2(0f, -20f); _tableViewRectTransform.anchoredPosition = new Vector2(0f, -2.5f); RectTransform _pageUp = _tableViewRectTransform.GetComponentsInChildren <RectTransform>(true).First(x => x.name == "PageUpButton"); _pageUp.anchoredPosition = new Vector2(0f, -1f); RectTransform _pageDown = _tableViewRectTransform.GetComponentsInChildren <RectTransform>(true).First(x => x.name == "PageDownButton"); _pageDown.anchoredPosition = new Vector2(0f, 1f); _searchButton = _levelListViewController.CreateUIButton("CreditsButton", new Vector2(-20f, 36.25f), new Vector2(20f, 6f), SearchPressed, "Search"); _searchButton.SetButtonTextSize(3f); _searchButton.ToggleWordWrapping(false); _sortByButton = _levelListViewController.CreateUIButton("CreditsButton", new Vector2(0f, 36.25f), new Vector2(20f, 6f), () => { SelectTopButtons(TopButtonsState.SortBy); }, "Sort By"); _sortByButton.SetButtonTextSize(3f); _sortByButton.ToggleWordWrapping(false); _playlistsButton = _levelListViewController.CreateUIButton("CreditsButton", new Vector2(20f, 36.25f), new Vector2(20f, 6f), PlaylistsButtonPressed, "Playlists"); _playlistsButton.SetButtonTextSize(3f); _playlistsButton.ToggleWordWrapping(false); _defButton = _levelListViewController.CreateUIButton("CreditsButton", new Vector2(-20f, 36.25f), new Vector2(20f, 6f), () => { SelectTopButtons(TopButtonsState.Select); SetLevels(_lastCharacteristic, SortMode.Default, ""); }, "Default"); _defButton.SetButtonTextSize(3f); _defButton.ToggleWordWrapping(false); _defButton.gameObject.SetActive(false); _newButton = _levelListViewController.CreateUIButton("CreditsButton", new Vector2(0f, 36.25f), new Vector2(20f, 6f), () => { SelectTopButtons(TopButtonsState.Select); SetLevels(_lastCharacteristic, SortMode.Newest, ""); }, "Newest"); _newButton.SetButtonTextSize(3f); _newButton.ToggleWordWrapping(false); _newButton.gameObject.SetActive(false); _authorButton = _levelListViewController.CreateUIButton("CreditsButton", new Vector2(20f, 36.25f), new Vector2(20f, 6f), () => { SelectTopButtons(TopButtonsState.Select); SetLevels(_lastCharacteristic, SortMode.Difficulty, ""); }, "Difficulty"); _authorButton.SetButtonTextSize(3f); _authorButton.ToggleWordWrapping(false); _authorButton.gameObject.SetActive(false); _detailViewController = Resources.FindObjectsOfTypeAll <StandardLevelDetailViewController>().First(x => x.name == "StandardLevelDetailViewController"); RectTransform buttonsRect = _detailViewController.GetComponentsInChildren <RectTransform>().First(x => x.name == "Buttons"); buttonsRect.anchoredPosition = new Vector2(0f, 10.75f); RectTransform customButtonsRect = Instantiate(buttonsRect, buttonsRect.parent, true); Destroy(customButtonsRect.GetComponent <ContentSizeFitter>()); Destroy(customButtonsRect.GetComponent <HorizontalLayoutGroup>()); customButtonsRect.name = "CustomUIButtonsHolder"; customButtonsRect.anchoredPosition = new Vector2(0f, 1.25f); _favoriteButton = customButtonsRect.GetComponentsInChildren <Button>().First(x => x.name == "PracticeButton"); _favoriteButton.SetButtonIcon(Base64Sprites.AddToFavorites); _favoriteButton.onClick.AddListener(() => { if (PluginConfig.favoriteSongs.Any(x => x.Contains(_detailViewController.difficultyBeatmap.level.levelID))) { PluginConfig.favoriteSongs.Remove(_detailViewController.difficultyBeatmap.level.levelID); PluginConfig.SaveConfig(); _favoriteButton.SetButtonIcon(Base64Sprites.AddToFavorites); PlaylistsCollection.RemoveLevelFromPlaylist(PlaylistsCollection.loadedPlaylists.First(x => x.playlistTitle == "Your favorite songs"), _detailViewController.difficultyBeatmap.level.levelID); } else { PluginConfig.favoriteSongs.Add(_detailViewController.difficultyBeatmap.level.levelID); PluginConfig.SaveConfig(); _favoriteButton.SetButtonIcon(Base64Sprites.RemoveFromFavorites); PlaylistsCollection.AddSongToPlaylist(PlaylistsCollection.loadedPlaylists.First(x => x.playlistTitle == "Your favorite songs"), new PlaylistSong() { levelId = _detailViewController.difficultyBeatmap.level.levelID, songName = _detailViewController.difficultyBeatmap.level.songName, level = SongDownloader.GetLevel(_detailViewController.difficultyBeatmap.level.levelID) }); } }); _deleteButton = customButtonsRect.GetComponentsInChildren <Button>().First(x => x.name == "PlayButton"); _deleteButton.SetButtonText("Delete"); _deleteButton.ToggleWordWrapping(false); _deleteButton.onClick.AddListener(DeletePressed); _deleteButton.GetComponentsInChildren <RectTransform>().First(x => x.name == "GlowContainer").gameObject.SetActive(false); _deleteButton.interactable = !PluginConfig.disableDeleteButton; //based on https://github.com/halsafar/BeatSaberSongBrowser/blob/master/SongBrowserPlugin/UI/Browser/SongBrowserUI.cs#L192 var statsPanel = _detailViewController.GetComponentsInChildren <CanvasRenderer>(true).First(x => x.name == "LevelParamsPanel"); var statTransforms = statsPanel.GetComponentsInChildren <RectTransform>(); var valueTexts = statsPanel.GetComponentsInChildren <TextMeshProUGUI>().Where(x => x.name == "ValueText").ToList(); foreach (RectTransform r in statTransforms) { if (r.name == "Separator") { continue; } r.sizeDelta = new Vector2(r.sizeDelta.x * 0.85f, r.sizeDelta.y * 0.85f); } var _starStatTransform = Instantiate(statTransforms[1], statsPanel.transform, false); _starStatText = _starStatTransform.GetComponentInChildren <TextMeshProUGUI>(); _starStatTransform.GetComponentInChildren <UnityEngine.UI.Image>().sprite = Base64Sprites.StarFull; _starStatText.text = "--"; initialized = true; }
private void SetupTweaks() { _mainFlowCoordinator = FindObjectOfType <MainFlowCoordinator>(); _mainFlowCoordinator.GetPrivateField <MainMenuViewController>("_mainMenuViewController").didFinishEvent += SongListTweaks_didFinishEvent; RectTransform viewControllersContainer = FindObjectsOfType <RectTransform>().First(x => x.name == "ViewControllers"); if (initialized || PluginConfig.disableSongListTweaks) { return; } Logger.Log("Setting up song list tweaks..."); try { var harmony = HarmonyInstance.Create("BeatSaverDownloaderHarmonyInstance"); harmony.PatchAll(Assembly.GetExecutingAssembly()); } catch (Exception e) { Logger.Log("Unable to patch level list! Exception: " + e); } _playlistsFlowCoordinator = new GameObject("PlaylistsFlowCoordinator").AddComponent <PlaylistsFlowCoordinator>(); _playlistsFlowCoordinator.didFinishEvent += _playlistsFlowCoordinator_didFinishEvent; if (SongLoader.AreSongsLoaded) { _levelCollection = SongLoader.CustomLevelCollectionSO; } else { SongLoader.SongsLoadedEvent += (SongLoader sender, List <CustomLevel> levels) => { _levelCollection = SongLoader.CustomLevelCollectionSO; }; } _simpleDialog = ReflectionUtil.GetPrivateField <SimpleDialogPromptViewController>(_mainFlowCoordinator, "_simpleDialogPromptViewController"); _simpleDialog = Instantiate(_simpleDialog.gameObject, _simpleDialog.transform.parent).GetComponent <SimpleDialogPromptViewController>(); _levelListViewController = viewControllersContainer.GetComponentInChildren <LevelPackLevelsViewController>(true); _levelListViewController.didSelectLevelEvent += _levelListViewController_didSelectLevelEvent; _levelPacksViewController = viewControllersContainer.GetComponentInChildren <LevelPacksViewController>(true); _levelPacksViewController.didSelectPackEvent += _levelPacksViewController_didSelectPackEvent; TableView _songSelectionTableView = _levelListViewController.GetComponentsInChildren <TableView>(true).First(); RectTransform _tableViewRectTransform = _levelListViewController.GetComponentsInChildren <RectTransform>(true).First(x => x.name == "LevelsTableView"); _tableViewRectTransform.sizeDelta = new Vector2(0f, -20.5f); _tableViewRectTransform.anchoredPosition = new Vector2(0f, -2.5f); Button _pageUp = _tableViewRectTransform.GetComponentsInChildren <Button>(true).First(x => x.name == "PageUpButton"); (_pageUp.transform as RectTransform).anchoredPosition = new Vector2(0f, -1f); Button _pageDown = _tableViewRectTransform.GetComponentsInChildren <Button>(true).First(x => x.name == "PageDownButton"); (_pageDown.transform as RectTransform).anchoredPosition = new Vector2(0f, 1f); _fastPageUpButton = Instantiate(_pageUp, _tableViewRectTransform, false); (_fastPageUpButton.transform as RectTransform).anchorMin = new Vector2(0.5f, 1f); (_fastPageUpButton.transform as RectTransform).anchorMax = new Vector2(0.5f, 1f); (_fastPageUpButton.transform as RectTransform).anchoredPosition = new Vector2(-26f, 1f); (_fastPageUpButton.transform as RectTransform).sizeDelta = new Vector2(8f, 6f); _fastPageUpButton.GetComponentsInChildren <RectTransform>().First(x => x.name == "BG").sizeDelta = new Vector2(8f, 6f); _fastPageUpButton.GetComponentsInChildren <UnityEngine.UI.Image>().First(x => x.name == "Arrow").sprite = Sprites.DoubleArrow; _fastPageUpButton.onClick.AddListener(delegate() { FastScrollUp(_songSelectionTableView, PluginConfig.fastScrollSpeed); }); _fastPageDownButton = Instantiate(_pageDown, _tableViewRectTransform, false); (_fastPageDownButton.transform as RectTransform).anchorMin = new Vector2(0.5f, 0f); (_fastPageDownButton.transform as RectTransform).anchorMax = new Vector2(0.5f, 0f); (_fastPageDownButton.transform as RectTransform).anchoredPosition = new Vector2(-26f, -1f); (_fastPageDownButton.transform as RectTransform).sizeDelta = new Vector2(8f, 6f); _fastPageDownButton.GetComponentsInChildren <RectTransform>().First(x => x.name == "BG").sizeDelta = new Vector2(8f, 6f); _fastPageDownButton.GetComponentsInChildren <UnityEngine.UI.Image>().First(x => x.name == "Arrow").sprite = Sprites.DoubleArrow; _fastPageDownButton.onClick.AddListener(delegate() { FastScrollDown(_songSelectionTableView, PluginConfig.fastScrollSpeed); }); _randomButton = Instantiate(viewControllersContainer.GetComponentsInChildren <Button>(true).First(x => x.name == "PracticeButton"), _levelListViewController.rectTransform, false); _randomButton.onClick = new Button.ButtonClickedEvent(); _randomButton.onClick.AddListener(() => { int randomRow = UnityEngine.Random.Range(0, _songSelectionTableView.dataSource.NumberOfCells()); _songSelectionTableView.ScrollToCellWithIdx(randomRow, TableView.ScrollPositionType.Beginning, false); _songSelectionTableView.SelectCellWithIdx(randomRow, true); }); _randomButton.name = "CustomUIButton"; (_randomButton.transform as RectTransform).anchorMin = new Vector2(0.5f, 0.5f); (_randomButton.transform as RectTransform).anchorMax = new Vector2(0.5f, 0.5f); (_randomButton.transform as RectTransform).anchoredPosition = new Vector2(35f, 36.25f); (_randomButton.transform as RectTransform).sizeDelta = new Vector2(8.8f, 6f); _randomButton.SetButtonText(""); _randomButton.SetButtonIcon(Sprites.RandomIcon); _randomButton.GetComponentsInChildren <UnityEngine.UI.Image>().First(x => x.name == "Stroke").sprite = Resources.FindObjectsOfTypeAll <Sprite>().First(x => x.name == "RoundRectSmallStroke"); var _randomIconLayout = _randomButton.GetComponentsInChildren <HorizontalLayoutGroup>().First(x => x.name == "Content"); _randomIconLayout.padding = new RectOffset(0, 0, 0, 0); _searchButton = _levelListViewController.CreateUIButton("CreditsButton", new Vector2(-20f, 36.25f), new Vector2(20f, 6f), SearchPressed, "Search"); _searchButton.SetButtonTextSize(3f); _searchButton.ToggleWordWrapping(false); _sortByButton = _levelListViewController.CreateUIButton("CreditsButton", new Vector2(0f, 36.25f), new Vector2(20f, 6f), () => { SelectTopButtons(TopButtonsState.SortBy); }, "Sort By"); _sortByButton.SetButtonTextSize(3f); _sortByButton.ToggleWordWrapping(false); _playlistsButton = _levelListViewController.CreateUIButton("CreditsButton", new Vector2(20f, 36.25f), new Vector2(20f, 6f), PlaylistsButtonPressed, "Playlists"); _playlistsButton.SetButtonTextSize(3f); _playlistsButton.ToggleWordWrapping(false); _defButton = _levelListViewController.CreateUIButton("CreditsButton", new Vector2(-20f, 36.25f), new Vector2(20f, 6f), () => { SelectTopButtons(TopButtonsState.Select); SetLevels(SortMode.Default, ""); }, "Default"); _defButton.SetButtonTextSize(3f); _defButton.ToggleWordWrapping(false); _defButton.gameObject.SetActive(false); _newButton = _levelListViewController.CreateUIButton("CreditsButton", new Vector2(0f, 36.25f), new Vector2(20f, 6f), () => { SelectTopButtons(TopButtonsState.Select); SetLevels(SortMode.Newest, ""); }, "Newest"); _newButton.SetButtonTextSize(3f); _newButton.ToggleWordWrapping(false); _newButton.gameObject.SetActive(false); _difficultyButton = _levelListViewController.CreateUIButton("CreditsButton", new Vector2(20f, 36.25f), new Vector2(20f, 6f), () => { SelectTopButtons(TopButtonsState.Select); SetLevels(SortMode.Difficulty, ""); }, "Difficulty"); _difficultyButton.SetButtonTextSize(3f); _difficultyButton.ToggleWordWrapping(false); _difficultyButton.gameObject.SetActive(false); _detailViewController = viewControllersContainer.GetComponentsInChildren <StandardLevelDetailViewController>(true).First(x => x.name == "LevelDetailViewController"); _detailViewController.didChangeDifficultyBeatmapEvent += _difficultyViewController_didSelectDifficultyEvent; RectTransform buttonsRect = _detailViewController.GetComponentsInChildren <RectTransform>(true).First(x => x.name == "PlayButtons"); _favoriteButton = Instantiate(viewControllersContainer.GetComponentsInChildren <Button>(true).First(x => x.name == "PracticeButton"), buttonsRect, false); _favoriteButton.onClick = new Button.ButtonClickedEvent(); _favoriteButton.onClick.AddListener(() => { if (PluginConfig.favoriteSongs.Any(x => x.Contains(_detailViewController.selectedDifficultyBeatmap.level.levelID))) { PluginConfig.favoriteSongs.Remove(_detailViewController.selectedDifficultyBeatmap.level.levelID); PluginConfig.SaveConfig(); _favoriteButton.SetButtonIcon(Sprites.AddToFavorites); PlaylistsCollection.RemoveLevelFromPlaylist(PlaylistsCollection.loadedPlaylists.First(x => x.playlistTitle == "Your favorite songs"), _detailViewController.selectedDifficultyBeatmap.level.levelID); } else { PluginConfig.favoriteSongs.Add(_detailViewController.selectedDifficultyBeatmap.level.levelID); PluginConfig.SaveConfig(); _favoriteButton.SetButtonIcon(Sprites.RemoveFromFavorites); PlaylistsCollection.AddSongToPlaylist(PlaylistsCollection.loadedPlaylists.First(x => x.playlistTitle == "Your favorite songs"), new PlaylistSong() { levelId = _detailViewController.selectedDifficultyBeatmap.level.levelID, songName = _detailViewController.selectedDifficultyBeatmap.level.songName, level = SongDownloader.GetLevel(_detailViewController.selectedDifficultyBeatmap.level.levelID) }); } }); _favoriteButton.name = "CustomUIButton"; _favoriteButton.SetButtonIcon(Sprites.AddToFavorites); (_favoriteButton.transform as RectTransform).sizeDelta = new Vector2(12f, 8.8f); var _favoriteIconLayout = _favoriteButton.GetComponentsInChildren <HorizontalLayoutGroup>().First(x => x.name == "Content"); _favoriteIconLayout.padding = new RectOffset(3, 3, 0, 0); _favoriteButton.transform.SetAsFirstSibling(); Button practiceButton = buttonsRect.GetComponentsInChildren <Button>().First(x => x.name == "PracticeButton"); (practiceButton.transform as RectTransform).sizeDelta = new Vector2(12f, 8.8f); var _practiceIconLayout = practiceButton.GetComponentsInChildren <HorizontalLayoutGroup>().First(x => x.name == "Content"); _practiceIconLayout.padding = new RectOffset(3, 3, 0, 0); _deleteButton = Instantiate(viewControllersContainer.GetComponentsInChildren <Button>(true).First(x => x.name == "PracticeButton"), buttonsRect, false); _deleteButton.onClick = new Button.ButtonClickedEvent(); _deleteButton.onClick.AddListener(DeletePressed); _deleteButton.name = "CustomUIButton"; _deleteButton.SetButtonIcon(Sprites.DeleteIcon); _deleteButton.interactable = !PluginConfig.disableDeleteButton; (_deleteButton.transform as RectTransform).sizeDelta = new Vector2(8.8f, 8.8f); _deleteButton.GetComponentsInChildren <UnityEngine.UI.Image>().First(x => x.name == "Stroke").sprite = Resources.FindObjectsOfTypeAll <Sprite>().First(x => x.name == "RoundRectSmallStroke"); var _deleteIconLayout = _deleteButton.GetComponentsInChildren <HorizontalLayoutGroup>().First(x => x.name == "Content"); _deleteIconLayout.padding = new RectOffset(0, 0, 1, 1); _deleteButton.transform.SetAsLastSibling(); //based on https://github.com/halsafar/BeatSaberSongBrowser/blob/master/SongBrowserPlugin/UI/Browser/SongBrowserUI.cs#L192 var statsPanel = _detailViewController.GetComponentsInChildren <LevelParamsPanel>(true).First(x => x.name == "LevelParamsPanel"); var statTransforms = statsPanel.GetComponentsInChildren <RectTransform>(true); var valueTexts = statsPanel.GetComponentsInChildren <TextMeshProUGUI>(true).Where(x => x.name == "ValueText").ToList(); foreach (RectTransform r in statTransforms) { if (r.name == "Separator") { continue; } r.sizeDelta = new Vector2(r.sizeDelta.x * 0.85f, r.sizeDelta.y * 0.85f); } var _starStatTransform = Instantiate(statTransforms[1], statsPanel.transform, false); _starStatText = _starStatTransform.GetComponentInChildren <TextMeshProUGUI>(true); _starStatTransform.GetComponentInChildren <UnityEngine.UI.Image>(true).sprite = Sprites.StarFull; _starStatText.text = "--"; ResultsViewController _standardLevelResultsViewController = viewControllersContainer.GetComponentsInChildren <ResultsViewController>(true).First(x => x.name == "StandardLevelResultsViewController"); _standardLevelResultsViewController.continueButtonPressedEvent += _standardLevelResultsViewController_continueButtonPressedEvent; initialized = true; }
private void SetModDetailsData(StandardLevelDetailViewController modDetails, int selectedMod) { modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "SongNameText").text = _mods[selectedMod].Name; modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "DurationText").text = "Author"; modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "DurationValueText").text = _mods[selectedMod].Author; try { Destroy(modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "BPMText").gameObject); Destroy(modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "BPMValueText").gameObject); Destroy(modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "BPMValueText").gameObject); Destroy(modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "NotesCountText").gameObject); Destroy(modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "NotesCountValueText").gameObject); Destroy(modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "DurationText").gameObject); Destroy(modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "DurationValueText").gameObject); Destroy(modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "ObstaclesCountText").gameObject); Destroy(modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "ObstaclesCountValueText").gameObject); Destroy(modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "Title").gameObject); Destroy(modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "HighScoreText").gameObject); Destroy(modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "HighScoreValueText").gameObject); Destroy(modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "MaxComboText").gameObject); Destroy(modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "MaxComboValueText").gameObject); Destroy(modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "MaxRankText").gameObject); Destroy(modDetails.GetComponentsInChildren <TextMeshProUGUI>().First(x => x.name == "MaxRankValueText").gameObject); Destroy(modDetails.GetComponentsInChildren <RectTransform>().First(x => x.name == "YourStats").gameObject); } catch (Exception e) { } if (_toggleButton == null) { _toggleButton = modDetails.GetComponentInChildren <Button>(); } if (_compatibilitytext == null) { // var temp = modDetails.GetComponentsInChildren<TextMeshProUGUI>().First(x => x.name == "DurationText"); //_compatibilitytext = _modMenuUi.CreateTMPText(temp.rectTransform, "a", new Vector2(0.7f, 0.5f)); // ive tried a lot of stuff im sorry for this horrible solution // it's ok ^ - Kaori //_compatibilitytext.text = " This plugin doesnt work with BSMODUI"; } if (true) { //Utils.Log("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); //TODO: IMPLEMENT STUFFS _toggleButton.gameObject.SetActive(true); _modMenuUi.SetButtonText(ref _toggleButton, "Select"); //_compatibilitytext.gameObject.SetActive(false); DestroyImmediate(_toggleButton.GetComponent <GameEventOnUIButtonClick>()); _toggleButton.onClick = new Button.ButtonClickedEvent(); _toggleButton.onClick.AddListener(delegate { Plugin._currentSaberPath = _mods[selected].Path; }); } else { _toggleButton.gameObject.SetActive(false); _compatibilitytext.gameObject.SetActive(true); } }