From 28ee5a59d7b663fc2339f43514fcf6554822bc02 Mon Sep 17 00:00:00 2001 From: MattNL Date: Sun, 31 Jul 2022 16:13:39 -0400 Subject: [PATCH] Some Music Editor changes -Fixed a bug where the newly added "Play overworld songs in creative" feature where the songs were being added while in the editor instead of upon closing it. -The categories now properly sort in the PCK file --- .../Utilities/Audio/AudioEditor.Designer.cs | 1 + .../Forms/Utilities/Audio/AudioEditor.cs | 55 +++++++++++++------ .../Forms/Utilities/Audio/AudioEditor.resx | 8 +-- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.Designer.cs b/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.Designer.cs index cd9e269f..629f1b14 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.Designer.cs +++ b/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.Designer.cs @@ -208,6 +208,7 @@ namespace PckStudio.Forms.Utilities this.Name = "AudioEditor"; this.Style = MetroFramework.MetroColorStyle.Silver; this.Theme = MetroFramework.MetroThemeStyle.Dark; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.AudioEditor_FormClosing); this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.AudioEditor_FormClosed); this.Load += new System.EventHandler(this.AudioEditor_Load); this.contextMenuStrip1.ResumeLayout(false); diff --git a/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs b/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs index ad4aea6d..4e84893d 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs +++ b/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs @@ -29,7 +29,6 @@ namespace PckStudio.Forms.Utilities PCKFile.FileData audioPCKFile; bool _isLittleEndian; public List cats = new List(); - public class NodeSorter : System.Collections.IComparer { public int Compare(object x, object y) @@ -444,23 +443,13 @@ namespace PckStudio.Forms.Utilities bool emptyCat = false; - PCKFile.FileData overworldMF = new PCKFile.FileData("", -1); - foreach (PCKFile.FileData mf in audioPCK.Files) + List new_order = audioPCK.Files.OrderBy(fd => fd.type).ToList(); + + audioPCK.Files.Clear(); + + foreach (PCKFile.FileData mf in new_order) { - mf.filepath = ""; - if (metroCheckBox1.Checked && mf.type == 0) overworldMF = mf; - if (metroCheckBox1.Checked && mf.type == 3 && overworldMF.type != -1) - { - foreach (ValueTuple property in overworldMF.properties) - { - if (property.Item1 == "CUENAME" && !mf.properties.Contains(property)) - { - mf.properties.Add(property); - Console.WriteLine(property.Item2); - } - } - mf.filepath = "include_overworld"; - } + audioPCK.Files.Add(mf); if (mf.properties.Count == 0) emptyCat = true; } @@ -515,5 +504,35 @@ namespace PckStudio.Forms.Utilities prompt.ShowDialog(); credits = prompt.Credits; } - } + + private void AudioEditor_FormClosing(object sender, FormClosingEventArgs e) + { + if (saved != true) return; + PCKFile.FileData overworldMF = new PCKFile.FileData("", -1); + + foreach (PCKFile.FileData mf in audioPCK.Files) + { + mf.filepath = ""; + if (metroCheckBox1.Checked && mf.type == 0) overworldMF = mf; + if (metroCheckBox1.Checked && mf.type == 3 && overworldMF.type != -1) + { + foreach (ValueTuple property in overworldMF.properties) + { + if (property.Item1 == "CUENAME" && !mf.properties.Contains(property)) + { + mf.properties.Add(property); + Console.WriteLine(property.Item2); + } + } + mf.filepath = "include_overworld"; + } + } + + using (var stream = new MemoryStream()) + { + PCKFileWriter.Write(stream, audioPCK, _isLittleEndian); + audioPCKFile.SetData(stream.ToArray()); + } + } + } } diff --git a/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.resx b/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.resx index 41bdeb22..794eca70 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.resx +++ b/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.resx @@ -146,7 +146,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADk - MAAAAk1TRnQBSQFMAgEBCQEAASgBAAEoAQABEAEAARABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAFA + MAAAAk1TRnQBSQFMAgEBCQEAATABAAEwAQABEAEAARABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAFA AwABMAMAAQEBAAEgBgABMBIAAzgB/wM1Af8DNQH/AzMB/wMwAf8DLwH/Ay0B/wMtAf8DJAH/AzsB/wM4 Af8DNQH/Ay0B/wMnAf8DNgH/AzIB/8AAAzgB/wN/Af8DeQH/A3kB/wN5Af8DcQH/A3EB/wN5Af8DeQH/ A3EB/wNxAf8DcQH/A3kB/wN5Af8DfwH/AzIB/8AAAzIB/wN2Af8DsAH/A7AB/wOvAf8DrwH/A68B/wOo @@ -543,13 +543,13 @@ 232, 64 - 193, 15 + 194, 15 14 - Add overworld songs to creative + Play overworld songs in Creative metroCheckBox1 @@ -561,7 +561,7 @@ $this - 0 + 2 True