/// <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> /// When the mouse moves over the list, we change the cursor. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param> private void tvLoadout_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { return; } ResultsTreeView.Cursor = ResultsTreeView.GetNodeAt(e.Location)?.Tag != null ? CustomCursors.ContextMenu : Cursors.Default; }
/// <summary> /// Pops up the context menu for the TreeView. /// </summary> /// <param name="sender">Source of the event.</param> /// <param name="e">Arguments of the event.</param> private void tvLoadout_MouseUp(object sender, MouseEventArgs e) { // Show menu only if the right mouse button is clicked if (e.Button != MouseButtons.Right) { return; } ResultsTreeView.Cursor = Cursors.Default; // Get the node that the user has clicked ResultsTreeView.SelectedNode = ResultsTreeView.GetNodeAt(e.Location); // Select the node the user has clicked contextMenu.Show(ResultsTreeView, e.Location); }
/// <summary> /// Pops up the context menu for the TreeView. /// </summary> /// <param name="sender">Source of the event.</param> /// <param name="e">Arguments of the event.</param> private void tvLoadout_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { // Show menu only if the right mouse button is clicked. if (e.Button == MouseButtons.Right) { // Point where the mouse is clicked. Point p = new Point(e.X, e.Y); // Get the node that the user has clicked. TreeNode node = ResultsTreeView.GetNodeAt(p); if (node != null && node.Tag != null) { // Select the node the user has clicked. ResultsTreeView.SelectedNode = node; RightClickContextMenuStrip.Show(ResultsTreeView, p); } } }
/// <summary> /// Treeview's context menu > Collapse all. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmiCollapseAll_Click(object sender, EventArgs e) { ResultsTreeView.CollapseAll(); m_allExpanded = false; }
/// <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; }