From 674d314b5523c3891032b915598e919baf196158 Mon Sep 17 00:00:00 2001 From: ww-rm Date: Fri, 21 Mar 2025 13:24:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E6=9F=A5=E6=89=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SpineViewer/Controls/SpineListView.cs | 45 ++++++++++++++++++--------- SpineViewer/Spine/Spine.cs | 34 ++++++++++++++++++++ 2 files changed, 64 insertions(+), 15 deletions(-) diff --git a/SpineViewer/Controls/SpineListView.cs b/SpineViewer/Controls/SpineListView.cs index b10114c..79df6c1 100644 --- a/SpineViewer/Controls/SpineListView.cs +++ b/SpineViewer/Controls/SpineListView.cs @@ -333,12 +333,9 @@ namespace SpineViewer.Controls { lock (Spines) { - lock (Spines) - { - var spine = spines[index]; - spines.RemoveAt(index); - spines.Add(spine); - } + var spine = spines[index]; + spines.RemoveAt(index); + spines.Add(spine); } var item = listView.Items[index]; listView.Items.RemoveAt(index); @@ -525,20 +522,38 @@ namespace SpineViewer.Controls private void AddFromFileDrop(string[] paths) { - var validPaths = paths.Where( - path => File.Exists(path) && - (Path.GetExtension(path).Equals(".skel", StringComparison.OrdinalIgnoreCase) || - Path.GetExtension(path).Equals(".json", StringComparison.OrdinalIgnoreCase)) - ).ToArray(); - - if (validPaths.Length > 1) + List validPaths = []; + foreach (var path in paths) { + if (File.Exists(path)) + { + if (Spine.Spine.CommonSkelSuffix.Contains(Path.GetExtension(path).ToLower())) + validPaths.Add(path); + } + else if (Directory.Exists(path)) + { + // 遍历该目录下所有深度文件,判断是否符合要求并ADD + foreach (var file in Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories)) + { + if (Spine.Spine.CommonSkelSuffix.Contains(Path.GetExtension(file).ToLower())) + validPaths.Add(file); + } + } + } + + if (validPaths.Count > 1) + { + if (validPaths.Count > 100) + { + if (MessageBox.Show($"共发现 {validPaths.Count} 个可加载骨骼,数量较大,是否一次性全部加载?", "操作确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) + return; + } var progressDialog = new Dialogs.ProgressDialog(); progressDialog.DoWork += BatchAdd_Work; - progressDialog.RunWorkerAsync(new Dialogs.BatchOpenSpineDialogResult(Spine.Version.Auto, validPaths)); + progressDialog.RunWorkerAsync(new Dialogs.BatchOpenSpineDialogResult(Spine.Version.Auto, validPaths.ToArray())); progressDialog.ShowDialog(); } - else if (validPaths.Length > 0) + else if (validPaths.Count > 0) { Insert(new Dialogs.OpenSpineDialogResult(Spine.Version.Auto, validPaths[0])); } diff --git a/SpineViewer/Spine/Spine.cs b/SpineViewer/Spine/Spine.cs index b41b86f..0e1b352 100644 --- a/SpineViewer/Spine/Spine.cs +++ b/SpineViewer/Spine/Spine.cs @@ -15,6 +15,7 @@ using System.Reflection; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Text.Json.Nodes; +using System.Collections.Immutable; namespace SpineViewer.Spine { @@ -37,6 +38,11 @@ namespace SpineViewer.Spine /// public abstract class Spine : SFML.Graphics.Drawable, IDisposable { + /// + /// 常规骨骼文件后缀集合 + /// + public static readonly ImmutableHashSet CommonSkelSuffix = [".skel", ".json"]; + /// /// 空动画标记 /// @@ -211,6 +217,7 @@ namespace SpineViewer.Spine // 设置 Version Version = attr.Version; + AssetsDir = Directory.GetParent(skelPath).FullName; SkelPath = Path.GetFullPath(skelPath); AtlasPath = Path.GetFullPath(atlasPath); Name = Path.GetFileNameWithoutExtension(skelPath); @@ -227,6 +234,12 @@ namespace SpineViewer.Spine [Category("基本信息"), DisplayName("运行时版本")] public Version Version { get; } + /// + /// 资源所在完整目录 + /// + [Category("基本信息"), DisplayName("资源目录")] + public string AssetsDir { get; } + /// /// skel 文件完整路径 /// @@ -239,6 +252,9 @@ namespace SpineViewer.Spine [Category("基本信息"), DisplayName("atlas文件路径")] public string AtlasPath { get; } + /// + /// 名称 + /// [Category("基本信息"), DisplayName("名称")] public string Name { get; } @@ -397,5 +413,23 @@ namespace SpineViewer.Spine /// [Browsable(false)] public bool IsSelected { get; set; } = false; + + /// + /// 显示调试 + /// + [Browsable(false)] + public bool IsDebug { get; set; } = false; + + /// + /// 显示包围盒 + /// + [Browsable(false)] + public bool DebugBounds { get; set; } = true; + + /// + /// 显示骨骼 + /// + [Browsable(false)] + public bool DebugBones { get; set; } = true; } }