示例#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)
                 {
                     chr13 = ReplaceTexture(dds.ToNutTexture(), 416, 416, chr13);
                     if (chr13Loc != null)
                     {
                         chr13.Save(chr13Loc);
                     }
                 }
                 if (sender == chr_00_renderer)
                 {
                     chr00 = ReplaceTexture(dds.ToNutTexture(), 128, 128, chr00);
                     if (chr00Loc != null)
                     {
                         chr00.Save(chr00Loc);
                     }
                 }
                 if (sender == chr_11_renderer)
                 {
                     chr11 = ReplaceTexture(dds.ToNutTexture(), 384, 384, chr13);
                     if (chr11Loc != null)
                     {
                         chr11.Save(chr11Loc);
                     }
                 }
             }
             if (filePath.ToLower().EndsWith(".png"))
             {
                 if (sender == stock_90_renderer)
                 {
                     stock90 = ReplaceTexture(NutEditor.FromPng(filePath, 0), 64, 64, chr13);
                     if (stock90Loc != null)
                     {
                         stock90.Save(stock90Loc);
                     }
                 }
             }
         }
         ((GLControl)sender).Invalidate();
     }
 }
示例#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");
            }
        }
示例#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();
                }
            }
        }
示例#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;
            }
        }
示例#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();
        }
示例#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);
                    }

                    // Replace OpenGL texture.
                    if (currentNut.glTexByHashId.ContainsKey(tex.HashId))
                    {
                        currentNut.glTexByHashId.Remove(tex.HashId);
                    }

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

                    currentNut.Nodes.Add(tex);
                    FillForm();
                }
            }
        }