From a036d1673a7a8e179fef839441ecf0d9f031ab47 Mon Sep 17 00:00:00 2001 From: dexy Date: Wed, 10 Nov 2021 03:04:35 +1100 Subject: [PATCH] Added Save All textures button to selection info form --- CodeWalker/World/WorldInfoForm.Designer.cs | 30 ++++- CodeWalker/World/WorldInfoForm.cs | 132 ++++++++++++++------- CodeWalker/World/WorldInfoForm.resx | 3 + 3 files changed, 117 insertions(+), 48 deletions(-) diff --git a/CodeWalker/World/WorldInfoForm.Designer.cs b/CodeWalker/World/WorldInfoForm.Designer.cs index 82a5afd..bc82296 100644 --- a/CodeWalker/World/WorldInfoForm.Designer.cs +++ b/CodeWalker/World/WorldInfoForm.Designer.cs @@ -70,6 +70,8 @@ namespace CodeWalker.World this.label25 = new System.Windows.Forms.Label(); this.SelectionModeComboBox = new System.Windows.Forms.ComboBox(); this.SaveFileDialog = new System.Windows.Forms.SaveFileDialog(); + this.SaveAllTexturesButton = new System.Windows.Forms.Button(); + this.FolderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); this.SelectionTabControl.SuspendLayout(); this.SelectionEntityTabPage.SuspendLayout(); this.SelectionArchetypeTabPage.SuspendLayout(); @@ -279,6 +281,8 @@ namespace CodeWalker.World // // splitContainer2.Panel1 // + this.splitContainer2.Panel1.Controls.Add(this.SaveAllTexturesButton); + this.splitContainer2.Panel1.Controls.Add(this.SaveTextureButton); this.splitContainer2.Panel1.Controls.Add(this.SelDrawableTexturesTreeView); // // splitContainer2.Panel2 @@ -296,7 +300,7 @@ namespace CodeWalker.World this.SelDrawableTexturesTreeView.HideSelection = false; this.SelDrawableTexturesTreeView.Location = new System.Drawing.Point(0, 0); this.SelDrawableTexturesTreeView.Name = "SelDrawableTexturesTreeView"; - this.SelDrawableTexturesTreeView.Size = new System.Drawing.Size(300, 454); + this.SelDrawableTexturesTreeView.Size = new System.Drawing.Size(300, 412); this.SelDrawableTexturesTreeView.TabIndex = 2; this.SelDrawableTexturesTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.SelDrawableTexturesTreeView_AfterSelect); // @@ -315,7 +319,6 @@ namespace CodeWalker.World // // tabPage3 // - this.tabPage3.Controls.Add(this.SaveTextureButton); this.tabPage3.Controls.Add(this.SelTextureDimensionsLabel); this.tabPage3.Controls.Add(this.SelTextureMipTrackBar); this.tabPage3.Controls.Add(this.SelTextureMipLabel); @@ -334,11 +337,13 @@ namespace CodeWalker.World // // SaveTextureButton // - this.SaveTextureButton.Location = new System.Drawing.Point(346, 396); + this.SaveTextureButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.SaveTextureButton.Enabled = false; + this.SaveTextureButton.Location = new System.Drawing.Point(124, 419); this.SaveTextureButton.Name = "SaveTextureButton"; - this.SaveTextureButton.Size = new System.Drawing.Size(54, 23); - this.SaveTextureButton.TabIndex = 38; - this.SaveTextureButton.Text = "Save..."; + this.SaveTextureButton.Size = new System.Drawing.Size(100, 23); + this.SaveTextureButton.TabIndex = 4; + this.SaveTextureButton.Text = "Save Selected..."; this.SaveTextureButton.UseVisualStyleBackColor = true; this.SaveTextureButton.Click += new System.EventHandler(this.SaveTextureButton_Click); // @@ -566,6 +571,17 @@ namespace CodeWalker.World this.SelectionModeComboBox.TabIndex = 31; this.SelectionModeComboBox.SelectedIndexChanged += new System.EventHandler(this.SelectionModeComboBox_SelectedIndexChanged); // + // SaveAllTexturesButton + // + this.SaveAllTexturesButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.SaveAllTexturesButton.Location = new System.Drawing.Point(3, 419); + this.SaveAllTexturesButton.Name = "SaveAllTexturesButton"; + this.SaveAllTexturesButton.Size = new System.Drawing.Size(100, 23); + this.SaveAllTexturesButton.TabIndex = 3; + this.SaveAllTexturesButton.Text = "Save All..."; + this.SaveAllTexturesButton.UseVisualStyleBackColor = true; + this.SaveAllTexturesButton.Click += new System.EventHandler(this.SaveAllTexturesButton_Click); + // // WorldInfoForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -654,5 +670,7 @@ namespace CodeWalker.World private PropertyGridFix HierarchyPropertyGrid; private System.Windows.Forms.Button SaveTextureButton; private System.Windows.Forms.SaveFileDialog SaveFileDialog; + private System.Windows.Forms.Button SaveAllTexturesButton; + private System.Windows.Forms.FolderBrowserDialog FolderBrowserDialog; } } \ No newline at end of file diff --git a/CodeWalker/World/WorldInfoForm.cs b/CodeWalker/World/WorldInfoForm.cs index 6d9c22a..4babfae 100644 --- a/CodeWalker/World/WorldInfoForm.cs +++ b/CodeWalker/World/WorldInfoForm.cs @@ -345,49 +345,9 @@ namespace CodeWalker.World Texture tex = texbase as Texture; YtdFile ytd = null; string errstr = string.Empty; - if ((tex == null)&&(texbase!=null)) + if ((tex == null) && (texbase != null)) { - //need to load from txd. - var arch = Selection.Archetype; - uint texhash = texbase.NameHash; - uint txdHash = (arch != null) ? arch.TextureDict.Hash : 0; - tex = TryGetTextureFromYtd(texhash, txdHash, out ytd); - if (tex == null) - { //search parent ytds... - uint ptxdhash = WorldForm.GameFileCache.TryGetParentYtdHash(txdHash); - while ((ptxdhash != 0) && (tex == null)) - { - tex = TryGetTextureFromYtd(texhash, ptxdhash, out ytd); - if (tex == null) - { - ptxdhash = WorldForm.GameFileCache.TryGetParentYtdHash(ptxdhash); - } - else - { } - } - if (tex == null) - { - ytd = WorldForm.GameFileCache.TryGetTextureDictForTexture(texhash); - if (ytd != null) - { - int tries = 0; - while (!ytd.Loaded && (tries < 500)) //wait upto ~5 sec - { - System.Threading.Thread.Sleep(10); - tries++; - } - if (ytd.Loaded) - { - tex = ytd.TextureDict.Lookup(texhash); - } - } - if (tex == null) - { - ytd = null; - errstr = ""; - } - } - } + tex = TryGetTexture(texbase, out ytd, ref errstr); } if (tex != null) { @@ -417,6 +377,7 @@ namespace CodeWalker.World SelTextureNameTextBox.Text = tex.Name; SelTextureDictionaryTextBox.Text = (ytd != null) ? ytd.Name : (ydr != null) ? ydr.Name : (ydd != null) ? ydd.Name : (yft != null) ? yft.Name : string.Empty; + SaveTextureButton.Enabled = true; } else { @@ -426,10 +387,57 @@ namespace CodeWalker.World SelTextureMipTrackBar.Value = 0; SelTextureMipTrackBar.Maximum = 0; SelTextureDimensionsLabel.Text = "-"; + SaveTextureButton.Enabled = false; currentTex = null; } } + private Texture TryGetTexture(TextureBase texbase, out YtdFile ytd, ref string errstr) + { + //need to load from txd. + var arch = Selection.Archetype; + uint texhash = texbase.NameHash; + uint txdHash = (arch != null) ? arch.TextureDict.Hash : 0; + var tex = TryGetTextureFromYtd(texhash, txdHash, out ytd); + if (tex == null) + { //search parent ytds... + uint ptxdhash = WorldForm.GameFileCache.TryGetParentYtdHash(txdHash); + while ((ptxdhash != 0) && (tex == null)) + { + tex = TryGetTextureFromYtd(texhash, ptxdhash, out ytd); + if (tex == null) + { + ptxdhash = WorldForm.GameFileCache.TryGetParentYtdHash(ptxdhash); + } + else + { } + } + if (tex == null) + { + ytd = WorldForm.GameFileCache.TryGetTextureDictForTexture(texhash); + if (ytd != null) + { + int tries = 0; + while (!ytd.Loaded && (tries < 500)) //wait upto ~5 sec + { + System.Threading.Thread.Sleep(10); + tries++; + } + if (ytd.Loaded) + { + tex = ytd.TextureDict.Lookup(texhash); + } + } + if (tex == null) + { + ytd = null; + errstr = ""; + } + } + } + return tex; + } + private Texture TryGetTextureFromYtd(uint texHash, uint txdHash, out YtdFile ytd) { if (txdHash != 0) @@ -528,6 +536,46 @@ namespace CodeWalker.World HierarchyPropertyGrid.SelectedObject = sele; } + private void SaveAllTexturesButton_Click(object sender, EventArgs e) + { + if (FolderBrowserDialog.ShowDialog() != DialogResult.OK) return; + string folderpath = FolderBrowserDialog.SelectedPath; + if (!folderpath.EndsWith("\\")) folderpath += "\\"; + + var texs = new List(); + foreach (TreeNode modelnode in SelDrawableTexturesTreeView.Nodes) + { + foreach (TreeNode geomnode in modelnode.Nodes) + { + foreach (TreeNode texnode in geomnode.Nodes) + { + var texbase = texnode.Tag as TextureBase; + var tex = texbase as Texture; + string errstr = ""; + if ((tex == null) && (texbase != null)) + { + tex = TryGetTexture(texbase, out _, ref errstr); + } + if (tex != null) + { + if (!texs.Contains(tex)) + { + texs.Add(tex); + } + } + } + } + } + + foreach (var tex in texs) + { + string fpath = folderpath + tex.Name + ".dds"; + byte[] dds = DDSIO.GetDDSFile(tex); + File.WriteAllBytes(fpath, dds); + } + + } + private void SaveTextureButton_Click(object sender, EventArgs e) { if (currentTex == null) return; diff --git a/CodeWalker/World/WorldInfoForm.resx b/CodeWalker/World/WorldInfoForm.resx index c7e1c95..f1325ce 100644 --- a/CodeWalker/World/WorldInfoForm.resx +++ b/CodeWalker/World/WorldInfoForm.resx @@ -120,6 +120,9 @@ 17, 17 + + 148, 17 +