From 91623032250f4428b4ed4fca4d7238a75e72ebe8 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Thu, 15 Aug 2024 16:31:00 +0200 Subject: [PATCH] MainForm - Small refactoring of functions --- PCK-Studio/MainForm.cs | 60 +++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index f139dc3d..9c64a624 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -263,16 +263,14 @@ namespace PckStudio private void openToolStripMenuItem_Click(object sender, EventArgs e) { - using (var ofd = new OpenFileDialog()) - { - ofd.CheckFileExists = true; - ofd.Filter = "PCK (Minecraft Console Package)|*.pck"; - if (ofd.ShowDialog(this) == DialogResult.OK) - { - LoadPckFromFile(ofd.FileName); - } - } - } + using var ofd = new OpenFileDialog(); + ofd.CheckFileExists = true; + ofd.Filter = "PCK (Minecraft Console Package)|*.pck"; + if (ofd.ShowDialog(this) == DialogResult.OK) + { + LoadPckFromFile(ofd.FileName); + } + } private PckFile OpenPck(string filePath) { @@ -1047,7 +1045,7 @@ namespace PckStudio BuildMainTreeView(); ReloadMetaTreeView(); } - } + } private void treeViewMain_DoubleClick(object sender, EventArgs e) { @@ -1351,12 +1349,12 @@ namespace PckStudio { List childNodes = new List(root.Count); foreach (TreeNode childNode in root) - { + { childNodes.Add(childNode); childNodes.AddRange(GetAllChildNodes(childNode.Nodes)); - } + } return childNodes; - } + } private void ImportFiles(string[] files) @@ -1570,7 +1568,7 @@ namespace PckStudio if (e.KeyData == Keys.Delete) deleteEntryToolStripMenuItem_Click(sender, e); } - + private bool TryGetLocFile(out LOCFile locFile) { if (!currentPCK.TryGetAsset("localisation.loc", PckAssetType.LocalisationFile, out PckAsset locAsset) && @@ -1681,12 +1679,12 @@ namespace PckStudio { string[] txtProperties = File.ReadAllLines(propertyFile); importSkinAsset.DeserializeProperties(txtProperties); - - // Because extracting/exporting an assest doesn't export + + // Because extracting/exporting an assest doesn't export // the actual loc value we just get an undefined loc key. // That's why why remove them after deserializing. - // - Miku - importSkinAsset.RemoveProperty("DISPLAYNAMEID"); + // - Miku + importSkinAsset.RemoveProperty("DISPLAYNAMEID"); importSkinAsset.RemoveProperty("THEMENAMEID"); BuildMainTreeView(); wasModified = true; @@ -1814,13 +1812,9 @@ namespace PckStudio { pckOpen.Image = Resources.pckDrop; string[] files = (string[])e.Data.GetData(DataFormats.FileDrop) ?? Array.Empty(); - foreach (string file in files) - { - string ext = Path.GetExtension(file); - if (ext.Equals(".pck", StringComparison.CurrentCultureIgnoreCase)) - e.Effect = DragDropEffects.Copy; - return; - } + e.Effect = files.Any(file => Path.GetExtension(file).Equals(".pck", StringComparison.CurrentCultureIgnoreCase)) + ? DragDropEffects.Copy + : DragDropEffects.None; } private void OpenPck_DragDrop(object sender, DragEventArgs e) @@ -2058,14 +2052,14 @@ namespace PckStudio if (treeViewMain.SelectedNode.TryGetTagData(out PckAsset asset)) { using var input = new MultiTextPrompt(); - if (input.ShowDialog(this) == DialogResult.OK) - { + if (input.ShowDialog(this) == DialogResult.OK) + { asset.DeserializeProperties(input.TextOutput); - ReloadMetaTreeView(); - wasModified = true; - } - } - } + ReloadMetaTreeView(); + wasModified = true; + } + } + } private void correctSkinDecimalsToolStripMenuItem_Click(object sender, EventArgs e) {