Ejemplo n.º 1
0
 public void ReEncode()
 {
     using (TextureConverterDialog dlg = new TextureConverterDialog())
     {
         dlg.LoadImages((ResourceNode as TPLTextureNode).GetImage(0));
         dlg.ShowDialog(MainForm.Instance, ResourceNode as TPLTextureNode);
     }
 }
Ejemplo n.º 2
0
 public override void OnReplace(string inStream, int filterIndex)
 {
     if (filterIndex == 8)
         base.OnReplace(inStream, filterIndex);
     else
         using (TextureConverterDialog dlg = new TextureConverterDialog())
         {
             dlg.ImageSource = inStream;
             dlg.ShowDialog(MainForm.Instance, (TPLTextureNode)_resource);
         }
 }
Ejemplo n.º 3
0
 public void ImportTexture()
 {
     string path;
     int index = Program.OpenFile(FileFilters.Images, out path);
     if (index > 0)
         using (TextureConverterDialog dlg = new TextureConverterDialog())
         {
             dlg.ImageSource = path;
             if (dlg.ShowDialog(MainForm.Instance, ResourceNode as REFTNode) == DialogResult.OK)
             {
                 BaseWrapper w = this.FindResource(dlg.REFTTextureNode, true);
                 w.EnsureVisible();
                 w.TreeView.SelectedNode = w;
             }
         }
 }
Ejemplo n.º 4
0
        private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int index = lstTextures.SelectedIndex;

            if ((_selectedTexture != null) && (_selectedTexture.Source is TEX0Node))
            {
                TEX0Node node = _selectedTexture.Source as TEX0Node;
                using (TextureConverterDialog dlg = new TextureConverterDialog())
                    if (dlg.ShowDialog(this, node) == DialogResult.OK)
                    {
                        _updating = true;
                        _selectedTexture.Reload();
                        lstTextures.SetItemCheckState(index, CheckState.Checked);
                        lstTextures.SetSelected(index, false);
                        _updating = false;

                        if (RenderStateChanged != null)
                        {
                            RenderStateChanged(this, null);
                        }
                    }
            }
        }
        public void Replace(string filename, bool useTextureConverter)
        {
            if (Texture == null) return;

            var ig = StringComparison.CurrentCultureIgnoreCase;
            if (filename.EndsWith(".tex0", ig) || filename.EndsWith(".brres", ig)) {
                using (ResourceNode node = NodeFactory.FromFile(null, filename)) {
                    TEX0Node tex0;
                    if (node is TEX0Node) {
                        tex0 = (TEX0Node)node;
                    } else {
                        tex0 = (TEX0Node)node.FindChild("Textures(NW4R)", false).Children[0];
                    }
                    string tempFile = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".png";
                    tex0.Export(tempFile);
                    Replace(tempFile, useTextureConverter); // call self with new file
                    File.Delete(tempFile);
                }
            } else {
                if (useTextureConverter) {
                    using (TextureConverterDialog dlg = new TextureConverterDialog()) {
                        dlg.ImageSource = filename;
                        if (dlg.ShowDialog(null, Texture) == DialogResult.OK) {
                            if (OnUpdate != null) OnUpdate(this);
                        }
                    }
                } else {
                    if (Texture.Format == WiiPixelFormat.CMPR) {
                        Bitmap bitmap = new Bitmap(filename);
                        UnsafeBuffer buffer = TextureConverter.CMPR.GeneratePreview(bitmap);
                        BrawlLib.IO.FileMap textureData = TextureConverter.CMPR.EncodeTEX0TextureCached(bitmap, Texture.LevelOfDetail, buffer);
                        Texture.ReplaceRaw(textureData);
                    } else {
                        Texture.Replace(filename);
                    }
                    if (OnUpdate != null) OnUpdate(this);
                }
            }
        }
Ejemplo n.º 6
0
        public void ImportTexture()
        {
            string path;
            int index = Program.OpenFile(FileFilters.TEX0, out path);
            if (index == 8)
            {
                TEX0Node node = NodeFactory.FromFile(null, path) as TEX0Node;
                ((BRESNode)_resource).GetOrCreateFolder<TEX0Node>().AddChild(node);

                string palette = Path.ChangeExtension(path, ".plt0");
                if (File.Exists(palette) && node.HasPalette)
                {
                    PLT0Node n = NodeFactory.FromFile(null, palette) as PLT0Node;
                    ((BRESNode)_resource).GetOrCreateFolder<PLT0Node>().AddChild(n);
                }

                BaseWrapper w = this.FindResource(node, true);
                w.EnsureVisible();
                w.TreeView.SelectedNode = w;
            }
            else if (index > 0)
                using (TextureConverterDialog dlg = new TextureConverterDialog())
                {
                    dlg.ImageSource = path;
                    if (dlg.ShowDialog(MainForm.Instance, ResourceNode as BRESNode) == DialogResult.OK)
                    {
                        BaseWrapper w = this.FindResource(dlg.TEX0TextureNode, true);
                        w.EnsureVisible();
                        w.TreeView.SelectedNode = w;
                    }
                }
        }
Ejemplo n.º 7
0
        public void ImportTexture()
        {
            string path;
            int index = Program.OpenFile(FileFilters.Images, out path);
            if (index == 8)
            {
                TPLTextureNode t = new TPLTextureNode() { Name = "Texture" };
                _resource.AddChild(t);
                t.Replace(path);

                BaseWrapper w = this.FindResource(t, true);
                w.EnsureVisible();
                w.TreeView.SelectedNode = w;
            }
            else if (index > 0)
                using (TextureConverterDialog dlg = new TextureConverterDialog())
                {
                    dlg.ImageSource = path;
                    if (dlg.ShowDialog(MainForm.Instance, ResourceNode as TPLNode) == DialogResult.OK)
                    {
                        BaseWrapper w = this.FindResource(dlg.TPLTextureNode, true);
                        w.EnsureVisible();
                        w.TreeView.SelectedNode = w;
                    }
                }
        }
Ejemplo n.º 8
0
 private void AddNewTEX0(object sender, string filename)
 {
     BRRESNode md80 = sc_selmap.FindChild("MiscData[80]", false) as BRRESNode;
     string dir = Path.Combine(Path.GetTempPath(), "BrawlStageManager-newimage-" + Guid.NewGuid());
     Directory.CreateDirectory(dir);
     string temp = Path.Combine(dir, GetTexInfoFor(sender).pat0.Texture + Path.GetExtension(filename));
     File.Copy(filename, temp);
     using (TextureConverterDialog dlg = new TextureConverterDialog()) {
         dlg.ImageSource = temp;
         dlg.InitialFormat =
             sender == prevbase ? WiiPixelFormat.CMPR
             : sender == frontstname ? WiiPixelFormat.I4
             : sender == icon ? WiiPixelFormat.CI8
             : sender == seriesicon ? WiiPixelFormat.I4
             : sender == selmap_mark ? WiiPixelFormat.IA4
             : (WiiPixelFormat?)null;
         dlg.InitialSize =
             sender == prevbase ? prevbaseResizeTo
             : sender == frontstname ? frontstnameResizeTo
             : sender == selmap_mark ? selmapMarkResizeTo
             : null;
         dlg.FormBorderStyle = FormBorderStyle.FixedSingle;
         dlg.ShowInTaskbar = true;
         if (dlg.ShowDialog(null, md80) == DialogResult.OK) {
             md80.IsDirty = true; // do this to be safe
             UpdateImage();
         }
     }
     Directory.Delete(dir, true);
 }
Ejemplo n.º 9
0
        public void ResizeAllPrevbases(Size newSize)
        {
            if (sc_selmap == null) return;
            var prevbases = from c in sc_selmap.FindChild("MiscData[80]/Textures(NW4R)", false).Children
                            where c is TEX0Node && c.Name.Contains("MenSelmapPrevbase")
                            select (TEX0Node)c;
            int i = 0;
            foreach (TEX0Node node in prevbases) {
                Bitmap origImage = node.GetImage(0);
                if (origImage.Width <= newSize.Width && origImage.Height <= newSize.Height) {
                    continue;
                }

                string file = TempFiles.Create(".png");
                if (useTextureConverter) {
                    origImage.Save(file);

                    TextureConverterDialog d = new TextureConverterDialog();
                    d.ImageSource = file;
                    d.InitialSize = newSize;
                    if (d.ShowDialog(null, node) == DialogResult.OK) {
                        node.IsDirty = true;
                        Console.WriteLine("Resized " + node);
                        i++;
                    } else if (MessageBox.Show(this, "Stop resizing textures here?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) {
                        break;
                    }
                } else {
                    Bitmap b = BitmapUtilities.Resize(origImage, newSize);
                    b.Save(file);

                    node.Replace(file);
                    Console.WriteLine("Resized " + node);
                    i++;
                }

                File.Delete(file);
            }
            MessageBox.Show("Resized " + i + " images.");
            UpdateImage();
        }
Ejemplo n.º 10
0
 public void Replace(object sender, string filename)
 {
     var ig = StringComparison.CurrentCultureIgnoreCase;
     if (filename.EndsWith(".tex0", ig)) {
         TEX0Node tex0 = GetTexInfoFor(sender).tex0;
         if (tex0 == null) return;
         tex0.Replace(filename);
         tex0.IsDirty = true;
         UpdateImage();
     } else if (filename.EndsWith(".brres", ig)) {
         using (ResourceNode node = NodeFactory.FromFile(null, filename)) {
             TEX0Node tex0;
             if (node is TEX0Node) {
                 tex0 = (TEX0Node)node;
             } else {
                 tex0 = (TEX0Node)node.FindChild("Textures(NW4R)", false).Children[0];
             }
             string tempFile = TempFiles.Create(".png");
             tex0.Export(tempFile);
             Replace(sender, tempFile); // call self with new file
         }
     } else {
         TEX0Node tex0 = GetTexInfoFor(sender).tex0;
         if (tex0 == null) {
             AddNewTEX0(sender, filename);
             return;
         } else if (useTextureConverter) {
             using (TextureConverterDialog dlg = new TextureConverterDialog()) {
                 dlg.ImageSource = filename;
                 dlg.InitialSize =
                     sender == prevbase ? prevbaseResizeTo
                     : sender == frontstname ? frontstnameResizeTo
                     : sender == selmap_mark ? selmapMarkResizeTo
                     : null;
                 dlg.FormBorderStyle = FormBorderStyle.FixedSingle;
                 dlg.ShowInTaskbar = true;
                 if (dlg.ShowDialog(null, tex0) == DialogResult.OK) {
                     tex0.IsDirty = true;
                     UpdateImage();
                 }
             }
         } else {
             Bitmap bmp = new Bitmap(filename);
             if (sender == prevbase && prevbaseResizeTo != null) {
                 bmp = BitmapUtilities.Resize(bmp, prevbaseResizeTo.Value);
             } else if (sender == frontstname && frontstnameResizeTo != null) {
                 bmp = BitmapUtilities.Resize(bmp, frontstnameResizeTo.Value);
             } else if (sender == selmap_mark && selmapMarkResizeTo != null) {
                 bmp = BitmapUtilities.Resize(bmp, selmapMarkResizeTo.Value);
             }
             if (sender == selmap_mark) {
                 ReplaceSelmapMark(bmp, tex0, false);
             } else {
                 int colorCount = BitmapUtilities.CountColors(bmp, 256).Align(16);
                 tex0.Replace(bmp, colorCount);
             }
             tex0.IsDirty = true;
             UpdateImage();
         }
     }
 }
Ejemplo n.º 11
0
        private void replaceTextureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int index = lstTextures.SelectedIndex;
            if ((_selectedTexture != null) && (_selectedTexture.Source is TEX0Node))
            {
                TEX0Node node = _selectedTexture.Source as TEX0Node;
                using (TextureConverterDialog dlg = new TextureConverterDialog())
                    if (dlg.ShowDialog(this, node) == DialogResult.OK)
                    {
                        _updating = true;
                        _selectedTexture.Reload();
                        lstTextures.SetItemCheckState(index, CheckState.Checked);
                        lstTextures.SetSelected(index, false);
                        _updating = false;

                        _mainWindow.ModelPanel.Invalidate();
                    }
            }
        }