From 5b6703f337b7965552712a0f1c7bd6185ebcf446 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:28:43 +0200 Subject: [PATCH 1/4] MainForm - Fix issue where new packs would overwrite last open pck file --- PCK-Studio/MainForm.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index e4e1b464..35eefda8 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -1461,8 +1461,7 @@ namespace PckStudio if (namePrompt.ShowDialog(this) == DialogResult.OK) { currentPCK = InitializePack(new Random().Next(8000, int.MaxValue), 0, namePrompt.NewText, true); - isTemplateFile = true; - wasModified = true; + MarkTemplateFile(); LoadEditorTab(); } } @@ -1474,8 +1473,7 @@ namespace PckStudio if (packPrompt.ShowDialog(this) == DialogResult.OK) { currentPCK = InitializeTexturePack(new Random().Next(8000, int.MaxValue), 0, packPrompt.PackName, packPrompt.PackRes, packPrompt.CreateSkinsPck); - isTemplateFile = true; - wasModified = true; + MarkTemplateFile(); LoadEditorTab(); } } @@ -1487,12 +1485,18 @@ namespace PckStudio if (packPrompt.ShowDialog(this) == DialogResult.OK) { currentPCK = InitializeMashUpPack(new Random().Next(8000, int.MaxValue), 0, packPrompt.PackName, packPrompt.PackRes); - isTemplateFile = true; - wasModified = false; + MarkTemplateFile(); LoadEditorTab(); } } + private void MarkTemplateFile() + { + isTemplateFile = true; + wasModified = true; + saveLocation = string.Empty; + } + private void quickChangeToolStripMenuItem_Click(object sender, EventArgs e) { using AdvancedOptions advanced = new AdvancedOptions(currentPCK); @@ -1839,6 +1843,8 @@ namespace PckStudio { if (!string.IsNullOrEmpty(saveLocation)) Save(saveLocation); + if (string.IsNullOrWhiteSpace(saveLocation) || isTemplateFile) + SaveTemplate(); } private void saveAsPCK(object sender, EventArgs e) From 32456093e4d0da1ea6f0676bb3fa451c1a2a79f7 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Fri, 16 Aug 2024 19:49:32 +0200 Subject: [PATCH 2/4] MainForm - Add support droping folder in --- PCK-Studio/MainForm.cs | 98 +++++++++++++++++++++++++++++++++--------- 1 file changed, 77 insertions(+), 21 deletions(-) diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 35eefda8..887ceae4 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -1254,17 +1254,6 @@ namespace PckStudio private void treeViewMain_DragDrop(object sender, DragEventArgs e) { - if (e.Data.GetDataPresent(DataFormats.FileDrop) && e.Data.GetData(DataFormats.FileDrop) is string[] files) - { - ImportFiles(files); - return; - } - - string dataFormat = typeof(TreeNode).FullName; - - if (!e.Data.GetDataPresent(dataFormat)) - return; - // Retrieve the client coordinates of the drop location. Point dragLocation = new Point(e.X, e.Y); Point targetPoint = treeViewMain.PointToClient(dragLocation); @@ -1274,9 +1263,30 @@ namespace PckStudio // Retrieve the node at the drop location. TreeNode targetNode = treeViewMain.GetNodeAt(targetPoint); + + if (e.Data.GetDataPresent(DataFormats.FileDrop) && e.Data.GetData(DataFormats.FileDrop) is string[] filesDropped) + { + IEnumerable files = filesDropped.Where(File.Exists); + IEnumerable directoryFiles = filesDropped + .Where(f => (File.GetAttributes(f) & FileAttributes.Directory) != 0) + .SelectMany(dir => Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories)); + + string baseDirectory = Path.GetDirectoryName(filesDropped.First()); + + IEnumerable importPaths = files.Concat(directoryFiles); + + ImportFiles(baseDirectory, importPaths, string.IsNullOrWhiteSpace(targetNode?.FullPath) ? string.Empty : targetNode?.FullPath); + return; + } + + string dataFormat = typeof(TreeNode).FullName; + if (targetNode is null) return; + if (!e.Data.GetDataPresent(dataFormat)) + return; + bool isTargetPckFile = targetNode.IsTagOfType(); TreeNode draggedNode = e.Data.GetData(dataFormat) as TreeNode; if (draggedNode == null) @@ -1356,33 +1366,79 @@ namespace PckStudio return childNodes; } - - private void ImportFiles(string[] files) + private void ImportFiles(string baseDirectory, IEnumerable files, string prefix) { + int fileCount = files.Count(); int addedCount = 0; + int skippedFiles = 0; + int skipAttempts = 3; + int typeDuplication = 0; + PckAssetType lastSelectedAssetType = PckAssetType.SkinFile; + bool askForAssetType = true; foreach (var filepath in files) { - using AddFilePrompt addFile = new AddFilePrompt(Path.GetFileName(filepath)); + string assetPath = Path.Combine(prefix + filepath.Substring(baseDirectory.Length)).TrimStart('/', '\\'); + PckAssetType assetType = lastSelectedAssetType; + + if (askForAssetType) + { + using AddFilePrompt addFile = new AddFilePrompt(assetPath); if (addFile.ShowDialog(this) != DialogResult.OK) + { + skippedFiles++; + skipAttempts--; + if (skipAttempts > 0) continue; - if (currentPCK.Contains(addFile.Filepath, addFile.Filetype)) + int remainingFileCount = fileCount - addedCount - skippedFiles; + DialogResult abortFurtherImport = MessageBox.Show($"Do you wan't to abort further file imports?\n{remainingFileCount} file(s) left.", "Abort further import", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); + if (abortFurtherImport == DialogResult.Yes) + { + skippedFiles += remainingFileCount; + break; + } + skipAttempts = 3; + continue; + } + + assetType = addFile.Filetype; + assetPath = addFile.Filepath; + + if (lastSelectedAssetType == assetType) + typeDuplication++; + lastSelectedAssetType = addFile.Filetype; + if (typeDuplication > 1) + { + DialogResult useSameTypeForRest = MessageBox.Show($"Do you want to import all remaining files as {lastSelectedAssetType}?", "Import all as", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); + if (useSameTypeForRest == DialogResult.Yes) { - MessageBox.Show(this, $"'{addFile.Filepath}' of type {addFile.Filetype} already exists.\nSkiping file.", "File already exists", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); + askForAssetType = false; + } + } + } + + if (currentPCK.Contains(filepath, assetType)) + { + if (askForAssetType) + MessageBox.Show(this, $"'{assetPath}' of type {assetType} already exists.\nSkiping file.", "File already exists", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); + Debug.WriteLine($"'{assetPath}' of type {assetType} already exists.\nSkiping file."); continue; } - PckAsset importedAsset = currentPCK.CreateNewAsset(addFile.Filepath, addFile.Filetype, () => File.ReadAllBytes(filepath)); + PckAsset importedAsset = currentPCK.CreateNewAsset(assetPath, assetType, () => File.ReadAllBytes(filepath)); string propertyFile = filepath + ".txt"; if (File.Exists(propertyFile)) { importedAsset.DeserializeProperties(File.ReadAllLines(propertyFile)); } addedCount++; - - BuildMainTreeView(); - wasModified = true; } - Trace.TraceInformation("[{0}] Imported {1} file(s).", nameof(ImportFiles), addedCount); + Trace.TraceInformation("[{0}] Imported {1} file(s).", nameof(ImportFiles), addedCount); + Trace.TraceInformation("[{0}] Skipped {1} file(s).", nameof(ImportFiles), skippedFiles); + if (addedCount > 0) + { + wasModified = true; + BuildMainTreeView(); + } } #endregion From 99d6fc4ffaf77ec59a9f8b17bcf2b43570f509b2 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Fri, 16 Aug 2024 20:27:29 +0200 Subject: [PATCH 3/4] MainForm - Focus app when draging files over it --- PCK-Studio/MainForm.cs | 48 +++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 887ceae4..66dd61ec 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -1236,26 +1236,30 @@ namespace PckStudio if ((node.TryGetTagData(out PckAsset asset) && currentPCK.Contains(asset.Filename, asset.Type)) || node.Parent is TreeNode) { - treeViewMain.DoDragDrop(node, DragDropEffects.Move); - } - } + // TODO: add (mouse) scrolling while dragging item(s) + treeViewMain.DoDragDrop(node, DragDropEffects.Scroll | DragDropEffects.Move); + } + } - private void treeViewMain_DragOver(object sender, DragEventArgs e) + private void treeViewMain_DragOver(object sender, DragEventArgs e) { Point dragLocation = new Point(e.X, e.Y); TreeNode node = treeViewMain.GetNodeAt(treeViewMain.PointToClient(dragLocation)); treeViewMain.SelectedNode = node.IsTagOfType() ? null : node; - } + } private void treeViewMain_DragEnter(object sender, DragEventArgs e) { e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : e.AllowedEffect; - } + BringToFront(); + FocusMe(); + treeViewMain.Focus(); + } private void treeViewMain_DragDrop(object sender, DragEventArgs e) { - // Retrieve the client coordinates of the drop location. - Point dragLocation = new Point(e.X, e.Y); + // Retrieve the client coordinates of the drop location. + Point dragLocation = new Point(e.X, e.Y); Point targetPoint = treeViewMain.PointToClient(dragLocation); if (!treeViewMain.ClientRectangle.Contains(targetPoint)) @@ -1383,12 +1387,12 @@ namespace PckStudio if (askForAssetType) { using AddFilePrompt addFile = new AddFilePrompt(assetPath); - if (addFile.ShowDialog(this) != DialogResult.OK) + if (addFile.ShowDialog(this) != DialogResult.OK) { skippedFiles++; skipAttempts--; if (skipAttempts > 0) - continue; + continue; int remainingFileCount = fileCount - addedCount - skippedFiles; DialogResult abortFurtherImport = MessageBox.Show($"Do you wan't to abort further file imports?\n{remainingFileCount} file(s) left.", "Abort further import", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); @@ -1411,7 +1415,7 @@ namespace PckStudio { DialogResult useSameTypeForRest = MessageBox.Show($"Do you want to import all remaining files as {lastSelectedAssetType}?", "Import all as", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (useSameTypeForRest == DialogResult.Yes) - { + { askForAssetType = false; } } @@ -1437,8 +1441,8 @@ namespace PckStudio if (addedCount > 0) { wasModified = true; - BuildMainTreeView(); - } + BuildMainTreeView(); + } } #endregion @@ -1518,7 +1522,7 @@ namespace PckStudio { currentPCK = InitializePack(new Random().Next(8000, int.MaxValue), 0, namePrompt.NewText, true); MarkTemplateFile(); - LoadEditorTab(); + LoadEditorTab(); } } @@ -1527,14 +1531,14 @@ namespace PckStudio CheckSaveState(); CreateTexturePackPrompt packPrompt = new CreateTexturePackPrompt(); if (packPrompt.ShowDialog(this) == DialogResult.OK) - { - currentPCK = InitializeTexturePack(new Random().Next(8000, int.MaxValue), 0, packPrompt.PackName, packPrompt.PackRes, packPrompt.CreateSkinsPck); + { + currentPCK = InitializeTexturePack(new Random().Next(8000, int.MaxValue), 0, packPrompt.PackName, packPrompt.PackRes, packPrompt.CreateSkinsPck); MarkTemplateFile(); - LoadEditorTab(); - } - } + LoadEditorTab(); + } + } - private void mashUpPackToolStripMenuItem_Click(object sender, EventArgs e) + private void mashUpPackToolStripMenuItem_Click(object sender, EventArgs e) { CheckSaveState(); CreateTexturePackPrompt packPrompt = new CreateTexturePackPrompt(); @@ -1542,7 +1546,7 @@ namespace PckStudio { currentPCK = InitializeMashUpPack(new Random().Next(8000, int.MaxValue), 0, packPrompt.PackName, packPrompt.PackRes); MarkTemplateFile(); - LoadEditorTab(); + LoadEditorTab(); } } @@ -1551,7 +1555,7 @@ namespace PckStudio isTemplateFile = true; wasModified = true; saveLocation = string.Empty; - } + } private void quickChangeToolStripMenuItem_Click(object sender, EventArgs e) { From 8f4109b10f6178297ece685f9c0e9453d860b70d Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Fri, 16 Aug 2024 20:31:20 +0200 Subject: [PATCH 4/4] SkinANIM - Remove 'SetMask' function to avoid confusion --- PCK-Studio/Forms/Editor/ANIMEditor.cs | 2 +- PCK-Studio/Internal/SkinANIM.cs | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/PCK-Studio/Forms/Editor/ANIMEditor.cs b/PCK-Studio/Forms/Editor/ANIMEditor.cs index cca46111..c379d7d2 100644 --- a/PCK-Studio/Forms/Editor/ANIMEditor.cs +++ b/PCK-Studio/Forms/Editor/ANIMEditor.cs @@ -362,7 +362,7 @@ namespace PckStudio.Forms.Editor if (diag.ShowDialog(this) != DialogResult.OK) return; - SkinANIM templateANIM = SkinANIM.Empty.SetMask(Templates[diag.SelectedItem]); + SkinANIM templateANIM = Templates[diag.SelectedItem]; DialogResult prompt = MessageBox.Show(this, "Would you like to add this preset's effects to your current ANIM? Otherwise all of your effects will be cleared. Either choice can be undone by pressing \"Restore ANIM\".", "", MessageBoxButtons.YesNo); if (prompt == DialogResult.Yes) templateANIM |= ruleset.Value; diff --git a/PCK-Studio/Internal/SkinANIM.cs b/PCK-Studio/Internal/SkinANIM.cs index 8c5c022a..ef3136cd 100644 --- a/PCK-Studio/Internal/SkinANIM.cs +++ b/PCK-Studio/Internal/SkinANIM.cs @@ -106,10 +106,5 @@ namespace PckStudio.Internal { return MemberwiseClone(); } - - internal SkinANIM SetMask(SkinAnimMask skinAnimMask) - { - return new SkinANIM(skinAnimMask); - } } }