/// <summary> /// Builds the tree view. /// </summary> private void BuildTreeView() { m_objects.Clear(); ResultsTreeView.Nodes.Clear(); // Decode EFT format if (m_loadoutFormat == LoadoutFormat.EFT) { m_loadoutInfo = LoadoutHelper.DeserializeEftFormat(m_clipboardText); } // Decode XML format if (m_loadoutFormat == LoadoutFormat.XML) { m_loadoutInfo = LoadoutHelper.DeserializeXmlFormat(m_clipboardText); } // Decode DNA format if (m_loadoutFormat == LoadoutFormat.DNA) { m_loadoutInfo = LoadoutHelper.DeserializeDnaFormat(m_clipboardText); } // Decode CLF format if (m_loadoutFormat == LoadoutFormat.CLF) { m_loadoutInfo = LoadoutHelper.DeserializeClfFormat(m_clipboardText); } if (m_loadoutInfo == null || !m_loadoutInfo.Loadouts.Any()) { return; } LoadoutNameLabel.Text = $"Name: {m_loadoutInfo.Loadouts.First().Name}{(m_loadoutFormat == LoadoutFormat.DNA ? " - DNA loadout" : String.Empty)}" .WordWrap(55); ShipTypeNameLabel.Text = $"Ship: {(m_loadoutInfo.Ship?.Name ?? String.Empty)}" .WordWrap(55); DescriptionLabel.Text = $"Description: {m_loadoutInfo.Loadouts.First().Description}" .WordWrap(55); m_objects.Add(m_loadoutInfo.Ship); BuildTreeNodes(m_loadoutInfo.Loadouts.First().Items); // Order the nodes TreeNode[] orderNodes = ResultsTreeView.Nodes.Cast <TreeNode>().OrderBy( node => LoadoutHelper.OrderedSlotNames.IndexOf(String.Intern(node.Text))).ToArray(); ResultsTreeView.Nodes.Clear(); ResultsTreeView.Nodes.AddRange(orderNodes); // Update the controls UpdatePlanStatus(); ResultsTreeView.ExpandAll(); ResultsTreeView.Enabled = true; Cursor = Cursors.Default; m_allExpanded = true; }
/// <summary> /// Treeview's context menu > Expand all. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmiExpandAll_Click(object sender, EventArgs e) { ResultsTreeView.ExpandAll(); m_allExpanded = true; }
/// <summary> /// Occur when the user changed the text box whiere he should paste the data from EFT. /// We rebuimd the objects list and update the right pane. /// </summary> /// <param name="sender">Source of the event.</param> /// <param name="e">Arguments of the event.</param> private void tbEFTLoadout_TextChanged(object sender, EventArgs e) { m_objects.Clear(); m_loadoutName = ""; ResultsTreeView.Nodes.Clear(); // If the box is empty, error if (PasteTextBox.Lines.Length == 0) { ResultsTreeView.Nodes.Add("Cannot determine ship type"); ResultsTreeView.Enabled = false; return; } // Error on first line ? string line = PasteTextBox.Lines[0]; if (String.IsNullOrEmpty(line) || !line.StartsWith("[") || !line.Contains(",")) { ResultsTreeView.Nodes.Add("Cannot determine ship type"); ResultsTreeView.Enabled = false; return; } // Retrieve the ship int commaIndex = line.IndexOf(','); string shipTypeName = line.Substring(1, commaIndex - 1); Item ship = StaticItems.Ships.AllItems.FirstOrDefault(x => x.Name == shipTypeName); if (ship != null) { m_objects.Add(ship); } else { // Couldn't find that ship ResultsTreeView.Nodes.Add("Cannot determine ship type"); ResultsTreeView.Enabled = false; return; } // Retrieve the loadout name int lineLength = line.Length; m_loadoutName = line.Substring(commaIndex + 1, (lineLength - commaIndex - 2)); // Add the items for (int i = 1; i < PasteTextBox.Lines.Length; i++) { line = PasteTextBox.Lines[i]; if (!String.IsNullOrEmpty(line)) { AddItem(line); } } // Update the controls UpdatePlanStatus(); ResultsTreeView.ExpandAll(); ResultsTreeView.Enabled = true; Cursor.Current = Cursors.Default; }