Example #1
0
        public static void RefreshData(IBeatmapLevel song = null)
        {
            try
            {
                Logger.Debug("Refresh waiting menu data");
                if (queuedSong == null)
                {
                    if (song == null)
                    {
                        song = SongListUtils.GetInstalledSong();
                    }
                    Logger.Debug($"Refresh Waiting Menu data - Song is {(song != null ? "not" : "")} loaded");
                    if (song != null)
                    {
                        level.text = $"Queued: { song.songName} by { song.songAuthorName }";
                        if (song is CustomLevel)
                        {
                            SongLoader.Instance.LoadAudioClipForLevel((CustomLevel)song, (customLevel) =>
                            {
                                Logger.Debug($"Loaded audio Clip for {song.songName}");
                                ReadyUp(customLevel);
                            });
                        }
                        else
                        {
                            ReadyUp(song);
                        }
                    }
                    else if (!downloading)
                    {
                        level.text = $"Downloading: { SteamAPI.GetSongName()}";

                        Logger.Debug($"We do not have the song in our library, lets start downloading it.");
                        downloading = true;
                        try
                        {
                            Utils.SongDownloader.Instance.StartCoroutine(Utils.SongDownloader.Instance.DownloadSong(SteamAPI.GetSongId(), LevelDownloadProgress, LevelDownloaded, LevelError));
                        } catch (Exception e)
                        {
                            LevelError(e.Message);
                            Logger.Error(e);
                        }
                    }
                }
                Dictionary <string, float> status = Controllers.PlayerController.Instance.GetConnectedPlayerDownloadStatus();
                middleViewController.Data.Clear();
                foreach (KeyValuePair <string, float> user in status.OrderBy(u => u.Value))
                {
                    Logger.Debug($"{user.Key}: {user.Value}");
                    CustomCellInfo cell = new CustomCellInfo(user.Key, user.Value == -1f ? "FAILED TO DOWNLOAD": user.Value == 1f ? "Ready" : $"Downloading song {(int) Math.Round(user.Value * 100, 0)}%", user.Value == 1f ? Sprites.checkmarkIcon : Sprites.crossIcon);
                    middleViewController.Data.Add(cell);
                }
                middleViewController._customListTableView.ReloadData();
                middleViewController._customListTableView.ScrollToCellWithIdx(0, TableView.ScrollPositionType.Beginning, false);
            }
            catch (Exception e)
            {
                Logger.Debug($"Exception: {e}");
                Logger.Error(e);
            }
        }