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 _songDetailViewController_favoriteButtonPressed(Song song) { if (PluginConfig.favoriteSongs.Any(x => x.Contains(song.hash))) { PluginConfig.favoriteSongs.Remove(SongDownloader.GetLevelID(song)); PluginConfig.SaveConfig(); _songDetailViewController.SetFavoriteState(false); PlaylistsCollection.RemoveLevelFromPlaylist(PlaylistsCollection.loadedPlaylists.First(x => x.playlistTitle == "Your favorite songs"), SongDownloader.GetLevelID(song)); } else { PluginConfig.favoriteSongs.Add(SongDownloader.GetLevelID(song)); PluginConfig.SaveConfig(); _songDetailViewController.SetFavoriteState(true); PlaylistsCollection.AddSongToPlaylist(PlaylistsCollection.loadedPlaylists.First(x => x.playlistTitle == "Your favorite songs"), new PlaylistSong() { levelId = SongDownloader.GetLevelID(song), songName = song.songName, level = SongDownloader.GetLevel(SongDownloader.GetLevelID(song)), key = song.id }); } }
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; }