private static void AddButtons(OptionsMenu optionsMenu) { var header = optionsMenu.AddHeader(0, "Filter by: Artist, Title, Mapper"); optionsMenu.scrollable.AddRow(header); var searchField = optionsMenu.AddButton(0, "Search:", new Action(() => { SongBrowser.shouldShowKeyboard = true; optionsMenu.keyboard.Show(); }), null, "Filter by: Artist, Title, Mapper", optionsMenu.textEntryButtonPrefab); optionsMenu.scrollable.AddRow(searchField.gameObject); searchText = searchField.gameObject.GetComponentInChildren <TextMeshPro>(); var difficultyHeader = optionsMenu.AddHeader(0, "Filter difficulty"); optionsMenu.scrollable.AddRow(difficultyHeader); string difficultyFilterText = difficultyFilter.ToString(); difficultyToggle = optionsMenu.AddButton (0, difficultyFilterText, new Action(() => { difficultyFilter++; if ((int)difficultyFilter > 4) { difficultyFilter = 0; } difficultyToggle.label.text = difficultyFilter.ToString(); SongBrowser.page = 1; SongBrowser.StartSongSearch(); }), null, "Filters the search to the selected difficulty"); difficultyToggle.button.doMeshExplosion = false; difficultyToggle.button.doParticles = false; optionsMenu.scrollable.AddRow(difficultyToggle.gameObject); var extraHeader = optionsMenu.AddHeader(0, "Extra"); optionsMenu.scrollable.AddRow(extraHeader); string curatedFilterText = "Curated only: " + curated.ToString(); curatedToggle = optionsMenu.AddButton (0, curatedFilterText, new Action(() => { if (curated) { curated = false; } else { curated = true; } curatedToggle.label.text = "Curated only: " + curated.ToString(); SongBrowser.page = 1; SongBrowser.StartSongSearch(); }), null, "Filters the search to curated maps only"); curatedToggle.button.doMeshExplosion = false; curatedToggle.button.doParticles = false; optionsMenu.scrollable.AddRow(curatedToggle.gameObject); var downloadFullPage = optionsMenu.AddButton (1, "Download current page", new Action(() => { DownloadFullPage(); }), null, "Downloads all songs from the current page, this will cause major stutters"); var RestoreSongs = optionsMenu.AddButton (0, "Restore Deleted Songs", new Action(() => { SongBrowser.RestoreDeletedSongs(); }), null, "Restores all the songs you have deleted."); //optionsMenu.scrollable.AddRow(RestoreSongs.gameObject); string popularityFilterText = "Sort by playcount: " + popularity.ToString(); popularityToggle = optionsMenu.AddButton (1, popularityFilterText, new Action(() => { if (popularity) { popularity = false; } else { popularity = true; } popularityToggle.label.text = "Sort by playcount: " + popularity.ToString(); SongBrowser.page = 1; SongBrowser.StartSongSearch(); }), null, "Sorts downloads by leaderboard scores rather than date."); popularityToggle.button.doMeshExplosion = false; popularityToggle.button.doParticles = false; optionsMenu.scrollable.AddRow(popularityToggle.gameObject); var downloadFolderBlock = optionsMenu.AddTextBlock(0, "You can hotload songs by placing them in Audica/Downloads and pressing F5"); optionsMenu.scrollable.AddRow(downloadFolderBlock); }
/// <summary> /// Coroutine that searches for songs using the web API /// </summary> /// <param name="search">Query text, e.g. song name, artist or mapper (partial matches possible)</param> /// <param name="onSearchComplete">Called with search result once search is completed, use to process search result</param> /// <param name="difficulty">Only find songs with given difficulty</param> /// <param name="curated">Only find songs that are curated</param> /// <param name="sortByPlayCount">Sort result by play count</param> /// <param name="page">Page to return (see APISongList.total_pages after initial search (page = 1) to check if multiple pages exist)</param> /// <param name="total">Bypasses all query and filter limitations and just returns entire song list (or max page size)</param> public static IEnumerator DoSongWebSearch(string search, Action <string, APISongList> onSearchComplete, DifficultyFilter difficulty, bool curated = false, bool sortByPlayCount = false, int page = 1, bool total = false, bool searchIsFilename = false) { if (UseNewAPI) { if (total) { string webSearch = "https://beta.maudica.com/api/maps?per_page=100&page={0}"; // initial search to initialize result list WWW www = new WWW(string.Format(webSearch, 1)); yield return(www); NewAPISongList list = JSON.Load(www.text).Make <NewAPISongList>(); APISongList result = new APISongList(); result.song_count = list.count; result.page = 1; result.pagesize = list.count; result.total_pages = 1; result.songs = new Song[list.count]; int numPages = (int)Math.Ceiling((double)list.count / 100); int currPage = 1; ConvertAPIList(list, result, 0); while (currPage <= numPages) { currPage++; www = new WWW(string.Format(webSearch, currPage)); yield return(www); list = JSON.Load(www.text).Make <NewAPISongList>(); ConvertAPIList(list, result, 100 * (currPage - 1)); } onSearchComplete(search, result); } else { string webSearch; string concatURL; if (searchIsFilename) { webSearch = search == null || search == "" ? "" : "&filename=" + WebUtility.UrlEncode(search); concatURL = newApiUrl + webSearch; } else { webSearch = search == null || search == "" ? "" : "&search=" + WebUtility.UrlEncode(search); string webPage = page == 1 ? "" : "&page=" + page.ToString(); string webDifficulty = difficulty == DifficultyFilter.All ? "" : "&difficulties%5B%5D=" + DifficultyToNewAPIValue(difficulty); string webDownloads = sortByPlayCount ? "&sort=downloads" : ""; concatURL = newApiUrl + webSearch + webDifficulty + webPage + webDownloads; } WWW www = new WWW(concatURL); yield return(www); NewAPISongList list = JSON.Load(www.text).Make <NewAPISongList>(); // convert to existing SongList format, then return APISongList result = new APISongList(); result.song_count = list.count; result.page = page; result.pagesize = 14; result.total_pages = (int)Math.Ceiling(result.song_count / (double)result.pagesize); result.songs = new Song[list.maps.Length]; ConvertAPIList(list, result, 0); onSearchComplete(search, result); } } else { string webSearch = search == null || search == "" ? "" : "&search=" + WebUtility.UrlEncode(search); string webPage = page == 1 ? "" : "&page=" + page.ToString(); string diff = difficulty.ToString(); string webDifficulty = diff == "All" ? "" : "&" + diff.ToLower() + "=true"; string webCurated = curated ? "&curated=true" : ""; string webPlaycount = sortByPlayCount ? "&sort=leaderboards" : ""; string concatURL = !total ? apiURL + webSearch + webDifficulty + webPage + webCurated + webPlaycount : "http://www.audica.wiki:5000/api/customsongs?pagesize=all"; WWW www = new WWW(concatURL); yield return(www); onSearchComplete(search, JSON.Load(www.text).Make <APISongList>()); } }