Ejemplo n.º 1
0
        //mxd
        private void SetItemsCount(TreeNode node)
        {
            ResourceTextureSet ts = node.Tag as ResourceTextureSet;

            if (ts == null)
            {
                throw new Exception("Expected IFilledTextureSet, but got null...");
            }


            if (node.Parent != null && General.Map.Config.MixTexturesFlats)
            {
                ts.MixTexturesAndFlats();
                node.Text += " [" + ts.Textures.Count + "]";
            }
            else
            {
                node.Text += " [" + (browseflats ? ts.Flats.Count : ts.Textures.Count) + "]";
            }

            foreach (TreeNode child in node.Nodes)
            {
                SetItemsCount(child);
            }
        }
Ejemplo n.º 2
0
 // Constructor
 protected DataReader(DataLocation dl, bool asreadonly)
 {
     // Keep information
     location   = dl;
     isreadonly = asreadonly;
     textureset = new ResourceTextureSet(GetTitle(), dl);
 }
        //mxd
        private void SetItemsCount(TreeNode node)
        {
            ResourceTextureSet ts = ((TreeNodeData)node.Tag).Set as ResourceTextureSet;

            if (ts == null)
            {
                throw new Exception("Expected ResourceTextureSet, but got null...");
            }

            if (node.Parent != null && General.Map.Config.MixTexturesFlats)
            {
                ts.MixTexturesAndFlats();
                if (ts.Textures.Count > 0)
                {
                    node.Text += " [" + ts.Textures.Count + "]";
                }
            }
            else
            {
                int texcount = (browseflats ? ts.Flats.Count : ts.Textures.Count);
                if (texcount > 0)
                {
                    node.Text += " [" + texcount + "]";
                }
            }

            foreach (TreeNode child in node.Nodes)
            {
                SetItemsCount(child);
            }
        }
Ejemplo n.º 4
0
 // Disposer
 public virtual void Dispose()
 {
     // Not already disposed?
     if (!isdisposed)
     {
         // Done
         textureset = null;
         isdisposed = true;
     }
 }
Ejemplo n.º 5
0
 // Constructor
 public DataReader(DataLocation dl)
 {
     // Keep information
     location   = dl;
     textureset = new ResourceTextureSet(GetTitle(), dl);
 }
Ejemplo n.º 6
0
        // This loads the textures
        public override ICollection <ImageData> LoadTextures(PatchNames pnames)
        {
            Dictionary <long, ImageData> images = new Dictionary <long, ImageData>();
            ICollection <ImageData>      collection;
            List <ImageData>             imgset = new List <ImageData>();

            // Error when suspended
            if (issuspended)
            {
                throw new Exception("Data reader is suspended");
            }

            subtexturesets = new Dictionary <string, ResourceTextureSet>();

            // Load from wad files (NOTE: backward order, because the last wad's images have priority)
            for (int i = wads.Count - 1; i >= 0; i--)
            {
                collection = wads[i].LoadTextures(pnames);

                ResourceTextureSet wadTextureSet = new ResourceTextureSet(wads[i].GetTitle(), location);
                // ano - moved this loop out from AddImagesToList
                // because we need to add the images to a
                // wad-specific list
                foreach (ImageData src in collection)
                {
                    // Check if exists in target list
                    if (!images.ContainsKey(src.LongName))
                    {
                        images.Add(src.LongName, src);
                        wadTextureSet.AddTexture(src);
                    }
                } // foreach

                subtexturesets.Add(wadTextureSet.Name, wadTextureSet);
            }             // for(wads)

            // Should we load the images in this directory as textures?
            if (roottextures)
            {
                collection = LoadDirectoryImages("", ImageDataFormat.DOOMPICTURE, false);
                AddImagesToList(images, collection);
            }

            // Add images from texture directory
            collection = LoadDirectoryImagesAndCategorize(TEXTURES_DIR, ImageDataFormat.DOOMPICTURE, images, false);

            // Load TEXTURE1 lump file
            imgset.Clear();
            string texture1file = FindFirstFile("TEXTURE1", false);

            if ((texture1file != null) && FileExists(texture1file))
            {
                MemoryStream filedata = LoadFile(texture1file);
                WADReader.LoadTextureSet("TEXTURE1", filedata, ref imgset, pnames);
                filedata.Dispose();
            }

            // Load TEXTURE2 lump file
            string texture2file = FindFirstFile("TEXTURE2", false);

            if ((texture2file != null) && FileExists(texture2file))
            {
                MemoryStream filedata = LoadFile(texture2file);
                WADReader.LoadTextureSet("TEXTURE2", filedata, ref imgset, pnames);
                filedata.Dispose();
            }

            // Add images from TEXTURE1 and TEXTURE2 lump files
            AddImagesToList(images, imgset);

            // Load TEXTURES lump file
            imgset.Clear();
            string[] alltexturefiles = GetAllFilesWithTitle("", "TEXTURES", false);
            foreach (string texturesfile in alltexturefiles)
            {
                MemoryStream filedata = LoadFile(texturesfile);
                WADReader.LoadHighresTextures(filedata, texturesfile, ref imgset, images, null);
                filedata.Dispose();
            }

            // Add images from TEXTURES lump file
            AddImagesToList(images, imgset);

            // Add images to the container-specific texture set
            foreach (ImageData img in images.Values)
            {
                textureset.AddTexture(img);
            }

            return(new List <ImageData>(images.Values));
        }
Ejemplo n.º 7
0
        //mxd
        private void CreateNodes(TreeNode root)
        {
            ResourceTextureSet set = root.Tag as ResourceTextureSet;

            if (set == null)
            {
                General.ErrorLogger.Add(ErrorType.Error, "Resource " + root.Name + " doesn't have TextureSet!");
                return;
            }

            int imageIndex = set.Location.type + 5;

            char[] separator = new[] { Path.AltDirectorySeparatorChar };

            ImageData[] images;
            if (browseflats)
            {
                images = new ImageData[set.Flats.Count];
                set.Flats.CopyTo(images, 0);
            }
            else
            {
                images = new ImageData[set.Textures.Count];
                set.Textures.CopyTo(images, 0);
            }
            Array.Sort(images, SortImageData);

            foreach (ImageData image in images)
            {
                string[] parts   = image.VirtualName.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                TreeNode curNode = root;

                if (parts.Length == 1)
                {
                    continue;
                }
                int localindex = (parts[0] == "[TEXTURES]" ? 8 : imageIndex);

                string category = set.Name;
                for (int i = 0; i < parts.Length - 1; i++)
                {
                    //string category = parts[i];
                    category += (Path.DirectorySeparatorChar + parts[i]);

                    //already got such category?
                    if (curNode.Nodes.Count > 0 && curNode.Nodes.ContainsKey(category))
                    {
                        curNode = curNode.Nodes[category];
                    }
                    else                     //create a new one
                    {
                        TreeNode n = new TreeNode(parts[i])
                        {
                            Name = category, ImageIndex = localindex, SelectedImageIndex = localindex
                        };

                        curNode.Nodes.Add(n);
                        curNode = n;

                        ResourceTextureSet ts = new ResourceTextureSet(category, set.Location);
                        ts.Level    = i + 1;
                        curNode.Tag = ts;
                    }

                    //add to current and parent nodes
                    if (i == parts.Length - 2)
                    {
                        TreeNode cn = curNode;
                        while (cn != root)
                        {
                            ResourceTextureSet curTs = cn.Tag as ResourceTextureSet;
                            if (image.IsFlat)
                            {
                                curTs.AddFlat(image);
                            }
                            else
                            {
                                curTs.AddTexture(image);
                            }
                            cn = cn.Parent;
                        }
                    }
                }
            }

            if (root.Nodes.Count == 1 && root.Nodes[0].Nodes.Count > 0)
            {
                TreeNode[] children = new TreeNode[root.Nodes[0].Nodes.Count];
                root.Nodes[0].Nodes.CopyTo(children, 0);
                root.Nodes.Clear();
                root.Nodes.AddRange(children);
                ((ResourceTextureSet)root.Tag).Level++;
            }

            foreach (TreeNode n in root.Nodes)
            {
                SetItemsCount(n);
            }
        }
        //mxd
        private void CreateNodes(TreeNode root)
        {
            TreeNodeData       rootdata = (TreeNodeData)root.Tag;
            ResourceTextureSet set      = rootdata.Set as ResourceTextureSet;

            if (set == null)
            {
                General.ErrorLogger.Add(ErrorType.Error, "Resource " + root.Name + " doesn't have TextureSet!");
                return;
            }

            int imageIndex = set.Location.type + 5;

            char[] separator = { Path.AltDirectorySeparatorChar };

            ImageData[] images;
            if (browseflats)
            {
                images = new ImageData[set.Flats.Count];
                set.Flats.CopyTo(images, 0);
            }
            else
            {
                images = new ImageData[set.Textures.Count];
                set.Textures.CopyTo(images, 0);
            }
            Array.Sort(images, SortImageData);

            List <ImageData> rootimages = new List <ImageData>();

            foreach (ImageData image in images)
            {
                string[] parts   = image.VirtualName.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                TreeNode curNode = root;

                if (parts.Length == 1)
                {
                    rootimages.Add(image);
                    continue;
                }

                int    localindex = ((parts[0] == "[TEXTURES]" || image is TEXTURESImage) ? 8 : imageIndex);
                string category   = set.Name;
                for (int i = 0; i < parts.Length - 1; i++)
                {
                    category += (Path.DirectorySeparatorChar + parts[i]);

                    //already got such category?
                    if (curNode.Nodes.Count > 0 && curNode.Nodes.ContainsKey(category))
                    {
                        curNode = curNode.Nodes[category];
                    }
                    else                     //create a new one
                    {
                        TreeNode n = new TreeNode(parts[i])
                        {
                            Name = category, ImageIndex = localindex, SelectedImageIndex = localindex
                        };
                        curNode.Nodes.Add(n);
                        curNode     = n;
                        curNode.Tag = new TreeNodeData {
                            Set = new ResourceTextureSet(category, set.Location), FolderName = parts[i]
                        };
                    }

                    // Add to current node
                    if (i == parts.Length - 2)
                    {
                        ResourceTextureSet curTs = ((TreeNodeData)curNode.Tag).Set as ResourceTextureSet;
                        if (image.IsFlat)
                        {
                            curTs.AddFlat(image);
                        }
                        else
                        {
                            curTs.AddTexture(image);
                        }
                    }
                }
            }

            // Shift the tree up when only single child node was added
            if (root.Nodes.Count == 1 && root.Nodes[0].Nodes.Count > 0)
            {
                TreeNode[] children = new TreeNode[root.Nodes[0].Nodes.Count];
                root.Nodes[0].Nodes.CopyTo(children, 0);
                root.Nodes.Clear();
                root.Nodes.AddRange(children);
            }

            // Add "All set textures" node
            if (General.Map.Config.MixTexturesFlats && root.Nodes.Count > 1)
            {
                TreeNode allnode = new TreeNode(ALL_IMAGES)
                {
                    Name               = ALL_IMAGES,
                    ImageIndex         = imageIndex,
                    SelectedImageIndex = imageIndex,
                    Tag = new TreeNodeData {
                        Set = set, FolderName = ALL_IMAGES
                    }
                };
                root.Nodes.Add(allnode);
            }

            // Sort immediate child nodes...
            TreeNode[] rootnodes = new TreeNode[root.Nodes.Count];
            root.Nodes.CopyTo(rootnodes, 0);
            Array.Sort(rootnodes, SortTreeNodes);
            root.Nodes.Clear();
            root.Nodes.AddRange(rootnodes);

            // Re-add root images
            ResourceTextureSet rootset = new ResourceTextureSet(set.Name, set.Location);

            if (browseflats)
            {
                foreach (ImageData data in rootimages)
                {
                    rootset.AddFlat(data);
                }
            }
            else
            {
                foreach (ImageData data in rootimages)
                {
                    rootset.AddTexture(data);
                }
            }
            if (General.Map.Config.MixTexturesFlats)
            {
                rootset.MixTexturesAndFlats();
            }

            // Store root data
            rootdata.Set = rootset;
            root.Tag     = rootdata;

            // Set root images count
            var rootsetimages = (browseflats ? rootset.Flats : rootset.Textures);

            if (rootsetimages.Count > 0)
            {
                root.Text += " [" + rootsetimages.Count + "]";
            }

            // Add image count to node titles
            foreach (TreeNode n in root.Nodes)
            {
                SetItemsCount(n);
            }
        }