Exemplo n.º 1
0
        public MainForm()
        {
            InitializeComponent();


            CreateMenus();
            if (Properties.Settings.Default.CarmaDirectory != "" && Directory.Exists(Path.Combine(Properties.Settings.Default.CarmaDirectory, "ZAD_VT")))
            {
                CarmaFolder = Properties.Settings.Default.CarmaDirectory;
            }
            else
            {
                InitialFindFolder();
            }
            ZAD modelsZAD = ZAD.Load(Path.Combine(Environment.CurrentDirectory, "models.zad"));
            //modelsZAD.AddEntryFromBuffer(File.ReadAllBytes("vteffect.fx"), "Data_Core/Content/Models/an_effect.fx");
            var entryToRemove = modelsZAD.Contents[5];

            modelsZAD.ReplaceEntryFromBuffer(entryToRemove, File.ReadAllBytes("vteffect.fx"));
            modelsZAD = ZAD.Load(Path.Combine(Environment.CurrentDirectory, "models.zad")); //*/
            foreach (var entry in modelsZAD.Contents)
            {
                Logger.LogToFile(Logger.LogLevel.Info, "{0}: {1}", modelsZAD.Contents.IndexOf(entry), entry.Name);
            }
            PageType.SelectedIndex   = 0;
            PageNumSelect.DataSource = pageNumSource;
            TileListBox.DataSource   = tileListSource;
            GetVTList();
        }
Exemplo n.º 2
0
        void ReplaceSelectedTexture_Click(object sender, EventArgs e)
        {
            var            textureToReplace = (crVTMapEntry)TextureList.SelectedItem;
            OpenFileDialog dialog           = new OpenFileDialog();

            dialog.InitialDirectory = Properties.Settings.Default.LastImportDirectory;
            dialog.Title            = "Export Texture";
            dialog.Filter           = "PNG Image (*.PNG)|*.png|JPEG Image (*.JPG, *.JPEG)|*.jpg;*.jpeg|BMP Image (*.BMP)|*.bmp|TIFF Image (*.TIF, *.TIFF)|*.tif;*.tiff|TGA Image (*.TGA)|*.tga|TDX Texture (*.TDX)|*.tdx";
            dialog.FileName         = Path.GetFileName(textureToReplace.FileName);
            var result = dialog.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK && Directory.Exists(Path.GetDirectoryName(dialog.FileName)))
            {
                Properties.Settings.Default.LastImportDirectory = Path.GetDirectoryName(dialog.FileName);
                Properties.Settings.Default.Save();
                var         vtPage    = (crVTPage)PageNumSelect.SelectedItem;
                var         fileType  = Path.GetExtension(dialog.FileName).ToUpper();
                ImageFormat imgFormat = ImageFormat.Png;
                Bitmap      image     = null;
                if (fileType == ".TGA")
                {
                    image = Paloma.TargaImage.LoadTargaImage(dialog.FileName);
                }
                else if (fileType == ".TDX")
                {
                    image = TDX.Load(dialog.FileName).Decompress();
                }
                else
                {
                    image = (Bitmap)Bitmap.FromFile(dialog.FileName);
                }
                //if (image.Width != textureToReplace.GetWidth(vtPage.PageNum) || image.Height != textureToReplace.GetHeight(vtPage.PageNum)) MessageBox.Show("Error: Image dimensions need to match the original texture!", "Texture Size Mismatch", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //else
                {
                    List <crVTPage> pages = null;
                    if (PageType.SelectedItem == "Diffuse")
                    {
                        pages = diffusePages;
                    }
                    else if (PageType.SelectedItem == "Specular")
                    {
                        pages = specularPages;
                    }
                    else if (PageType.SelectedItem == "Normal")
                    {
                        pages = normalPages;
                    }
                    foreach (var page in pages)
                    {
                        if (page.PageNum == 0)
                        {
                            continue;
                        }
                        int    targetWidth  = textureToReplace.GetWidth(page.PageNum);
                        int    targetHeight = textureToReplace.GetHeight(page.PageNum);
                        Bitmap mipimage     = null;
                        if (image.Width != targetWidth || image.Height != targetHeight)
                        {
                            mipimage = new Bitmap(targetWidth, targetHeight);
                            var      srcRect  = new RectangleF(0, 0, image.Width, image.Height);
                            var      destRect = new RectangleF(0, 0, targetWidth, targetHeight);
                            Graphics grfx     = Graphics.FromImage(mipimage);
                            grfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                            grfx.DrawImage(image, destRect, srcRect, GraphicsUnit.Pixel);
                        }
                        else
                        {
                            mipimage = image;
                        }
                        var tiles = page.ImportTexture(mipimage, textureToReplace);
                        foreach (var tile in tiles)
                        {
                            ZAD      currentZAD = ZAD.Load(tile.ZADFile);
                            ZADEntry tileEntry  = currentZAD.Contents.Find(possibleEntry => possibleEntry.Name == tile.ZADEntryLocation);
                            currentZAD.ReplaceEntryFromBuffer(tileEntry, tile.Texture.SaveToBuffer());
                        }

                        /*foreach(var tile in tiles)
                         * {
                         *  using (ZipArchive zip = ZipFile.Open(tile.ZADFile, ZipArchiveMode.Update))
                         *  {
                         *
                         *      var zipentry = zip.GetEntry(tile.ZADEntryLocation);
                         *      zipentry.Delete();
                         *      zipentry = zip.CreateEntry(tile.ZADEntryLocation, CompressionLevel.NoCompression);
                         *      using (Stream stream = zipentry.Open())
                         *      {
                         *          tile.Texture.Save(stream);
                         *      }
                         *
                         *  }
                         * }*/
                    }
                }
            }
        }