From 8be79bcd1739473340abd00ee4e88496afe2c4ef Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sun, 7 Jul 2024 14:51:51 +0200 Subject: [PATCH 01/14] MainForm - Fix null exception when droping in anything other than a file onto start page --- PCK-Studio/MainForm.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 7b0f3923..28fb46d6 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -1944,7 +1944,7 @@ private void CheckSaveState() private void OpenPck_DragEnter(object sender, DragEventArgs e) { pckOpen.Image = Resources.pckDrop; - string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); + string[] files = (string[])e.Data.GetData(DataFormats.FileDrop) ?? Array.Empty(); foreach (string file in files) { string ext = Path.GetExtension(file); From 384e1e2246654433f664d698a5dce8fad0a55766 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Thu, 11 Jul 2024 12:17:49 +0200 Subject: [PATCH 02/14] AddLanguage - Fix returning empty string when nothing is selected --- PCK-Studio/Forms/Additional-Popups/Loc/AddLanguage.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/PCK-Studio/Forms/Additional-Popups/Loc/AddLanguage.cs b/PCK-Studio/Forms/Additional-Popups/Loc/AddLanguage.cs index 7ee71b98..1ee39979 100644 --- a/PCK-Studio/Forms/Additional-Popups/Loc/AddLanguage.cs +++ b/PCK-Studio/Forms/Additional-Popups/Loc/AddLanguage.cs @@ -10,6 +10,7 @@ public AddLanguage(string[] avalibleLanguages) { InitializeComponent(); LanguageComboBox.Items.AddRange(avalibleLanguages); + LanguageComboBox.SelectedIndex = 0; } private void AddBtn_Click(object sender, EventArgs e) From 3f897beb1d8a3199da5378f134a27db208c60c14 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Thu, 11 Jul 2024 12:19:54 +0200 Subject: [PATCH 03/14] LOCEditor - Fix resizing bug and overall errors that where occurring --- PCK-Studio/Forms/Editor/LOCEditor.Designer.cs | 38 ++++-- PCK-Studio/Forms/Editor/LOCEditor.cs | 51 +++----- PCK-Studio/Forms/Editor/LOCEditor.resx | 122 +++++++++++------- 3 files changed, 126 insertions(+), 85 deletions(-) diff --git a/PCK-Studio/Forms/Editor/LOCEditor.Designer.cs b/PCK-Studio/Forms/Editor/LOCEditor.Designer.cs index 0b1f3d13..999fb412 100644 --- a/PCK-Studio/Forms/Editor/LOCEditor.Designer.cs +++ b/PCK-Studio/Forms/Editor/LOCEditor.Designer.cs @@ -45,6 +45,8 @@ private void InitializeComponent() this.dataGridViewLocEntryData = new System.Windows.Forms.DataGridView(); this.textBoxReplaceAll = new System.Windows.Forms.TextBox(); this.treeViewLocKeys = new System.Windows.Forms.TreeView(); + this.Language = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.DisplayName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.contextMenuStrip1.SuspendLayout(); this.GridContextMenu.SuspendLayout(); this.menuStrip.SuspendLayout(); @@ -95,9 +97,10 @@ private void InitializeComponent() // menuStrip // this.menuStrip.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(13)))), ((int)(((byte)(13)))), ((int)(((byte)(13))))); + this.locSort.SetColumnSpan(this.menuStrip, 3); + resources.ApplyResources(this.menuStrip, "menuStrip"); this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem}); - resources.ApplyResources(this.menuStrip, "menuStrip"); this.menuStrip.Name = "menuStrip"; // // fileToolStripMenuItem @@ -118,10 +121,11 @@ private void InitializeComponent() // this.locSort.AccessibleRole = System.Windows.Forms.AccessibleRole.Table; resources.ApplyResources(this.locSort, "locSort"); - this.locSort.Controls.Add(this.buttonReplaceAll, 2, 0); - this.locSort.Controls.Add(this.dataGridViewLocEntryData, 1, 1); - this.locSort.Controls.Add(this.textBoxReplaceAll, 1, 0); - this.locSort.Controls.Add(this.treeViewLocKeys, 0, 0); + this.locSort.Controls.Add(this.buttonReplaceAll, 2, 1); + this.locSort.Controls.Add(this.dataGridViewLocEntryData, 1, 2); + this.locSort.Controls.Add(this.menuStrip, 0, 0); + this.locSort.Controls.Add(this.textBoxReplaceAll, 1, 1); + this.locSort.Controls.Add(this.treeViewLocKeys, 0, 1); this.locSort.Name = "locSort"; // // buttonReplaceAll @@ -136,6 +140,8 @@ private void InitializeComponent() // this.dataGridViewLocEntryData.AllowUserToAddRows = false; this.dataGridViewLocEntryData.AllowUserToDeleteRows = false; + this.dataGridViewLocEntryData.AllowUserToResizeColumns = false; + this.dataGridViewLocEntryData.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dataGridViewLocEntryData.BackgroundColor = System.Drawing.Color.FromArgb(((int)(((byte)(13)))), ((int)(((byte)(13)))), ((int)(((byte)(13))))); this.dataGridViewLocEntryData.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control; @@ -145,7 +151,10 @@ private void InitializeComponent() dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; this.dataGridViewLocEntryData.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; - this.dataGridViewLocEntryData.ColumnHeadersVisible = false; + this.dataGridViewLocEntryData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; + this.dataGridViewLocEntryData.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Language, + this.DisplayName}); this.locSort.SetColumnSpan(this.dataGridViewLocEntryData, 2); this.dataGridViewLocEntryData.ContextMenuStrip = this.GridContextMenu; resources.ApplyResources(this.dataGridViewLocEntryData, "dataGridViewLocEntryData"); @@ -171,18 +180,28 @@ private void InitializeComponent() this.treeViewLocKeys.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViewLocKeys_AfterSelect); this.treeViewLocKeys.KeyDown += new System.Windows.Forms.KeyEventHandler(this.treeView1_KeyDown); // + // Language + // + this.Language.FillWeight = 15F; + resources.ApplyResources(this.Language, "Language"); + this.Language.Name = "Language"; + this.Language.ReadOnly = true; + // + // DisplayName + // + resources.ApplyResources(this.DisplayName, "DisplayName"); + this.DisplayName.Name = "DisplayName"; + // // LOCEditor // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.menuStrip); this.Controls.Add(this.locSort); this.Name = "LOCEditor"; this.Style = MetroFramework.MetroColorStyle.Silver; this.Theme = MetroFramework.MetroThemeStyle.Dark; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.LOCEditor_FormClosing); this.Load += new System.EventHandler(this.LOCEditor_Load); - this.Resize += new System.EventHandler(this.LOCEditor_Resize); this.contextMenuStrip1.ResumeLayout(false); this.GridContextMenu.ResumeLayout(false); this.menuStrip.ResumeLayout(false); @@ -191,7 +210,6 @@ private void InitializeComponent() this.locSort.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewLocEntryData)).EndInit(); this.ResumeLayout(false); - this.PerformLayout(); } @@ -211,5 +229,7 @@ private void InitializeComponent() private System.Windows.Forms.MenuStrip menuStrip; private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem; + private System.Windows.Forms.DataGridViewTextBoxColumn Language; + private System.Windows.Forms.DataGridViewTextBoxColumn DisplayName; } } \ No newline at end of file diff --git a/PCK-Studio/Forms/Editor/LOCEditor.cs b/PCK-Studio/Forms/Editor/LOCEditor.cs index def6082f..ca829183 100644 --- a/PCK-Studio/Forms/Editor/LOCEditor.cs +++ b/PCK-Studio/Forms/Editor/LOCEditor.cs @@ -17,7 +17,6 @@ namespace PckStudio.Forms.Editor { public partial class LOCEditor : MetroForm { - DataTable tbl; LOCFile currentLoc; PckAsset _asset; @@ -30,13 +29,6 @@ public LOCEditor(PckAsset asset) var reader = new LOCFileReader(); currentLoc = reader.FromStream(ms); } - tbl = new DataTable(); - tbl.Columns.Add(new DataColumn("Language") { ReadOnly = true }); - tbl.Columns.Add("Display Name"); - dataGridViewLocEntryData.DataSource = tbl; - DataGridViewColumn column = dataGridViewLocEntryData.Columns[1]; - column.Width = dataGridViewLocEntryData.Width; - saveToolStripMenuItem.Visible = !Settings.Default.AutoSaveChanges; } @@ -61,17 +53,15 @@ private void treeViewLocKeys_AfterSelect(object sender, TreeViewEventArgs e) private void addDisplayIDToolStripMenuItem_Click(object sender, EventArgs e) { - if (treeViewLocKeys.SelectedNode is TreeNode) - using (TextPrompt prompt = new TextPrompt()) + using (TextPrompt prompt = new TextPrompt()) + { + prompt.OKButtonText = "Add"; + if (prompt.ShowDialog(this) == DialogResult.OK && + currentLoc.AddLocKey(prompt.NewText, "")) { - prompt.OKButtonText = "Add"; - if (prompt.ShowDialog(this) == DialogResult.OK && - !currentLoc.LocKeys.ContainsKey(prompt.NewText) && - currentLoc.AddLocKey(prompt.NewText, "")) - { - treeViewLocKeys.Nodes.Add(prompt.NewText); - } + treeViewLocKeys.Nodes.Add(prompt.NewText); } + } } private void deleteDisplayIDToolStripMenuItem_Click(object sender, EventArgs e) @@ -79,18 +69,23 @@ private void deleteDisplayIDToolStripMenuItem_Click(object sender, EventArgs e) if (treeViewLocKeys.SelectedNode is TreeNode t && currentLoc.RemoveLocKey(t.Text)) { treeViewLocKeys.SelectedNode.Remove(); + ReloadTranslationTable(); } } private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { - if (e.ColumnIndex != 1 || - treeViewLocKeys.SelectedNode == null) + if (e.ColumnIndex != 1 || + treeViewLocKeys.SelectedNode is null) { MessageBox.Show(this, "something went wrong"); return; } - currentLoc.SetLocEntry(treeViewLocKeys.SelectedNode.Text, tbl.Rows[e.RowIndex][0].ToString(), tbl.Rows[e.RowIndex][1].ToString()); + var row = dataGridViewLocEntryData.Rows[e.RowIndex]; + string locKey = treeViewLocKeys.SelectedNode.Text; + string language = row.Cells[0].Value.ToString(); + string value = row.Cells[1].Value.ToString(); + currentLoc.SetLocEntry(locKey, language, value); } private void treeView1_KeyDown(object sender, KeyEventArgs e) @@ -101,25 +96,21 @@ private void treeView1_KeyDown(object sender, KeyEventArgs e) private void buttonReplaceAll_Click(object sender, EventArgs e) { - for (int i = 0; i < tbl.Rows.Count; i++) + for (int i = 0; i < dataGridViewLocEntryData.Rows.Count; i++) { - tbl.Rows[i][1] = textBoxReplaceAll.Text; + dataGridViewLocEntryData.Rows[i].Cells[1].Value = textBoxReplaceAll.Text; } currentLoc.SetLocEntry(treeViewLocKeys.SelectedNode.Text, textBoxReplaceAll.Text); } - private void LOCEditor_Resize(object sender, EventArgs e) - { - DataGridViewColumn column = dataGridViewLocEntryData.Columns[1]; - column.Width = dataGridViewLocEntryData.Width - dataGridViewLocEntryData.Columns[0].Width; - } - private void ReloadTranslationTable() { - tbl.Rows.Clear(); + dataGridViewLocEntryData.Rows.Clear(); + if (treeViewLocKeys.SelectedNode is null) + return; foreach (var l in currentLoc.GetLocEntries(treeViewLocKeys.SelectedNode.Text)) - tbl.Rows.Add(l.Key, l.Value); + dataGridViewLocEntryData.Rows.Add(l.Key, l.Value); } private IEnumerable GetAvailableLanguages() diff --git a/PCK-Studio/Forms/Editor/LOCEditor.resx b/PCK-Studio/Forms/Editor/LOCEditor.resx index 76a0a275..73b694cc 100644 --- a/PCK-Studio/Forms/Editor/LOCEditor.resx +++ b/PCK-Studio/Forms/Editor/LOCEditor.resx @@ -169,40 +169,7 @@ 321, 17 - - 98, 22 - - - Save - - - 37, 20 - - - File - - - 20, 60 - - - 860, 24 - - - 4 - - - menuStrip - - - System.Windows.Forms.MenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 2 - 3 @@ -214,7 +181,7 @@ NoControl - 783, 3 + 783, 23 74, 23 @@ -237,14 +204,26 @@ 0 + + True + + + Language + + + True + + + Display Name + Fill - 303, 32 + 303, 52 - 554, 525 + 554, 532 1 @@ -265,7 +244,7 @@ Fill - 303, 3 + 303, 23 474, 20 @@ -283,16 +262,16 @@ locSort - 2 + 3 Fill - 3, 3 + 3, 23 - 294, 554 + 294, 561 0 @@ -307,16 +286,19 @@ locSort - 3 + 4 + + + Fill - 20, 87 + 20, 60 - 2 + 3 - 860, 560 + 860, 587 3 @@ -331,10 +313,46 @@ $this - 3 + 2 - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="buttonReplaceAll" Row="0" RowSpan="1" Column="2" ColumnSpan="1" /><Control Name="dataGridViewLocEntryData" Row="1" RowSpan="1" Column="1" ColumnSpan="2" /><Control Name="textBoxReplaceAll" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="treeViewLocKeys" Row="0" RowSpan="2" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Absolute,300,Percent,100,AutoSize,0" /><Rows Styles="AutoSize,0,Percent,100,Absolute,20" /></TableLayoutSettings> + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="buttonReplaceAll" Row="1" RowSpan="1" Column="2" ColumnSpan="1" /><Control Name="dataGridViewLocEntryData" Row="2" RowSpan="1" Column="1" ColumnSpan="2" /><Control Name="menuStrip" Row="0" RowSpan="1" Column="0" ColumnSpan="3" /><Control Name="textBoxReplaceAll" Row="1" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="treeViewLocKeys" Row="1" RowSpan="2" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Absolute,300,Percent,100,AutoSize,0" /><Rows Styles="Absolute,20,AutoSize,0,Percent,100" /></TableLayoutSettings> + + + Fill + + + 98, 22 + + + Save + + + 37, 16 + + + File + + + 0, 0 + + + 860, 20 + + + 4 + + + menuStrip + + + System.Windows.Forms.MenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + locSort + + + 2 True @@ -2896,6 +2914,18 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Language + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + DisplayName + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + LOCEditor From ae0650e385d05cc8dd158371d31d7a0bcfc9febf Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Thu, 11 Jul 2024 13:42:40 +0200 Subject: [PATCH 04/14] v7.0.0.2 --- PCK-Studio/Properties/AssemblyInfo.cs | 2 +- Version.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/PCK-Studio/Properties/AssemblyInfo.cs b/PCK-Studio/Properties/AssemblyInfo.cs index 967d6ade..bf8b4f5d 100644 --- a/PCK-Studio/Properties/AssemblyInfo.cs +++ b/PCK-Studio/Properties/AssemblyInfo.cs @@ -32,6 +32,6 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("7.0.0.1")] +[assembly: AssemblyVersion("7.0.0.2")] [assembly: AssemblyFileVersion("7.0.0.0")] [assembly: NeutralResourcesLanguage("")] diff --git a/Version.json b/Version.json index e4be63b7..88ef4e47 100644 --- a/Version.json +++ b/Version.json @@ -1,6 +1,6 @@ { - "version": "7.0.0.1", - "url": "https://github.com/PhoenixARC/-PCK-Studio/releases/download/v7.0.0.1/PCK-Studio.zip", + "version": "7.0.0.2", + "url": "https://github.com/PhoenixARC/-PCK-Studio/releases/download/v7.0.0.2/PCK-Studio.zip", "changelog": "https://raw.githubusercontent.com/PhoenixARC/-PCK-Studio/main/CHANGELOG.md", "mandatory": false } \ No newline at end of file From 2a1be6cf4c015cd025a80a5abd85f49665179c27 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sun, 14 Jul 2024 17:49:40 +0200 Subject: [PATCH 05/14] MainForm - Remove prioritizing Skins.pck when adding skins --- PCK-Studio/MainForm.cs | 48 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 28fb46d6..6e3d7d75 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -961,36 +961,36 @@ private void createSkinToolStripMenuItem_Click(object sender, EventArgs e) using AddSkinPrompt add = new AddSkinPrompt(locFile); if (add.ShowDialog(this) == DialogResult.OK) { - if (currentPCK.HasAsset("Skins.pck", PckAssetType.SkinDataFile)) // Prioritize Skins.pck - { - TreeNode subPCK = treeViewMain.Nodes.Find("Skins.pck", false).FirstOrDefault(); - if (subPCK.Nodes.ContainsKey("Skins")) add.SkinAsset.Filename = add.SkinAsset.Filename.Insert(0, "Skins/"); - add.SkinAsset.Filename = add.SkinAsset.Filename.Insert(0, "Skins.pck/"); - TreeNode newNode = new TreeNode(Path.GetFileName(add.SkinAsset.Filename)); - newNode.Tag = add.SkinAsset; - SetNodeIcon(newNode, PckAssetType.SkinFile); - subPCK.Nodes.Add(newNode); - RebuildSubPCK(newNode.FullPath); - } - else + //if (currentPCK.HasAsset("Skins.pck", PckAssetType.SkinDataFile)) // Prioritize Skins.pck + //{ + // TreeNode subPCK = treeViewMain.Nodes.Find("Skins.pck", false).FirstOrDefault(); + // if (subPCK.Nodes.ContainsKey("Skins")) add.SkinAsset.Filename = add.SkinAsset.Filename.Insert(0, "Skins/"); + // add.SkinAsset.Filename = add.SkinAsset.Filename.Insert(0, "Skins.pck/"); + // TreeNode newNode = new TreeNode(Path.GetFileName(add.SkinAsset.Filename)); + // newNode.Tag = add.SkinAsset; + // SetNodeIcon(newNode, PckAssetType.SkinFile); + // subPCK.Nodes.Add(newNode); + // RebuildSubPCK(newNode.FullPath); + //} + //else { if (treeViewMain.Nodes.ContainsKey("Skins")) add.SkinAsset.Filename = add.SkinAsset.Filename.Insert(0, "Skins/"); // Then Skins folder currentPCK.AddAsset(add.SkinAsset); } if (add.HasCape) { - if (currentPCK.HasAsset("Skins.pck", PckAssetType.SkinDataFile)) // Prioritize Skins.pck - { - TreeNode subPCK = treeViewMain.Nodes.Find("Skins.pck", false).FirstOrDefault(); - if (subPCK.Nodes.ContainsKey("Skins")) add.CapeAsset.Filename = add.CapeAsset.Filename.Insert(0, "Skins/"); - add.CapeAsset.Filename = add.CapeAsset.Filename.Insert(0, "Skins.pck/"); - TreeNode newNode = new TreeNode(Path.GetFileName(add.CapeAsset.Filename)); - newNode.Tag = add.CapeAsset; - SetNodeIcon(newNode, PckAssetType.SkinFile); - subPCK.Nodes.Add(newNode); - RebuildSubPCK(newNode.FullPath); - } - else + //if (currentPCK.HasAsset("Skins.pck", PckAssetType.SkinDataFile)) // Prioritize Skins.pck + //{ + // TreeNode subPCK = treeViewMain.Nodes.Find("Skins.pck", false).FirstOrDefault(); + // if (subPCK.Nodes.ContainsKey("Skins")) add.CapeAsset.Filename = add.CapeAsset.Filename.Insert(0, "Skins/"); + // add.CapeAsset.Filename = add.CapeAsset.Filename.Insert(0, "Skins.pck/"); + // TreeNode newNode = new TreeNode(Path.GetFileName(add.CapeAsset.Filename)); + // newNode.Tag = add.CapeAsset; + // SetNodeIcon(newNode, PckAssetType.SkinFile); + // subPCK.Nodes.Add(newNode); + // RebuildSubPCK(newNode.FullPath); + //} + //else { if (treeViewMain.Nodes.ContainsKey("Skins")) add.CapeAsset.Filename = add.CapeAsset.Filename.Insert(0, "Skins/"); // Then Skins folder currentPCK.AddAsset(add.CapeAsset); From 5b3c76723afa522878721fb774a00053407ddb38 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sun, 14 Jul 2024 17:57:40 +0200 Subject: [PATCH 06/14] FilterPrompt - Add 'PageBackColor' property for setting background color --- PCK-Studio/Forms/Additional-Popups/FilterPrompt.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/PCK-Studio/Forms/Additional-Popups/FilterPrompt.cs b/PCK-Studio/Forms/Additional-Popups/FilterPrompt.cs index f2a2c2f5..19162383 100644 --- a/PCK-Studio/Forms/Additional-Popups/FilterPrompt.cs +++ b/PCK-Studio/Forms/Additional-Popups/FilterPrompt.cs @@ -29,6 +29,8 @@ internal partial class FilterPrompt : MetroForm public string AcceptButtonText { get => acceptButton.Text; set => acceptButton.Text = value; } public string CancelButtonText { get => cancelButton.Text; set => cancelButton.Text = value; } + public Color PageBackColor { get; set; } = Color.FromArgb(64, 64, 64); + private object selectedItem; public object SelectedItem => selectedItem; @@ -56,7 +58,7 @@ public TreeView AddFilterPage(string categoryName, string key, FilterPredicate f var pageView = new TreeView() { Dock = DockStyle.Fill, - BackColor = Color.FromArgb(64, 64, 64), + BackColor = PageBackColor, }; pageView.AfterSelect += (sender, e) => { From 70c45352962943f9be494512f2042d91168f0758 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sun, 14 Jul 2024 17:58:29 +0200 Subject: [PATCH 07/14] MainForm - Remove adding 'Skins' folder inside Skins.pck --- PCK-Studio/MainForm.cs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 6e3d7d75..9d5902d3 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -429,15 +429,15 @@ private void BuildMainTreeView() treeViewMain.Nodes.Clear(); BuildPckTreeView(treeViewMain.Nodes, currentPCK); - if (isTemplateFile && currentPCK.HasAsset("Skins.pck", PckAssetType.SkinDataFile)) - { - TreeNode skinsNode = treeViewMain.Nodes.Find("Skins.pck", false).FirstOrDefault(); - TreeNode folderNode = CreateNode("Skins"); - folderNode.ImageIndex = 0; - folderNode.SelectedImageIndex = 0; - if (!skinsNode.Nodes.ContainsKey("Skins")) - skinsNode.Nodes.Add(folderNode); - } + //if (isTemplateFile && currentPCK.HasAsset("Skins.pck", PckAssetType.SkinDataFile)) + //{ + // TreeNode skinsNode = treeViewMain.Nodes.Find("Skins.pck", false).FirstOrDefault(); + // TreeNode folderNode = CreateNode("Skins"); + // folderNode.ImageIndex = 0; + // folderNode.SelectedImageIndex = 0; + // if (!skinsNode.Nodes.ContainsKey("Skins")) + // skinsNode.Nodes.Add(folderNode); + //} treeViewMain.Sort(); TreeNode[] selectedNodes = treeViewMain.FindPath(selectedNodeText); @@ -2238,12 +2238,6 @@ private void CreateSkinsPCKToolStripMenuItem1_Click(object sender, EventArgs e) LittleEndianCheckBox.Checked ? OMI.Endianness.LittleEndian : OMI.Endianness.BigEndian)); BuildMainTreeView(); - - TreeNode skinsNode = treeViewMain.Nodes.Find("Skins.pck", false).FirstOrDefault(); - TreeNode folderNode = CreateNode("Skins"); - folderNode.ImageIndex = 0; - folderNode.SelectedImageIndex = 0; - skinsNode.Nodes.Add(folderNode); } private void editAllEntriesToolStripMenuItem_Click(object sender, EventArgs e) From 7be4ca67b2db785242c8fede327cdad942e51f85 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sun, 14 Jul 2024 19:15:10 +0200 Subject: [PATCH 08/14] Editors - Use extension method 'GetData' to deserialize data --- PCK-Studio/Forms/Editor/AudioEditor.cs | 6 +----- PCK-Studio/Forms/Editor/COLEditor.cs | 7 +------ PCK-Studio/Forms/Editor/LOCEditor.cs | 6 +----- PCK-Studio/MainForm.cs | 6 +----- 4 files changed, 4 insertions(+), 21 deletions(-) diff --git a/PCK-Studio/Forms/Editor/AudioEditor.cs b/PCK-Studio/Forms/Editor/AudioEditor.cs index 0e545d67..9ced2d7d 100644 --- a/PCK-Studio/Forms/Editor/AudioEditor.cs +++ b/PCK-Studio/Forms/Editor/AudioEditor.cs @@ -72,11 +72,7 @@ public AudioEditor(PckAsset asset, bool isLittleEndian) _isLittleEndian = isLittleEndian; _audioAsset = asset; - using (var stream = new MemoryStream(asset.Data)) - { - var reader = new PckAudioFileReader(isLittleEndian ? OMI.Endianness.LittleEndian : OMI.Endianness.BigEndian); - _audioFile = reader.FromStream(stream); - } + _audioFile = _audioAsset.GetData(new PckAudioFileReader(isLittleEndian ? OMI.Endianness.LittleEndian : OMI.Endianness.BigEndian)); SetUpTree(); } diff --git a/PCK-Studio/Forms/Editor/COLEditor.cs b/PCK-Studio/Forms/Editor/COLEditor.cs index cf2f9bda..c61fb1b9 100644 --- a/PCK-Studio/Forms/Editor/COLEditor.cs +++ b/PCK-Studio/Forms/Editor/COLEditor.cs @@ -33,12 +33,7 @@ public COLEditor(PckAsset asset) saveToolStripMenuItem1.Visible = !Settings.Default.AutoSaveChanges; _asset = asset; - - using(var stream = new MemoryStream(asset.Data)) - { - var reader = new COLFileReader(); - colourfile = reader.FromStream(stream); - } + colourfile = asset.GetData(new COLFileReader()); TU12ToolStripMenuItem.Click += (sender, e) => SetUpDefaultFile(sender, e, 0); TU13ToolStripMenuItem.Click += (sender, e) => SetUpDefaultFile(sender, e, 1); diff --git a/PCK-Studio/Forms/Editor/LOCEditor.cs b/PCK-Studio/Forms/Editor/LOCEditor.cs index ca829183..ebcc4ce8 100644 --- a/PCK-Studio/Forms/Editor/LOCEditor.cs +++ b/PCK-Studio/Forms/Editor/LOCEditor.cs @@ -24,11 +24,7 @@ public LOCEditor(PckAsset asset) { InitializeComponent(); _asset = asset; - using (var ms = new MemoryStream(asset.Data)) - { - var reader = new LOCFileReader(); - currentLoc = reader.FromStream(ms); - } + currentLoc = asset.GetData(new LOCFileReader()); saveToolStripMenuItem.Visible = !Settings.Default.AutoSaveChanges; } diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 9d5902d3..78bbfd41 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -1752,11 +1752,7 @@ private bool TryGetLocFile(out LOCFile locFile) try { - using (var stream = new MemoryStream(locAsset.Data)) - { - var reader = new LOCFileReader(); - locFile = reader.FromStream(stream); - } + locFile = locAsset.GetData(new LOCFileReader()); return true; } catch (Exception ex) From 6af20ea0bf6a8bea3b9a2915d48bd28edf636f05 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sun, 14 Jul 2024 19:17:54 +0200 Subject: [PATCH 09/14] PckAudioFile - Rename member variable 'audioType' to 'AudioType' --- PCK-Studio/FileFormats/PckAudioFile.cs | 6 +++--- PCK-Studio/Forms/Editor/AudioEditor.cs | 12 ++++++------ .../Internal/IO/PckAudio/PckAudioFileWriter.cs | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/PCK-Studio/FileFormats/PckAudioFile.cs b/PCK-Studio/FileFormats/PckAudioFile.cs index 0ceb6608..22f3671b 100644 --- a/PCK-Studio/FileFormats/PckAudioFile.cs +++ b/PCK-Studio/FileFormats/PckAudioFile.cs @@ -44,15 +44,15 @@ public enum EAudioParameterType : int } public string Name { get; set; } = string.Empty; - public EAudioParameterType parameterType { get; } - public EAudioType audioType { get; } + public EAudioType AudioType { get; } public List SongNames { get; } = new List(); + public EAudioParameterType parameterType { get; } public AudioCategory(string name, EAudioParameterType parameterType, EAudioType audioType) { this.Name = name; this.parameterType = parameterType; - this.audioType = audioType; + this.AudioType = audioType; } } diff --git a/PCK-Studio/Forms/Editor/AudioEditor.cs b/PCK-Studio/Forms/Editor/AudioEditor.cs index 9ced2d7d..24c50f8c 100644 --- a/PCK-Studio/Forms/Editor/AudioEditor.cs +++ b/PCK-Studio/Forms/Editor/AudioEditor.cs @@ -89,7 +89,7 @@ public void SetUpTree() foreach (string songname in category.SongNames.FindAll(s => s.Contains('\\'))) category.SongNames[category.SongNames.IndexOf(songname)] = songname.Replace('\\', '/'); - if (category.audioType == PckAudioFile.AudioCategory.EAudioType.Creative) + if (category.AudioType == PckAudioFile.AudioCategory.EAudioType.Creative) { if (category.Name == "include_overworld" && _audioFile.TryGetCategory(PckAudioFile.AudioCategory.EAudioType.Overworld, out PckAudioFile.AudioCategory overworldCategory)) @@ -104,7 +104,7 @@ public void SetUpTree() playOverworldInCreative.Visible = true; } - TreeNode treeNode = new TreeNode(GetCategoryFromId(category.audioType), (int)category.audioType, (int)category.audioType); + TreeNode treeNode = new TreeNode(GetCategoryFromId(category.AudioType), (int)category.AudioType, (int)category.AudioType); treeNode.Tag = category; treeView1.Nodes.Add(treeNode); } @@ -153,7 +153,7 @@ private void addCategoryStripMenuItem_Click(object sender, EventArgs e) playOverworldInCreative.Checked = false; } - TreeNode treeNode = new TreeNode(GetCategoryFromId(category.audioType), (int)category.audioType, (int)category.audioType); + TreeNode treeNode = new TreeNode(GetCategoryFromId(category.AudioType), (int)category.AudioType, (int)category.AudioType); treeNode.Tag = category; treeView1.Nodes.Add(treeNode); @@ -386,7 +386,7 @@ private void saveToolStripMenuItem1_Click(object sender, EventArgs e) } category.Name = ""; - if (playOverworldInCreative.Checked && category.audioType == PckAudioFile.AudioCategory.EAudioType.Creative) + if (playOverworldInCreative.Checked && category.AudioType == PckAudioFile.AudioCategory.EAudioType.Creative) { foreach (var name in overworldCategory.SongNames) { @@ -576,9 +576,9 @@ private void setCategoryToolStripMenuItem_Click(object sender, EventArgs e) add.ButtonText = "Save"; if (add.ShowDialog(this) != DialogResult.OK) return; - _audioFile.RemoveCategory(category.audioType); + _audioFile.RemoveCategory(category.AudioType); - _audioFile.AddCategory(category.parameterType, GetCategoryId(add.SelectedItem), category.audioType == PckAudioFile.AudioCategory.EAudioType.Overworld && playOverworldInCreative.Checked ? "include_overworld" : ""); + _audioFile.AddCategory(category.parameterType, GetCategoryId(add.SelectedItem), category.AudioType == PckAudioFile.AudioCategory.EAudioType.Overworld && playOverworldInCreative.Checked ? "include_overworld" : ""); var newCategory = _audioFile.GetCategory(GetCategoryId(add.SelectedItem)); diff --git a/PCK-Studio/Internal/IO/PckAudio/PckAudioFileWriter.cs b/PCK-Studio/Internal/IO/PckAudio/PckAudioFileWriter.cs index a2bfa4c7..ffed6cba 100644 --- a/PCK-Studio/Internal/IO/PckAudio/PckAudioFileWriter.cs +++ b/PCK-Studio/Internal/IO/PckAudio/PckAudioFileWriter.cs @@ -71,7 +71,7 @@ private void WriteCategories(EndiannessAwareBinaryWriter writer) foreach (var category in _file.Categories) { writer.Write((int)category.parameterType); - writer.Write((int)category.audioType); + writer.Write((int)category.AudioType); WriteString(writer, category.Name); } } From b4aaef0c8d33bba83c49bb0b1f26c734e8a5035b Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sun, 14 Jul 2024 19:19:15 +0200 Subject: [PATCH 10/14] COLEditor - Clean up default color table initialization --- PCK-Studio/Forms/Editor/COLEditor.cs | 40 +++++++++++++++------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/PCK-Studio/Forms/Editor/COLEditor.cs b/PCK-Studio/Forms/Editor/COLEditor.cs index c61fb1b9..db7158e4 100644 --- a/PCK-Studio/Forms/Editor/COLEditor.cs +++ b/PCK-Studio/Forms/Editor/COLEditor.cs @@ -63,26 +63,30 @@ private void SetUpDefaultFile(object sender, EventArgs e, int ID, bool targetVer if (result == DialogResult.No) return; } + byte[] colorData = ID switch + { + 0 => Resources.tu12colours, + 1 => Resources.tu13colours, + 2 => Resources.tu14colours, + 3 => Resources.tu19colours, + 4 => Resources.tu31colours, + 5 => Resources.tu32colours, + 6 => Resources.tu43colours, + 7 => Resources.tu46colours, + 8 => Resources.tu51colours, + 9 => Resources.tu53colours, + 10 => Resources.tu54colours, + 11 => Resources.tu69colours, + 12 => Resources._1_91_colours, + _ => throw new ArgumentOutOfRangeException(nameof(ID)), + }; var reader = new COLFileReader(); - - switch (ID) + using (var stream = new MemoryStream(colorData)) { - case 0: using (var stream = new MemoryStream(Properties.Resources.tu12colours)) default_colourfile = reader.FromStream(stream); break; - case 1: using (var stream = new MemoryStream(Properties.Resources.tu13colours)) default_colourfile = reader.FromStream(stream); break; - case 2: using (var stream = new MemoryStream(Properties.Resources.tu14colours)) default_colourfile = reader.FromStream(stream); break; - case 3: using (var stream = new MemoryStream(Properties.Resources.tu19colours)) default_colourfile = reader.FromStream(stream); break; - case 4: using (var stream = new MemoryStream(Properties.Resources.tu31colours)) default_colourfile = reader.FromStream(stream); break; - case 5: using (var stream = new MemoryStream(Properties.Resources.tu32colours)) default_colourfile = reader.FromStream(stream); break; - case 6: using (var stream = new MemoryStream(Properties.Resources.tu43colours)) default_colourfile = reader.FromStream(stream); break; - case 7: using (var stream = new MemoryStream(Properties.Resources.tu46colours)) default_colourfile = reader.FromStream(stream); break; - case 8: using (var stream = new MemoryStream(Properties.Resources.tu51colours)) default_colourfile = reader.FromStream(stream); break; - case 9: using (var stream = new MemoryStream(Properties.Resources.tu53colours)) default_colourfile = reader.FromStream(stream); break; - case 10: using (var stream = new MemoryStream(Properties.Resources.tu54colours)) default_colourfile = reader.FromStream(stream); break; - case 11: using (var stream = new MemoryStream(Properties.Resources.tu69colours)) default_colourfile = reader.FromStream(stream); break; - case 12: using (var stream = new MemoryStream(Properties.Resources._1_91_colours)) default_colourfile = reader.FromStream(stream); break; - default: return; - } - SetUpTable(targetVersion); + default_colourfile = reader.FromStream(stream); + } + + SetUpTable(targetVersion); } void AddEntry(TreeView treeView, List cache, string name, object tag) From 978c13674b29055c1c957f8b91f9dbab9af13dc8 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sun, 14 Jul 2024 19:20:29 +0200 Subject: [PATCH 11/14] Clean up AudioEditor --- PCK-Studio/Forms/Editor/AudioEditor.cs | 55 ++++++++++++++------------ 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/PCK-Studio/Forms/Editor/AudioEditor.cs b/PCK-Studio/Forms/Editor/AudioEditor.cs index 24c50f8c..f7655f33 100644 --- a/PCK-Studio/Forms/Editor/AudioEditor.cs +++ b/PCK-Studio/Forms/Editor/AudioEditor.cs @@ -33,7 +33,7 @@ public partial class AudioEditor : MetroForm bool _isLittleEndian = false; MainForm parent = null; - public static readonly List Categories = new List + private static readonly List Categories = new List { "Overworld", "Nether", @@ -114,55 +114,60 @@ public void SetUpTree() private void verifyFileLocationToolStripMenuItem_Click(object sender, EventArgs e) { - if (treeView1.SelectedNode == null || treeView2.SelectedNode == null) return; + if (treeView1.SelectedNode == null || treeView2.SelectedNode == null) + return; var entry = treeView2.SelectedNode; - if (!parent.CreateDataFolder()) return; + if (!parent.CreateDataFolder()) + return; string FileName = Path.Combine(parent.GetDataPath(), entry.Text + ".binka"); - if (File.Exists(FileName)) MessageBox.Show(this, "\"" + entry.Text + ".binka\" exists in the \"Data\" folder", "File found"); - else MessageBox.Show(this, "\"" + entry.Text + ".binka\" does not exist in the \"Data\" folder. The game will crash when attempting to load this track.", "File missing"); + if (File.Exists(FileName)) + MessageBox.Show(this, $"\"{entry.Text}.binka\" exists in the \"Data\" folder", "File found"); + else + MessageBox.Show(this, $"\"{entry.Text}.binka\" does not exist in the \"Data\" folder. The game will crash when attempting to load this track.", "File missing"); } private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { treeView2.Nodes.Clear(); if (e.Node.Tag is PckAudioFile.AudioCategory category) + { foreach (var name in category.SongNames) { treeView2.Nodes.Add(name); } - if (treeView2.Nodes.Count > 0) treeView2.SelectedNode = treeView2.Nodes[0]; + } + if (treeView2.Nodes.Count > 0) + treeView2.SelectedNode = treeView2.Nodes[0]; } private void addCategoryStripMenuItem_Click(object sender, EventArgs e) { string[] available = Categories.FindAll(str => !_audioFile.HasCategory(GetCategoryId(str))).ToArray(); - if (available.Length > 0) + if (available.Length == 0) { - using ItemSelectionPopUp add = new ItemSelectionPopUp(available); - if (add.ShowDialog(this) == DialogResult.OK) - _audioFile.AddCategory(GetCategoryId(add.SelectedItem)); - else return; + MessageBox.Show(this, "There are no more categories that could be added", "All possible categories are used"); + } + + using ItemSelectionPopUp add = new ItemSelectionPopUp(available); + if (add.ShowDialog(this) == DialogResult.OK) + _audioFile.AddCategory(GetCategoryId(add.SelectedItem)); + else return; - var category = _audioFile.GetCategory(GetCategoryId(add.SelectedItem)); + var category = _audioFile.GetCategory(GetCategoryId(add.SelectedItem)); - if (GetCategoryId(add.SelectedItem) == PckAudioFile.AudioCategory.EAudioType.Creative) - { - playOverworldInCreative.Visible = true; - playOverworldInCreative.Checked = false; - } + if (GetCategoryId(add.SelectedItem) == PckAudioFile.AudioCategory.EAudioType.Creative) + { + playOverworldInCreative.Visible = true; + playOverworldInCreative.Checked = false; + } TreeNode treeNode = new TreeNode(GetCategoryFromId(category.AudioType), (int)category.AudioType, (int)category.AudioType); - treeNode.Tag = category; - treeView1.Nodes.Add(treeNode); + treeNode.Tag = category; + treeView1.Nodes.Add(treeNode); - SetUpTree(); - } - else - { - MessageBox.Show(this, "There are no more categories that could be added", "All possible categories are used"); - } + SetUpTree(); } private void addEntryMenuItem_Click(object sender, EventArgs e) From 2dcc2c80c3ed5f1843186bead840f7196605a1ef Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sun, 14 Jul 2024 19:21:41 +0200 Subject: [PATCH 12/14] MainForm - Format code segments --- PCK-Studio/MainForm.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 78bbfd41..797749b7 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -567,7 +567,7 @@ private void HandleColourFile(PckAsset asset) { using COLEditor diag = new COLEditor(asset); wasModified = diag.ShowDialog(this) == DialogResult.OK; - } + } public void HandleSkinFile(PckAsset asset) { @@ -1687,8 +1687,10 @@ public bool CreateDataFolder() if (!HasDataFolder()) { DialogResult result = MessageBox.Show(this, "There is not a \"Data\" folder present in the pack folder. Would you like to create one?", "Folder missing", MessageBoxButtons.YesNo); - if (result == DialogResult.No) return false; - else Directory.CreateDirectory(GetDataPath()); + if (result == DialogResult.No) + return false; + else + Directory.CreateDirectory(GetDataPath()); } return true; } @@ -1926,7 +1928,7 @@ private void CheckSaveState() { if (currentPCK is not null && wasModified && - MessageBox.Show(this, "Save PCK?", "Unsaved PCK", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) + MessageBox.Show(this, "Save PCK?", "Unsaved PCK", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { if (isTemplateFile || string.IsNullOrEmpty(saveLocation)) { @@ -2125,13 +2127,12 @@ private void generateMipMapTextureToolStripMenuItem_Click(object sender, EventAr currentPCK.RemoveAsset(currentPCK.GetAsset(mippedPath, PckAssetType.TextureFile)); PckAsset mipMappedAsset = new PckAsset(mippedPath, PckAssetType.TextureFile); - Image originalTexture = asset.GetTexture(); - int NewWidth = Math.Max(originalTexture.Width / (int)Math.Pow(2, i - 1), 1); - int NewHeight = Math.Max(originalTexture.Height / (int)Math.Pow(2, i - 1), 1); + int newWidth = Math.Max(originalTexture.Width / (int)Math.Pow(2, i - 1), 1); + int newHeight = Math.Max(originalTexture.Height / (int)Math.Pow(2, i - 1), 1); - Rectangle tileArea = new Rectangle(0, 0, NewWidth, NewHeight); - Image mippedTexture = new Bitmap(NewWidth, NewHeight); + Rectangle tileArea = new Rectangle(0, 0, newWidth, newHeight); + Image mippedTexture = new Bitmap(newWidth, newHeight); using (Graphics gfx = Graphics.FromImage(mippedTexture)) { gfx.SmoothingMode = SmoothingMode.None; From c41fecde909001b5c3d7f90d6f4cb95ae678c6a9 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Tue, 16 Jul 2024 20:07:34 +0200 Subject: [PATCH 13/14] Format code to conform with code style guide lines --- PCK-Studio/FileFormats/CSMBFile.cs | 2 +- PCK-Studio/FileFormats/PckAudioFile.cs | 8 +- .../Forms/Additional-Popups/AddSkinPrompt.cs | 2 +- .../Additional-Popups/Animation/ChangeTile.cs | 4 +- .../Animation/FrameEditor.cs | 1 - .../Animation/SetBulkSpeed.cs | 2 +- .../Additional-Popups/EntityForms/AddEntry.cs | 6 +- .../Forms/Additional-Popups/FilterPrompt.cs | 9 +- .../Forms/Additional-Popups/TextPrompt.cs | 3 +- PCK-Studio/Forms/ContributorsForm.cs | 5 +- PCK-Studio/Forms/Editor/ANIMEditor.cs | 76 +++++++----- PCK-Studio/Forms/Editor/AnimationEditor.cs | 19 +-- PCK-Studio/Forms/Editor/AudioEditor.cs | 92 +++++++++------ PCK-Studio/Forms/Editor/BehaviourEditor.cs | 49 ++++---- PCK-Studio/Forms/Editor/BoxEditor.cs | 2 +- PCK-Studio/Forms/Editor/COLEditor.cs | 108 ++++++++++-------- PCK-Studio/Forms/Editor/GameRuleFileEditor.cs | 29 ++--- PCK-Studio/Forms/Editor/LOCEditor.cs | 31 ++--- PCK-Studio/Forms/Editor/MaterialsEditor.cs | 48 ++++---- PCK-Studio/Forms/Editor/TextureAtlasEditor.cs | 25 ++-- PCK-Studio/Forms/Features/CemuPanel.cs | 16 +-- PCK-Studio/Forms/Features/PckManager.cs | 22 ++-- .../Skins-And-Textures/AdvancedOptions.cs | 2 +- .../Forms/Skins-And-Textures/SkinPreview.cs | 14 +-- .../Forms/Skins-And-Textures/generateModel.cs | 58 +++++----- .../Interfaces/IPckAssetDeserializer.cs | 7 +- PCK-Studio/Interfaces/IPckAssetSerializer.cs | 7 +- PCK-Studio/Internal/Animation.cs | 50 ++++---- PCK-Studio/Internal/App/ApplicationScope.cs | 4 +- PCK-Studio/Internal/App/Profiler.cs | 5 - .../Deserializer/AnimationDeserializer.cs | 6 +- .../Internal/IO/3DST/3DSTextureReader.cs | 2 +- .../Internal/IO/3DST/3DSTextureWriter.cs | 2 +- PCK-Studio/Internal/IO/3DST/TextureCodec.cs | 22 ++-- PCK-Studio/Internal/IO/CSMB/CSMBFileWriter.cs | 2 +- .../IO/PckAudio/PckAudioFileReader.cs | 9 +- .../IO/PckAudio/PckAudioFileWriter.cs | 8 +- PCK-Studio/Internal/IO/TGA/TGADeserializer.cs | 4 +- PCK-Studio/Internal/IO/TGA/TGAFileData.cs | 1 - PCK-Studio/Internal/IO/TGA/TGAReader.cs | 2 +- PCK-Studio/Internal/IO/TGA/TGASerializer.cs | 4 +- PCK-Studio/Internal/IO/TGA/TGAWriter.cs | 2 +- PCK-Studio/Internal/Misc/FileCacher.cs | 6 +- PCK-Studio/Internal/Misc/OpenFolderDialog.cs | 20 ++-- PCK-Studio/Internal/ResourceLocation.cs | 22 +++- .../Serializer/AnimationSerializer.cs | 27 +++-- .../Internal/Serializer/ImageSerializer.cs | 23 +++- PCK-Studio/Internal/SkinAnimFlag.cs | 1 - PCK-Studio/Internal/SkinAnimMask.cs | 4 - PCK-Studio/Internal/SkinBOX.cs | 12 +- PCK-Studio/MainForm.cs | 95 ++++++++------- 51 files changed, 535 insertions(+), 445 deletions(-) diff --git a/PCK-Studio/FileFormats/CSMBFile.cs b/PCK-Studio/FileFormats/CSMBFile.cs index 9bc1db11..b07d8f80 100644 --- a/PCK-Studio/FileFormats/CSMBFile.cs +++ b/PCK-Studio/FileFormats/CSMBFile.cs @@ -47,7 +47,7 @@ public class CSMBPart public CSMBParentPart Parent = 0; public float posX, posY, posZ = 0.0f; public float sizeX, sizeY, sizeZ = 0.0f; - public int uvX, uvY = 0; + public int uvX, uvY = 0; public bool HideWArmour, MirrorTexture = false; public float Inflation = 0.0f; } diff --git a/PCK-Studio/FileFormats/PckAudioFile.cs b/PCK-Studio/FileFormats/PckAudioFile.cs index 22f3671b..14c32616 100644 --- a/PCK-Studio/FileFormats/PckAudioFile.cs +++ b/PCK-Studio/FileFormats/PckAudioFile.cs @@ -72,7 +72,7 @@ public void AddCredits(params string[] credits) /// public void ApplyCredits(LOCFile locFile) { - foreach (var credit in Credits) + foreach (KeyValuePair credit in Credits) { locFile.SetLocEntry(credit.Key, credit.Value); } @@ -135,7 +135,8 @@ public bool AddCategory(AudioCategory.EAudioParameterType parameterType, AudioCa category > AudioCategory.EAudioType.Unused) throw new InvalidCategoryException(nameof(category)); bool exists = HasCategory(category); - if (!exists) _categories[(int)category] = new AudioCategory(name, parameterType, category); + if (!exists) + _categories[(int)category] = new AudioCategory(name, parameterType, category); return !exists; } @@ -149,7 +150,8 @@ public bool AddCategory(AudioCategory.EAudioType category) public bool RemoveCategory(AudioCategory.EAudioType category) { bool exists = HasCategory(category); - if (exists) _categories[(int)category] = null; + if (exists) + _categories[(int)category] = null; return exists; } diff --git a/PCK-Studio/Forms/Additional-Popups/AddSkinPrompt.cs b/PCK-Studio/Forms/Additional-Popups/AddSkinPrompt.cs index 7fed446d..1b1f40a4 100644 --- a/PCK-Studio/Forms/Additional-Popups/AddSkinPrompt.cs +++ b/PCK-Studio/Forms/Additional-Popups/AddSkinPrompt.cs @@ -185,7 +185,7 @@ private void skinPictureBox_MouseClick(object sender, MouseEventArgs e) { if (ofd.FileName.EndsWith(".3dst")) { - using (var fs = File.OpenRead(ofd.FileName)) + using (FileStream fs = File.OpenRead(ofd.FileName)) { var reader = new _3DSTextureReader(); CheckImage(reader.FromStream(fs)); diff --git a/PCK-Studio/Forms/Additional-Popups/Animation/ChangeTile.cs b/PCK-Studio/Forms/Additional-Popups/Animation/ChangeTile.cs index 6ddf116f..58fdc3aa 100644 --- a/PCK-Studio/Forms/Additional-Popups/Animation/ChangeTile.cs +++ b/PCK-Studio/Forms/Additional-Popups/Animation/ChangeTile.cs @@ -60,9 +60,9 @@ private void GetTileDataToView(ResourceCategory key) ResourceCategory.ItemAnimation => (Tiles.ItemTileInfos, Tiles.ItemImageList, "Items"), _ => throw new InvalidOperationException(nameof(key)) }; - var view = filterPrompt.AddFilterPage(name, null, filterPredicate); + TreeView view = filterPrompt.AddFilterPage(name, null, filterPredicate); view.ImageList = imgList; - foreach ((int i, var tileData) in textureInfos?.enumerate()) + foreach ((int i, JsonTileInfo tileData) in textureInfos?.enumerate()) { if (string.IsNullOrEmpty(tileData.InternalName) || view.Nodes.ContainsKey(tileData.InternalName)) continue; diff --git a/PCK-Studio/Forms/Additional-Popups/Animation/FrameEditor.cs b/PCK-Studio/Forms/Additional-Popups/Animation/FrameEditor.cs index 2ec384b7..6c57344b 100644 --- a/PCK-Studio/Forms/Additional-Popups/Animation/FrameEditor.cs +++ b/PCK-Studio/Forms/Additional-Popups/Animation/FrameEditor.cs @@ -1,7 +1,6 @@ using System; using MetroFramework.Forms; using System.Windows.Forms; -using System.Diagnostics; namespace PckStudio.Forms.Additional_Popups.Animation { diff --git a/PCK-Studio/Forms/Additional-Popups/Animation/SetBulkSpeed.cs b/PCK-Studio/Forms/Additional-Popups/Animation/SetBulkSpeed.cs index c79f9cc9..6a8628c8 100644 --- a/PCK-Studio/Forms/Additional-Popups/Animation/SetBulkSpeed.cs +++ b/PCK-Studio/Forms/Additional-Popups/Animation/SetBulkSpeed.cs @@ -1,6 +1,6 @@ using System; -using MetroFramework.Forms; using System.Windows.Forms; +using MetroFramework.Forms; namespace PckStudio.Forms.Additional_Popups.Animation { diff --git a/PCK-Studio/Forms/Additional-Popups/EntityForms/AddEntry.cs b/PCK-Studio/Forms/Additional-Popups/EntityForms/AddEntry.cs index 38ebc4e4..1057ab70 100644 --- a/PCK-Studio/Forms/Additional-Popups/EntityForms/AddEntry.cs +++ b/PCK-Studio/Forms/Additional-Popups/EntityForms/AddEntry.cs @@ -19,14 +19,14 @@ public AddEntry(string dataType, System.Drawing.Image[] entityImages) { filterPrompt = new FilterPrompt(); filterPrompt.OnSelectedItemChanged += FilterPrompt_OnSelectedItemChanged; - var treeViewEntity = filterPrompt.AddFilterPage("Entities", null, filterPredicate); + TreeView treeViewEntity = filterPrompt.AddFilterPage("Entities", null, filterPredicate); ImageList entities = new ImageList(); entities.ColorDepth = ColorDepth.Depth32Bit; entities.ImageSize = new System.Drawing.Size(32, 32); entities.Images.AddRange(entityImages); treeViewEntity.ImageList = entities; - var entityInfos = dataType switch + List entityInfos = dataType switch { "models" => Entities.ModelInfos, "materials" => Entities.MaterialInfos, @@ -36,7 +36,7 @@ public AddEntry(string dataType, System.Drawing.Image[] entityImages) int i = 0; - foreach(var entity in entityInfos) + foreach(EntityInfo entity in entityInfos) { TreeNode entityNode = new TreeNode(entity.DisplayName) { diff --git a/PCK-Studio/Forms/Additional-Popups/FilterPrompt.cs b/PCK-Studio/Forms/Additional-Popups/FilterPrompt.cs index 19162383..d86ea855 100644 --- a/PCK-Studio/Forms/Additional-Popups/FilterPrompt.cs +++ b/PCK-Studio/Forms/Additional-Popups/FilterPrompt.cs @@ -17,7 +17,6 @@ **/ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Drawing; using System.Windows.Forms; using MetroFramework.Forms; @@ -31,8 +30,8 @@ internal partial class FilterPrompt : MetroForm public Color PageBackColor { get; set; } = Color.FromArgb(64, 64, 64); - private object selectedItem; - public object SelectedItem => selectedItem; + private object _selectedItem; + public object SelectedItem => _selectedItem; public int SelectedTabIndex => tabController.SelectedIndex; @@ -62,7 +61,7 @@ public TreeView AddFilterPage(string categoryName, string key, FilterPredicate f }; pageView.AfterSelect += (sender, e) => { - selectedItem = e.Node.Tag; + _selectedItem = e.Node.Tag; Events[nameof(OnSelectedItemChanged)]?.DynamicInvoke(this, EventArgs.Empty); }; pageView.Tag = new List(4); @@ -114,7 +113,7 @@ private void CancelBtn_Click(object sender, EventArgs e) private void AcceptBtn_Click(object sender, EventArgs e) { - DialogResult = selectedItem is null ? DialogResult.Cancel : DialogResult.OK; + DialogResult = _selectedItem is null ? DialogResult.Cancel : DialogResult.OK; } } } diff --git a/PCK-Studio/Forms/Additional-Popups/TextPrompt.cs b/PCK-Studio/Forms/Additional-Popups/TextPrompt.cs index cb7c3f3e..44df0816 100644 --- a/PCK-Studio/Forms/Additional-Popups/TextPrompt.cs +++ b/PCK-Studio/Forms/Additional-Popups/TextPrompt.cs @@ -40,7 +40,8 @@ private void OKBtn_Click(object sender, EventArgs e) { MessageBox.Show(this, "Please insert a value in the text box.", "Empty string"); } - else DialogResult = DialogResult.OK; + else + DialogResult = DialogResult.OK; } private void RenamePrompt_Load(object sender, EventArgs e) diff --git a/PCK-Studio/Forms/ContributorsForm.cs b/PCK-Studio/Forms/ContributorsForm.cs index cd2a528e..bcddc813 100644 --- a/PCK-Studio/Forms/ContributorsForm.cs +++ b/PCK-Studio/Forms/ContributorsForm.cs @@ -14,9 +14,6 @@ public partial class ContributorsForm : MetroForm public ContributorsForm() { InitializeComponent(); -#if false - Task.Run(GetContributors); -#endif string buildConfig = ""; #if BETA buildConfig = "Beta"; @@ -33,7 +30,7 @@ public ContributorsForm() protected override void OnLoad(EventArgs e) { base.OnLoad(e); - foreach (var contributorsName in ApplicationScope.Contributors) + foreach (Octokit.RepositoryContributor contributorsName in ApplicationScope.Contributors) { if (InvokeRequired) Invoke(() => contributorsLayoutPanel.Controls.Add(new GithubUserPanel(contributorsName))); diff --git a/PCK-Studio/Forms/Editor/ANIMEditor.cs b/PCK-Studio/Forms/Editor/ANIMEditor.cs index 49f40357..29c21b8e 100644 --- a/PCK-Studio/Forms/Editor/ANIMEditor.cs +++ b/PCK-Studio/Forms/Editor/ANIMEditor.cs @@ -20,7 +20,7 @@ public partial class ANIMEditor : MetroFramework.Forms.MetroForm sealed class ANIMRuleSet { - public SkinANIM Value => anim; + public SkinANIM Value => _anim; public Action OnCheckboxChanged; private class Bictionary : Dictionary @@ -41,15 +41,15 @@ public T1 this[T2 index] internal void AddRange(IEnumerable<(T1, T2)> range) { - foreach (var (key, value) in range) + foreach ((T1 key, T2 value) in range) { Add(key, value); } } } private Bictionary checkBoxLinkage; - private SkinANIM anim; - private bool ignoreCheckChanged = false; + private SkinANIM _anim; + private bool _ignoreCheckChanged = false; public ANIMRuleSet(params (CheckBox, SkinAnimFlag)[] linkage) { @@ -58,7 +58,7 @@ public ANIMRuleSet(params (CheckBox, SkinAnimFlag)[] linkage) Debug.WriteLine($"Not all {nameof(SkinAnimFlag)} are mapped to a given checkbox."); checkBoxLinkage.AddRange(linkage); - foreach (var (checkbox, _) in linkage) + foreach ((CheckBox checkbox, SkinAnimFlag _) in linkage) { checkbox.CheckedChanged += checkedChanged; } @@ -66,7 +66,7 @@ public ANIMRuleSet(params (CheckBox, SkinAnimFlag)[] linkage) internal void SetAll(bool state) { - foreach (var item in checkBoxLinkage) + foreach (KeyValuePair item in checkBoxLinkage) { IgnoreAndDo(item.Key, checkbox => { @@ -84,25 +84,28 @@ internal void SetAll(bool state) break; case SkinAnimFlag.RESOLUTION_64x64: checkbox.Enabled = !state; - if(state) checkbox.Checked = false; // Prioritize slim model > classic model, LCE would + // Prioritize slim model > classic model, LCE would + if(state) + checkbox.Checked = false; break; } - anim.SetFlag(item.Value, checkbox.Checked); + _anim.SetFlag(item.Value, checkbox.Checked); }); } - OnCheckboxChanged?.Invoke(anim); + OnCheckboxChanged?.Invoke(_anim); } internal void ApplyAnim(SkinANIM anim) { - this.anim = anim; - foreach (var item in checkBoxLinkage) + this._anim = anim; + foreach (KeyValuePair item in checkBoxLinkage) { /* * not the best way to do this but whatever lol * fix for both model flags being unset when both are set to true, with slim model prioritized of course */ - if (item.Value == SkinAnimFlag.RESOLUTION_64x64 && anim.GetFlag(SkinAnimFlag.SLIM_MODEL)) continue; + if (item.Value == SkinAnimFlag.RESOLUTION_64x64 && anim.GetFlag(SkinAnimFlag.SLIM_MODEL)) + continue; item.Key.Checked = anim.GetFlag(item.Value); } @@ -110,7 +113,7 @@ internal void ApplyAnim(SkinANIM anim) private void checkedChanged(object sender, EventArgs e) { - if (!ignoreCheckChanged && sender is CheckBox checkBox && checkBoxLinkage.ContainsKey(checkBox)) + if (!_ignoreCheckChanged && sender is CheckBox checkBox && checkBoxLinkage.ContainsKey(checkBox)) { switch (checkBoxLinkage[checkBox]) { @@ -151,8 +154,8 @@ private void checkedChanged(object sender, EventArgs e) default: break; } - anim.SetFlag(checkBoxLinkage[checkBox], checkBox.Checked && checkBox.Enabled); - OnCheckboxChanged?.Invoke(anim); + _anim.SetFlag(checkBoxLinkage[checkBox], checkBox.Checked && checkBox.Enabled); + OnCheckboxChanged?.Invoke(_anim); } } @@ -163,9 +166,9 @@ private void Uncheck(CheckBox checkBox) private void IgnoreAndDo(CheckBox checkBox, Action action) { - ignoreCheckChanged = true; + _ignoreCheckChanged = true; action.Invoke(checkBox); - ignoreCheckChanged = false; + _ignoreCheckChanged = false; } } @@ -176,14 +179,14 @@ private ANIMEditor() saveButton.Visible = !Settings.Default.AutoSaveChanges; } - public ANIMEditor(string ANIM) : this() + public ANIMEditor(string animString) : this() { - if (!SkinANIM.IsValidANIM(ANIM)) + if (!SkinANIM.IsValidANIM(animString)) { DialogResult = DialogResult.Abort; Close(); } - var anim = initialANIM = SkinANIM.FromString(ANIM); + SkinANIM anim = initialANIM = SkinANIM.FromString(animString); setDisplayAnim(anim); ruleset.ApplyAnim(anim); } @@ -254,7 +257,8 @@ private void importButton_Click(object sender, EventArgs e) string value = string.Empty; while (!SkinANIM.IsValidANIM(value)) { - if (!string.IsNullOrWhiteSpace(value)) MessageBox.Show(this, $"The following value \"{value}\" is not valid. Please try again."); + if (!string.IsNullOrWhiteSpace(value)) + MessageBox.Show(this, $"The following value \"{value}\" is not valid. Please try again."); TextPrompt diag = new TextPrompt(value); diag.LabelText = "ANIM"; diag.OKButtonText = "Ok"; @@ -262,7 +266,8 @@ private void importButton_Click(object sender, EventArgs e) { value = diag.NewText; } - else return; + else + return; } ruleset.ApplyAnim(SkinANIM.FromString(value)); } @@ -306,15 +311,24 @@ private void exportButton_Click(object sender, EventArgs e) graphic.FillRectangle(Brushes.Magenta, new Rectangle(16, 16, 24, 16)); if (img.Height == 64) { - if (ruleset.Value.GetFlag(SkinAnimFlag.RIGHT_ARM_DISABLED)) graphic.FillRectangle(Brushes.Magenta, new Rectangle(40, 16, 16, 16)); - if (ruleset.Value.GetFlag(SkinAnimFlag.RIGHT_LEG_DISABLED)) graphic.FillRectangle(Brushes.Magenta, new Rectangle(0, 16, 16, 16)); - if (ruleset.Value.GetFlag(SkinAnimFlag.BODY_OVERLAY_DISABLED)) graphic.FillRectangle(Brushes.Magenta, new Rectangle(16, 32, 24, 16)); - if (ruleset.Value.GetFlag(SkinAnimFlag.RIGHT_ARM_OVERLAY_DISABLED)) graphic.FillRectangle(Brushes.Magenta, new Rectangle(40, 32, 16, 16)); - if (ruleset.Value.GetFlag(SkinAnimFlag.RIGHT_LEG_OVERLAY_DISABLED)) graphic.FillRectangle(Brushes.Magenta, new Rectangle(0, 32, 16, 16)); - if (ruleset.Value.GetFlag(SkinAnimFlag.LEFT_LEG_OVERLAY_DISABLED)) graphic.FillRectangle(Brushes.Magenta, new Rectangle(0, 48, 16, 16)); - if (ruleset.Value.GetFlag(SkinAnimFlag.LEFT_LEG_DISABLED)) graphic.FillRectangle(Brushes.Magenta, new Rectangle(16, 48, 16, 16)); - if (ruleset.Value.GetFlag(SkinAnimFlag.LEFT_ARM_DISABLED)) graphic.FillRectangle(Brushes.Magenta, new Rectangle(32, 48, 16, 16)); - if (ruleset.Value.GetFlag(SkinAnimFlag.LEFT_ARM_OVERLAY_DISABLED)) graphic.FillRectangle(Brushes.Magenta, new Rectangle(48, 48, 16, 16)); + if (ruleset.Value.GetFlag(SkinAnimFlag.RIGHT_ARM_DISABLED)) + graphic.FillRectangle(Brushes.Magenta, new Rectangle(40, 16, 16, 16)); + if (ruleset.Value.GetFlag(SkinAnimFlag.RIGHT_LEG_DISABLED)) + graphic.FillRectangle(Brushes.Magenta, new Rectangle(0, 16, 16, 16)); + if (ruleset.Value.GetFlag(SkinAnimFlag.BODY_OVERLAY_DISABLED)) + graphic.FillRectangle(Brushes.Magenta, new Rectangle(16, 32, 24, 16)); + if (ruleset.Value.GetFlag(SkinAnimFlag.RIGHT_ARM_OVERLAY_DISABLED)) + graphic.FillRectangle(Brushes.Magenta, new Rectangle(40, 32, 16, 16)); + if (ruleset.Value.GetFlag(SkinAnimFlag.RIGHT_LEG_OVERLAY_DISABLED)) + graphic.FillRectangle(Brushes.Magenta, new Rectangle(0, 32, 16, 16)); + if (ruleset.Value.GetFlag(SkinAnimFlag.LEFT_LEG_OVERLAY_DISABLED)) + graphic.FillRectangle(Brushes.Magenta, new Rectangle(0, 48, 16, 16)); + if (ruleset.Value.GetFlag(SkinAnimFlag.LEFT_LEG_DISABLED)) + graphic.FillRectangle(Brushes.Magenta, new Rectangle(16, 48, 16, 16)); + if (ruleset.Value.GetFlag(SkinAnimFlag.LEFT_ARM_DISABLED)) + graphic.FillRectangle(Brushes.Magenta, new Rectangle(32, 48, 16, 16)); + if (ruleset.Value.GetFlag(SkinAnimFlag.LEFT_ARM_OVERLAY_DISABLED)) + graphic.FillRectangle(Brushes.Magenta, new Rectangle(48, 48, 16, 16)); } else { diff --git a/PCK-Studio/Forms/Editor/AnimationEditor.cs b/PCK-Studio/Forms/Editor/AnimationEditor.cs index b6ab15e4..0446c80e 100644 --- a/PCK-Studio/Forms/Editor/AnimationEditor.cs +++ b/PCK-Studio/Forms/Editor/AnimationEditor.cs @@ -32,7 +32,6 @@ using PckStudio.Extensions; using PckStudio.Properties; using PckStudio.Internal; -using AnimatedGif; using PckStudio.Internal.Deserializer; namespace PckStudio.Forms.Editor @@ -157,7 +156,8 @@ private TreeNode FindNodeByName(TreeNode treeNode, string name) { foreach (TreeNode node in treeNode.Nodes) { - if (node.Text.ToLower() == name.ToLower()) return node; + if (node.Text.ToLower() == name.ToLower()) + return node; return FindNodeByName(node, name); } return null; @@ -241,8 +241,10 @@ private void frameTreeView_DragDrop(object sender, DragEventArgs e) private bool ContainsNode(TreeNode node1, TreeNode node2) { // Check the parent node of the second node. - if (node2.Parent == null) return false; - if (node2.Parent.Equals(node1)) return true; + if (node2.Parent == null) + return false; + if (node2.Parent.Equals(node1)) + return true; // If the parent node is not null or equal to the first node, // call the ContainsNode method recursively using the parent of @@ -252,7 +254,7 @@ private bool ContainsNode(TreeNode node1, TreeNode node2) private void treeView1_doubleClick(object sender, EventArgs e) { - var frame = _animation.GetFrame(frameTreeView.SelectedNode.Index); + Animation.Frame frame = _animation.GetFrame(frameTreeView.SelectedNode.Index); using FrameEditor diag = new FrameEditor(frame.Ticks, _animation.GetTextureIndex(frame.Texture), TextureIcons); if (diag.ShowDialog(this) == DialogResult.OK) { @@ -319,7 +321,8 @@ private void importJavaAnimationToolStripMenuItem_Click(object sender, EventArgs // -MattNL Filter = "Animation Scripts (*.mcmeta)|*.png.mcmeta" }; - if (fileDialog.ShowDialog(this) != DialogResult.OK) return; + if (fileDialog.ShowDialog(this) != DialogResult.OK) + return; Debug.WriteLine("Selected Animation Script: " + fileDialog.FileName); string textureFile = fileDialog.FileName.Substring(0, fileDialog.FileName.Length - ".mcmeta".Length); @@ -355,7 +358,7 @@ private void exportJavaAnimationToolStripMenuItem_Click(object sender, EventArgs string jsondata = JsonConvert.SerializeObject(mcmeta, Formatting.Indented); string filename = fileDialog.FileName; File.WriteAllText(filename, jsondata); - var finalTexture = _animation.BuildTexture(); + Image finalTexture = _animation.BuildTexture(); // removes ".mcmeta" from filename string texturePath = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename)); finalTexture.Save(texturePath); @@ -451,7 +454,7 @@ private void importAnimationTextureToolStripMenuItem_Click(object sender, EventA if (ofd.ShowDialog(this) != DialogResult.OK) return; Image img = Image.FromFile(ofd.FileName); - var textures = img.Split(ImageLayoutDirection.Vertical); + IEnumerable textures = img.Split(ImageLayoutDirection.Vertical); _animation = new Animation(textures, string.Empty); LoadAnimationTreeView(); } diff --git a/PCK-Studio/Forms/Editor/AudioEditor.cs b/PCK-Studio/Forms/Editor/AudioEditor.cs index f7655f33..19a8a236 100644 --- a/PCK-Studio/Forms/Editor/AudioEditor.cs +++ b/PCK-Studio/Forms/Editor/AudioEditor.cs @@ -82,7 +82,7 @@ public void SetUpTree() treeView1.BeginUpdate(); treeView1.Nodes.Clear(); - foreach (var category in _audioFile.Categories) + foreach (PckAudioFile.AudioCategory category in _audioFile.Categories) { // fix songs with directories using backslash instead of forward slash // Songs with a backslash instead of a forward slash would not play in RPCS3 @@ -116,7 +116,7 @@ private void verifyFileLocationToolStripMenuItem_Click(object sender, EventArgs { if (treeView1.SelectedNode == null || treeView2.SelectedNode == null) return; - var entry = treeView2.SelectedNode; + TreeNode entry = treeView2.SelectedNode; if (!parent.CreateDataFolder()) return; @@ -151,11 +151,11 @@ private void addCategoryStripMenuItem_Click(object sender, EventArgs e) } using ItemSelectionPopUp add = new ItemSelectionPopUp(available); - if (add.ShowDialog(this) == DialogResult.OK) - _audioFile.AddCategory(GetCategoryId(add.SelectedItem)); - else return; + if (add.ShowDialog(this) != DialogResult.OK) + return; - var category = _audioFile.GetCategory(GetCategoryId(add.SelectedItem)); + _audioFile.AddCategory(GetCategoryId(add.SelectedItem)); + PckAudioFile.AudioCategory category = _audioFile.GetCategory(GetCategoryId(add.SelectedItem)); if (GetCategoryId(add.SelectedItem) == PckAudioFile.AudioCategory.EAudioType.Creative) { @@ -174,7 +174,8 @@ private void addEntryMenuItem_Click(object sender, EventArgs e) { if (treeView1.SelectedNode is TreeNode t && t.Tag is PckAudioFile.AudioCategory) { - if (!parent.CreateDataFolder()) return; + if (!parent.CreateDataFolder()) + return; OpenFileDialog ofn = new OpenFileDialog(); ofn.Multiselect = true; @@ -182,7 +183,9 @@ private void addEntryMenuItem_Click(object sender, EventArgs e) ofn.Title = "Please choose WAV or BINKA files to add to your pack"; ofn.ShowDialog(this); ofn.Dispose(); - if (string.IsNullOrEmpty(ofn.FileName)) return; // Return if name is null or if the user cancels + // Return if name is null or if the user cancels + if (string.IsNullOrEmpty(ofn.FileName)) + return; ProcessEntries(ofn.FileNames); } @@ -224,7 +227,7 @@ private void removeEntryMenuItem_Click(object sender, EventArgs e) } } - async void ProcessEntries(string[] FileList) + async void ProcessEntries(string[] fileList) { int success = 0; int exitCode = 0; @@ -235,7 +238,7 @@ async void ProcessEntries(string[] FileList) Directory.CreateDirectory(ApplicationScope.DataCacher.CacheDirectory); // create directory in case it doesn't exist - foreach (string file in FileList) + foreach (string file in fileList) { if (Path.GetExtension(file) == ".binka" || Path.GetExtension(file) == ".wav") { @@ -243,7 +246,8 @@ async void ProcessEntries(string[] FileList) songName = Regex.Replace(songName, @"[^\u0000-\u007F]+", "_"); // Replace UTF characters string cacheSongFile = Path.Combine(ApplicationScope.DataCacher.CacheDirectory, songName + Path.GetExtension(file)); - if(File.Exists(cacheSongFile)) File.Delete(cacheSongFile); + if (File.Exists(cacheSongFile)) + File.Delete(cacheSongFile); string new_loc = Path.Combine(parent.GetDataPath(), songName + ".binka"); bool is_duplicate_file = false; // To handle if a file already in the pack is dropped back in @@ -264,13 +268,14 @@ async void ProcessEntries(string[] FileList) string diag_text = "A file named \"" + Path.GetFileNameWithoutExtension(file) + ".binka\" already exists in the Data folder."; - if (is_duplicate_file) diag_text = "\"" + Path.GetFileNameWithoutExtension(file) + ".binka\" has an identical copy present in the Data folder."; + if (is_duplicate_file) + diag_text = "\"" + Path.GetFileNameWithoutExtension(file) + ".binka\" has an identical copy present in the Data folder."; diag_text += " Pressing yes will replace the existing file. By pressing no, the song entry will be added without affecting the file." + "You can also cancel this operation and all files in queue."; DialogResult user_prompt = MessageBox.Show(this, diag_text, "File already exists", MessageBoxButtons.YesNoCancel); - while (user_prompt == DialogResult.None) ; // Stops the editor from adding or processing the file until the user has made their choice + while (user_prompt == DialogResult.None) // Stops the editor from adding or processing the file until the user has made their choice if (user_prompt == DialogResult.Cancel) { break; @@ -290,7 +295,8 @@ async void ProcessEntries(string[] FileList) { // deletes the file so that the copy function can happen safely // and ignore duplicate files because well... they're duplicates lol - if (File.Exists(new_loc) && !is_duplicate_file) File.Delete(new_loc); + if (File.Exists(new_loc) && !is_duplicate_file) + File.Delete(new_loc); } } @@ -314,7 +320,8 @@ await Task.Run(() => exitCode = Binka.ToBinka(cacheSongFile, new_loc, (int)compressionUpDown.Value); }); - if (!File.Exists(cacheSongFile)) MessageBox.Show(this, $"\"{songName}.wav\" failed to convert for some reason. Please report this on the communtiy Discord server, which can be found under \"More\" in the toolbar at the top of the program.", "Conversion failed"); + if (!File.Exists(cacheSongFile)) + MessageBox.Show(this, $"\"{songName}.wav\" failed to convert for some reason. Please report this on the communtiy Discord server, which can be found under \"More\" in the toolbar at the top of the program.", "Conversion failed"); else { success++; @@ -323,7 +330,8 @@ await Task.Run(() => Cursor.Current = Cursors.Default; - if (exitCode != 0) continue; + if (exitCode != 0) + continue; } // if the file is NOT a .wav and doesn't exist, copy the file @@ -344,7 +352,7 @@ await Task.Run(() => waitDiag.Close(); waitDiag.Dispose(); - MessageBox.Show(this, $"Successfully processed and/or converted {success}/{FileList.Length} file{(FileList.Length != 1 ? "s" : "" )}", "Done!"); + MessageBox.Show(this, $"Successfully processed and/or converted {success}/{fileList.Length} file{(fileList.Length != 1 ? "s" : "" )}", "Done!"); } private void Binka_DragDrop(object sender, DragEventArgs e) @@ -353,7 +361,8 @@ private void Binka_DragDrop(object sender, DragEventArgs e) // Gets the MainForm so we can access the Save Location if (treeView1.SelectedNode != null) { - if (!parent.CreateDataFolder()) return; + if (!parent.CreateDataFolder()) + return; ProcessEntries((string[])e.Data.GetData(DataFormats.FileDrop, false)); } @@ -372,7 +381,7 @@ private void saveToolStripMenuItem1_Click(object sender, EventArgs e) PckAudioFile.AudioCategory overworldCategory = _audioFile.GetCategory(PckAudioFile.AudioCategory.EAudioType.Overworld); bool songs_missing = false; - foreach (var category in _audioFile.Categories) + foreach (PckAudioFile.AudioCategory category in _audioFile.Categories) { if (category.SongNames.Count < 1) { @@ -432,7 +441,8 @@ private void helpToolStripMenuItem_Click(object sender, EventArgs e) private void deleteUnusedBINKAsToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show(this, "This will delete all unused BINKA songs in the Data directory. This cannot be undone. Are you sure you want to continue?", "Warning", MessageBoxButtons.YesNo); - if (dr != DialogResult.Yes) return; + if (dr != DialogResult.Yes) + return; var totalSongList = new List(); foreach (string song in _audioFile.Categories.SelectMany(cat => cat.SongNames)) { @@ -440,7 +450,8 @@ private void deleteUnusedBINKAsToolStripMenuItem_Click(object sender, EventArgs totalSongList.Add(song); } - if (!parent.CreateDataFolder()) return; + if (!parent.CreateDataFolder()) + return; int totalDeleted = 0; foreach (string song in Directory.GetFiles(parent.GetDataPath(), "*.binka")) { @@ -500,19 +511,23 @@ private void BINKACompressionToolStripMenuItem_Click(object sender, EventArgs e) private void openDataFolderToolStripMenuItem_Click(object sender, EventArgs e) { - if (!parent.CreateDataFolder()) return; + if (!parent.CreateDataFolder()) + return; Process.Start("explorer.exe", parent.GetDataPath()); } private void AudioEditor_Shown(object sender, EventArgs e) { - if (Owner.Owner is MainForm p) parent = p; - else Close(); + if (Owner.Owner is MainForm p) + parent = p; + else + Close(); } private async void bulkReplaceExistingFilesToolStripMenuItem_Click(object sender, EventArgs e) { - if (!parent.CreateDataFolder()) return; + if (!parent.CreateDataFolder()) + return; int exitCode = 0; @@ -523,7 +538,10 @@ private async void bulkReplaceExistingFilesToolStripMenuItem_Click(object sender ofn.Title = "Please choose WAV or BINKA files to replace existing track files"; ofn.ShowDialog(this); ofn.Dispose(); - if (string.IsNullOrEmpty(ofn.FileName)) return; // Return if name is null or if the user cancels + + // Return if name is null or if the user cancels + if (string.IsNullOrEmpty(ofn.FileName)) + return; var totalSongList = new List(); foreach (string song in _audioFile.Categories.SelectMany(cat => cat.SongNames)) @@ -536,7 +554,8 @@ private async void bulkReplaceExistingFilesToolStripMenuItem_Click(object sender string song_name = Path.GetFileNameWithoutExtension(file); string file_ext = Path.GetExtension(file).ToLower(); string new_loc = Path.Combine(parent.GetDataPath(), Path.GetFileNameWithoutExtension(file) + ".binka"); - if (!totalSongList.Contains(song_name) || file == new_loc) continue; + if (!totalSongList.Contains(song_name) || file == new_loc) + continue; Console.WriteLine(file); File.Delete(new_loc); @@ -556,9 +575,11 @@ await Task.Run(() => waitDiag.Dispose(); Cursor.Current = Cursors.Default; - if (exitCode != 0) continue; + if (exitCode != 0) + continue; } - else if(file_ext == ".binka") File.Copy(file, Path.Combine(parent.GetDataPath(), Path.GetFileName(file))); + else if(file_ext == ".binka") + File.Copy(file, Path.Combine(parent.GetDataPath(), Path.GetFileName(file))); } } @@ -572,20 +593,22 @@ private void convertToWAVToolStripMenuItem_Click(object sender, EventArgs e) private void setCategoryToolStripMenuItem_Click(object sender, EventArgs e) { - if (!(treeView1.SelectedNode is TreeNode t && t.Tag is PckAudioFile.AudioCategory category)) return; + if (!(treeView1.SelectedNode is TreeNode t && t.Tag is PckAudioFile.AudioCategory category)) + return; string[] available = Categories.FindAll(str => !_audioFile.HasCategory(GetCategoryId(str))).ToArray(); if (available.Length > 0) { using ItemSelectionPopUp add = new ItemSelectionPopUp(available); add.ButtonText = "Save"; - if (add.ShowDialog(this) != DialogResult.OK) return; + if (add.ShowDialog(this) != DialogResult.OK) + return; _audioFile.RemoveCategory(category.AudioType); _audioFile.AddCategory(category.parameterType, GetCategoryId(add.SelectedItem), category.AudioType == PckAudioFile.AudioCategory.EAudioType.Overworld && playOverworldInCreative.Checked ? "include_overworld" : ""); - var newCategory = _audioFile.GetCategory(GetCategoryId(add.SelectedItem)); + PckAudioFile.AudioCategory newCategory = _audioFile.GetCategory(GetCategoryId(add.SelectedItem)); category.SongNames.ForEach(c => newCategory.SongNames.Add(c)); @@ -601,10 +624,11 @@ private void organizeTracksToolStripMenuItem_Click(object sender, EventArgs e) { if(MessageBox.Show(this, "This function will move all binka files in the \"Data\" folder into a \"Music\" folder, to keep your data better organized. Would you like to continue?", "Move tracks?", MessageBoxButtons.YesNo) == DialogResult.Yes) { - if (treeView1.Nodes.Count < 1 || !parent.CreateDataFolder()) return; + if (treeView1.Nodes.Count < 1 || !parent.CreateDataFolder()) + return; string musicdir = Path.Combine(parent.GetDataPath(), "Music"); Directory.CreateDirectory(musicdir); - foreach (var category in _audioFile.Categories) + foreach (PckAudioFile.AudioCategory category in _audioFile.Categories) { for (var i = 0; i < category.SongNames.Count; i++) // using standard for loop so the list can be modified { diff --git a/PCK-Studio/Forms/Editor/BehaviourEditor.cs b/PCK-Studio/Forms/Editor/BehaviourEditor.cs index bd9b4d4f..c47957ee 100644 --- a/PCK-Studio/Forms/Editor/BehaviourEditor.cs +++ b/PCK-Studio/Forms/Editor/BehaviourEditor.cs @@ -23,7 +23,7 @@ public partial class BehaviourEditor : MetroForm { // Behaviours File Format research by Miku and MattNL private readonly PckAsset _asset; - BehaviourFile behaviourFile; + BehaviourFile _behaviourFile; private readonly List BehaviourData = Entities.BehaviourInfos; @@ -31,7 +31,7 @@ void SetUpTree() { treeView1.BeginUpdate(); treeView1.Nodes.Clear(); - foreach (var entry in behaviourFile.entries) + foreach (var entry in _behaviourFile.entries) { TreeNode EntryNode = new TreeNode(entry.name); @@ -62,12 +62,7 @@ public BehaviourEditor(PckAsset asset) saveToolStripMenuItem1.Visible = !Settings.Default.AutoSaveChanges; _asset = asset; - - using (var stream = new MemoryStream(asset.Data)) - { - var reader = new BehavioursReader(); - behaviourFile = reader.FromStream(stream); - } + _behaviourFile = asset.GetData(new BehavioursReader()); treeView1.ImageList = new ImageList(); treeView1.ImageList.Images.AddRange(ApplicationScope.EntityImages); @@ -77,7 +72,8 @@ public BehaviourEditor(PckAsset asset) private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { - if (treeView1.SelectedNode is null) return; + if (treeView1.SelectedNode is null) + return; bool isValidOverride = treeView1.SelectedNode.Tag is BehaviourFile.RiderPositionOverride.PositionOverride; MobIsTamedCheckbox.Enabled = isValidOverride; @@ -101,7 +97,8 @@ private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) private void removeToolStripMenuItem_Click(object sender, EventArgs e) { - if (treeView1.SelectedNode is null) return; + if (treeView1.SelectedNode is null) + return; treeView1.SelectedNode.Remove(); } @@ -147,15 +144,18 @@ private void zUpDown_ValueChanged(object sender, EventArgs e) private void changeToolStripMenuItem_Click(object sender, EventArgs e) { - if (treeView1.SelectedNode == null) return; - if (!(treeView1.SelectedNode.Tag is BehaviourFile.RiderPositionOverride entry)) return; + if (treeView1.SelectedNode == null) + return; + if (!(treeView1.SelectedNode.Tag is BehaviourFile.RiderPositionOverride entry)) + return; var diag = new AddEntry("behaviours", ApplicationScope.EntityImages); if (diag.ShowDialog(this) == DialogResult.OK) { - if (String.IsNullOrEmpty(diag.SelectedEntity)) return; - if (behaviourFile.entries.FindAll(behaviour => behaviour.name == diag.SelectedEntity).Count() > 0) + if (string.IsNullOrEmpty(diag.SelectedEntity)) + return; + if (_behaviourFile.entries.FindAll(behaviour => behaviour.name == diag.SelectedEntity).Count() > 0) { MessageBox.Show(this, "You cannot have two entries for one entity. Please use the \"Add New Position Override\" tool to add multiple overrides for entities", "Error", MessageBoxButtons.OK); return; @@ -164,7 +164,7 @@ private void changeToolStripMenuItem_Click(object sender, EventArgs e) entry.name = diag.SelectedEntity; treeView1.SelectedNode.Tag = entry; - var behaviour = BehaviourData.Find(b => b.InternalName == entry.name); + EntityInfo behaviour = BehaviourData.Find(b => b.InternalName == entry.name); treeView1.SelectedNode.Text = behaviour.DisplayName; treeView1.SelectedNode.ImageIndex = BehaviourData.IndexOf(behaviour); @@ -183,7 +183,8 @@ private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs private void addNewPositionOverrideToolStripMenuItem_Click(object sender, EventArgs e) { - if (treeView1.SelectedNode.Tag is BehaviourFile.RiderPositionOverride.PositionOverride) treeView1.SelectedNode = treeView1.SelectedNode.Parent; + if (treeView1.SelectedNode.Tag is BehaviourFile.RiderPositionOverride.PositionOverride) + treeView1.SelectedNode = treeView1.SelectedNode.Parent; if (treeView1.SelectedNode.Tag is BehaviourFile.RiderPositionOverride) { @@ -201,8 +202,9 @@ private void addNewEntryToolStripMenuItem_Click(object sender, EventArgs e) if(diag.ShowDialog(this) == DialogResult.OK) { - if (string.IsNullOrEmpty(diag.SelectedEntity)) return; - if (behaviourFile.entries.FindAll(behaviour => behaviour.name == diag.SelectedEntity).Count() > 0) + if (string.IsNullOrEmpty(diag.SelectedEntity)) + return; + if (_behaviourFile.entries.FindAll(behaviour => behaviour.name == diag.SelectedEntity).Count() > 0) { MessageBox.Show(this, "You cannot have two entries for one entity. Please use the \"Add New Position Override\" tool to add multiple overrides for entities", "Error", MessageBoxButtons.OK); return; @@ -212,7 +214,7 @@ private void addNewEntryToolStripMenuItem_Click(object sender, EventArgs e) TreeNode NewOverrideNode = new TreeNode(NewOverride.name); NewOverrideNode.Tag = NewOverride; - var behaviour = BehaviourData.Find(b => b.InternalName == NewOverride.name); + EntityInfo behaviour = BehaviourData.Find(b => b.InternalName == NewOverride.name); NewOverrideNode.Text = behaviour.DisplayName; NewOverrideNode.ImageIndex = BehaviourData.IndexOf(behaviour); NewOverrideNode.SelectedImageIndex = NewOverrideNode.ImageIndex; @@ -226,7 +228,8 @@ private void addNewEntryToolStripMenuItem_Click(object sender, EventArgs e) private void treeView1_KeyDown(object sender, KeyEventArgs e) { - if (e.KeyCode == Keys.Delete) removeToolStripMenuItem_Click(sender, e); + if (e.KeyCode == Keys.Delete) + removeToolStripMenuItem_Click(sender, e); } private void treeView1_MouseHover(object sender, EventArgs e) @@ -236,7 +239,7 @@ private void treeView1_MouseHover(object sender, EventArgs e) private void saveToolStripMenuItem1_Click(object sender, EventArgs e) { - behaviourFile = new BehaviourFile(); + _behaviourFile = new BehaviourFile(); foreach (TreeNode node in treeView1.Nodes) { if(node.Tag is BehaviourFile.RiderPositionOverride entry) @@ -251,11 +254,11 @@ private void saveToolStripMenuItem1_Click(object sender, EventArgs e) } } - behaviourFile.entries.Add(entry); + _behaviourFile.entries.Add(entry); } } - _asset.SetData(new BehavioursWriter(behaviourFile)); + _asset.SetData(new BehavioursWriter(_behaviourFile)); DialogResult = DialogResult.OK; } diff --git a/PCK-Studio/Forms/Editor/BoxEditor.cs b/PCK-Studio/Forms/Editor/BoxEditor.cs index cae9d054..8af249bf 100644 --- a/PCK-Studio/Forms/Editor/BoxEditor.cs +++ b/PCK-Studio/Forms/Editor/BoxEditor.cs @@ -23,7 +23,7 @@ public BoxEditor(SkinBOX box, bool hasInflation) throw new Exception("Failed to parse BOX value"); } - closeButton.Visible =!Settings.Default.AutoSaveChanges; + closeButton.Visible = !Settings.Default.AutoSaveChanges; inflationUpDown.Enabled = hasInflation; diff --git a/PCK-Studio/Forms/Editor/COLEditor.cs b/PCK-Studio/Forms/Editor/COLEditor.cs index db7158e4..73966b8a 100644 --- a/PCK-Studio/Forms/Editor/COLEditor.cs +++ b/PCK-Studio/Forms/Editor/COLEditor.cs @@ -15,9 +15,9 @@ namespace PckStudio.Forms.Editor { public partial class COLEditor : MetroForm { - ColorContainer default_colourfile; - ColorContainer colourfile; - string clipboard_color = "#FFFFFF"; + ColorContainer _defaultColourfile; + ColorContainer _colourfile; + string _clipboard_color = "#FFFFFF"; private readonly PckAsset _asset; @@ -33,7 +33,7 @@ public COLEditor(PckAsset asset) saveToolStripMenuItem1.Visible = !Settings.Default.AutoSaveChanges; _asset = asset; - colourfile = asset.GetData(new COLFileReader()); + _colourfile = asset.GetData(new COLFileReader()); TU12ToolStripMenuItem.Click += (sender, e) => SetUpDefaultFile(sender, e, 0); TU13ToolStripMenuItem.Click += (sender, e) => SetUpDefaultFile(sender, e, 1); @@ -55,15 +55,16 @@ public COLEditor(PckAsset asset) colorTreeView.SelectedNode = colorTreeView.Nodes[0]; } - private void SetUpDefaultFile(object sender, EventArgs e, int ID, bool targetVersion = true) + private void SetUpDefaultFile(object sender, EventArgs e, int id, bool showMessageBox = true) { - if(targetVersion) + if (showMessageBox) { - var result = MessageBox.Show(this, "This function will set up your colour table to match that of the chosen version. You may lose some entries in the table. Are you sure you would like to continue?", "Target update version?", MessageBoxButtons.YesNo); - if (result == DialogResult.No) return; + DialogResult result = MessageBox.Show(this, "This function will set up your colour table to match that of the chosen version. You may lose some entries in the table. Are you sure you would like to continue?", "Target update version?", MessageBoxButtons.YesNo); + if (result == DialogResult.No) + return; } - byte[] colorData = ID switch + byte[] colorData = id switch { 0 => Resources.tu12colours, 1 => Resources.tu13colours, @@ -78,15 +79,15 @@ private void SetUpDefaultFile(object sender, EventArgs e, int ID, bool targetVer 10 => Resources.tu54colours, 11 => Resources.tu69colours, 12 => Resources._1_91_colours, - _ => throw new ArgumentOutOfRangeException(nameof(ID)), + _ => throw new ArgumentOutOfRangeException(nameof(id)), }; var reader = new COLFileReader(); using (var stream = new MemoryStream(colorData)) { - default_colourfile = reader.FromStream(stream); + _defaultColourfile = reader.FromStream(stream); } - SetUpTable(targetVersion); + SetUpTable(showMessageBox); } void AddEntry(TreeView treeView, List cache, string name, object tag) @@ -110,7 +111,7 @@ void SetUpTable(bool targetVersion) underwaterTreeView.Nodes.Clear(); fogTreeView.Nodes.Clear(); - ColorContainer temp = targetVersion ? default_colourfile : colourfile; + ColorContainer temp = targetVersion ? _defaultColourfile : _colourfile; List CurrentEntries = new List(); @@ -122,19 +123,21 @@ void SetUpTable(bool targetVersion) // fixes the duplicate entry bug if (targetVersion) { - foreach(var col in colourfile.Colors) + foreach(ColorContainer.Color col in _colourfile.Colors) { - if (default_colourfile.Colors.Find(c => c.Name == col.Name) == null) continue; + if (_defaultColourfile.Colors.Find(c => c.Name == col.Name) == null) + continue; CurrentEntries.Add(col.Name); AddEntry(colorTreeView, colorCache, col.Name, col); } } - foreach (var col in temp.Colors) + foreach (ColorContainer.Color col in temp.Colors) { - var entry = colourfile.Colors.Find(color => color.Name == col.Name); - if (CurrentEntries.Contains(col.Name)) continue; - var color = entry ?? col; + ColorContainer.Color entry = _colourfile.Colors.Find(color => color.Name == col.Name); + if (CurrentEntries.Contains(col.Name)) + continue; + ColorContainer.Color color = entry ?? col; AddEntry(colorTreeView, colorCache, color.Name, color); } CurrentEntries.Clear(); @@ -142,22 +145,24 @@ void SetUpTable(bool targetVersion) // fixes the duplicate entry bug if (targetVersion) { - foreach (var col in colourfile.WaterColors) + foreach (ColorContainer.WaterColor col in _colourfile.WaterColors) { - if (default_colourfile.WaterColors.Find(c => c.Name == col.Name) == null) continue; - var entry = colourfile.WaterColors.Find(color => color.Name == col.Name); - var color = entry ?? col; + if (_defaultColourfile.WaterColors.Find(c => c.Name == col.Name) == null) + continue; + ColorContainer.WaterColor entry = _colourfile.WaterColors.Find(color => color.Name == col.Name); + ColorContainer.WaterColor color = entry ?? col; AddEntry(waterTreeView, waterCache, color.Name, color); AddEntry(underwaterTreeView, underwaterCache, color.Name, color); AddEntry(fogTreeView, fogCache, color.Name, color); } } - foreach (var col in temp.WaterColors) + foreach (ColorContainer.WaterColor col in temp.WaterColors) { - var entry = colourfile.WaterColors.Find(color => color.Name == col.Name); - if (CurrentEntries.Contains(col.Name)) continue; - var color = entry ?? col; + ColorContainer.WaterColor entry = _colourfile.WaterColors.Find(color => color.Name == col.Name); + if (CurrentEntries.Contains(col.Name)) + continue; + ColorContainer.WaterColor color = entry ?? col; AddEntry(waterTreeView, waterCache, color.Name, color); AddEntry(underwaterTreeView, underwaterCache, color.Name, color); AddEntry(fogTreeView, fogCache, color.Name, color); @@ -287,14 +292,14 @@ private void treeView4_AfterSelect(object sender, TreeViewEventArgs e) private void saveToolStripMenuItem1_Click(object sender, EventArgs e) { - _asset.SetData(new COLFileWriter(colourfile)); + _asset.SetData(new COLFileWriter(_colourfile)); DialogResult = DialogResult.OK; } public void treeView1_KeyDown(object sender, KeyEventArgs e) { - var node = colorTreeView.SelectedNode; + TreeNode node = colorTreeView.SelectedNode; if (e.KeyCode == Keys.Delete && node.Tag is ColorContainer.Color) { restoreOriginalColorToolStripMenuItem_Click(sender, e); @@ -311,7 +316,7 @@ public void treeView1_KeyDown(object sender, KeyEventArgs e) private void treeView2_KeyDown(object sender, KeyEventArgs e) { - var node = waterTreeView.SelectedNode; + TreeNode node = waterTreeView.SelectedNode; if (e.KeyCode == Keys.Delete && node.Tag is ColorContainer.WaterColor) { restoreOriginalColorToolStripMenuItem_Click(sender, e); @@ -328,7 +333,7 @@ private void treeView2_KeyDown(object sender, KeyEventArgs e) private void treeView3_KeyDown(object sender, KeyEventArgs e) { - var node = underwaterTreeView.SelectedNode; + TreeNode node = underwaterTreeView.SelectedNode; if (e.KeyCode == Keys.Delete && node.Tag is ColorContainer.WaterColor) { restoreOriginalColorToolStripMenuItem_Click(sender, e); @@ -345,7 +350,7 @@ private void treeView3_KeyDown(object sender, KeyEventArgs e) private void treeView4_KeyDown(object sender, KeyEventArgs e) { - var node = fogTreeView.SelectedNode; + TreeNode node = fogTreeView.SelectedNode; if (e.KeyCode == Keys.Delete && node.Tag is ColorContainer.WaterColor) { restoreOriginalColorToolStripMenuItem_Click(sender, e); @@ -390,9 +395,12 @@ private void color_ValueChanged(object sender, EventArgs e) { var waterColorEntry = (tabControl.SelectedTab.Controls[0] as TreeView).SelectedNode.Tag as ColorContainer.WaterColor; - if (tabControl.SelectedTab == waterTab) waterColorEntry.SurfaceColor = color; - else if (tabControl.SelectedTab == underwaterTab) waterColorEntry.UnderwaterColor = color; - else waterColorEntry.FogColor = color; + if (tabControl.SelectedTab == waterTab) + waterColorEntry.SurfaceColor = color; + else if (tabControl.SelectedTab == underwaterTab) + waterColorEntry.UnderwaterColor = color; + else + waterColorEntry.FogColor = color; } pictureBox1.BackColor = color; @@ -405,7 +413,8 @@ private void setColorBtn_Click(object sender, EventArgs e) colorPick.AllowFullOpen = true; colorPick.AnyColor = true; colorPick.SolidColorOnly = tabControl.SelectedTab == colorsTab; - if (colorPick.ShowDialog(this) != DialogResult.OK) return; + if (colorPick.ShowDialog(this) != DialogResult.OK) + return; pictureBox1.BackColor = colorPick.Color; if (tabControl.SelectedTab == waterTab && waterTreeView.SelectedNode != null && waterTreeView.SelectedNode.Tag != null && waterTreeView.SelectedNode.Tag is ColorContainer.WaterColor) @@ -465,9 +474,10 @@ private void restoreOriginalColorToolStripMenuItem_Click(object sender, EventArg if (tab == colorsTab) { - ColorContainer.Color col_entry = default_colourfile.Colors.Find(color => color.Name == node.Text); + ColorContainer.Color col_entry = _defaultColourfile.Colors.Find(color => color.Name == node.Text); - if (col_entry == null) return; + if (col_entry == null) + return; color = col_entry.ColorPallette; @@ -475,9 +485,10 @@ private void restoreOriginalColorToolStripMenuItem_Click(object sender, EventArg } else { - ColorContainer.WaterColor WaterEntry = default_colourfile.WaterColors.Find(color => color.Name == node.Text); + ColorContainer.WaterColor WaterEntry = _defaultColourfile.WaterColors.Find(color => color.Name == node.Text); - if (WaterEntry == null) return; + if (WaterEntry == null) + return; color = tab == waterTab ? WaterEntry.SurfaceColor : @@ -569,12 +580,12 @@ private void metroTextBox1_TextChanged(object sender, EventArgs e) private void copyColorToolStripMenuItem_Click(object sender, EventArgs e) { - clipboard_color = colorTextbox.Text; + _clipboard_color = colorTextbox.Text; } private void pasteColorToolStripMenuItem_Click(object sender, EventArgs e) { - colorTextbox.Text = clipboard_color; + colorTextbox.Text = _clipboard_color; } private void COLEditor_FormClosing(object sender, FormClosingEventArgs e) @@ -594,7 +605,7 @@ private void colorTextbox_KeyPress(object sender, KeyPressEventArgs e) private void stripPS4BiomesToolStripMenuItem_Click(object sender, EventArgs e) { - if(colourfile.WaterColors.Count > 0) + if(_colourfile.WaterColors.Count > 0) { List PS4Biomes = new List { @@ -605,9 +616,10 @@ private void stripPS4BiomesToolStripMenuItem_Click(object sender, EventArgs e) "mega_taiga_mutated" }; - foreach (var col in colourfile.WaterColors.ToList()) + foreach (ColorContainer.WaterColor col in _colourfile.WaterColors.ToList()) { - if (PS4Biomes.Contains(col.Name)) colourfile.WaterColors.Remove(col); + if (PS4Biomes.Contains(col.Name)) + _colourfile.WaterColors.Remove(col); } SetUpTable(false); @@ -628,12 +640,12 @@ private void addColorToolStripMenuItem_Click(object sender, EventArgs e) entry.Name = prompt.NewText; entry.ColorPallette = Color.FromArgb(0xFFFFFF); - if(colourfile.Colors.Find(c => c.Name == entry.Name) != null) + if(_colourfile.Colors.Find(c => c.Name == entry.Name) != null) { MessageBox.Show(this, $"\"{entry.Name}\" already exists in this color table", "Color not added"); } - colourfile.Colors.Add(entry); + _colourfile.Colors.Add(entry); AddEntry(colorTreeView, colorCache, entry.Name, entry); } } @@ -647,7 +659,7 @@ private void removeColorToolStripMenuItem_Click(object sender, EventArgs e) && entry != null && entry.Tag is ColorContainer.Color color) { - colourfile.Colors.Remove(color); + _colourfile.Colors.Remove(color); RemoveEntry(entry, colorCache); } } diff --git a/PCK-Studio/Forms/Editor/GameRuleFileEditor.cs b/PCK-Studio/Forms/Editor/GameRuleFileEditor.cs index ce356d52..0abbcf56 100644 --- a/PCK-Studio/Forms/Editor/GameRuleFileEditor.cs +++ b/PCK-Studio/Forms/Editor/GameRuleFileEditor.cs @@ -17,19 +17,13 @@ **/ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Windows.Forms; using PckStudio.Forms.Additional_Popups.Grf; using PckStudio.Internal.Misc; using OMI.Formats.GameRule; -using OMI.Workers.GameRule; -using System.Diagnostics; -using OMI.Formats.Pck; -using PckStudio.Forms.Additional_Popups; using PckStudio.Properties; using PckStudio.ToolboxItems; -using PckStudio.Extensions; namespace PckStudio.Forms.Editor { @@ -58,7 +52,7 @@ private void OnLoad(object sender, EventArgs e) private void LoadGameRuleTree(TreeNodeCollection root, GameRuleFile.GameRule parentRule) { - foreach (var rule in parentRule.ChildRules) + foreach (GameRuleFile.GameRule rule in parentRule.ChildRules) { TreeNode node = new TreeNode(rule.Name); node.Tag = rule; @@ -106,7 +100,7 @@ private void ReloadParameterTreeView() { GrfParametersTreeView.Nodes.Clear(); if (GrfTreeView.SelectedNode is TreeNode t && t.Tag is GameRuleFile.GameRule rule) - foreach (var param in rule.Parameters) + foreach (KeyValuePair param in rule.Parameters) { GrfParametersTreeView.Nodes.Add(new TreeNode($"{param.Key}: {param.Value}") { Tag = param}); } @@ -114,7 +108,8 @@ private void ReloadParameterTreeView() private void addDetailContextMenuItem_Click(object sender, EventArgs e) { - if (GrfTreeView.SelectedNode == null || !(GrfTreeView.SelectedNode.Tag is GameRuleFile.GameRule)) return; + if (GrfTreeView.SelectedNode == null || !(GrfTreeView.SelectedNode.Tag is GameRuleFile.GameRule)) + return; var grfTag = GrfTreeView.SelectedNode.Tag as GameRuleFile.GameRule; AddParameter prompt = new AddParameter(); if (prompt.ShowDialog(this) == DialogResult.OK) @@ -164,7 +159,7 @@ private void GrfDetailsTreeView_NodeMouseDoubleClick(object sender, TreeNodeMous private void addGameRuleToolStripMenuItem_Click(object sender, EventArgs e) { bool isValidNode = GrfTreeView.SelectedNode is TreeNode t && t.Tag is GameRuleFile.GameRule; - var parentRule = isValidNode + GameRuleFile.GameRule parentRule = isValidNode ? GrfTreeView.SelectedNode.Tag as GameRuleFile.GameRule : _file.Root; @@ -180,9 +175,9 @@ private void addGameRuleToolStripMenuItem_Click(object sender, EventArgs e) prompt.ShowDialog(this) == DialogResult.OK && !string.IsNullOrWhiteSpace(prompt.NewText)) { - var tag = parentRule.AddRule(prompt.NewText); - TreeNode node = new TreeNode(tag.Name); - node.Tag = tag; + GameRuleFile.GameRule rule = parentRule.AddRule(prompt.NewText); + TreeNode node = new TreeNode(rule.Name); + node.Tag = rule; root.Add(node); } } @@ -190,15 +185,15 @@ private void addGameRuleToolStripMenuItem_Click(object sender, EventArgs e) private void removeGameRuleToolStripMenuItem_Click(object sender, EventArgs e) { - if (GrfTreeView.SelectedNode is TreeNode t && t.Tag is GameRuleFile.GameRule tag && removeTag(tag)) + if (GrfTreeView.SelectedNode is TreeNode t && t.Tag is GameRuleFile.GameRule tag && RemoveTag(tag)) t.Remove(); } - private bool removeTag(GameRuleFile.GameRule rule) + private bool RemoveTag(GameRuleFile.GameRule rule) { _ = rule.Parent ?? throw new ArgumentNullException(nameof(rule.Parent)); - foreach (var subTag in rule.ChildRules.ToList()) - return removeTag(subTag); + foreach (GameRuleFile.GameRule subTag in rule.ChildRules.ToList()) + return RemoveTag(subTag); return rule.Parent.ChildRules.Remove(rule); } diff --git a/PCK-Studio/Forms/Editor/LOCEditor.cs b/PCK-Studio/Forms/Editor/LOCEditor.cs index ebcc4ce8..28a13436 100644 --- a/PCK-Studio/Forms/Editor/LOCEditor.cs +++ b/PCK-Studio/Forms/Editor/LOCEditor.cs @@ -17,29 +17,29 @@ namespace PckStudio.Forms.Editor { public partial class LOCEditor : MetroForm { - LOCFile currentLoc; + LOCFile _currentLoc; PckAsset _asset; public LOCEditor(PckAsset asset) { InitializeComponent(); _asset = asset; - currentLoc = asset.GetData(new LOCFileReader()); + _currentLoc = asset.GetData(new LOCFileReader()); saveToolStripMenuItem.Visible = !Settings.Default.AutoSaveChanges; } private void LOCEditor_Load(object sender, EventArgs e) { RPC.SetPresence("LOC Editor", "Editing localization File."); - foreach(string locKey in currentLoc.LocKeys.Keys) + foreach(string locKey in _currentLoc.LocKeys.Keys) treeViewLocKeys.Nodes.Add(locKey); } private void treeViewLocKeys_AfterSelect(object sender, TreeViewEventArgs e) { - var node = e.Node; + TreeNode node = e.Node; if (node == null || - !currentLoc.LocKeys.ContainsKey(node.Text)) + !_currentLoc.LocKeys.ContainsKey(node.Text)) { MessageBox.Show(this, "Selected Node does not seem to be in the loc file"); return; @@ -53,7 +53,7 @@ private void addDisplayIDToolStripMenuItem_Click(object sender, EventArgs e) { prompt.OKButtonText = "Add"; if (prompt.ShowDialog(this) == DialogResult.OK && - currentLoc.AddLocKey(prompt.NewText, "")) + _currentLoc.AddLocKey(prompt.NewText, "")) { treeViewLocKeys.Nodes.Add(prompt.NewText); } @@ -62,7 +62,7 @@ private void addDisplayIDToolStripMenuItem_Click(object sender, EventArgs e) private void deleteDisplayIDToolStripMenuItem_Click(object sender, EventArgs e) { - if (treeViewLocKeys.SelectedNode is TreeNode t && currentLoc.RemoveLocKey(t.Text)) + if (treeViewLocKeys.SelectedNode is TreeNode t && _currentLoc.RemoveLocKey(t.Text)) { treeViewLocKeys.SelectedNode.Remove(); ReloadTranslationTable(); @@ -77,11 +77,11 @@ private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs MessageBox.Show(this, "something went wrong"); return; } - var row = dataGridViewLocEntryData.Rows[e.RowIndex]; + DataGridViewRow row = dataGridViewLocEntryData.Rows[e.RowIndex]; string locKey = treeViewLocKeys.SelectedNode.Text; string language = row.Cells[0].Value.ToString(); string value = row.Cells[1].Value.ToString(); - currentLoc.SetLocEntry(locKey, language, value); + _currentLoc.SetLocEntry(locKey, language, value); } private void treeView1_KeyDown(object sender, KeyEventArgs e) @@ -97,7 +97,7 @@ private void buttonReplaceAll_Click(object sender, EventArgs e) dataGridViewLocEntryData.Rows[i].Cells[1].Value = textBoxReplaceAll.Text; } - currentLoc.SetLocEntry(treeViewLocKeys.SelectedNode.Text, textBoxReplaceAll.Text); + _currentLoc.SetLocEntry(treeViewLocKeys.SelectedNode.Text, textBoxReplaceAll.Text); } private void ReloadTranslationTable() @@ -105,15 +105,16 @@ private void ReloadTranslationTable() dataGridViewLocEntryData.Rows.Clear(); if (treeViewLocKeys.SelectedNode is null) return; - foreach (var l in currentLoc.GetLocEntries(treeViewLocKeys.SelectedNode.Text)) - dataGridViewLocEntryData.Rows.Add(l.Key, l.Value); + foreach (KeyValuePair locEntry in _currentLoc.GetLocEntries(treeViewLocKeys.SelectedNode.Text)) + dataGridViewLocEntryData.Rows.Add(locEntry.Key, locEntry.Value); } private IEnumerable GetAvailableLanguages() { foreach (var lang in LOCFile.ValidLanguages) { - if (currentLoc.Languages.Contains(lang)) continue; + if (_currentLoc.Languages.Contains(lang)) + continue; yield return lang; } yield break; @@ -125,14 +126,14 @@ private void addLanguageToolStripMenuItem_Click(object sender, EventArgs e) using (var dialog = new AddLanguage(avalibleLang)) if (dialog.ShowDialog(this) == DialogResult.OK) { - currentLoc.AddLanguage(dialog.SelectedLanguage); + _currentLoc.AddLanguage(dialog.SelectedLanguage); ReloadTranslationTable(); } } private void saveToolStripMenuItem_Click(object sender, EventArgs e) { - _asset.SetData(new LOCFileWriter(currentLoc, 2)); + _asset.SetData(new LOCFileWriter(_currentLoc, 2)); DialogResult = DialogResult.OK; } diff --git a/PCK-Studio/Forms/Editor/MaterialsEditor.cs b/PCK-Studio/Forms/Editor/MaterialsEditor.cs index 8a878314..619c61f2 100644 --- a/PCK-Studio/Forms/Editor/MaterialsEditor.cs +++ b/PCK-Studio/Forms/Editor/MaterialsEditor.cs @@ -21,7 +21,7 @@ public partial class MaterialsEditor : MetroForm { // Materials File Format research by PhoenixARC private readonly PckAsset _asset; - MaterialContainer materialFile; + MaterialContainer _materialFile; private readonly List MaterialData = Entities.BehaviourInfos; @@ -34,11 +34,11 @@ void SetUpTree() { treeView1.BeginUpdate(); treeView1.Nodes.Clear(); - foreach (var entry in materialFile) + foreach (MaterialContainer.Material entry in _materialFile) { TreeNode EntryNode = new TreeNode(entry.Name); - var material = MaterialData.Find(m => m.InternalName == entry.Name); + EntityInfo material = MaterialData.Find(m => m.InternalName == entry.Name); if(material != null) { EntryNode.Text = material.DisplayName; @@ -73,9 +73,9 @@ public MaterialsEditor(PckAsset asset) using (var stream = new MemoryStream(asset.Data)) { var reader = new MaterialFileReader(); - materialFile = reader.FromStream(stream); + _materialFile = reader.FromStream(stream); - if (materialFile.hasInvalidEntries()) + if (_materialFile.hasInvalidEntries()) { DialogResult dr = MessageBox.Show(this, "Unsupported entities were found in this file. Would you like to display them?", "Invalid data found", MessageBoxButtons.YesNo); @@ -91,7 +91,8 @@ public MaterialsEditor(PckAsset asset) private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { - if (e.Node == null) return; + if (e.Node == null) + return; bool enable = e.Node.Tag is MaterialContainer.Material && treeView1.SelectedNode != null; materialComboBox.Enabled = enable; @@ -105,7 +106,8 @@ private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) } private void removeToolStripMenuItem_Click(object sender, EventArgs e) { - if (treeView1.SelectedNode == null) return; + if (treeView1.SelectedNode == null) + return; treeView1.SelectedNode.Remove(); } @@ -117,27 +119,28 @@ private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs private void treeView1_KeyDown(object sender, KeyEventArgs e) { - if (e.KeyCode == Keys.Delete) removeToolStripMenuItem_Click(sender, e); + if (e.KeyCode == Keys.Delete) + removeToolStripMenuItem_Click(sender, e); } private void saveToolStripMenuItem1_Click(object sender, EventArgs e) { - materialFile = new MaterialContainer(); + _materialFile = new MaterialContainer(); foreach (TreeNode node in treeView1.Nodes) { if(node.Tag is MaterialContainer.Material entry) { - materialFile.Add(entry); + _materialFile.Add(entry); } } foreach (MaterialContainer.Material mat in hiddenInvalidEntries) { - materialFile.Add(mat); + _materialFile.Add(mat); } - _asset.SetData(new MaterialFileWriter(materialFile)); + _asset.SetData(new MaterialFileWriter(_materialFile)); DialogResult = DialogResult.OK; } @@ -148,22 +151,23 @@ private void addToolStripMenuItem_Click(object sender, EventArgs e) if (diag.ShowDialog(this) == DialogResult.OK) { - if (string.IsNullOrEmpty(diag.SelectedEntity)) return; - if (materialFile.FindAll(mat => mat.Name == diag.SelectedEntity).Count() > 0) + if (string.IsNullOrEmpty(diag.SelectedEntity)) + return; + if (_materialFile.FindAll(mat => mat.Name == diag.SelectedEntity).Count() > 0) { MessageBox.Show(this, "You cannot have two entries for one entity. Please use the \"Add New Position Override\" tool to add multiple overrides for entities", "Error", MessageBoxButtons.OK); return; } - var NewEntry = new MaterialContainer.Material(diag.SelectedEntity, "entity_alphatest"); + var newEntry = new MaterialContainer.Material(diag.SelectedEntity, "entity_alphatest"); - TreeNode NewEntryNode = new TreeNode(NewEntry.Name); - NewEntryNode.Tag = NewEntry; + TreeNode newEntryNode = new TreeNode(newEntry.Name); + newEntryNode.Tag = newEntry; - var material = MaterialData.Find(m => m.InternalName == NewEntry.Name); - NewEntryNode.Text = material.DisplayName; - NewEntryNode.ImageIndex = MaterialData.IndexOf(material); - NewEntryNode.SelectedImageIndex = NewEntryNode.ImageIndex; - treeView1.Nodes.Add(NewEntryNode); + EntityInfo material = MaterialData.Find(m => m.InternalName == newEntry.Name); + newEntryNode.Text = material.DisplayName; + newEntryNode.ImageIndex = MaterialData.IndexOf(material); + newEntryNode.SelectedImageIndex = newEntryNode.ImageIndex; + treeView1.Nodes.Add(newEntryNode); } } diff --git a/PCK-Studio/Forms/Editor/TextureAtlasEditor.cs b/PCK-Studio/Forms/Editor/TextureAtlasEditor.cs index 5ffd1b2f..58865e18 100644 --- a/PCK-Studio/Forms/Editor/TextureAtlasEditor.cs +++ b/PCK-Studio/Forms/Editor/TextureAtlasEditor.cs @@ -110,7 +110,7 @@ public TextureAtlasEditor(PckFile pckFile, ResourceLocation resourceLocation, Im _rowCount = atlas.Width / _tileAreaSize.Width; _columnCount = atlas.Height / _tileAreaSize.Height; _resourceLocation = resourceLocation; - var tileInfos = resourceLocation.Category switch + List tileInfos = resourceLocation.Category switch { ResourceCategory.BlockAtlas => Tiles.BlockTileInfos, ResourceCategory.ItemAtlas => Tiles.ItemTileInfos, @@ -127,7 +127,7 @@ public TextureAtlasEditor(PckFile pckFile, ResourceLocation resourceLocation, Im originalPictureBox.Image = new Bitmap(atlas); - var images = atlas.Split(_tileAreaSize, _imageLayout); + IEnumerable images = atlas.Split(_tileAreaSize, _imageLayout); AtlasTile MakeTile((int index, Image value) p) { @@ -168,7 +168,7 @@ AtlasTile MakeTile((int index, Image value) p) private bool AcquireColorTable(PckFile pckFile) { - if (pckFile.TryGetAsset("colours.col", PckAssetType.ColourTableFile, out var colAsset) && + if (pckFile.TryGetAsset("colours.col", PckAssetType.ColourTableFile, out PckAsset colAsset) && colAsset.Size > 0) { using var ms = new MemoryStream(colAsset.Data); @@ -246,7 +246,7 @@ private void SetImageDisplayed(int index) // asset size check dont have to be done here the deserializer handles it. -Miku if (playAnimationsToolStripMenuItem.Checked && hasAnimation) { - var animation = animationAsset.GetDeserializedData(AnimationDeserializer.DefaultDeserializer); + Animation animation = animationAsset.GetDeserializedData(AnimationDeserializer.DefaultDeserializer); selectTilePictureBox.Image = animation.CreateAnimationImage(); selectTilePictureBox.Start(); } @@ -343,7 +343,7 @@ private static int GetSelectedImageIndex( default: break; - }; + } return GetSelectedIndex(result.X, result.Y, rowCount, columnCount, imageLayout); } @@ -359,7 +359,7 @@ private static int GetSelectedIndex(int x, int y, int rowCount, int columnCount, private static Rectangle GetAtlasArea(int index, int tileWidth, int tileHeight, int rowCount, int columnCount, Size size, ImageLayoutDirection imageLayout) { - var p = GetSelectedPoint(index, rowCount, columnCount, imageLayout); + Point p = GetSelectedPoint(index, rowCount, columnCount, imageLayout); var ap = new Point(p.X * size.Width, p.Y * size.Height); return new Rectangle(ap, new Size(size.Width * tileWidth, size.Height * tileHeight)); } @@ -384,7 +384,7 @@ private void SetTile(Image texture) g.DrawImage(texture, dataTile.Area); } - var tile = _selectedTile != dataTile ? dataTile : _selectedTile; + AtlasTile tile = _selectedTile != dataTile ? dataTile : _selectedTile; _tiles[tile.Index] = new AtlasTile(tile.Index, tile.Area, tile.Tile, texture); selectTilePictureBox.Image = texture; UpdateAtlasDisplay(); @@ -394,7 +394,7 @@ private Color GetBlendColor() { if (dataTile.Tile.HasColourEntry && dataTile.Tile.ColourEntry is not null) { - var col = FindBlendColorByKey(dataTile.Tile.ColourEntry.DefaultName); + Color col = FindBlendColorByKey(dataTile.Tile.ColourEntry.DefaultName); return col; } @@ -518,14 +518,14 @@ private void animationButton_Click(object sender, EventArgs e) { ResourceCategory animationResourceCategory = _resourceLocation.Category == ResourceCategory.ItemAtlas ? ResourceCategory.ItemAnimation : ResourceCategory.BlockAnimation; string animationAssetPath = $"{ResourceLocation.GetPathFromCategory(animationResourceCategory)}/{_selectedTile.Tile.InternalName}.png"; - var file = _pckFile.GetOrCreate(animationAssetPath, PckAssetType.TextureFile); + PckAsset asset = _pckFile.GetOrCreate(animationAssetPath, PckAssetType.TextureFile); - var animation = file.GetDeserializedData(AnimationDeserializer.DefaultDeserializer); + Animation animation = asset.GetDeserializedData(AnimationDeserializer.DefaultDeserializer); var animationEditor = new AnimationEditor(animation, _selectedTile.Tile.DisplayName); if (animationEditor.ShowDialog(this) == DialogResult.OK) { - file.SetSerializedData(animationEditor.Result, AnimationSerializer.DefaultSerializer); + asset.SetSerializedData(animationEditor.Result, AnimationSerializer.DefaultSerializer); // so animations can automatically update upon saving SelectedIndex = _selectedTile.Index; } @@ -597,7 +597,8 @@ private void setColorButton_Click(object sender, EventArgs e) colorPick.CustomColors = GameConstants.DyeColors.Select(c => c.ToBGR()).ToArray(); - if (colorPick.ShowDialog(this) != DialogResult.OK) return; + if (colorPick.ShowDialog(this) != DialogResult.OK) + return; selectTilePictureBox.BlendColor = colorPick.Color; selectTilePictureBox.Image = dataTile.Texture; diff --git a/PCK-Studio/Forms/Features/CemuPanel.cs b/PCK-Studio/Forms/Features/CemuPanel.cs index e09cc7e8..3c7bc387 100644 --- a/PCK-Studio/Forms/Features/CemuPanel.cs +++ b/PCK-Studio/Forms/Features/CemuPanel.cs @@ -96,8 +96,8 @@ private bool TryApplyPermanentCemuConfig() reader.ReadLine(); xml.Load(reader); } - var configNode = xml.SelectSingleNode("config"); - var mlcpathNode = configNode.SelectSingleNode("MlcPath"); + XmlNode configNode = xml.SelectSingleNode("config"); + XmlNode mlcpathNode = configNode.SelectSingleNode("MlcPath"); GameDirectoryTextBox.Text = mlcpathNode.InnerText; GameDirectoryTextBox.Enabled = false; BrowseDirectoryBtn.Enabled = false; @@ -171,9 +171,9 @@ public DLCDirectoryInfo(DirectoryInfo directory) { _basePckPath = directory.GetFiles().FirstOrDefault(f => f.Name.EndsWith(".pck")).FullName; _ = _basePckPath ?? throw new NullReferenceException($"Could not find any '.pck' inside {directory.Name}"); - if (TryGetDataDirectory(directory, out var dataDir)) + if (TryGetDataDirectory(directory, out DirectoryInfo dataDir)) { - var tpFileInfo = dataDir.GetFiles().FirstOrDefault(f => !f.Name.Equals("audio.pck") && f.Name.EndsWith(".pck")); + FileInfo tpFileInfo = dataDir.GetFiles().FirstOrDefault(f => !f.Name.Equals("audio.pck") && f.Name.EndsWith(".pck")); _hasTexturePack = tpFileInfo is not null; _texturePackPath = _hasTexturePack ? tpFileInfo.FullName : string.Empty; } @@ -186,7 +186,7 @@ public DLCDirectoryInfo(string path) private bool TryGetDataDirectory(DirectoryInfo directory, out DirectoryInfo dataDirectory) { - var dirs = directory.GetDirectories("Data", SearchOption.TopDirectoryOnly); + DirectoryInfo[] dirs = directory.GetDirectories("Data", SearchOption.TopDirectoryOnly); dataDirectory = dirs.Length != 0 ? dirs[0] : null; return dirs.Length != 0; } @@ -219,11 +219,11 @@ private void ListDLCs() return; } - foreach (var directoryInfo in dlcDirectory.GetDirectories()) + foreach (DirectoryInfo directoryInfo in dlcDirectory.GetDirectories()) { if (directoryInfo.GetFileSystemInfos().Length != 0) { - var node = DLCTreeView.Nodes.Add(directoryInfo.Name); + TreeNode node = DLCTreeView.Nodes.Add(directoryInfo.Name); node.Tag = new DLCDirectoryInfo(directoryInfo); } } @@ -302,7 +302,7 @@ private void addCustomPckToolStripMenuItem_Click(object sender, EventArgs e) private void removePckToolStripMenuItem_Click(object sender, EventArgs e) { string pckName = DLCTreeView.SelectedNode.Text; - var result = MessageBox.Show(this, $"Are you sure you want to permanently delete '{pckName}'?", "Hold up!", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + DialogResult result = MessageBox.Show(this, $"Are you sure you want to permanently delete '{pckName}'?", "Hold up!", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result == DialogResult.Yes) { string directoryPath = GetContentSubDirectory("WiiU", "DLC", pckName); diff --git a/PCK-Studio/Forms/Features/PckManager.cs b/PCK-Studio/Forms/Features/PckManager.cs index 6348649c..ee51b1b4 100644 --- a/PCK-Studio/Forms/Features/PckManager.cs +++ b/PCK-Studio/Forms/Features/PckManager.cs @@ -22,8 +22,8 @@ namespace PckStudio.Forms.Features { public partial class PckManager : MetroFramework.Forms.MetroForm { - private Control currentlyShowingControl; - private string currentlyShowingControlName; + private Control _currentlyShowingControl; + private string _currentlyShowingControlName; private const string CemU = "Cemu"; // TODO: Implement these Panels @@ -47,29 +47,29 @@ public PckManager() protected override void OnGotFocus(EventArgs e) { - currentlyShowingControl?.Focus(); + _currentlyShowingControl?.Focus(); } private void supportedPlatformComboBox_SelectionChangeCommitted(object sender, EventArgs e) { - if (!supportedPlatformComboBox.SelectedItem.Equals(currentlyShowingControlName)) + if (!supportedPlatformComboBox.SelectedItem.Equals(_currentlyShowingControlName)) { - mainPanel.Controls.Remove(currentlyShowingControl); - currentlyShowingControlName = supportedPlatformComboBox.Items[supportedPlatformComboBox.SelectedIndex].ToString(); + mainPanel.Controls.Remove(_currentlyShowingControl); + _currentlyShowingControlName = supportedPlatformComboBox.Items[supportedPlatformComboBox.SelectedIndex].ToString(); try { - currentlyShowingControl = currentlyShowingControlName switch + _currentlyShowingControl = _currentlyShowingControlName switch { CemU => new CemuPanel(), //WiiU => throw new NotImplementedException($"{text}-Panel is currently not implemented."), //PS3 => throw new NotImplementedException($"{text}-Panel is currently not implemented."), //PSVita => throw new NotImplementedException($"{text}-Panel is currently not implemented."), //RPCS3 => throw new NotImplementedException($"{text}-Panel is currently not implemented."), - _ => throw new Exception($"No Panel found for: {currentlyShowingControlName}"), + _ => throw new Exception($"No Panel found for: {_currentlyShowingControlName}"), }; - currentlyShowingControl.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right; - mainPanel.SetColumnSpan(currentlyShowingControl, 2); - mainPanel.Controls.Add(currentlyShowingControl, 0, 1); + _currentlyShowingControl.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right; + mainPanel.SetColumnSpan(_currentlyShowingControl, 2); + mainPanel.Controls.Add(_currentlyShowingControl, 0, 1); } catch (NotImplementedException ex) { diff --git a/PCK-Studio/Forms/Skins-And-Textures/AdvancedOptions.cs b/PCK-Studio/Forms/Skins-And-Textures/AdvancedOptions.cs index da4ee2fb..863353b7 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/AdvancedOptions.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/AdvancedOptions.cs @@ -23,7 +23,7 @@ public bool IsLittleEndian _endianness = value ? Endianness.LittleEndian : Endianness.BigEndian; } } - private PckFile _pckFile; + private readonly PckFile _pckFile; private Endianness _endianness; public AdvancedOptions(PckFile pckFile) diff --git a/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.cs b/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.cs index e3ce8ed0..1be7abce 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.cs @@ -9,26 +9,26 @@ namespace PckStudio.Forms { public partial class SkinPreview : Form { - Image Texture; - ModelBase Model; + Image _texture; + ModelBase _model; public SkinPreview(Image img, SkinANIM anim, ModelBase model = null) { InitializeComponent(); - Texture = img; + _texture = img; - Model = model ?? new Steve64x32Model(Texture); + _model = model ?? new Steve64x32Model(_texture); if (img.Width == 64 && img.Height == 64) { - Model = model ?? new Steve64x64Model(Texture, anim); + _model = model ?? new Steve64x64Model(_texture, anim); } } - private void SkinPreview_Load(object sender, EventArgs e) => RenderModel(Texture); + private void SkinPreview_Load(object sender, EventArgs e) => RenderModel(_texture); public void RenderModel(Image source) { - Model.AddToModelView(ModelView); + _model.AddToModelView(ModelView); } } } diff --git a/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs b/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs index fea72585..a912fa34 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/generateModel.cs @@ -24,7 +24,7 @@ namespace PckStudio.Forms public partial class generateModel : MetroForm { [Obsolete("We don't need a full control to get an image")] - private PictureBox skinPreview = new PictureBox(); + private PictureBox _skinPreview = new PictureBox(); private Image _previewImage; public Image PreviewImage => _previewImage; @@ -549,7 +549,7 @@ private void GenerateUVTextureMap() using (Graphics graphics = Graphics.FromImage(uvPictureBox.Image)) { graphics.ApplyConfig(_graphicsConfig); - foreach (var part in modelBoxes) + foreach (SkinBOX part in modelBoxes) { float width = part.Size.X * 2; float height = part.Size.Y * 2; @@ -874,9 +874,9 @@ private void DrawArmorOffsets(Graphics g) private void generateModel_Load(object sender, EventArgs e) { - if (Screen.PrimaryScreen.Bounds.Height >= 780 && Screen.PrimaryScreen.Bounds.Width >= 1080) { + if (Screen.PrimaryScreen.Bounds.Height >= 780 && Screen.PrimaryScreen.Bounds.Width >= 1080) return; - } + Rerender(); } @@ -1092,7 +1092,7 @@ private void buttonIMPORT_Click(object sender, EventArgs e) // Creates Model Data and Finalizes private void buttonDone_Click(object sender, EventArgs e) { - foreach (var part in modelBoxes) + foreach (SkinBOX part in modelBoxes) { _asset.AddProperty("BOX", part); } @@ -1154,7 +1154,7 @@ private void buttonTemplate_Click(object sender, EventArgs e) private void UpdateListView() { listViewBoxes.Items.Clear(); - foreach (var part in modelBoxes) + foreach (SkinBOX part in modelBoxes) { ListViewItem listViewItem = new ListViewItem(part.Type); listViewItem.Tag = part; @@ -1209,15 +1209,15 @@ private void buttonImportModel_Click(object sender, EventArgs e) reader.ReadLine(); string part = reader.ReadLine(); reader.ReadLine(); - var PosX = reader.ReadLine(); - var PosY = reader.ReadLine(); - var PosZ = reader.ReadLine(); - var SizeX = reader.ReadLine(); - var SizeY = reader.ReadLine(); - var SizeZ = reader.ReadLine(); - var UvX = reader.ReadLine(); - var UvY = reader.ReadLine(); - modelBoxes.Add(SkinBOX.FromString($"{part} {PosX} {PosY} {PosZ} {SizeX} {SizeY} {SizeZ} {UvX} {UvY}")); + var posX = reader.ReadLine(); + var posY = reader.ReadLine(); + var posZ = reader.ReadLine(); + var sizeX = reader.ReadLine(); + var sizeY = reader.ReadLine(); + var sizeZ = reader.ReadLine(); + var uvX = reader.ReadLine(); + var uvY = reader.ReadLine(); + modelBoxes.Add(SkinBOX.FromString($"{part} {posX} {posY} {posZ} {sizeX} {sizeY} {sizeZ} {uvX} {uvY}")); } } @@ -1231,7 +1231,7 @@ private void cloneToolStripMenuItem_Click(object sender, EventArgs e) try { ListViewItem listViewItem = new ListViewItem(); - var selected = listViewBoxes.SelectedItems[0]; + ListViewItem selected = listViewBoxes.SelectedItems[0]; listViewItem.Text = selected.Text; listViewItem.Tag = selected.Tag; int num = 0; @@ -1423,26 +1423,26 @@ private void OpenJSONButton_Click(object sender, EventArgs e) } [Obsolete("Just whyyyyy")] - public string JSONToCSM(string InputFilePath) + public string JSONToCSM(string inputFilePath) { - CSMJObject jsonDe = JsonConvert.DeserializeObject(File.ReadAllText(InputFilePath)); + CSMJObject jsonDe = JsonConvert.DeserializeObject(File.ReadAllText(inputFilePath)); StringBuilder sb = new StringBuilder(); foreach (CSMJObjectGroup group in jsonDe.Groups) { - string PARENT = group.Name; + string parent = group.Name; foreach (int i in group.children) { string name = jsonDe.Elements[i].Name; - float PosX = jsonDe.Elements[i].from[0] + group.origin[0]; - float PosY = jsonDe.Elements[i].from[1] + group.origin[1]; - float PosZ = jsonDe.Elements[i].from[2] + group.origin[2]; - float SizeX = jsonDe.Elements[i].to[0] - jsonDe.Elements[i].from[0]; - float SizeY = jsonDe.Elements[i].to[1] - jsonDe.Elements[i].from[1]; - float SizeZ = jsonDe.Elements[i].to[2] - jsonDe.Elements[i].from[2]; - float U = 0; - float V = 0; - - sb.AppendLine(name + "\n" + PARENT + "\n" + name + "\n" + PosX + "\n" + PosY + "\n" + PosZ + "\n" + SizeX + "\n" + SizeY + "\n" + SizeZ + "\n" + U + "\n" + V); + float posX = jsonDe.Elements[i].from[0] + group.origin[0]; + float posY = jsonDe.Elements[i].from[1] + group.origin[1]; + float posZ = jsonDe.Elements[i].from[2] + group.origin[2]; + float sizeX = jsonDe.Elements[i].to[0] - jsonDe.Elements[i].from[0]; + float sizeY = jsonDe.Elements[i].to[1] - jsonDe.Elements[i].from[1]; + float sizeZ = jsonDe.Elements[i].to[2] - jsonDe.Elements[i].from[2]; + float u = 0; + float v = 0; + + sb.AppendLine(name + "\n" + parent + "\n" + name + "\n" + posX + "\n" + posY + "\n" + posZ + "\n" + sizeX + "\n" + sizeY + "\n" + sizeZ + "\n" + u + "\n" + v); } } return sb.ToString(); diff --git a/PCK-Studio/Interfaces/IPckAssetDeserializer.cs b/PCK-Studio/Interfaces/IPckAssetDeserializer.cs index 358b23c0..3416c6d5 100644 --- a/PCK-Studio/Interfaces/IPckAssetDeserializer.cs +++ b/PCK-Studio/Interfaces/IPckAssetDeserializer.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using OMI.Formats.Pck; +using OMI.Formats.Pck; namespace PckStudio.Interfaces { diff --git a/PCK-Studio/Interfaces/IPckAssetSerializer.cs b/PCK-Studio/Interfaces/IPckAssetSerializer.cs index 46cdf4e0..dbaa903b 100644 --- a/PCK-Studio/Interfaces/IPckAssetSerializer.cs +++ b/PCK-Studio/Interfaces/IPckAssetSerializer.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using OMI.Formats.Pck; +using OMI.Formats.Pck; namespace PckStudio.Interfaces { diff --git a/PCK-Studio/Internal/Animation.cs b/PCK-Studio/Internal/Animation.cs index b64bd9e7..3d37d509 100644 --- a/PCK-Studio/Internal/Animation.cs +++ b/PCK-Studio/Internal/Animation.cs @@ -29,21 +29,21 @@ public sealed class Animation { public const int MinimumFrameTime = 1; - public int FrameCount => frames.Count; + public int FrameCount => _frames.Count; - public int TextureCount => textures.Count; + public int TextureCount => _textures.Count; public bool Interpolate { get; set; } = false; - private readonly List textures; + private readonly List _textures; - private readonly IList frames = new List(); + private readonly IList _frames = new List(); private object _syncLock = new object(); public Animation(IEnumerable textures) { - this.textures = new List(textures); + _textures = new List(textures); } public Animation(IEnumerable textures, string ANIM) @@ -63,7 +63,7 @@ public int Ticks } set { - lock(l_ticks) + lock(_syncObject) { _ticks = value; } @@ -71,7 +71,7 @@ public int Ticks } private int _ticks; - private object l_ticks = new object(); + private object _syncObject = new object(); public Frame(Image texture) : this(texture, MinimumFrameTime) { } @@ -119,7 +119,7 @@ private void ParseAnim(string anim) private void CheckTextureIndex(int index) { - if (!textures.IndexInRange(index)) + if (!_textures.IndexInRange(index)) throw new ArgumentOutOfRangeException(nameof(index)); } @@ -127,8 +127,8 @@ private void CheckTextureIndex(int index) public Frame AddFrame(int textureIndex, int frameTime) { CheckTextureIndex(textureIndex); - Frame frame = new Frame(textures[textureIndex], frameTime); - frames.Add(frame); + Frame frame = new Frame(_textures[textureIndex], frameTime); + _frames.Add(frame); return frame; } @@ -142,15 +142,15 @@ private void AddSingleFrames() public bool RemoveFrame(int frameIndex) { - frames.RemoveAt(frameIndex); + _frames.RemoveAt(frameIndex); return true; } - public Frame GetFrame(int index) => frames[index]; + public Frame GetFrame(int index) => _frames[index]; public IReadOnlyCollection GetFrames() { - return new ReadOnlyCollection(frames); + return new ReadOnlyCollection(_frames); } public IReadOnlyCollection GetInterpolatedFrames() @@ -166,10 +166,10 @@ private IEnumerable InternalGetInterpolatedFrames() { for (int i = 0; i < FrameCount; i++) { - Frame currentFrame = frames[i]; - Frame nextFrame = frames[0]; + Frame currentFrame = _frames[i]; + Frame nextFrame = _frames[0]; if (i + 1 < FrameCount) - nextFrame = frames[i + 1]; + nextFrame = _frames[i + 1]; for (int tick = 0; tick < currentFrame.Ticks; tick++) { double delta = 1.0f - tick / (double)currentFrame.Ticks; @@ -182,50 +182,50 @@ private IEnumerable InternalGetInterpolatedFrames() public IReadOnlyCollection GetTextures() { - return textures; + return _textures; } public int GetTextureIndex(Image frameTexture) { _ = frameTexture ?? throw new ArgumentNullException(nameof(frameTexture)); - return textures.IndexOf(frameTexture); + return _textures.IndexOf(frameTexture); } public void SetFrame(int frameIndex, Frame frame) { lock(_syncLock) { - frames[frameIndex] = frame; + _frames[frameIndex] = frame; } } public void SetFrame(int frameIndex, int textureIndex, int frameTime = MinimumFrameTime) { CheckTextureIndex(textureIndex); - SetFrame(frameIndex, new Frame(textures[textureIndex], frameTime)); + SetFrame(frameIndex, new Frame(_textures[textureIndex], frameTime)); } public string BuildAnim() { StringBuilder stringBuilder = new StringBuilder(Interpolate ? "#" : string.Empty); - foreach (var frame in frames) + foreach (Frame frame in _frames) stringBuilder.Append($"{GetTextureIndex(frame.Texture)}*{frame.Ticks},"); return stringBuilder.ToString(0, stringBuilder.Length - 1); } public Image BuildTexture() { - if (textures[0].Width != textures[0].Height) + if (_textures[0].Width != _textures[0].Height) throw new Exception("Invalid size"); - return textures.Combine(ImageLayoutDirection.Vertical); + return _textures.Combine(ImageLayoutDirection.Vertical); } internal void SetFrameTicks(int ticks) { lock(_syncLock) { - foreach (var frame in frames) + foreach (Frame frame in _frames) { frame.Ticks = ticks; } @@ -236,7 +236,7 @@ internal void SwapFrames(int sourceIndex, int destinationIndex) { lock(_syncLock) { - frames.Swap(sourceIndex, destinationIndex); + _frames.Swap(sourceIndex, destinationIndex); } } diff --git a/PCK-Studio/Internal/App/ApplicationScope.cs b/PCK-Studio/Internal/App/ApplicationScope.cs index a9578fce..df66124b 100644 --- a/PCK-Studio/Internal/App/ApplicationScope.cs +++ b/PCK-Studio/Internal/App/ApplicationScope.cs @@ -1,5 +1,5 @@ using System; -using System.Diagnostics; +using System.Collections.Generic; using System.Drawing; using System.Linq; using PckStudio.Properties; @@ -55,7 +55,7 @@ internal static void Initialize() internal static void GetContributors() { var ghClient = new Octokit.GitHubClient(new Octokit.ProductHeaderValue(Application.ProductName + "Credits")); - var allContributorsAct = ghClient.Repository.GetAllContributors("PhoenixARC", "-PCK-Studio"); + Task> allContributorsAct = ghClient.Repository.GetAllContributors("PhoenixARC", "-PCK-Studio"); allContributorsAct.Wait(); Contributors = allContributorsAct.Result.ToArray(); } diff --git a/PCK-Studio/Internal/App/Profiler.cs b/PCK-Studio/Internal/App/Profiler.cs index aa9af3ef..1de57454 100644 --- a/PCK-Studio/Internal/App/Profiler.cs +++ b/PCK-Studio/Internal/App/Profiler.cs @@ -15,13 +15,8 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. **/ -using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; namespace PckStudio.Internal.App { diff --git a/PCK-Studio/Internal/Deserializer/AnimationDeserializer.cs b/PCK-Studio/Internal/Deserializer/AnimationDeserializer.cs index fca18165..3c0c0e54 100644 --- a/PCK-Studio/Internal/Deserializer/AnimationDeserializer.cs +++ b/PCK-Studio/Internal/Deserializer/AnimationDeserializer.cs @@ -21,8 +21,8 @@ public Animation Deserialize(PckAsset asset) _ = asset ?? throw new ArgumentNullException(nameof(asset)); if (asset.Size > 0) { - var texture = asset.GetTexture(); - var frameTextures = texture.Split(ImageLayoutDirection.Vertical); + Image texture = asset.GetTexture(); + IEnumerable frameTextures = texture.Split(ImageLayoutDirection.Vertical); var _animation = new Animation(frameTextures, asset.GetProperty("ANIM")); return _animation; } @@ -31,7 +31,7 @@ public Animation Deserialize(PckAsset asset) public Animation DeserializeJavaAnimation(JObject jsonObject, Image texture) { - var textures = texture.Split(ImageLayoutDirection.Vertical); + IEnumerable textures = texture.Split(ImageLayoutDirection.Vertical); Animation result = new Animation(textures); if (jsonObject["animation"] is not JToken animation) return result; diff --git a/PCK-Studio/Internal/IO/3DST/3DSTextureReader.cs b/PCK-Studio/Internal/IO/3DST/3DSTextureReader.cs index 73831659..0def6f89 100644 --- a/PCK-Studio/Internal/IO/3DST/3DSTextureReader.cs +++ b/PCK-Studio/Internal/IO/3DST/3DSTextureReader.cs @@ -17,7 +17,7 @@ public Image FromFile(string filename) if (File.Exists(filename)) { Image img = null; - using (var fs = File.OpenRead(filename)) + using (FileStream fs = File.OpenRead(filename)) { img = FromStream(fs); } diff --git a/PCK-Studio/Internal/IO/3DST/3DSTextureWriter.cs b/PCK-Studio/Internal/IO/3DST/3DSTextureWriter.cs index 2008e53b..6ffbb76d 100644 --- a/PCK-Studio/Internal/IO/3DST/3DSTextureWriter.cs +++ b/PCK-Studio/Internal/IO/3DST/3DSTextureWriter.cs @@ -19,7 +19,7 @@ public _3DSTextureWriter(Image image, _3DSTextureFormat format = _3DSTextureForm public void WriteToFile(string filename) { - using(var fs = File.OpenWrite(filename)) + using(FileStream fs = File.OpenWrite(filename)) { WriteToStream(fs); } diff --git a/PCK-Studio/Internal/IO/3DST/TextureCodec.cs b/PCK-Studio/Internal/IO/3DST/TextureCodec.cs index a313c4bf..e2aaead1 100644 --- a/PCK-Studio/Internal/IO/3DST/TextureCodec.cs +++ b/PCK-Studio/Internal/IO/3DST/TextureCodec.cs @@ -346,20 +346,24 @@ public static Bitmap Decode(byte[] data, int width, int height, _3DSTextureForma int[] etc1Order = etc1Scramble(width, height); int i = 0; - for (int tY = 0; tY < height / 4; tY++) { - for (int tX = 0; tX < width / 4; tX++) { + for (int tY = 0; tY < height / 4; tY++) + { + for (int tX = 0; tX < width / 4; tX++) + { int TX = etc1Order[i] % (width / 4); int TY = (etc1Order[i] - TX) / (width / 4); - for (int y = 0; y < 4; y++) { - for (int x = 0; x < 4; x++) { - dataOffset = ((TX * 4) + x + (((TY * 4) + y) * width)) * 4; + for (int y = 0; y < 4; y++) + { + for (int x = 0; x < 4; x++) + { + dataOffset = ((TX * 4) + x + (((TY * 4) + y) * width)) * 4; long outputOffset = ((tX * 4) + x + (((tY * 4 + y)) * width)) * 4; Buffer.BlockCopy(decodedData, (int)dataOffset, output, (int)outputOffset, 4); } } i += 1; - } + } } break; @@ -577,8 +581,10 @@ private static Color etc1Pixel(uint r, uint g, uint b, int x, int y, uint block, private static byte saturate(int value) { - if (value > 0xff) return 0xff; - if (value < 0) return 0; + if (value > 0xff) + return 0xff; + if (value < 0) + return 0; return (byte)(value & 0xff); } diff --git a/PCK-Studio/Internal/IO/CSMB/CSMBFileWriter.cs b/PCK-Studio/Internal/IO/CSMB/CSMBFileWriter.cs index ede501b7..b572b092 100644 --- a/PCK-Studio/Internal/IO/CSMB/CSMBFileWriter.cs +++ b/PCK-Studio/Internal/IO/CSMB/CSMBFileWriter.cs @@ -17,7 +17,7 @@ public CSMBFileWriter(CSMBFile csmb) public void WriteToFile(string filename) { - using(var fs = File.OpenWrite(filename)) + using (FileStream fs = File.OpenWrite(filename)) { WriteToStream(fs); } diff --git a/PCK-Studio/Internal/IO/PckAudio/PckAudioFileReader.cs b/PCK-Studio/Internal/IO/PckAudio/PckAudioFileReader.cs index 97500de1..e0c641f5 100644 --- a/PCK-Studio/Internal/IO/PckAudio/PckAudioFileReader.cs +++ b/PCK-Studio/Internal/IO/PckAudio/PckAudioFileReader.cs @@ -3,7 +3,6 @@ using PckStudio.FileFormats; using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using System.Text; @@ -34,7 +33,7 @@ public PckAudioFile FromFile(string filename) if(File.Exists(filename)) { PckAudioFile file; - using(var fs = File.OpenRead(filename)) + using(FileStream fs = File.OpenRead(filename)) { file = FromStream(fs); } @@ -95,7 +94,7 @@ private void ReadCategorySongs(EndiannessAwareBinaryReader reader) { List credits = new List(); List creditIds = new List(); - foreach (var c in _OriginalAudioTypeOrder) + foreach (PckAudioFile.AudioCategory.EAudioType c in _OriginalAudioTypeOrder) { int audioCount = reader.ReadInt32(); for (; 0 < audioCount; audioCount--) @@ -118,8 +117,8 @@ private void ReadCategorySongs(EndiannessAwareBinaryReader reader) throw new InvalidDataException(nameof(key)); } } - }; - foreach (var credit in credits.Zip(creditIds, (str, id) => (str, id))) + } + foreach ((string str, string id) credit in credits.Zip(creditIds, (str, id) => (str, id))) { _file.SetCredit(credit.id, credit.str); } diff --git a/PCK-Studio/Internal/IO/PckAudio/PckAudioFileWriter.cs b/PCK-Studio/Internal/IO/PckAudio/PckAudioFileWriter.cs index ffed6cba..2538e885 100644 --- a/PCK-Studio/Internal/IO/PckAudio/PckAudioFileWriter.cs +++ b/PCK-Studio/Internal/IO/PckAudio/PckAudioFileWriter.cs @@ -27,7 +27,7 @@ public PckAudioFileWriter(PckAudioFile file, Endianness endianness) public void WriteToFile(string filename) { - using(var fs = File.OpenWrite(filename)) + using (FileStream fs = File.OpenWrite(filename)) { WriteToStream(fs); } @@ -68,7 +68,7 @@ private void WriteLookUpTable(EndiannessAwareBinaryWriter writer) private void WriteCategories(EndiannessAwareBinaryWriter writer) { writer.Write(_file.Categories.Length); - foreach (var category in _file.Categories) + foreach (PckAudioFile.AudioCategory category in _file.Categories) { writer.Write((int)category.parameterType); writer.Write((int)category.AudioType); @@ -79,7 +79,7 @@ private void WriteCategories(EndiannessAwareBinaryWriter writer) private void WriteCategorySongs(EndiannessAwareBinaryWriter writer) { bool addCredit = true; - foreach (var category in _file.Categories) + foreach (PckAudioFile.AudioCategory category in _file.Categories) { writer.Write(category.SongNames.Count + (addCredit ? _file.Credits.Count * 2 : 0)); foreach (var name in category.SongNames) @@ -89,7 +89,7 @@ private void WriteCategorySongs(EndiannessAwareBinaryWriter writer) } if (addCredit) { - foreach (var credit in _file.Credits) + foreach (KeyValuePair credit in _file.Credits) { writer.Write(LUT.IndexOf("CREDIT")); WriteString(writer, credit.Value); diff --git a/PCK-Studio/Internal/IO/TGA/TGADeserializer.cs b/PCK-Studio/Internal/IO/TGA/TGADeserializer.cs index 55690de6..23e43625 100644 --- a/PCK-Studio/Internal/IO/TGA/TGADeserializer.cs +++ b/PCK-Studio/Internal/IO/TGA/TGADeserializer.cs @@ -22,11 +22,11 @@ namespace PckStudio.Internal.IO.TGA { internal static class TGADeserializer { - private static TGAReader reader = new TGAReader(); + private static TGAReader _reader = new TGAReader(); public static Image DeserializeFromStream(Stream stream) { - TGAFileData tgaImg = reader.FromStream(stream); + TGAFileData tgaImg = _reader.FromStream(stream); return tgaImg.Bitmap; } } diff --git a/PCK-Studio/Internal/IO/TGA/TGAFileData.cs b/PCK-Studio/Internal/IO/TGA/TGAFileData.cs index f1ad1111..92936e17 100644 --- a/PCK-Studio/Internal/IO/TGA/TGAFileData.cs +++ b/PCK-Studio/Internal/IO/TGA/TGAFileData.cs @@ -17,7 +17,6 @@ **/ using System.IO; using System.Drawing; -using System; namespace PckStudio.Internal.IO.TGA { diff --git a/PCK-Studio/Internal/IO/TGA/TGAReader.cs b/PCK-Studio/Internal/IO/TGA/TGAReader.cs index 4ed2442a..fae9d530 100644 --- a/PCK-Studio/Internal/IO/TGA/TGAReader.cs +++ b/PCK-Studio/Internal/IO/TGA/TGAReader.cs @@ -38,7 +38,7 @@ public TGAFileData FromFile(string filename) { if (File.Exists(filename)) { - using( var fs = File.OpenRead(filename) ) + using(FileStream fs = File.OpenRead(filename) ) { return FromStream(fs); } diff --git a/PCK-Studio/Internal/IO/TGA/TGASerializer.cs b/PCK-Studio/Internal/IO/TGA/TGASerializer.cs index f82d5119..a467174a 100644 --- a/PCK-Studio/Internal/IO/TGA/TGASerializer.cs +++ b/PCK-Studio/Internal/IO/TGA/TGASerializer.cs @@ -22,11 +22,11 @@ namespace PckStudio.Internal.IO.TGA { internal static class TGASerializer { - private static TGAWriter writer = new TGAWriter(); + private static TGAWriter _writer = new TGAWriter(); public static void SerializeToStream(Stream stream, Image image) { - writer.WriteToStream(stream, image); + _writer.WriteToStream(stream, image); } } } \ No newline at end of file diff --git a/PCK-Studio/Internal/IO/TGA/TGAWriter.cs b/PCK-Studio/Internal/IO/TGA/TGAWriter.cs index 97fa1727..ad749d00 100644 --- a/PCK-Studio/Internal/IO/TGA/TGAWriter.cs +++ b/PCK-Studio/Internal/IO/TGA/TGAWriter.cs @@ -134,7 +134,7 @@ public void WriteToStream(Stream stream, Image image) public void WriteToFile(string filename, Image image) { - using (var fs = File.OpenWrite(filename)) + using (FileStream fs = File.OpenWrite(filename)) { WriteToStream(fs, image); } diff --git a/PCK-Studio/Internal/Misc/FileCacher.cs b/PCK-Studio/Internal/Misc/FileCacher.cs index 2cafa897..3a810d10 100644 --- a/PCK-Studio/Internal/Misc/FileCacher.cs +++ b/PCK-Studio/Internal/Misc/FileCacher.cs @@ -58,10 +58,8 @@ public void Cache(byte[] data, string filename) string destinationFilepath = Path.Combine(_cacheDirectory, filename); if (!File.Exists(destinationFilepath)) { - using (FileStream fsDst = File.OpenWrite(destinationFilepath)) - { - fsDst.Write(data, 0, data.Length); - } + using FileStream fsDst = File.OpenWrite(destinationFilepath); + fsDst.Write(data, 0, data.Length); } } } diff --git a/PCK-Studio/Internal/Misc/OpenFolderDialog.cs b/PCK-Studio/Internal/Misc/OpenFolderDialog.cs index 97af8b90..02ac4eca 100644 --- a/PCK-Studio/Internal/Misc/OpenFolderDialog.cs +++ b/PCK-Studio/Internal/Misc/OpenFolderDialog.cs @@ -2,15 +2,15 @@ * Source by: Simon Mourier(https://stackoverflow.com/users/403671/simon-mourier) */ +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; +using System.Windows; // for WPF support +using System.Windows.Interop; // for WPF support + namespace PckStudio.Internal.Misc { - using System; - using System.Diagnostics; - using System.Runtime.InteropServices; - using System.Runtime.InteropServices.ComTypes; - using System.Windows; // for WPF support - using System.Windows.Interop; // for WPF support - public class OpenFolderDialog { public virtual string ResultPath { get; protected set; } @@ -43,13 +43,13 @@ protected virtual int SetOptions(int options) var dialog = (IFileOpenDialog)new FileOpenDialog(); if (!string.IsNullOrEmpty(InputPath)) { - if (CheckHr(SHCreateItemFromParsingName(InputPath, null, typeof(IShellItem).GUID, out var item), throwOnError) != 0) + if (CheckHr(SHCreateItemFromParsingName(InputPath, null, typeof(IShellItem).GUID, out IShellItem item), throwOnError) != 0) return null; dialog.SetFolder(item); } - var options = FOS.FOS_PICKFOLDERS; + FOS options = FOS.FOS_PICKFOLDERS; options = (FOS)SetOptions((int)options); dialog.SetOptions(options); @@ -84,7 +84,7 @@ protected virtual int SetOptions(int options) if (CheckHr(hr, throwOnError) != 0) return null; - if (CheckHr(dialog.GetResult(out var result), throwOnError) != 0) + if (CheckHr(dialog.GetResult(out IShellItem result), throwOnError) != 0) return null; if (CheckHr(result.GetDisplayName(SIGDN.SIGDN_DESKTOPABSOLUTEPARSING, out var path), throwOnError) != 0) diff --git a/PCK-Studio/Internal/ResourceLocation.cs b/PCK-Studio/Internal/ResourceLocation.cs index 59a726be..d1c677ed 100644 --- a/PCK-Studio/Internal/ResourceLocation.cs +++ b/PCK-Studio/Internal/ResourceLocation.cs @@ -1,9 +1,23 @@ -using System; +/* Copyright (c) 2024-present miku-666 + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1.The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. +**/ +using System; using System.Collections.Generic; using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace PckStudio.Internal { diff --git a/PCK-Studio/Internal/Serializer/AnimationSerializer.cs b/PCK-Studio/Internal/Serializer/AnimationSerializer.cs index fd3bcb9d..fa209fe3 100644 --- a/PCK-Studio/Internal/Serializer/AnimationSerializer.cs +++ b/PCK-Studio/Internal/Serializer/AnimationSerializer.cs @@ -1,12 +1,21 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; +/* Copyright (c) 2024-present miku-666 + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1.The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. +**/ using System.Drawing; -using System.Drawing.Imaging; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using OMI.Formats.Pck; using PckStudio.Extensions; using PckStudio.Interfaces; @@ -21,7 +30,7 @@ public void Serialize(Animation animation, ref PckAsset asset) { string anim = animation.BuildAnim(); asset.SetProperty("ANIM", anim); - var texture = animation.BuildTexture(); + Image texture = animation.BuildTexture(); asset.SetTexture(texture); } } diff --git a/PCK-Studio/Internal/Serializer/ImageSerializer.cs b/PCK-Studio/Internal/Serializer/ImageSerializer.cs index 8bd8241b..dfd4c3f1 100644 --- a/PCK-Studio/Internal/Serializer/ImageSerializer.cs +++ b/PCK-Studio/Internal/Serializer/ImageSerializer.cs @@ -1,12 +1,25 @@ -using System; -using System.Collections.Generic; +/* Copyright (c) 2024-present miku-666 + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1.The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. +**/ +using System; using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using OMI.Formats.Pck; using PckStudio.Interfaces; using PckStudio.Internal.IO.TGA; diff --git a/PCK-Studio/Internal/SkinAnimFlag.cs b/PCK-Studio/Internal/SkinAnimFlag.cs index 456c4c91..f4f8af0e 100644 --- a/PCK-Studio/Internal/SkinAnimFlag.cs +++ b/PCK-Studio/Internal/SkinAnimFlag.cs @@ -15,7 +15,6 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. **/ -using System; namespace PckStudio.Internal { diff --git a/PCK-Studio/Internal/SkinAnimMask.cs b/PCK-Studio/Internal/SkinAnimMask.cs index 05a3b097..fc7e7b47 100644 --- a/PCK-Studio/Internal/SkinAnimMask.cs +++ b/PCK-Studio/Internal/SkinAnimMask.cs @@ -1,9 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace PckStudio.Internal { [Flags] diff --git a/PCK-Studio/Internal/SkinBOX.cs b/PCK-Studio/Internal/SkinBOX.cs index 5f7c743f..c324b6ec 100644 --- a/PCK-Studio/Internal/SkinBOX.cs +++ b/PCK-Studio/Internal/SkinBOX.cs @@ -51,10 +51,10 @@ public static SkinBOX FromString(string value) { throw new ArgumentException("Arguments must have at least a length of 9"); } - var type = arguments[0]; - var pos = TryGetVector3(arguments, 1); - var size = TryGetVector3(arguments, 4); - var uv = TryGetVector2(arguments, 7); + string type = arguments[0]; + Vector3 pos = TryGetVector3(arguments, 1); + Vector3 size = TryGetVector3(arguments, 4); + Vector2 uv = TryGetVector2(arguments, 7); var skinBox = new SkinBOX(type, pos, size, uv); if (arguments.Length >= 10) skinBox.HideWithArmor = arguments[9] == "1"; @@ -86,9 +86,9 @@ private static Vector2 TryGetVector2(string[] arguments, int startIndex) private static Vector3 TryGetVector3(string[] arguments, int startIndex) { - var vec2 = TryGetVector2(arguments, startIndex); + Vector2 xy = TryGetVector2(arguments, startIndex); float.TryParse(arguments[startIndex + 2], out float z); - return new Vector3(vec2, z); + return new Vector3(xy, z); } public override int GetHashCode() diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 797749b7..48397756 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -403,7 +403,8 @@ private TreeNode BuildNodeTreeBySeperator(TreeNodeCollection root, string path, bool alreadyExists = root.ContainsKey(nodeText); TreeNode subNode = alreadyExists ? root[nodeText] : CreateNode(nodeText); - if (!alreadyExists) root.Add(subNode); + if (!alreadyExists) + root.Add(subNode); return BuildNodeTreeBySeperator(subNode.Nodes, subPath, seperator); } @@ -417,7 +418,7 @@ private void BuildPckTreeView(TreeNodeCollection root, PckFile pckFile) TreeNode node = BuildNodeTreeBySeperator(root, asset.Filename, '/'); node.Tag = asset; SetNodeIcon(node, asset.Type); - }; + } } private void BuildMainTreeView() @@ -484,7 +485,7 @@ private void HandleTextureFile(PckAsset asset) Animation animation = asset.GetDeserializedData(AnimationDeserializer.DefaultDeserializer); string internalName = Path.GetFileNameWithoutExtension(asset.Filename); - var textureInfos = resourceLocation.Category switch + IList textureInfos = resourceLocation.Category switch { ResourceCategory.BlockAnimation => Tiles.BlockTileInfos, ResourceCategory.ItemAnimation => Tiles.ItemTileInfos, @@ -516,8 +517,8 @@ private void HandleGameRuleFile(PckAsset asset) dialog.ButtonText = "Ok"; if (dialog.ShowDialog() != DialogResult.OK) return; - - var compressiontype = dialog.SelectedItem switch + + GameRuleFile.CompressionType compressiontype = dialog.SelectedItem switch { use_deflate => GameRuleFile.CompressionType.Deflate, use_xmem => GameRuleFile.CompressionType.XMem, @@ -722,7 +723,8 @@ private void extractFolderFile(string outPath, PckAsset asset) abbPath = abbPath.Substring(startIndex, abbPath.Length - startIndex); string finalPath = ($"{outPath}/{abbPath}/").Replace('\\', '/'); - if (!Directory.Exists(finalPath)) Directory.CreateDirectory(finalPath); + if (!Directory.Exists(finalPath)) + Directory.CreateDirectory(finalPath); extractFile(finalPath + "/" + Path.GetFileName(asset.Filename), asset); } @@ -746,13 +748,13 @@ private void extractFolder(string outPath) } else { - foreach (PckAsset _asset in currentPCK.GetAssets()) + foreach (PckAsset asset in currentPCK.GetAssets()) { - if (_asset.Filename.StartsWith(selectedFolder)) + if (asset.Filename.StartsWith(selectedFolder)) { - extractFolderFile(outPath, _asset); + extractFolderFile(outPath, asset); } - }; + } } } @@ -918,10 +920,11 @@ private void deleteFileToolStripMenuItem_Click(object sender, EventArgs e) private void renameFileToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode node = treeViewMain.SelectedNode; - if (node == null) return; + if (node == null) + return; string path = node.FullPath; - bool isFile = node.TryGetTagData(out var asset); + bool isFile = node.TryGetTagData(out PckAsset asset); using TextPrompt diag = new TextPrompt(isFile ? asset.Filename : Path.GetFileName(node.FullPath)); @@ -943,7 +946,8 @@ private void renameFileToolStripMenuItem_Click(object sender, EventArgs e) { if (childNode.Tag is PckAsset folderAsset) { - if (folderAsset.Filename == diag.NewText) continue; + if (folderAsset.Filename == diag.NewText) + continue; folderAsset.Filename = childNode.FullPath; } } @@ -974,7 +978,8 @@ private void createSkinToolStripMenuItem_Click(object sender, EventArgs e) //} //else { - if (treeViewMain.Nodes.ContainsKey("Skins")) add.SkinAsset.Filename = add.SkinAsset.Filename.Insert(0, "Skins/"); // Then Skins folder + if (treeViewMain.Nodes.ContainsKey("Skins")) + add.SkinAsset.Filename = add.SkinAsset.Filename.Insert(0, "Skins/"); // Then Skins folder currentPCK.AddAsset(add.SkinAsset); } if (add.HasCape) @@ -992,7 +997,8 @@ private void createSkinToolStripMenuItem_Click(object sender, EventArgs e) //} //else { - if (treeViewMain.Nodes.ContainsKey("Skins")) add.CapeAsset.Filename = add.CapeAsset.Filename.Insert(0, "Skins/"); // Then Skins folder + if (treeViewMain.Nodes.ContainsKey("Skins")) + add.CapeAsset.Filename = add.CapeAsset.Filename.Insert(0, "Skins/"); // Then Skins folder currentPCK.AddAsset(add.CapeAsset); } } @@ -1067,7 +1073,8 @@ private void createAnimatedTextureToolStripMenuItem_Click(object sender, EventAr bool IsSubPCKNode(string nodePath, string extention = ".pck") { // written by miku, implemented and modified by MattNL - if (nodePath.EndsWith(extention)) return false; + if (nodePath.EndsWith(extention)) + return false; string[] subpaths = nodePath.Split('/'); @@ -1116,11 +1123,13 @@ void RebuildSubPCK(string childPath) { // Support for if a file is edited within a nested PCK File (AKA SubPCK) - if (!IsSubPCKNode(childPath)) return; + if (!IsSubPCKNode(childPath)) + return; TreeNode parent = GetSubPCK(childPath); Debug.WriteLine(parent.Name); - if (parent == null) return; + if (parent == null) + return; PckAsset parentAsset = parent.Tag as PckAsset; PckFile parentAssetPck = @@ -1142,8 +1151,9 @@ void RebuildSubPCK(string childPath) { PckAsset newAsset = newPCKFile.CreateNewAsset(asset.Filename, asset.Type); // check for skins folder so files are placed consistently in final pck - if (asset.Filename.StartsWith("Skins/") && parentAsset.Type is PckAssetType.SkinDataFile) hasSkinsFolder = true; - foreach (var prop in asset.GetProperties()) + if (asset.Filename.StartsWith("Skins/") && parentAsset.Type is PckAssetType.SkinDataFile) + hasSkinsFolder = true; + foreach (KeyValuePair prop in asset.GetProperties()) newAsset.AddProperty(prop); newAsset.SetData(asset.Data); } @@ -1155,7 +1165,7 @@ void RebuildSubPCK(string childPath) PckAsset newAsset = newPCKFile.CreateNewAsset( (hasSkinsFolder ? "Skins/" : String.Empty) + nodeAsset.Filename.Replace(parentAsset.Filename + "/", String.Empty), nodeAsset.Type); - foreach (var prop in nodeAsset.GetProperties()) + foreach (KeyValuePair prop in nodeAsset.GetProperties()) newAsset.AddProperty(prop); newAsset.SetData(nodeAsset.Data); } @@ -1171,9 +1181,9 @@ void RebuildSubPCK(string childPath) MessageBox.Show(this, $"Files added successfully to {parentAsset.Filename}"); } - } + } - private void treeViewMain_DoubleClick(object sender, EventArgs e) + private void treeViewMain_DoubleClick(object sender, EventArgs e) { if (treeViewMain.SelectedNode.TryGetTagData(out PckAsset asset)) { @@ -1283,7 +1293,7 @@ private void cloneFileToolStripMenuItem_Click(object sender, EventArgs e) TreeNode newNode = new TreeNode(); newNode.Text = Path.GetFileName(diag.NewText); var newFile = new PckAsset(diag.NewText, asset.Type); - foreach (var property in asset.GetProperties()) + foreach (KeyValuePair property in asset.GetProperties()) { newFile.AddProperty(property); } @@ -1303,11 +1313,17 @@ private void cloneFileToolStripMenuItem_Click(object sender, EventArgs e) return; } - if (node.Parent == null) treeViewMain.Nodes.Insert(node.Index + 1, newNode); //adds generated file node - else node.Parent.Nodes.Insert(node.Index + 1, newNode);//adds generated file node to selected folder - - if (!IsSubPCKNode(node.FullPath)) currentPCK.InsertAsset(node.Index + 1, newFile); - else RebuildSubPCK(node.FullPath); + // adds generated file node + if (node.Parent == null) + treeViewMain.Nodes.Insert(node.Index + 1, newNode); + // adds generated file node to selected folder + else + node.Parent.Nodes.Insert(node.Index + 1, newNode); + + if (!IsSubPCKNode(node.FullPath)) + currentPCK.InsertAsset(node.Index + 1, newFile); + else + RebuildSubPCK(node.FullPath); BuildMainTreeView(); wasModified = true; } @@ -1332,7 +1348,7 @@ private void ReloadMetaTreeView() if (treeViewMain.SelectedNode is TreeNode node && node.Tag is PckAsset asset) { - foreach (var property in asset.GetProperties()) + foreach (KeyValuePair property in asset.GetProperties()) { treeMeta.Nodes.Add(CreateNode(property.Key, property)); } @@ -1468,7 +1484,7 @@ private void treeViewMain_DragDrop(object sender, DragEventArgs e) List pckFiles = GetEndingNodes(draggedNode.Nodes).Where(t => t.IsTagOfType()).Select(t => t.Tag as PckAsset).ToList(); string oldPath = draggedNode.FullPath; string newPath = Path.Combine(isTargetPckFile ? Path.GetDirectoryName(targetNode.FullPath) : targetNode.FullPath, draggedNode.Text).Replace('\\', '/'); - foreach (var pckFile in pckFiles) + foreach (PckAsset pckFile in pckFiles) { pckFile.Filename = Path.Combine(newPath, pckFile.Filename.Substring(oldPath.Length + 1)).Replace('\\', '/'); } @@ -1506,11 +1522,11 @@ private void ImportFiles(string[] files) MessageBox.Show(this, $"'{addFile.Filepath}' of type {addFile.Filetype} already exists.", "Import failed", MessageBoxButtons.OK, MessageBoxIcon.Warning); continue; } - var importedFile = currentPCK.CreateNewAsset(addFile.Filepath, addFile.Filetype, () => File.ReadAllBytes(filepath)); + PckAsset importedAsset = currentPCK.CreateNewAsset(addFile.Filepath, addFile.Filetype, () => File.ReadAllBytes(filepath)); string propertyFile = filepath + ".txt"; if (File.Exists(propertyFile)) { - importedFile.DeserializePropertiesFromString(File.ReadAllText(propertyFile)); + importedAsset.DeserializePropertiesFromString(File.ReadAllText(propertyFile)); } addedCount++; @@ -1845,15 +1861,16 @@ private void folderToolStripMenuItem_Click(object sender, EventArgs e) if (treeViewMain.SelectedNode is TreeNode node) { if (node.Tag is PckAsset asset && - (asset.Type != PckAssetType.TexturePackInfoFile && - asset.Type != PckAssetType.SkinDataFile)) + asset.Type != PckAssetType.TexturePackInfoFile && + asset.Type != PckAssetType.SkinDataFile) { if (node.Parent is TreeNode parentNode) { nodeCollection = parentNode.Nodes; } } - else nodeCollection = node.Nodes; + else + nodeCollection = node.Nodes; } nodeCollection.Add(folerNode); } @@ -1954,10 +1971,10 @@ private void OpenPck_DragEnter(object sender, DragEventArgs e) private void OpenPck_DragDrop(object sender, DragEventArgs e) { - string[] Filepaths = (string[])e.Data.GetData(DataFormats.FileDrop, false); - if (Filepaths.Length > 1) + string[] filepaths = (string[])e.Data.GetData(DataFormats.FileDrop, false); + if (filepaths.Length > 1) MessageBox.Show(this, "Only one pck file at a time is currently supported"); - LoadPckFromFile(Filepaths[0]); + LoadPckFromFile(filepaths[0]); } private void OpenPck_DragLeave(object sender, EventArgs e) From 4c2d68e5e903b03613942bfd3ae131c27029dee8 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Tue, 16 Jul 2024 20:15:49 +0200 Subject: [PATCH 14/14] TextPrompt - Auto focus textbox when opening prompt --- PCK-Studio/Forms/Additional-Popups/TextPrompt.resx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PCK-Studio/Forms/Additional-Popups/TextPrompt.resx b/PCK-Studio/Forms/Additional-Popups/TextPrompt.resx index 33d4d182..02ee0f57 100644 --- a/PCK-Studio/Forms/Additional-Popups/TextPrompt.resx +++ b/PCK-Studio/Forms/Additional-Popups/TextPrompt.resx @@ -214,7 +214,7 @@ 165, 23 - 5 + 1 InputTextBox