Ejemplo n.º 1
0
 private void chr_13_renderer_DragDrop(object sender, DragEventArgs e)
 {
     if (e.Data.GetDataPresent(DataFormats.FileDrop))
     {
         string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
         foreach (string filePath in files)
         {
             if (filePath.ToLower().EndsWith(".dds"))
             {
                 DDS dds = new DDS(new FileData(filePath));
                 if (sender == chr_13_renderer)
                 {
                     chr_13 = ReplaceTexture(dds.ToNutTexture(), 416, 416, chr_13);
                     if (chr_13_loc != null)
                     {
                         chr_13.Save(chr_13_loc);
                     }
                 }
                 if (sender == chr_00_renderer)
                 {
                     chr_00 = ReplaceTexture(dds.ToNutTexture(), 128, 128, chr_00);
                     if (chr_00_loc != null)
                     {
                         chr_00.Save(chr_00_loc);
                     }
                 }
                 if (sender == chr_11_renderer)
                 {
                     chr_11 = ReplaceTexture(dds.ToNutTexture(), 384, 384, chr_13);
                     if (chr_11_loc != null)
                     {
                         chr_11.Save(chr_11_loc);
                     }
                 }
             }
             if (filePath.ToLower().EndsWith(".png"))
             {
                 if (sender == stock_90_renderer)
                 {
                     stock_90 = ReplaceTexture(NUTEditor.fromPNG(filePath, 0), 64, 64, chr_13);
                     if (stock_90_loc != null)
                     {
                         stock_90.Save(stock_90_loc);
                     }
                 }
             }
         }
         ((GLControl)sender).Invalidate();
     }
 }
Ejemplo n.º 2
0
        private void importBack(string filename)
        {
            if (dontModify)
            {
                return;
            }

            NutTexture tex = textureFromFile[filename];

            try
            {
                DDS        dds  = new DDS(new FileData(filename));
                NutTexture ntex = dds.ToNutTexture();

                tex.Height = ntex.Height;
                tex.Width  = ntex.Width;
                tex.pixelInternalFormat = ntex.pixelInternalFormat;
                tex.surfaces            = ntex.surfaces;
                tex.pixelFormat         = ntex.pixelFormat;

                //GL.DeleteTexture(NUT.glTexByHashId[tex.HASHID]);
                currentNut.glTexByHashId.Remove(tex.HashId);
                currentNut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex));

                FillForm();
                textureListBox.SelectedItem = tex;
                glControl1.Invalidate();
            }
            catch
            {
                Console.WriteLine("Could not be open for editing");
            }
        }
Ejemplo n.º 3
0
        private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentNut == null || textureListBox.SelectedItem == null)
            {
                return;
            }
            using (var ofd = new OpenFileDialog())
            {
                NutTexture texture = (NutTexture)(textureListBox.SelectedItem);

                ofd.Filter = "Supported Formats|*.dds;*.png|" +
                             "DirectDraw Surface (.dds)|*.dds|" +
                             "Portable Network Graphics (.png)|*.png|" +
                             "All files(*.*)|*.*";

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    NutTexture newTexture = null;
                    string     extension  = Path.GetExtension(ofd.FileName).ToLowerInvariant();
                    if (extension == ".dds")
                    {
                        DDS dds = new DDS(new FileData(ofd.FileName));
                        newTexture = dds.ToNutTexture();
                    }
                    else if (extension == ".png")
                    {
                        newTexture = fromPNG(ofd.FileName, 1);
                    }
                    else
                    {
                        return;
                    }

                    texture.Height = newTexture.Height;
                    texture.Width  = newTexture.Width;
                    texture.pixelInternalFormat = newTexture.pixelInternalFormat;
                    texture.surfaces            = newTexture.surfaces;
                    texture.pixelFormat         = newTexture.pixelFormat;

                    Edited = true;

                    //GL.DeleteTexture(NUT.glTexByHashId[texture.HASHID]);
                    currentNut.glTexByHashId.Remove(texture.HashId);
                    currentNut.glTexByHashId.Add(texture.HashId, NUT.CreateTexture2D(texture));

                    FillForm();
                }
            }
        }
Ejemplo n.º 4
0
        public void ConvertToDdsNut(bool regenerateMipMaps = true)
        {
            for (int i = 0; i < Nodes.Count; i++)
            {
                NutTexture originalTexture = (NutTexture)Nodes[i];

                // Reading/writing mipmaps is only supported for DDS textures,
                // so we will need to convert all the textures.
                DDS        dds        = new DDS(originalTexture);
                NutTexture ddsTexture = dds.ToNutTexture();
                ddsTexture.HashId = originalTexture.HashId;

                if (regenerateMipMaps)
                {
                    RegenerateMipmapsFromTexture2D(ddsTexture);
                }

                Nodes[i] = ddsTexture;
            }
        }
Ejemplo n.º 5
0
        private void importNutFromFolder(object sender, EventArgs e)
        {
            using (FolderSelectDialog f = new FolderSelectDialog())
            {
                if (f.ShowDialog() == DialogResult.OK)
                {
                    Edited = true;
                    if (!Directory.Exists(f.SelectedPath))
                    {
                        Directory.CreateDirectory(f.SelectedPath);
                    }
                    NUT nut;
                    nut = currentNut;

                    foreach (var texPath in Directory.GetFiles(f.SelectedPath))
                    {
                        string extension = Path.GetExtension(texPath).ToLowerInvariant();
                        if (!(extension == ".dds" || extension == ".png"))
                        {
                            continue;
                        }
                        int  texId;
                        bool isTex = int.TryParse(Path.GetFileNameWithoutExtension(texPath), NumberStyles.HexNumber,
                                                  new CultureInfo("en-US"), out texId);

                        NutTexture texture = null;
                        if (isTex)
                        {
                            foreach (NutTexture tex in nut.Nodes)
                            {
                                if (tex.HashId == texId)
                                {
                                    texture = tex;
                                }
                            }
                        }

                        if (texture == null)
                        {
                            //new texture
                            NutTexture tex = null;
                            if (extension == ".dds")
                            {
                                DDS dds = new DDS(new FileData(texPath));
                                tex = dds.ToNutTexture();
                            }
                            else if (extension == ".png")
                            {
                                tex = fromPNG(texPath, 1);
                            }

                            if (isTex)
                            {
                                tex.HashId = texId;
                            }
                            else
                            {
                                tex.HashId = nut.Nodes.Count;
                            }
                            nut.Nodes.Add(tex);
                            currentNut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex));
                            FillForm();
                        }
                        else
                        {
                            //existing texture
                            NutTexture tex = texture;

                            NutTexture ntex = null;
                            if (extension == ".dds")
                            {
                                DDS dds = new DDS(new FileData(texPath));
                                ntex = dds.ToNutTexture();
                            }
                            else if (extension == ".png")
                            {
                                ntex = fromPNG(texPath, 1);
                            }

                            tex.Height = ntex.Height;
                            tex.Width  = ntex.Width;
                            tex.pixelInternalFormat = ntex.pixelInternalFormat;
                            tex.surfaces            = ntex.surfaces;
                            tex.pixelFormat         = ntex.pixelFormat;

                            //GL.DeleteTexture(NUT.glTexByHashId[tex.HASHID]);
                            currentNut.glTexByHashId.Remove(tex.HashId);
                            currentNut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex));
                            FillForm();
                        }
                    }
                    if (!Runtime.TextureContainers.Contains(nut))
                    {
                        Runtime.TextureContainers.Add(nut);
                    }
                }
            }
            FillForm();
        }
Ejemplo n.º 6
0
        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentNut == null)
            {
                return;
            }
            using (var ofd = new OpenFileDialog())
            {
                ofd.Filter = "Supported Formats|*.dds;*.png|" +
                             "DirectDraw Surface (.dds)|*.dds|" +
                             "Portable Network Graphics (.png)|*.png|" +
                             "All files(*.*)|*.*";

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    int  texId;
                    bool isTex = int.TryParse(Path.GetFileNameWithoutExtension(ofd.FileName), NumberStyles.HexNumber,
                                              new CultureInfo("en-US"), out texId);

                    if (isTex)
                    {
                        foreach (NutTexture te in currentNut.Nodes)
                        {
                            if (texId == te.HashId)
                            {
                                isTex = false;
                            }
                        }
                    }

                    NutTexture tex       = null;
                    string     extension = Path.GetExtension(ofd.FileName).ToLowerInvariant();
                    if (extension == ".dds")
                    {
                        DDS dds = new DDS(new FileData(ofd.FileName));
                        tex = dds.ToNutTexture();
                    }
                    else if (extension == ".png")
                    {
                        tex = fromPNG(ofd.FileName, 1);
                    }
                    else
                    {
                        return;
                    }

                    Edited = true;

                    if (isTex)
                    {
                        tex.HashId = texId;
                    }
                    else
                    {
                        tex.HashId = 0x40FFFF00 | (currentNut.Nodes.Count);
                    }

                    if (currentNut.glTexByHashId.ContainsKey(tex.HashId))
                    {
                        currentNut.glTexByHashId.Remove(tex.HashId);
                    }

                    currentNut.Nodes.Add(tex);
                    currentNut.glTexByHashId.Add(tex.HashId, NUT.CreateTexture2D(tex));
                    FillForm();
                }
            }
        }