private void PopulateTree(TreeNode pNode, ImageList images, InvMarketGroup pGroup) { // Lazy loading of child nodes to improve performance. if (pGroup == null) { // Already added children. return; } int groupID = pGroup.marketGroupID; // Get child groups. List <InvMarketGroup> groups = InvMarketGroup.GetGroupChildren(groupID); groups = groups.OrderBy(g => g.marketGroupName).ToList(); // Get types for group. List <InvType> groupTypes = InvType.GetMarketGroupTypes(groupID); //groupTypes = groupTypes.OrderBy(g => g.name).ToList(); groupTypes.Sort((a, b) => { InvMetaType mA = InvMetaType.GetMetaType(a.typeID); InvMetaType mB = InvMetaType.GetMetaType(b.typeID); if (mA == null) { if (mB == null) { // Both null, sort by name. return(a.name.CompareTo(b.name)); } // A is null it goes first. return(-1); } if (mB == null) { // B is null it goes first. return(1); } // Neither null, compare by meta level. int cmp = mA.metaGroupID.CompareTo(mB.metaGroupID); if (cmp != 0) { return(cmp); } // Same level, compare by name. return(a.name.CompareTo(b.name)); }); // Begin update. marketTree.BeginUpdate(); // Clear the subtree. pNode.Nodes.Clear(); // Add the child groups. PopulateTreeGroups(pNode.Nodes, images, groups); // Add types to group. foreach (InvType type in groupTypes) { if (!type.published) { continue; } TreeNode tNode = pNode.Nodes.Add(type.name); tNode.Tag = type; // Add image. string imgName = "type:" + type.typeID.ToString(); Image img = ImageManager.GetTypeImage(type.typeID, 64, true); if (img != null) { images.Images.Add(imgName, img); } tNode.ImageKey = imgName; tNode.SelectedImageKey = imgName; } // Clear the tag so we don't have to reload the subtree again. pNode.Tag = null; marketTree.EndUpdate(); }
private void PopulateTreeGroups(TreeNodeCollection pNode, ImageList images, List <InvMarketGroup> groups) { foreach (InvMarketGroup group in groups) { if (group.marketGroupID == 350001) { // Skip Infantry gear group. (Obsolete) continue; } // Check for blueprint groups with no tech 1 bps. if (bpGroup.Contains(group.parentGroupID)) { // A blueprint sub group. bpGroup.Add(group.marketGroupID); List <InvType> groupTypes = InvType.GetMarketGroupTypes(group.marketGroupID); List <InvMarketGroup> subGroups = InvMarketGroup.GetGroupChildren(group.marketGroupID); while (subGroups.Count > 0) { InvMarketGroup subGroup = subGroups[0]; subGroups.Remove(subGroup); groupTypes.AddRange(InvType.GetMarketGroupTypes(subGroup.marketGroupID)); subGroups.AddRange(InvMarketGroup.GetGroupChildren(subGroup.marketGroupID)); } bool foundT1 = false; foreach (InvType type in groupTypes) { Blueprint bp = Blueprint.GetType(type.typeID); if (bp?.manufacturing != null) { foreach (ActivityProduct prod in bp.manufacturing.products) { if (InvMetaType.GetMetaType(prod.typeID) == null) { bpHasTech1.Add(group.marketGroupID); foundT1 = true; break; } } } if (foundT1) { break; } } if (!bpHasTech1.Contains(group.marketGroupID)) { // No Tech I so don't list. continue; } } // Create the new group node. TreeNode node = pNode.Add(group.marketGroupName); node.Tag = group; // Add temp holder. TreeNode gNode = node.Nodes.Add("Groups:"); // Add node image. string imgName = "icon:" + group.iconID.ToString(); Image img = ImageManager.GetIconImage(group.iconID); if (img != null) { images.Images.Add(imgName, img); } node.ImageKey = imgName; node.SelectedImageKey = imgName; } }