/// <summary> /// Occurs when we downloaded a loadout from Battleclinic /// </summary> /// <param name="feed"></param> /// <param name="errorMessage"></param> /// <returns></returns> private void OnLoadoutDownloaded(SerializableLoadoutFeed loadoutFeed, string errorMessage) { if (this.IsDisposed) { return; } // Reset the controls btnPlan.Enabled = false; m_prerequisites.Clear(); tvLoadout.Nodes.Clear(); Cursor.Current = Cursors.Default; // Was there an error ? if (!String.IsNullOrEmpty(errorMessage) || loadoutFeed.Race.Loadouts.Length == 0) { lblTrainTime.Text = "Couldn't download that loadout.\r\n" + errorMessage; lblTrainTime.Visible = true; return; } var loadout = loadoutFeed.Race.Loadouts[0]; // Fill the items tree var slotTypes = loadout.Slots.GroupBy(x => x.SlotType); foreach (var slotType in slotTypes) { TreeNode typeNode = new TreeNode(s_typeMap[slotType.Key]); foreach (var slot in slotType) { Item item = StaticItems.GetItem(slot.ItemID); if (item == null) { continue; } TreeNode slotNode = new TreeNode(); slotNode.Text = item.Name; slotNode.Tag = item; typeNode.Nodes.Add(slotNode); m_prerequisites.AddRange(item.Prerequisites); } tvLoadout.Nodes.Add(typeNode); } // Compute the training time UpdatePlanningControls(); tvLoadout.ExpandAll(); }
/// <summary> /// Occurs when we downloaded a loadouts feed from Battleclinic /// </summary> /// <param name="feed"></param> /// <param name="errorMessage"></param> /// <returns></returns> private void OnLoadoutFeedDownloaded(SerializableLoadoutFeed feed, string errorMessage) { if (this.IsDisposed) { return; } // Restore the default cursor instead of the waiting one Cursor.Current = Cursors.Default; m_selectedLoadout = null; btnLoad.Enabled = false; btnPlan.Enabled = false; // Was there an error ? if (!String.IsNullOrEmpty(errorMessage)) { lblShip.Text = "There was a problem connecting to Battleclinic, it may be down for maintainance.\r\n" + errorMessage; return; } // Are there no feeds ? if (feed.Race == null || feed.Race.Loadouts.Length == 0) { lblShip.Text = "There are no loadouts for " + m_ship.Name + ", why not submit one to Battleclinic?"; return; } // Add the listview items for every loadout lvLoadouts.Items.Clear(); foreach (SerializableLoadout loadout in feed.Race.Loadouts) { ListViewItem lvi = new ListViewItem(loadout.LoadoutName); lvi.Text = loadout.LoadoutName; lvi.SubItems.Add(loadout.Author); lvi.SubItems.Add(loadout.rating.ToString()); lvi.SubItems.Add(loadout.SubmissionDateString); lvi.Tag = loadout; lvLoadouts.Items.Add(lvi); } // Update the header lblShip.Text = "Found " + lvLoadouts.Items.Count.ToString() + " loadouts"; // Update the listview's comparer and sort lvLoadouts.Sort(); // Enable the "load" button btnLoad.Enabled = true; }