diff --git a/SpineViewer/Controls/SkelFileListBox.Designer.cs b/SpineViewer/Controls/SkelFileListBox.Designer.cs new file mode 100644 index 0000000..386dc73 --- /dev/null +++ b/SpineViewer/Controls/SkelFileListBox.Designer.cs @@ -0,0 +1,197 @@ +namespace SpineViewer.Controls +{ + partial class SkelFileListBox + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region 组件设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要修改 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + tableLayoutPanel1 = new TableLayoutPanel(); + flowLayoutPanel1 = new FlowLayoutPanel(); + button_AddFolder = new Button(); + button_AddFile = new Button(); + label_Tip = new Label(); + listBox = new ListBox(); + contextMenuStrip = new ContextMenuStrip(components); + toolStripMenuItem_SelectAll = new ToolStripMenuItem(); + toolStripMenuItem_Paste = new ToolStripMenuItem(); + toolStripMenuItem_Remove = new ToolStripMenuItem(); + folderBrowserDialog = new FolderBrowserDialog(); + openFileDialog_Skel = new OpenFileDialog(); + tableLayoutPanel1.SuspendLayout(); + flowLayoutPanel1.SuspendLayout(); + contextMenuStrip.SuspendLayout(); + SuspendLayout(); + // + // tableLayoutPanel1 + // + tableLayoutPanel1.ColumnCount = 1; + tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); + tableLayoutPanel1.Controls.Add(flowLayoutPanel1, 0, 0); + tableLayoutPanel1.Controls.Add(listBox, 0, 1); + tableLayoutPanel1.Dock = DockStyle.Fill; + tableLayoutPanel1.Location = new Point(0, 0); + tableLayoutPanel1.Name = "tableLayoutPanel1"; + tableLayoutPanel1.RowCount = 2; + tableLayoutPanel1.RowStyles.Add(new RowStyle()); + tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); + tableLayoutPanel1.Size = new Size(801, 394); + tableLayoutPanel1.TabIndex = 0; + // + // flowLayoutPanel1 + // + flowLayoutPanel1.AutoSize = true; + flowLayoutPanel1.AutoSizeMode = AutoSizeMode.GrowAndShrink; + flowLayoutPanel1.Controls.Add(button_AddFolder); + flowLayoutPanel1.Controls.Add(button_AddFile); + flowLayoutPanel1.Controls.Add(label_Tip); + flowLayoutPanel1.Dock = DockStyle.Fill; + flowLayoutPanel1.Location = new Point(3, 3); + flowLayoutPanel1.Name = "flowLayoutPanel1"; + flowLayoutPanel1.Size = new Size(795, 40); + flowLayoutPanel1.TabIndex = 1; + // + // button_AddFolder + // + button_AddFolder.AutoSize = true; + button_AddFolder.AutoSizeMode = AutoSizeMode.GrowAndShrink; + button_AddFolder.Location = new Point(3, 3); + button_AddFolder.Name = "button_AddFolder"; + button_AddFolder.Size = new Size(122, 34); + button_AddFolder.TabIndex = 0; + button_AddFolder.Text = "添加文件夹..."; + button_AddFolder.UseVisualStyleBackColor = true; + button_AddFolder.Click += button_AddFolder_Click; + // + // button_AddFile + // + button_AddFile.AutoSize = true; + button_AddFile.AutoSizeMode = AutoSizeMode.GrowAndShrink; + button_AddFile.Location = new Point(131, 3); + button_AddFile.Name = "button_AddFile"; + button_AddFile.Size = new Size(104, 34); + button_AddFile.TabIndex = 1; + button_AddFile.Text = "添加文件..."; + button_AddFile.UseVisualStyleBackColor = true; + button_AddFile.Click += button_AddFile_Click; + // + // label_Tip + // + label_Tip.Anchor = AnchorStyles.Left; + label_Tip.AutoSize = true; + label_Tip.Location = new Point(241, 8); + label_Tip.Name = "label_Tip"; + label_Tip.Size = new Size(139, 24); + label_Tip.TabIndex = 3; + label_Tip.Text = "已添加 0 个文件"; + label_Tip.TextAlign = ContentAlignment.MiddleCenter; + // + // listBox + // + listBox.AllowDrop = true; + listBox.ContextMenuStrip = contextMenuStrip; + listBox.Dock = DockStyle.Fill; + listBox.FormattingEnabled = true; + listBox.HorizontalScrollbar = true; + listBox.ItemHeight = 24; + listBox.Location = new Point(3, 49); + listBox.Name = "listBox"; + listBox.SelectionMode = SelectionMode.MultiExtended; + listBox.Size = new Size(795, 342); + listBox.TabIndex = 0; + listBox.DragDrop += listBox_DragDrop; + listBox.DragEnter += listBox_DragEnter; + // + // contextMenuStrip + // + contextMenuStrip.ImageScalingSize = new Size(24, 24); + contextMenuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem_SelectAll, toolStripMenuItem_Paste, toolStripMenuItem_Remove }); + contextMenuStrip.Name = "contextMenuStrip"; + contextMenuStrip.Size = new Size(184, 94); + // + // toolStripMenuItem_SelectAll + // + toolStripMenuItem_SelectAll.Name = "toolStripMenuItem_SelectAll"; + toolStripMenuItem_SelectAll.ShortcutKeys = Keys.Control | Keys.A; + toolStripMenuItem_SelectAll.Size = new Size(183, 30); + toolStripMenuItem_SelectAll.Text = "全选"; + toolStripMenuItem_SelectAll.Click += toolStripMenuItem_SelectAll_Click; + // + // toolStripMenuItem_Paste + // + toolStripMenuItem_Paste.Name = "toolStripMenuItem_Paste"; + toolStripMenuItem_Paste.ShortcutKeys = Keys.Control | Keys.V; + toolStripMenuItem_Paste.Size = new Size(183, 30); + toolStripMenuItem_Paste.Text = "粘贴"; + toolStripMenuItem_Paste.Click += toolStripMenuItem_Paste_Click; + // + // toolStripMenuItem_Remove + // + toolStripMenuItem_Remove.Name = "toolStripMenuItem_Remove"; + toolStripMenuItem_Remove.ShortcutKeys = Keys.Delete; + toolStripMenuItem_Remove.Size = new Size(183, 30); + toolStripMenuItem_Remove.Text = "移除"; + toolStripMenuItem_Remove.Click += toolStripMenuItem_Remove_Click; + // + // openFileDialog_Skel + // + openFileDialog_Skel.AddExtension = false; + openFileDialog_Skel.AddToRecent = false; + openFileDialog_Skel.Filter = "skel 文件 (*.skel; *.json)|*.skel;*.json|二进制文件 (*.skel)|*.skel|文本文件 (*.json)|*.json|所有文件 (*.*)|*.*"; + openFileDialog_Skel.Multiselect = true; + openFileDialog_Skel.Title = "批量选择skel文件"; + // + // SkelFileListBox + // + AutoScaleDimensions = new SizeF(11F, 24F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(tableLayoutPanel1); + Name = "SkelFileListBox"; + Size = new Size(801, 394); + tableLayoutPanel1.ResumeLayout(false); + tableLayoutPanel1.PerformLayout(); + flowLayoutPanel1.ResumeLayout(false); + flowLayoutPanel1.PerformLayout(); + contextMenuStrip.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private TableLayoutPanel tableLayoutPanel1; + private ListBox listBox; + private FlowLayoutPanel flowLayoutPanel1; + private Button button_AddFolder; + private Button button_AddFile; + private FolderBrowserDialog folderBrowserDialog; + private Label label_Tip; + private ContextMenuStrip contextMenuStrip; + private OpenFileDialog openFileDialog_Skel; + private ToolStripMenuItem toolStripMenuItem_SelectAll; + private ToolStripMenuItem toolStripMenuItem_Paste; + private ToolStripMenuItem toolStripMenuItem_Remove; + } +} diff --git a/SpineViewer/Controls/SkelFileListBox.cs b/SpineViewer/Controls/SkelFileListBox.cs new file mode 100644 index 0000000..a94fafb --- /dev/null +++ b/SpineViewer/Controls/SkelFileListBox.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.IO; + +namespace SpineViewer.Controls +{ + public partial class SkelFileListBox : UserControl + { + public SkelFileListBox() + { + InitializeComponent(); + Items = listBox.Items; + } + + /// + /// ListBox.Items + /// + public readonly ListBox.ObjectCollection Items; + + /// + /// 从路径列表添加 + /// + private void AddFromFileDrop(string[] paths) + { + foreach (var path in paths) + { + if (File.Exists(path)) + { + if (Spine.Spine.CommonSkelSuffix.Contains(Path.GetExtension(path).ToLower())) + listBox.Items.Add(Path.GetFullPath(path)); + } + else if (Directory.Exists(path)) + { + foreach (var file in Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories)) + { + if (Spine.Spine.CommonSkelSuffix.Contains(Path.GetExtension(file).ToLower())) + listBox.Items.Add(file); + } + } + } + } + + private void button_AddFolder_Click(object sender, EventArgs e) + { + if (folderBrowserDialog.ShowDialog() != DialogResult.OK) + return; + + var path = folderBrowserDialog.SelectedPath; + if (Directory.Exists(path)) + { + foreach (var file in Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories)) + { + if (Spine.Spine.CommonSkelSuffix.Contains(Path.GetExtension(file).ToLower())) + listBox.Items.Add(file); + } + } + + label_Tip.Text = $"已选择 {listBox.Items.Count} 个文件"; + } + + private void button_AddFile_Click(object sender, EventArgs e) + { + if (openFileDialog_Skel.ShowDialog() != DialogResult.OK) + return; + + foreach (var p in openFileDialog_Skel.FileNames) + listBox.Items.Add(Path.GetFullPath(p)); + + label_Tip.Text = $"已选择 {listBox.Items.Count} 个文件"; + } + + private void listBox_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop)) + e.Effect = DragDropEffects.Copy; + else + e.Effect = DragDropEffects.None; + } + + private void listBox_DragDrop(object sender, DragEventArgs e) + { + if (!e.Data.GetDataPresent(DataFormats.FileDrop)) + return; + + AddFromFileDrop((string[])e.Data.GetData(DataFormats.FileDrop)); + label_Tip.Text = $"已选择 {listBox.Items.Count} 个文件"; + } + + private void toolStripMenuItem_SelectAll_Click(object sender, EventArgs e) + { + for (int i = 0; i < listBox.Items.Count; i++) + listBox.SelectedIndices.Add(i); + } + + private void toolStripMenuItem_Paste_Click(object sender, EventArgs e) + { + if (!Clipboard.ContainsFileDropList()) + return; + + var fileDropList = Clipboard.GetFileDropList(); + var paths = new string[fileDropList.Count]; + fileDropList.CopyTo(paths, 0); + AddFromFileDrop(paths); + label_Tip.Text = $"已选择 {listBox.Items.Count} 个文件"; + } + + private void toolStripMenuItem_Remove_Click(object sender, EventArgs e) + { + var indices = new int[listBox.SelectedIndices.Count]; + listBox.SelectedIndices.CopyTo(indices, 0); + for (int i = indices.Length - 1; i >= 0; i--) + listBox.Items.RemoveAt(indices[i]); + label_Tip.Text = $"已选择 {listBox.Items.Count} 个文件"; + } + } +} diff --git a/SpineViewer/Controls/SkelFileListBox.resx b/SpineViewer/Controls/SkelFileListBox.resx new file mode 100644 index 0000000..8397bc9 --- /dev/null +++ b/SpineViewer/Controls/SkelFileListBox.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 556, 18 + + + 286, 21 + + + 31, 27 + + \ No newline at end of file diff --git a/SpineViewer/Dialogs/BatchOpenSpineDialog.Designer.cs b/SpineViewer/Dialogs/BatchOpenSpineDialog.Designer.cs index dc5ea53..78357e2 100644 --- a/SpineViewer/Dialogs/BatchOpenSpineDialog.Designer.cs +++ b/SpineViewer/Dialogs/BatchOpenSpineDialog.Designer.cs @@ -37,10 +37,7 @@ tableLayoutPanel2 = new TableLayoutPanel(); button_Ok = new Button(); button_Cancel = new Button(); - listBox_FilePath = new ListBox(); - button_SelectSkel = new Button(); - label_Tip = new Label(); - openFileDialog_Skel = new OpenFileDialog(); + skelFileListBox = new SpineViewer.Controls.SkelFileListBox(); panel.SuspendLayout(); tableLayoutPanel1.SuspendLayout(); tableLayoutPanel2.SuspendLayout(); @@ -53,7 +50,7 @@ panel.Location = new Point(0, 0); panel.Name = "panel"; panel.Padding = new Padding(50, 15, 50, 10); - panel.Size = new Size(1126, 449); + panel.Size = new Size(1033, 453); panel.TabIndex = 1; // // tableLayoutPanel1 @@ -62,22 +59,20 @@ tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle()); tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); tableLayoutPanel1.Controls.Add(label4, 0, 0); - tableLayoutPanel1.Controls.Add(label3, 0, 3); - tableLayoutPanel1.Controls.Add(comboBox_Version, 1, 3); - tableLayoutPanel1.Controls.Add(tableLayoutPanel2, 0, 4); - tableLayoutPanel1.Controls.Add(listBox_FilePath, 0, 2); - tableLayoutPanel1.Controls.Add(button_SelectSkel, 0, 1); - tableLayoutPanel1.Controls.Add(label_Tip, 1, 1); + tableLayoutPanel1.Controls.Add(label3, 0, 2); + tableLayoutPanel1.Controls.Add(comboBox_Version, 1, 2); + tableLayoutPanel1.Controls.Add(tableLayoutPanel2, 0, 3); + tableLayoutPanel1.Controls.Add(skelFileListBox, 1, 1); tableLayoutPanel1.Dock = DockStyle.Fill; tableLayoutPanel1.Location = new Point(50, 15); tableLayoutPanel1.Name = "tableLayoutPanel1"; - tableLayoutPanel1.RowCount = 5; + tableLayoutPanel1.RowCount = 4; tableLayoutPanel1.RowStyles.Add(new RowStyle()); tableLayoutPanel1.RowStyles.Add(new RowStyle()); tableLayoutPanel1.RowStyles.Add(new RowStyle()); tableLayoutPanel1.RowStyles.Add(new RowStyle()); - tableLayoutPanel1.RowStyles.Add(new RowStyle()); - tableLayoutPanel1.Size = new Size(1026, 424); + tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F)); + tableLayoutPanel1.Size = new Size(933, 428); tableLayoutPanel1.TabIndex = 1; // // label4 @@ -88,7 +83,7 @@ label4.Location = new Point(15, 15); label4.Margin = new Padding(15); label4.Name = "label4"; - label4.Size = new Size(996, 24); + label4.Size = new Size(903, 24); label4.TabIndex = 14; label4.Text = "说明:批量导入只需要选择skel文件,atlas文件需要在同目录下并且与skel文件名相同"; label4.TextAlign = ContentAlignment.MiddleCenter; @@ -97,7 +92,7 @@ // label3.Anchor = AnchorStyles.Right; label3.AutoSize = true; - label3.Location = new Point(90, 307); + label3.Location = new Point(3, 317); label3.Name = "label3"; label3.Size = new Size(50, 24); label3.TabIndex = 12; @@ -108,7 +103,7 @@ comboBox_Version.Anchor = AnchorStyles.Left; comboBox_Version.DropDownStyle = ComboBoxStyle.DropDownList; comboBox_Version.FormattingEnabled = true; - comboBox_Version.Location = new Point(146, 303); + comboBox_Version.Location = new Point(59, 313); comboBox_Version.Name = "comboBox_Version"; comboBox_Version.Size = new Size(182, 32); comboBox_Version.Sorted = true; @@ -125,17 +120,17 @@ tableLayoutPanel2.Controls.Add(button_Ok, 0, 0); tableLayoutPanel2.Controls.Add(button_Cancel, 1, 0); tableLayoutPanel2.Dock = DockStyle.Bottom; - tableLayoutPanel2.Location = new Point(3, 381); + tableLayoutPanel2.Location = new Point(3, 385); tableLayoutPanel2.Name = "tableLayoutPanel2"; tableLayoutPanel2.RowCount = 1; tableLayoutPanel2.RowStyles.Add(new RowStyle()); - tableLayoutPanel2.Size = new Size(1020, 40); + tableLayoutPanel2.Size = new Size(927, 40); tableLayoutPanel2.TabIndex = 11; // // button_Ok // button_Ok.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - button_Ok.Location = new Point(368, 3); + button_Ok.Location = new Point(321, 3); button_Ok.Margin = new Padding(3, 3, 30, 3); button_Ok.Name = "button_Ok"; button_Ok.Size = new Size(112, 34); @@ -147,7 +142,7 @@ // button_Cancel // button_Cancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - button_Cancel.Location = new Point(540, 3); + button_Cancel.Location = new Point(493, 3); button_Cancel.Margin = new Padding(30, 3, 3, 3); button_Cancel.Name = "button_Cancel"; button_Cancel.Size = new Size(112, 34); @@ -156,47 +151,14 @@ button_Cancel.UseVisualStyleBackColor = true; button_Cancel.Click += button_Cancel_Click; // - // listBox_FilePath + // skelFileListBox // - tableLayoutPanel1.SetColumnSpan(listBox_FilePath, 2); - listBox_FilePath.Dock = DockStyle.Fill; - listBox_FilePath.FormattingEnabled = true; - listBox_FilePath.HorizontalScrollbar = true; - listBox_FilePath.ItemHeight = 24; - listBox_FilePath.Location = new Point(3, 97); - listBox_FilePath.Name = "listBox_FilePath"; - listBox_FilePath.Size = new Size(1020, 200); - listBox_FilePath.TabIndex = 2; - // - // button_SelectSkel - // - button_SelectSkel.Anchor = AnchorStyles.None; - button_SelectSkel.Location = new Point(3, 57); - button_SelectSkel.Name = "button_SelectSkel"; - button_SelectSkel.Size = new Size(137, 34); - button_SelectSkel.TabIndex = 1; - button_SelectSkel.Text = "选择文件..."; - button_SelectSkel.UseVisualStyleBackColor = true; - button_SelectSkel.Click += button_SelectSkel_Click; - // - // label_Tip - // - label_Tip.AutoSize = true; - label_Tip.Dock = DockStyle.Fill; - label_Tip.Location = new Point(146, 54); - label_Tip.Name = "label_Tip"; - label_Tip.Size = new Size(877, 40); - label_Tip.TabIndex = 0; - label_Tip.Text = "已选择 0 个文件"; - label_Tip.TextAlign = ContentAlignment.MiddleLeft; - // - // openFileDialog_Skel - // - openFileDialog_Skel.AddExtension = false; - openFileDialog_Skel.AddToRecent = false; - openFileDialog_Skel.Filter = "skel 文件 (*.skel; *.json)|*.skel;*.json|二进制文件 (*.skel)|*.skel|文本文件 (*.json)|*.json|所有文件 (*.*)|*.*"; - openFileDialog_Skel.Multiselect = true; - openFileDialog_Skel.Title = "批量选择skel文件"; + tableLayoutPanel1.SetColumnSpan(skelFileListBox, 2); + skelFileListBox.Dock = DockStyle.Fill; + skelFileListBox.Location = new Point(3, 57); + skelFileListBox.Name = "skelFileListBox"; + skelFileListBox.Size = new Size(927, 250); + skelFileListBox.TabIndex = 15; // // BatchOpenSpineDialog // @@ -204,7 +166,7 @@ AutoScaleDimensions = new SizeF(11F, 24F); AutoScaleMode = AutoScaleMode.Font; CancelButton = button_Cancel; - ClientSize = new Size(1126, 449); + ClientSize = new Size(1033, 453); Controls.Add(panel); FormBorderStyle = FormBorderStyle.FixedDialog; Icon = (Icon)resources.GetObject("$this.Icon"); @@ -214,7 +176,6 @@ ShowInTaskbar = false; StartPosition = FormStartPosition.CenterScreen; Text = "批量打开骨骼"; - Load += BatchOpenSpineDialog_Load; panel.ResumeLayout(false); tableLayoutPanel1.ResumeLayout(false); tableLayoutPanel1.PerformLayout(); @@ -225,15 +186,12 @@ #endregion private Panel panel; private TableLayoutPanel tableLayoutPanel1; - private Label label_Tip; - private ListBox listBox_FilePath; - private Button button_SelectSkel; private TableLayoutPanel tableLayoutPanel2; private Button button_Ok; private Button button_Cancel; private Label label3; private ComboBox comboBox_Version; - private OpenFileDialog openFileDialog_Skel; private Label label4; + private Controls.SkelFileListBox skelFileListBox; } } \ No newline at end of file diff --git a/SpineViewer/Dialogs/BatchOpenSpineDialog.cs b/SpineViewer/Dialogs/BatchOpenSpineDialog.cs index 387f777..70bf944 100644 --- a/SpineViewer/Dialogs/BatchOpenSpineDialog.cs +++ b/SpineViewer/Dialogs/BatchOpenSpineDialog.cs @@ -27,33 +27,19 @@ namespace SpineViewer.Dialogs comboBox_Version.SelectedValue = Spine.Version.Auto; } - private void BatchOpenSpineDialog_Load(object sender, EventArgs e) - { - button_SelectSkel_Click(sender, e); - } - - private void button_SelectSkel_Click(object sender, EventArgs e) - { - if (openFileDialog_Skel.ShowDialog() == DialogResult.OK) - { - listBox_FilePath.Items.Clear(); - foreach (var p in openFileDialog_Skel.FileNames) - listBox_FilePath.Items.Add(Path.GetFullPath(p)); - label_Tip.Text = $"已选择 {listBox_FilePath.Items.Count} 个文件"; - } - } - private void button_Ok_Click(object sender, EventArgs e) { var version = (Spine.Version)comboBox_Version.SelectedValue; - if (listBox_FilePath.Items.Count <= 0) + var items = skelFileListBox.Items; + + if (items.Count <= 0) { MessageBox.Info("未选择任何文件"); return; } - foreach (string p in listBox_FilePath.Items) + foreach (string p in items) { if (!File.Exists(p)) { @@ -68,7 +54,7 @@ namespace SpineViewer.Dialogs return; } - Result = new(version, listBox_FilePath.Items.Cast().ToArray()); + Result = new(version, items.Cast().ToArray()); DialogResult = DialogResult.OK; } diff --git a/SpineViewer/Dialogs/BatchOpenSpineDialog.resx b/SpineViewer/Dialogs/BatchOpenSpineDialog.resx index 8297dc3..55a66f3 100644 --- a/SpineViewer/Dialogs/BatchOpenSpineDialog.resx +++ b/SpineViewer/Dialogs/BatchOpenSpineDialog.resx @@ -117,9 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 92, 26 - diff --git a/SpineViewer/Dialogs/ConvertFileFormatDialog.Designer.cs b/SpineViewer/Dialogs/ConvertFileFormatDialog.Designer.cs index c9b298f..2dc90e4 100644 --- a/SpineViewer/Dialogs/ConvertFileFormatDialog.Designer.cs +++ b/SpineViewer/Dialogs/ConvertFileFormatDialog.Designer.cs @@ -31,6 +31,7 @@ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ConvertFileFormatDialog)); panel = new Panel(); tableLayoutPanel1 = new TableLayoutPanel(); + comboBox_TargetVersion = new ComboBox(); flowLayoutPanel_TargetFormat = new FlowLayoutPanel(); radioButton_BinaryTarget = new RadioButton(); radioButton_JsonTarget = new RadioButton(); @@ -41,19 +42,13 @@ tableLayoutPanel2 = new TableLayoutPanel(); button_Ok = new Button(); button_Cancel = new Button(); - listBox_FilePath = new ListBox(); - button_SelectSkel = new Button(); - label_Tip = new Label(); label2 = new Label(); - flowLayoutPanel_SourceFormat = new FlowLayoutPanel(); - radioButton_BinarySource = new RadioButton(); - radioButton_JsonSource = new RadioButton(); + skelFileListBox = new SpineViewer.Controls.SkelFileListBox(); openFileDialog_Skel = new OpenFileDialog(); panel.SuspendLayout(); tableLayoutPanel1.SuspendLayout(); flowLayoutPanel_TargetFormat.SuspendLayout(); tableLayoutPanel2.SuspendLayout(); - flowLayoutPanel_SourceFormat.SuspendLayout(); SuspendLayout(); // // panel @@ -63,7 +58,7 @@ panel.Location = new Point(0, 0); panel.Name = "panel"; panel.Padding = new Padding(50, 15, 50, 10); - panel.Size = new Size(1039, 530); + panel.Size = new Size(1051, 538); panel.TabIndex = 2; // // tableLayoutPanel1 @@ -71,40 +66,49 @@ tableLayoutPanel1.ColumnCount = 2; tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle()); tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); - tableLayoutPanel1.Controls.Add(flowLayoutPanel_TargetFormat, 1, 5); - tableLayoutPanel1.Controls.Add(label1, 0, 4); + tableLayoutPanel1.Controls.Add(comboBox_TargetVersion, 1, 3); + tableLayoutPanel1.Controls.Add(flowLayoutPanel_TargetFormat, 1, 4); + tableLayoutPanel1.Controls.Add(label1, 0, 3); tableLayoutPanel1.Controls.Add(label4, 0, 0); - tableLayoutPanel1.Controls.Add(label3, 0, 3); - tableLayoutPanel1.Controls.Add(comboBox_SourceVersion, 1, 3); - tableLayoutPanel1.Controls.Add(tableLayoutPanel2, 0, 6); - tableLayoutPanel1.Controls.Add(listBox_FilePath, 0, 2); - tableLayoutPanel1.Controls.Add(button_SelectSkel, 0, 1); - tableLayoutPanel1.Controls.Add(label_Tip, 1, 1); - tableLayoutPanel1.Controls.Add(label2, 0, 5); - tableLayoutPanel1.Controls.Add(flowLayoutPanel_SourceFormat, 1, 4); + tableLayoutPanel1.Controls.Add(label3, 0, 2); + tableLayoutPanel1.Controls.Add(comboBox_SourceVersion, 1, 2); + tableLayoutPanel1.Controls.Add(tableLayoutPanel2, 0, 5); + tableLayoutPanel1.Controls.Add(label2, 0, 4); + tableLayoutPanel1.Controls.Add(skelFileListBox, 0, 1); tableLayoutPanel1.Dock = DockStyle.Fill; tableLayoutPanel1.Location = new Point(50, 15); tableLayoutPanel1.Name = "tableLayoutPanel1"; - tableLayoutPanel1.RowCount = 7; + tableLayoutPanel1.RowCount = 6; tableLayoutPanel1.RowStyles.Add(new RowStyle()); tableLayoutPanel1.RowStyles.Add(new RowStyle()); tableLayoutPanel1.RowStyles.Add(new RowStyle()); tableLayoutPanel1.RowStyles.Add(new RowStyle()); tableLayoutPanel1.RowStyles.Add(new RowStyle()); tableLayoutPanel1.RowStyles.Add(new RowStyle()); - tableLayoutPanel1.RowStyles.Add(new RowStyle()); - tableLayoutPanel1.Size = new Size(939, 505); + tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F)); + tableLayoutPanel1.Size = new Size(951, 513); tableLayoutPanel1.TabIndex = 1; // + // comboBox_TargetVersion + // + comboBox_TargetVersion.Anchor = AnchorStyles.Left; + comboBox_TargetVersion.DropDownStyle = ComboBoxStyle.DropDownList; + comboBox_TargetVersion.FormattingEnabled = true; + comboBox_TargetVersion.Location = new Point(95, 356); + comboBox_TargetVersion.Name = "comboBox_TargetVersion"; + comboBox_TargetVersion.Size = new Size(182, 32); + comboBox_TargetVersion.Sorted = true; + comboBox_TargetVersion.TabIndex = 21; + // // flowLayoutPanel_TargetFormat // flowLayoutPanel_TargetFormat.AutoSize = true; flowLayoutPanel_TargetFormat.Controls.Add(radioButton_BinaryTarget); flowLayoutPanel_TargetFormat.Controls.Add(radioButton_JsonTarget); flowLayoutPanel_TargetFormat.Dock = DockStyle.Fill; - flowLayoutPanel_TargetFormat.Location = new Point(146, 381); + flowLayoutPanel_TargetFormat.Location = new Point(95, 394); flowLayoutPanel_TargetFormat.Name = "flowLayoutPanel_TargetFormat"; - flowLayoutPanel_TargetFormat.Size = new Size(790, 34); + flowLayoutPanel_TargetFormat.Size = new Size(853, 34); flowLayoutPanel_TargetFormat.TabIndex = 19; // // radioButton_BinaryTarget @@ -116,7 +120,6 @@ radioButton_BinaryTarget.TabIndex = 17; radioButton_BinaryTarget.Text = "二进制 (*.skel)"; radioButton_BinaryTarget.UseVisualStyleBackColor = true; - radioButton_BinaryTarget.CheckedChanged += radioButton_Target_CheckedChanged; // // radioButton_JsonTarget // @@ -129,17 +132,16 @@ radioButton_JsonTarget.TabStop = true; radioButton_JsonTarget.Text = "文本 (*.json)"; radioButton_JsonTarget.UseVisualStyleBackColor = true; - radioButton_JsonTarget.CheckedChanged += radioButton_Target_CheckedChanged; // // label1 // label1.Anchor = AnchorStyles.Right; label1.AutoSize = true; - label1.Location = new Point(72, 346); + label1.Location = new Point(3, 360); label1.Name = "label1"; - label1.Size = new Size(68, 24); + label1.Size = new Size(86, 24); label1.TabIndex = 15; - label1.Text = "源格式:"; + label1.Text = "目标版本:"; // // label4 // @@ -149,7 +151,7 @@ label4.Location = new Point(15, 15); label4.Margin = new Padding(15); label4.Name = "label4"; - label4.Size = new Size(909, 24); + label4.Size = new Size(921, 24); label4.TabIndex = 14; label4.Text = "说明:将在每个文件同级目录下生成目标格式后缀的文件,会覆盖已存在文件"; label4.TextAlign = ContentAlignment.MiddleCenter; @@ -158,19 +160,19 @@ // label3.Anchor = AnchorStyles.Right; label3.AutoSize = true; - label3.Location = new Point(72, 307); + label3.Location = new Point(21, 322); label3.Name = "label3"; label3.Size = new Size(68, 24); label3.TabIndex = 12; label3.Text = "源版本:"; // - // comboBox_Version + // comboBox_SourceVersion // comboBox_SourceVersion.Anchor = AnchorStyles.Left; comboBox_SourceVersion.DropDownStyle = ComboBoxStyle.DropDownList; comboBox_SourceVersion.FormattingEnabled = true; - comboBox_SourceVersion.Location = new Point(146, 303); - comboBox_SourceVersion.Name = "comboBox_Version"; + comboBox_SourceVersion.Location = new Point(95, 318); + comboBox_SourceVersion.Name = "comboBox_SourceVersion"; comboBox_SourceVersion.Size = new Size(182, 32); comboBox_SourceVersion.Sorted = true; comboBox_SourceVersion.TabIndex = 13; @@ -186,17 +188,17 @@ tableLayoutPanel2.Controls.Add(button_Ok, 0, 0); tableLayoutPanel2.Controls.Add(button_Cancel, 1, 0); tableLayoutPanel2.Dock = DockStyle.Bottom; - tableLayoutPanel2.Location = new Point(3, 462); + tableLayoutPanel2.Location = new Point(3, 470); tableLayoutPanel2.Name = "tableLayoutPanel2"; tableLayoutPanel2.RowCount = 1; tableLayoutPanel2.RowStyles.Add(new RowStyle()); - tableLayoutPanel2.Size = new Size(933, 40); + tableLayoutPanel2.Size = new Size(945, 40); tableLayoutPanel2.TabIndex = 11; // // button_Ok // button_Ok.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - button_Ok.Location = new Point(324, 3); + button_Ok.Location = new Point(330, 3); button_Ok.Margin = new Padding(3, 3, 30, 3); button_Ok.Name = "button_Ok"; button_Ok.Size = new Size(112, 34); @@ -208,7 +210,7 @@ // button_Cancel // button_Cancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - button_Cancel.Location = new Point(496, 3); + button_Cancel.Location = new Point(502, 3); button_Cancel.Margin = new Padding(30, 3, 3, 3); button_Cancel.Name = "button_Cancel"; button_Cancel.Size = new Size(112, 34); @@ -217,84 +219,24 @@ button_Cancel.UseVisualStyleBackColor = true; button_Cancel.Click += button_Cancel_Click; // - // listBox_FilePath - // - tableLayoutPanel1.SetColumnSpan(listBox_FilePath, 2); - listBox_FilePath.Dock = DockStyle.Fill; - listBox_FilePath.FormattingEnabled = true; - listBox_FilePath.HorizontalScrollbar = true; - listBox_FilePath.ItemHeight = 24; - listBox_FilePath.Location = new Point(3, 97); - listBox_FilePath.Name = "listBox_FilePath"; - listBox_FilePath.Size = new Size(933, 200); - listBox_FilePath.TabIndex = 2; - // - // button_SelectSkel - // - button_SelectSkel.Anchor = AnchorStyles.None; - button_SelectSkel.Location = new Point(3, 57); - button_SelectSkel.Name = "button_SelectSkel"; - button_SelectSkel.Size = new Size(137, 34); - button_SelectSkel.TabIndex = 1; - button_SelectSkel.Text = "选择文件..."; - button_SelectSkel.UseVisualStyleBackColor = true; - button_SelectSkel.Click += button_SelectSkel_Click; - // - // label_Tip - // - label_Tip.AutoSize = true; - label_Tip.Dock = DockStyle.Fill; - label_Tip.Location = new Point(146, 54); - label_Tip.Name = "label_Tip"; - label_Tip.Size = new Size(790, 40); - label_Tip.TabIndex = 0; - label_Tip.Text = "已选择 0 个文件"; - label_Tip.TextAlign = ContentAlignment.MiddleLeft; - // // label2 // label2.Anchor = AnchorStyles.Right; label2.AutoSize = true; - label2.Location = new Point(54, 386); + label2.Location = new Point(3, 399); label2.Name = "label2"; label2.Size = new Size(86, 24); label2.TabIndex = 16; label2.Text = "目标格式:"; // - // flowLayoutPanel_SourceFormat + // skelFileListBox // - flowLayoutPanel_SourceFormat.AutoSize = true; - flowLayoutPanel_SourceFormat.Controls.Add(radioButton_BinarySource); - flowLayoutPanel_SourceFormat.Controls.Add(radioButton_JsonSource); - flowLayoutPanel_SourceFormat.Dock = DockStyle.Fill; - flowLayoutPanel_SourceFormat.Location = new Point(146, 341); - flowLayoutPanel_SourceFormat.Name = "flowLayoutPanel_SourceFormat"; - flowLayoutPanel_SourceFormat.Size = new Size(790, 34); - flowLayoutPanel_SourceFormat.TabIndex = 18; - // - // radioButton_BinarySource - // - radioButton_BinarySource.AutoSize = true; - radioButton_BinarySource.Checked = true; - radioButton_BinarySource.Location = new Point(3, 3); - radioButton_BinarySource.Name = "radioButton_BinarySource"; - radioButton_BinarySource.Size = new Size(151, 28); - radioButton_BinarySource.TabIndex = 17; - radioButton_BinarySource.TabStop = true; - radioButton_BinarySource.Text = "二进制 (*.skel)"; - radioButton_BinarySource.UseVisualStyleBackColor = true; - radioButton_BinarySource.CheckedChanged += radioButton_Source_CheckedChanged; - // - // radioButton_JsonSource - // - radioButton_JsonSource.AutoSize = true; - radioButton_JsonSource.Location = new Point(160, 3); - radioButton_JsonSource.Name = "radioButton_JsonSource"; - radioButton_JsonSource.Size = new Size(135, 28); - radioButton_JsonSource.TabIndex = 18; - radioButton_JsonSource.Text = "文本 (*.json)"; - radioButton_JsonSource.UseVisualStyleBackColor = true; - radioButton_JsonSource.CheckedChanged += radioButton_Source_CheckedChanged; + tableLayoutPanel1.SetColumnSpan(skelFileListBox, 2); + skelFileListBox.Dock = DockStyle.Fill; + skelFileListBox.Location = new Point(3, 57); + skelFileListBox.Name = "skelFileListBox"; + skelFileListBox.Size = new Size(945, 255); + skelFileListBox.TabIndex = 20; // // openFileDialog_Skel // @@ -310,7 +252,7 @@ AutoScaleDimensions = new SizeF(11F, 24F); AutoScaleMode = AutoScaleMode.Font; CancelButton = button_Cancel; - ClientSize = new Size(1039, 530); + ClientSize = new Size(1051, 538); Controls.Add(panel); FormBorderStyle = FormBorderStyle.FixedDialog; Icon = (Icon)resources.GetObject("$this.Icon"); @@ -320,15 +262,12 @@ ShowInTaskbar = false; StartPosition = FormStartPosition.CenterScreen; Text = "骨骼文件格式转换"; - Load += ConvertFileFormatDialog_Load; panel.ResumeLayout(false); tableLayoutPanel1.ResumeLayout(false); tableLayoutPanel1.PerformLayout(); flowLayoutPanel_TargetFormat.ResumeLayout(false); flowLayoutPanel_TargetFormat.PerformLayout(); tableLayoutPanel2.ResumeLayout(false); - flowLayoutPanel_SourceFormat.ResumeLayout(false); - flowLayoutPanel_SourceFormat.PerformLayout(); ResumeLayout(false); } @@ -342,17 +281,13 @@ private TableLayoutPanel tableLayoutPanel2; private Button button_Ok; private Button button_Cancel; - private ListBox listBox_FilePath; - private Button button_SelectSkel; - private Label label_Tip; private OpenFileDialog openFileDialog_Skel; private Label label1; private Label label2; - private RadioButton radioButton_BinarySource; - private FlowLayoutPanel flowLayoutPanel_SourceFormat; - private RadioButton radioButton_JsonSource; private FlowLayoutPanel flowLayoutPanel_TargetFormat; private RadioButton radioButton_BinaryTarget; private RadioButton radioButton_JsonTarget; + private Controls.SkelFileListBox skelFileListBox; + private ComboBox comboBox_TargetVersion; } } \ No newline at end of file diff --git a/SpineViewer/Dialogs/ConvertFileFormatDialog.cs b/SpineViewer/Dialogs/ConvertFileFormatDialog.cs index 9a3907d..67ec272 100644 --- a/SpineViewer/Dialogs/ConvertFileFormatDialog.cs +++ b/SpineViewer/Dialogs/ConvertFileFormatDialog.cs @@ -13,62 +13,44 @@ namespace SpineViewer.Dialogs { public partial class ConvertFileFormatDialog : Form { - // TODO: 增加版本转换选项 - // TODO: 使用结果包装类 - public string[] SkelPaths { get; private set; } - public Spine.Version SourceVersion { get; private set; } - public Spine.Version TargetVersion { get; private set; } - public bool JsonSource { get; private set; } - public bool JsonTarget { get; private set; } + /// + /// 对话框结果, 取消时为 null + /// + public ConvertFileFormatDialogResult Result { get; private set; } public ConvertFileFormatDialog() { InitializeComponent(); - // XXX: 文件格式转换暂时不支持自动检测版本 - var impVersions = VersionHelper.Names.ToDictionary(); - impVersions.Remove(Spine.Version.Auto); - - comboBox_SourceVersion.DataSource = impVersions.ToList(); + comboBox_SourceVersion.DataSource = VersionHelper.Names.ToList(); comboBox_SourceVersion.DisplayMember = "Value"; comboBox_SourceVersion.ValueMember = "Key"; - comboBox_SourceVersion.SelectedValue = Spine.Version.V38; - //comboBox_TargetVersion.DataSource = VersionHelper.Versions.ToList(); - //comboBox_TargetVersion.DisplayMember = "Value"; - //comboBox_TargetVersion.ValueMember = "Key"; - //comboBox_TargetVersion.SelectedValue = Spine.Version.V38; - } + comboBox_SourceVersion.SelectedValue = Spine.Version.Auto; - private void ConvertFileFormatDialog_Load(object sender, EventArgs e) - { - button_SelectSkel_Click(sender, e); - } - - private void button_SelectSkel_Click(object sender, EventArgs e) - { - if (openFileDialog_Skel.ShowDialog() == DialogResult.OK) - { - listBox_FilePath.Items.Clear(); - foreach (var p in openFileDialog_Skel.FileNames) - listBox_FilePath.Items.Add(Path.GetFullPath(p)); - label_Tip.Text = $"已选择 {listBox_FilePath.Items.Count} 个文件"; - } + // 目标版本不包含自动 + var versionsWithoutAuto = VersionHelper.Names.ToDictionary(); + versionsWithoutAuto.Remove(Spine.Version.Auto); + comboBox_TargetVersion.DataSource = versionsWithoutAuto.ToList(); + comboBox_TargetVersion.DisplayMember = "Value"; + comboBox_TargetVersion.ValueMember = "Key"; + comboBox_TargetVersion.SelectedValue = Spine.Version.V38; } private void button_Ok_Click(object sender, EventArgs e) { var sourceVersion = (Spine.Version)comboBox_SourceVersion.SelectedValue; - var targetVersion = (Spine.Version)comboBox_SourceVersion.SelectedValue; // TODO: 增加目标版本 - var jsonSource = radioButton_JsonSource.Checked; + var targetVersion = (Spine.Version)comboBox_TargetVersion.SelectedValue; var jsonTarget = radioButton_JsonTarget.Checked; - if (listBox_FilePath.Items.Count <= 0) + var items = skelFileListBox.Items; + + if (items.Count <= 0) { MessageBox.Info("未选择任何文件"); return; } - foreach (string p in listBox_FilePath.Items) + foreach (string p in items) { if (!File.Exists(p)) { @@ -77,7 +59,7 @@ namespace SpineViewer.Dialogs } } - if (!SkeletonConverter.ImplementedVersions.Contains(sourceVersion)) + if (sourceVersion != Spine.Version.Auto && !SkeletonConverter.ImplementedVersions.Contains(sourceVersion)) { MessageBox.Info($"{sourceVersion.GetName()} 版本尚未实现(咕咕咕~)"); return; @@ -89,18 +71,7 @@ namespace SpineViewer.Dialogs return; } - if (jsonSource == jsonTarget && sourceVersion == targetVersion) - { - MessageBox.Info($"不需要转换相同的格式和版本"); - return; - } - - SkelPaths = listBox_FilePath.Items.Cast().ToArray(); - SourceVersion = sourceVersion; - TargetVersion = targetVersion; - JsonSource = jsonSource; - JsonTarget = jsonTarget; - + Result = new(items.Cast().ToArray(), sourceVersion, targetVersion, jsonTarget); DialogResult = DialogResult.OK; } @@ -108,21 +79,31 @@ namespace SpineViewer.Dialogs { DialogResult = DialogResult.Cancel; } + } - private void radioButton_Source_CheckedChanged(object sender, EventArgs e) - { - if (radioButton_BinarySource.Checked) - radioButton_JsonTarget.Checked = true; - else - radioButton_BinaryTarget.Checked = true; - } + /// + /// 文件格式转换对话框结果包装类 + /// + public class ConvertFileFormatDialogResult(string[] skelPaths, Spine.Version sourceVersion, Spine.Version targetVersion, bool jsonTarget) + { + /// + /// 骨骼文件路径列表 + /// + public string[] SkelPaths => skelPaths; - private void radioButton_Target_CheckedChanged(object sender, EventArgs e) - { - if (radioButton_BinaryTarget.Checked) - radioButton_JsonSource.Checked = true; - else - radioButton_BinarySource.Checked = true; - } + /// + /// 源版本 + /// + public Spine.Version SourceVersion => sourceVersion; + + /// + /// 目标版本 + /// + public Spine.Version TargetVersion => targetVersion; + + /// + /// 目标格式是否为 Json + /// + public bool JsonTarget => jsonTarget; } }