Example #1
0
 public void OnUpdate()
 {
     if (Input.GetKeyDown(KeyCode.R))
     {
         PlaylistsCollection.ReloadPlaylists();
     }
 }
Example #2
0
 public void OnApplicationStart()
 {
     Sprites.ConvertToSprites();
     PlaylistsCollection.ReloadPlaylists();
     SongCore.Loader.SongsLoadedEvent += Loader_SongsLoadedEvent;
     //  SongCore.Loader.OnLevelPacksRefreshed += ;
 }
Example #3
0
 public void OnUpdate()
 {
     if (Input.GetKeyDown(KeyCode.P))
     {
         PlaylistsCollection.ReloadPlaylists();
         PlaylistsCollection.MatchSongsForAllPlaylists(true);
     }
 }
 private void _playlistDetailViewController_selectButtonPressed(Playlist playlist)
 {
     _playlistDetailViewController.SetSelectButtonState(false);
     StartCoroutine(DownloadPlaylistFile(playlist.fileLoc, (path) => {
         _playlistDetailViewController.SetSelectButtonState(true);
         PlaylistsCollection.ReloadPlaylists(false);
         _playlistsListViewController.Refresh();
     }));
 }
Example #5
0
 public void OnApplicationStart()
 {
     SceneManager.sceneLoaded        += SceneManager_sceneLoaded;
     SceneManager.activeSceneChanged += SceneManager_activeSceneChanged;
     PluginConfig.LoadOrCreateConfig();
     Base64Sprites.ConvertToSprites();
     PlaylistsCollection.ReloadPlaylists();
     SongLoader.SongsLoadedEvent += SongLoader_SongsLoadedEvent;
 }
Example #6
0
 private void SongLoader_SongsLoadedEvent(SongLoader sender, List <CustomLevel> levels)
 {
     try
     {
         PlaylistsCollection.MatchSongsForAllPlaylists(true);
     }
     catch (Exception e)
     {
         Misc.Logger.Exception("Unable to match songs for all playlists! Exception: " + e);
     }
 }
Example #7
0
 public void SongCore_SongsLoadedEvent(SongCore.Loader sender, Dictionary <string, CustomPreviewBeatmapLevel> levels)
 {
     try
     {
         PlaylistsCollection.MatchSongsForAllPlaylists(true);
     }
     catch (Exception e)
     {
         Logger.Exception("Unable to match songs for all playlists! Exception: " + e);
     }
 }
Example #8
0
 public void SongLoader_SongsLoadedEvent(SongLoader sender, List <CustomLevel> levels)
 {
     try
     {
         PlaylistsCollection.MatchSongsForAllPlaylists(true);
     }
     catch (Exception e)
     {
         Plugin.log.Critical("Unable to match songs for all playlists! Exception: " + e);
     }
 }
Example #9
0
        public void OnApplicationStart()
        {
            instance = this;
            PluginConfig.LoadConfig();
            Sprites.ConvertToSprites();
            PlaylistsCollection.ReloadPlaylists();
            SongLoader.SongsLoadedEvent += SongLoader_SongsLoadedEvent;

            BSEvents.OnLoad();
            BSEvents.menuSceneLoadedFresh += OnMenuSceneLoadedFresh;
        }
 private void _playlistDetailViewController_selectButtonPressed(Playlist playlist)
 {
     _playlistDetailViewController.SetSelectButtonState(false);
     StartCoroutine(DownloadPlaylistFile(playlist.fileLoc, (path) => {
         _playlistDetailViewController.SetSelectButtonState(true);
         PlaylistsCollection.ReloadPlaylists(false);
         _playlistsListViewController.Refresh();
         //bananbread playlists levelpacks
         SongListTweaks.Instance.UpdateLevelPacks();
     }));
 }
Example #11
0
        public void OnApplicationStart()
        {
            SceneManager.sceneLoaded        += SceneManager_sceneLoaded;
            SceneManager.activeSceneChanged += SceneManager_activeSceneChanged;;
            PluginConfig.LoadOrCreateConfig();
            Sprites.ConvertToSprites();
            PlaylistsCollection.ReloadPlaylists();
            SongLoader.SongsLoadedEvent += SongLoader_SongsLoadedEvent;

            BSEvents.OnLoad();
            BSEvents.menuSceneLoadedFresh += OnMenuSceneLoadedFresh;
        }
Example #12
0
        protected override void OnClosed(EventArgs e)
        {
            AbortSearch();
            mResults.Dispose();             //Closes down the search thread

            if (mPlaylists != null)
            {
                mPlaylists.Dispose();
                mPlaylists = null;
            }
            base.OnClosed(e);
        }
Example #13
0
        public void OnApplicationStart()
        {
            Instance = this;

            PluginConfig.LoadOrCreateConfig();

            Base64Sprites.Init();

            PlaylistsCollection.ReloadPlaylists();
            SongCore.Loader.SongsLoadedEvent += SongCore_SongsLoadedEvent;

            BSEvents.OnLoad();
            BSEvents.menuSceneLoadedFresh += OnMenuSceneLoadedFresh;
        }
        private List <BeatmapLevelSO> FilterPlaylist()
        {
            // bail if no playlist, usually means the settings stored one the user then moved.
            if (this.CurrentPlaylist == null)
            {
                Logger.Error("Trying to load a null playlist...");
                this.Settings.filterMode = SongFilterMode.None;
                return(null);
            }

            // Get song keys
            PlaylistsCollection.MatchSongsForPlaylist(this.CurrentPlaylist, true);

            Logger.Debug("Filtering songs for playlist: {0}", this.CurrentPlaylist.playlistTitle);

            Dictionary <String, BeatmapLevelSO> levelDict = new Dictionary <string, BeatmapLevelSO>();

            foreach (KeyValuePair <string, List <BeatmapLevelSO> > entry in _levelPackToSongs)
            {
                foreach (BeatmapLevelSO level in entry.Value)
                {
                    if (!levelDict.ContainsKey(level.levelID))
                    {
                        levelDict.Add(level.levelID, level);
                    }
                }
            }

            List <BeatmapLevelSO> songList = new List <BeatmapLevelSO>();

            foreach (PlaylistSong ps in this.CurrentPlaylist.songs)
            {
                if (ps.level != null)
                {
                    songList.Add(levelDict[ps.level.levelID]);
                }
                else
                {
                    Logger.Debug("Could not find song in playlist: {0}", ps.songName);
                }
            }

            Logger.Debug("Playlist filtered song count: {0}", songList.Count);
            return(songList);
        }
        public static void SetPlaylistPacks()
        {
            SongCoreBeatmapLevelPackCollectionSO newCollection            = SongCore.Loader.CustomBeatmapLevelPackCollectionSO;
            List <CustomBeatmapLevelPack>        _customBeatmapLevelPacks = newCollection.GetPrivateField <List <CustomBeatmapLevelPack> >("_customBeatmapLevelPacks");
            List <IBeatmapLevelPack>             _allBeatmapLevelPacks    = newCollection.GetPrivateField <IBeatmapLevelPack[]>("_allBeatmapLevelPacks").ToList();

            _customBeatmapLevelPacks.RemoveAll(x => x.packID.StartsWith($"{CustomLevelLoaderSO.kCustomLevelPackPrefixId}Playlist_"));
            _allBeatmapLevelPacks.RemoveAll(x => x.packID.StartsWith($"{CustomLevelLoaderSO.kCustomLevelPackPrefixId}Playlist_"));

            newCollection.SetPrivateField("_customBeatmapLevelPacks", _customBeatmapLevelPacks);
            newCollection.SetPrivateField("_allBeatmapLevelPacks", _allBeatmapLevelPacks.ToArray());

            foreach (var playlist in PlaylistsCollection.loadedPlaylists)
            {
                var pack = PlaylistsCollection.CreateLevelPackFromPlaylist(playlist);
                Logging.Log.Info($"{pack.packName} {pack.beatmapLevelCollection.beatmapLevels.Count()}");
                newCollection.AddLevelPack(pack);
            }
        }
        public IEnumerator DownloadPlaylist(Playlist playlist)
        {
            PlaylistsCollection.MatchSongsForPlaylist(playlist, true);

            List <PlaylistSong> needToDownload = playlist.songs.Where(x => x.level == null).ToList();

            Logger.Log($"Need to download {needToDownload.Count} songs");

            _downloadingPlaylist = true;
            foreach (var item in needToDownload)
            {
                Song beatSaverSong = null;

                if (String.IsNullOrEmpty(playlist.customArchiveUrl))
                {
                    Logger.Log("Obtaining hash and url for " + item.key + ": " + item.songName);
                    yield return(GetInfoForSong(playlist, item, (Song song) => { beatSaverSong = song; }));
                }
                else
                {
                    string archiveUrl = playlist.customArchiveUrl.Replace("[KEY]", item.key);

                    beatSaverSong = new Song()
                    {
                        songName            = item.songName,
                        id                  = item.key,
                        downloadingProgress = 0f,
                        hash                = (item.levelId == null ? "" : item.levelId),
                        downloadUrl         = archiveUrl
                    };
                }

                if (beatSaverSong != null && !SongLoader.CustomLevels.Any(x => x.levelID.Substring(0, 32) == beatSaverSong.hash.ToUpper()))
                {
                    _downloadQueueViewController.EnqueueSong(beatSaverSong, true);
                }
            }
            _downloadingPlaylist = false;
        }
        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
                });
            }
        }
Example #18
0
        private void ConnectToFoobar()
        {
            try
            {
                if (mPlaylists != null)
                {
                    mPlaylists.Dispose();
                }

                mFoobar    = new Foobar2000.Application07Class();
                mPlaylists = new PlaylistsCollection(mFoobar);
            }
            catch (Exception ex)
            {
                mFoobar    = null;
                mPlaylists = null;
                System.Diagnostics.Trace.TraceWarning("Foobar2000 COM server could not be instantiated: " + ex.Message);
            }
            NotifyPropertyChanged("FoobarPresent");
            NotifyPropertyChanged("FoobarVersion");
            NotifyPropertyChanged("FoobarPlaylists");
            SelectedPlaylistIndex = 0;             //Should always be "Entire Library"
        }
        /// <summary>
        /// Get the song cache from the game.
        /// </summary>
        public void UpdateLevelRecords()
        {
            Stopwatch timer = new Stopwatch();

            timer.Start();

            // Calculate some information about the custom song dir
            String customSongsPath                   = Path.Combine(Environment.CurrentDirectory, CUSTOM_SONGS_DIR);
            String revSlashCustomSongPath            = customSongsPath.Replace('\\', '/');
            double currentCustomSongDirLastWriteTIme = (File.GetLastWriteTimeUtc(customSongsPath) - EPOCH).TotalMilliseconds;
            bool   customSongDirChanged              = false;

            if (_customSongDirLastWriteTime != currentCustomSongDirLastWriteTIme)
            {
                customSongDirChanged        = true;
                _customSongDirLastWriteTime = currentCustomSongDirLastWriteTIme;
            }

            if (!Directory.Exists(customSongsPath))
            {
                Logger.Error("CustomSong directory is missing...");
                return;
            }

            // Map some data for custom songs
            Regex     r = new Regex(@"(\d+-\d+)", RegexOptions.IgnoreCase);
            Stopwatch lastWriteTimer = new Stopwatch();

            lastWriteTimer.Start();
            foreach (KeyValuePair <string, CustomPreviewBeatmapLevel> level in SongCore.Loader.CustomLevels)
            {
                // If we already know this levelID, don't both updating it.
                // SongLoader should filter duplicates but in case of failure we don't want to crash
                if (!_cachedLastWriteTimes.ContainsKey(level.Value.levelID) || customSongDirChanged)
                {
                    double lastWriteTime = GetSongUserDate(level.Value);
                    _cachedLastWriteTimes[level.Value.levelID] = lastWriteTime;
                }
            }

            lastWriteTimer.Stop();
            Logger.Info("Determining song download time and determining mappings took {0}ms", lastWriteTimer.ElapsedMilliseconds);

            // Update song Infos, directory tree, and sort
            this.UpdatePlayCounts();

            // Check if we need to upgrade settings file favorites
            try
            {
                this.Settings.ConvertFavoritesToPlaylist(SongCore.Loader.CustomLevels);
            }
            catch (Exception e)
            {
                Logger.Exception("FAILED TO CONVERT FAVORITES TO PLAYLIST!", e);
            }

            // load the current editing playlist or make one
            if (CurrentEditingPlaylist == null && !String.IsNullOrEmpty(this.Settings.currentEditingPlaylistFile))
            {
                Logger.Debug("Loading playlist for editing: {0}", this.Settings.currentEditingPlaylistFile);
                CurrentEditingPlaylist = Playlist.LoadPlaylist(this.Settings.currentEditingPlaylistFile);
                PlaylistsCollection.MatchSongsForPlaylist(CurrentEditingPlaylist, true);
            }

            if (CurrentEditingPlaylist == null)
            {
                Logger.Debug("Current editing playlist does not exit, create...");
                CurrentEditingPlaylist = new Playlist
                {
                    playlistTitle  = "Song Browser Favorites",
                    playlistAuthor = "SongBrowser",
                    fileLoc        = this.Settings.currentEditingPlaylistFile,
                    image          = Base64Sprites.SpriteToBase64(Base64Sprites.BeastSaberLogo),
                    songs          = new List <PlaylistSong>(),
                };
            }

            CurrentEditingPlaylistLevelIds = new HashSet <string>();
            foreach (PlaylistSong ps in CurrentEditingPlaylist.songs)
            {
                // Sometimes we cannot match a song
                string levelId = null;
                if (ps.level != null)
                {
                    levelId = ps.level.levelID;
                }
                else if (!String.IsNullOrEmpty(ps.levelId))
                {
                    levelId = ps.levelId;
                }
                else
                {
                    //Logger.Debug("MISSING SONG {0}", ps.songName);
                    continue;
                }

                CurrentEditingPlaylistLevelIds.Add(levelId);
            }

            // Signal complete
            if (SongCore.Loader.CustomLevels.Count > 0)
            {
                didFinishProcessingSongs?.Invoke(SongCore.Loader.CustomLevels);
            }

            timer.Stop();

            Logger.Info("Updating songs infos took {0}ms", timer.ElapsedMilliseconds);
        }
        /// <summary>
        /// Get the song cache from the game.
        /// </summary>
        public void UpdateLevelRecords()
        {
            Stopwatch timer = new Stopwatch();

            timer.Start();

            // Calculate some information about the custom song dir
            String customSongsPath                   = Path.Combine(Environment.CurrentDirectory, CUSTOM_SONGS_DIR);
            String revSlashCustomSongPath            = customSongsPath.Replace('\\', '/');
            double currentCustomSongDirLastWriteTIme = (File.GetLastWriteTimeUtc(customSongsPath) - EPOCH).TotalMilliseconds;
            bool   customSongDirChanged              = false;

            if (_customSongDirLastWriteTime != currentCustomSongDirLastWriteTIme)
            {
                customSongDirChanged        = true;
                _customSongDirLastWriteTime = currentCustomSongDirLastWriteTIme;
            }

            if (!Directory.Exists(customSongsPath))
            {
                Logger.Error("CustomSong directory is missing...");
                return;
            }
            IEnumerable <string> directories = Directory.EnumerateDirectories(customSongsPath, "*.*", SearchOption.AllDirectories);

            // Get LastWriteTimes
            Stopwatch lastWriteTimer = new Stopwatch();

            lastWriteTimer.Start();
            foreach (var level in SongLoader.CustomLevels)
            {
                // If we already know this levelID, don't both updating it.
                // SongLoader should filter duplicates but in case of failure we don't want to crash
                if (!_cachedLastWriteTimes.ContainsKey(level.levelID) || customSongDirChanged)
                {
                    // Always use the newest date.
                    var lastWriteTime  = File.GetLastWriteTimeUtc(level.customSongInfo.path);
                    var lastCreateTime = File.GetCreationTimeUtc(level.customSongInfo.path);
                    var lastTime       = lastWriteTime > lastCreateTime ? lastWriteTime : lastCreateTime;
                    _cachedLastWriteTimes[level.levelID] = (lastTime - EPOCH).TotalMilliseconds;
                }

                if (!_levelIdToCustomLevel.ContainsKey(level.levelID))
                {
                    _levelIdToCustomLevel.Add(level.levelID, level);
                }

                if (!_levelIdToSongVersion.ContainsKey(level.levelID))
                {
                    DirectoryInfo info = new DirectoryInfo(level.customSongInfo.path);
                    string        currentDirectoryName = info.Name;

                    String version = level.customSongInfo.path.Replace(revSlashCustomSongPath, "").Replace(currentDirectoryName, "").Replace("/", "");
                    if (!String.IsNullOrEmpty(version))
                    {
                        _levelIdToSongVersion.Add(level.levelID, version);

                        if (!_keyToSong.ContainsKey(version))
                        {
                            _keyToSong.Add(version, level);
                        }
                    }
                }
            }

            lastWriteTimer.Stop();
            Logger.Info("Determining song download time and determining mappings took {0}ms", lastWriteTimer.ElapsedMilliseconds);

            // Update song Infos, directory tree, and sort
            this.UpdateScoreSaberDataMapping();
            this.UpdatePlayCounts();

            // Check if we need to upgrade settings file favorites
            try
            {
                this.Settings.ConvertFavoritesToPlaylist(_levelIdToCustomLevel, _levelIdToSongVersion);
            }
            catch (Exception e)
            {
                Logger.Exception("FAILED TO CONVERT FAVORITES TO PLAYLIST!", e);
            }

            // load the current editing playlist or make one
            if (CurrentEditingPlaylist == null && !String.IsNullOrEmpty(this.Settings.currentEditingPlaylistFile))
            {
                Logger.Debug("Loading playlist for editing: {0}", this.Settings.currentEditingPlaylistFile);
                CurrentEditingPlaylist = Playlist.LoadPlaylist(this.Settings.currentEditingPlaylistFile);
                PlaylistsCollection.MatchSongsForPlaylist(CurrentEditingPlaylist);
            }

            if (CurrentEditingPlaylist == null)
            {
                Logger.Debug("Current editing playlist does not exit, create...");
                CurrentEditingPlaylist = new Playlist
                {
                    playlistTitle  = "Song Browser Favorites",
                    playlistAuthor = "SongBrowser",
                    fileLoc        = this.Settings.currentEditingPlaylistFile,
                    image          = Base64Sprites.PlaylistIconB64,
                    songs          = new List <PlaylistSong>(),
                };
            }

            CurrentEditingPlaylistLevelIds = new HashSet <string>();
            foreach (PlaylistSong ps in CurrentEditingPlaylist.songs)
            {
                // Sometimes we cannot match a song
                if (ps.level == null)
                {
                    continue;
                }

                CurrentEditingPlaylistLevelIds.Add(ps.level.levelID);
            }

            // Actually sort and filter
            //this.ProcessSongList();

            // Signal complete
            if (SongLoader.CustomLevels.Count > 0)
            {
                didFinishProcessingSongs?.Invoke(SongLoader.CustomLevels);
            }

            timer.Stop();

            Logger.Info("Updating songs infos took {0}ms", timer.ElapsedMilliseconds);
        }
Example #21
0
 private void Loader_SongsLoadedEvent(SongCore.Loader arg1, Dictionary <string, CustomPreviewBeatmapLevel> arg2)
 {
     PlaylistsCollection.MatchSongsForAllPlaylists();
     //   DebugLogPlaylists();
 }
Example #22
0
        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;
        }
Example #23
0
 private void SongLoader_SongsLoadedEvent(SongLoader sender, List <CustomLevel> levels)
 {
     PlaylistsCollection.MatchSongsForAllPlaylists(true);
 }
Example #24
0
        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;
        }