/// <summary> /// Called when the download button has been clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnDownloadButtonClicked(object sender, EventArgs e) { // Go to song select if host if (OnlineManager.CurrentGame?.HostId == OnlineManager.Self.OnlineUser.Id) { var game = (QuaverGame)GameBase.Game; var screen = game.CurrentScreen as MultiplayerScreen; screen?.Exit(() => new SelectScreen(screen), 0, QuaverScreenChangeType.AddToStack); return; } if (Game.MapsetId == -1 || !OnlineManager.CurrentGame.PlayersWithoutMap.Contains(OnlineManager.Self.OnlineUser.Id)) { return; } if (CurrentDownload != null) { if (CurrentDownload.MapsetId == Game.MapsetId) { NotificationManager.Show(NotificationLevel.Error, "The mapset is already downloading. Slow down!"); return; } // ReSharper disable twice DelegateSubtraction CurrentDownload.Progress.ValueChanged -= OnDownloadProgressChanged; CurrentDownload.Completed.ValueChanged -= OnDownloadCompleted; } CurrentDownload = MapsetDownloadManager.Download(Game.MapsetId); CurrentDownload.Progress.ValueChanged += OnDownloadProgressChanged; CurrentDownload.Completed.ValueChanged += OnDownloadCompleted; }
/// <summary> /// Called when /// </summary> public void OnClicked() { var screen = (DownloadScreen)Container.View.Screen; // On the very first click of this mapset, set the bindables value // so that the download status can be aware of this clicked on mapset. if (screen.SelectedMapset.Value != this) { screen.SelectedMapset.Value = this; return; } if (Download != null) { NotificationManager.Show(NotificationLevel.Error, "This mapset is already downloading!"); return; } screen.SelectedMapset.Value = null; // Begin downloading the map. Download = MapsetDownloadManager.Download(Mapset); if (Download == null) { return; } // Update the progress bar Download.Progress.ValueChanged += (o, e) => Progress.Bindable.Value = e.Value.ProgressPercentage; // Handle download completions. Download.Completed.ValueChanged += (o, e) => { if (e.Value.Cancelled) { NotificationManager.Show(NotificationLevel.Info, $"Cancelled download for mapset: {MapsetId}!"); } else if (e.Value.Error == null) { NotificationManager.Show(NotificationLevel.Success, $"Downloaded: {Mapset["artist"]} - {Mapset["title"]}!"); // Animate it off-screen MoveToX(-Width, Easing.OutQuint, 400); // Remove the mapset from the list and destroy it. Container.Mapsets.Remove(this); ThreadScheduler.RunAfter(Destroy, 450); Container.RealignMapsets(); } else { NotificationManager.Show(NotificationLevel.Error, $"An error has occurred while downloading: {MapsetId}."); } }; }