Ejemplo n.º 1
0
        private void SetupTree()
        {
            // Set up the market tree.
            marketTree.BeginUpdate();
            marketTree.Nodes.Clear();
            // Set up the images.
            marketTree.ImageList = new ImageList();
            // Get child groups.
            List <InvMarketGroup> groups = InvMarketGroup.GetRootGroups();

            groups = groups.OrderBy(g => g.marketGroupName).ToList();
            // Add the groups.
            PopulateTreeGroups(marketTree.Nodes, marketTree.ImageList, groups);
            marketTree.EndUpdate();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Inventory Item Market Groups
        /// </summary>
        /// <returns><c>Bag</c> of Market Groups available on the market</returns>
        internal static Bag <InvMarketGroup> MarketGroups()
        {
            var list = new IndexedList <InvMarketGroup>();

            foreach (invMarketGroups marketGroup in Context.invMarketGroups)
            {
                var item = new InvMarketGroup
                {
                    ID          = marketGroup.marketGroupID,
                    Description = marketGroup.description.Clean(),
                    IconID      = marketGroup.iconID,
                    Name        = marketGroup.marketGroupName,
                    ParentID    = marketGroup.parentGroupID
                };

                list.Items.Add(item);
            }

            return(new Bag <InvMarketGroup>(list));
        }
Ejemplo n.º 3
0
 public MarketTreeNode(InvMarketGroup group)
 {
     Name        = group.MarketGroupName;
     Id          = group.MarketGroupId;
     IsFocusable = false;
 }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
 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;
     }
 }
Ejemplo n.º 6
0
        public static string PreloadImages(BackgroundWorker worker)
        {
            if (UserData.typeIconZip == null || UserData.typeIconZip?.Length == 0)
            {
                // No zip file specified.
                return(null);
            }
            // Get inv types and icons.
            worker.ReportProgress(0, "Finding needed images.");
            List <int>            types  = new List <int>();
            List <int>            icons  = new List <int>();
            List <InvMarketGroup> groups = InvMarketGroup.GetRootGroups();

            while (groups.Count > 0)
            {
                InvMarketGroup group = groups[0];
                groups.Remove(group);
                // Add icon.
                icons.Add(group.iconID);
                // Add child groups to search list.
                groups.AddRange(InvMarketGroup.GetGroupChildren(group.marketGroupID));
                // Get types for group.
                List <InvType> groupTypes = InvType.GetMarketGroupTypes(group.marketGroupID);
                // Add types to group.
                foreach (InvType type in groupTypes)
                {
                    if (!type.published)
                    {
                        continue;
                    }
                    types.Add(type.typeID);
                }
            }
            List <string> files = new List <string>();

            foreach (int typeID in types)
            {
                string zipImageFile = "Types/" + typeID.ToString() + "_32.png";
                files.Add(zipImageFile);
            }
            int typesComplete = 0;

            worker.ReportProgress(0, "Opening types Zip...");
            if (UserData.typeIconZip != null && File.Exists(UserData.typeIconZip))
            {
                FileStream fileStream   = File.OpenRead(UserData.typeIconZip);
                ZipArchive zip          = new ZipArchive(fileStream);
                int        totalFiles   = types.Count;
                int        failedFiles  = 0;
                int        skippedFiles = 0;
                foreach (int typeID in types)
                {
                    ZipArchiveEntry zipFile = zip.GetEntry("Types/" + typeID.ToString() + "_64.png");
                    if (zipFile == null)
                    {
                        continue;
                    }
                    Stream       zStream   = zipFile.Open();
                    MemoryStream memStream = new MemoryStream();
                    zStream.CopyTo(memStream);
                    memStream.Position = 0;
                    try
                    {
                        Image img = Image.FromStream(memStream);
                        images[zipFile.FullName] = img;
                    }
                    catch (ArgumentException)
                    {
                        failedFiles++;
                        skippedFiles++;
                    }
                    typesComplete++;
                    if (typesComplete % 10 == 0)
                    {
                        double pct = (double)typesComplete / (double)totalFiles;
                        string msg = "Loading type image files... (" + (typesComplete - skippedFiles) + " of " + totalFiles + " complete)";
                        if (failedFiles > 0)
                        {
                            msg += " (" + failedFiles + " failed.)";
                        }
                        worker.ReportProgress(Math.Min((int)(pct * 50.0), 100), msg);
                    }
                }
            }
            int iconsComplete = 0;

            worker.ReportProgress(50, "Opening icons Zip...");
            if (UserData.iconsZip != null && File.Exists(UserData.iconsZip))
            {
                // Open the zip archive.
                FileStream fileStream = File.OpenRead(UserData.iconsZip);
                ZipArchive zip        = new ZipArchive(fileStream);
                int        totalFiles = icons.Count;
                foreach (int iconID in icons)
                {
                    IconID icon = IconID.GetIconID(iconID);
                    if (icon == null)
                    {
                        continue;
                    }
                    // Construct image path.
                    string iconFile  = icon.iconFile;
                    int    lastSlash = iconFile.LastIndexOf('/');
                    iconFile = "Icons/items/" + iconFile.Substring(lastSlash + 1);
                    // Get the file.
                    MemoryStream    memStream = new MemoryStream();
                    ZipArchiveEntry zipFile   = zip.GetEntry(iconFile);
                    if (zipFile == null)
                    {
                        continue;
                    }
                    Stream zStream = zipFile.Open();
                    zStream.CopyTo(memStream);
                    memStream.Position = 0;
                    try
                    {
                        Image img = Image.FromStream(memStream);
                        images[iconFile] = img;
                    }
                    catch (ArgumentException)
                    {
                    }
                    iconsComplete++;
                    if (iconsComplete % 10 == 0)
                    {
                        double pct = (double)iconsComplete / (double)totalFiles;
                        string msg = "Loading Icon image files... (" + iconsComplete + " of " + totalFiles + " complete)";
                        worker.ReportProgress(Math.Min((int)(pct * 50.0) + 50, 100), msg);
                    }
                }
            }
            worker.ReportProgress(100, "Loaded " + typesComplete + " type images and " + iconsComplete + " icon images loaded.");
            return(null);
        }