From 2535a9ebf9ed21a3347f6c833c5655aad2ea319d Mon Sep 17 00:00:00 2001 From: ww-rm Date: Fri, 21 Mar 2025 01:05:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=90=E8=A1=8C=E6=97=B6?= =?UTF-8?q?=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SpineViewer/Dialogs/BatchOpenSpineDialog.cs | 4 +- .../Dialogs/ConvertFileFormatDialog.cs | 6 +-- SpineViewer/Dialogs/OpenSpineDialog.cs | 4 +- SpineViewer/Spine/TypeConverter.cs | 2 +- SpineViewer/Spine/Version.cs | 37 +++++++++++++++---- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/SpineViewer/Dialogs/BatchOpenSpineDialog.cs b/SpineViewer/Dialogs/BatchOpenSpineDialog.cs index d31a583..e3879e5 100644 --- a/SpineViewer/Dialogs/BatchOpenSpineDialog.cs +++ b/SpineViewer/Dialogs/BatchOpenSpineDialog.cs @@ -18,7 +18,7 @@ namespace SpineViewer.Dialogs public BatchOpenSpineDialog() { InitializeComponent(); - comboBox_Version.DataSource = VersionHelper.Versions.ToList(); + comboBox_Version.DataSource = VersionHelper.Names.ToList(); comboBox_Version.DisplayMember = "Value"; comboBox_Version.ValueMember = "Key"; comboBox_Version.SelectedValue = Spine.Version.Auto; @@ -61,7 +61,7 @@ namespace SpineViewer.Dialogs if (version != Spine.Version.Auto && !Spine.Spine.ImplementedVersions.Contains(version)) { - MessageBox.Show($"{version.String()} 版本尚未实现(咕咕咕~)", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show($"{version.GetName()} 版本尚未实现(咕咕咕~)", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } diff --git a/SpineViewer/Dialogs/ConvertFileFormatDialog.cs b/SpineViewer/Dialogs/ConvertFileFormatDialog.cs index 85fc584..05f193b 100644 --- a/SpineViewer/Dialogs/ConvertFileFormatDialog.cs +++ b/SpineViewer/Dialogs/ConvertFileFormatDialog.cs @@ -24,7 +24,7 @@ namespace SpineViewer.Dialogs InitializeComponent(); // XXX: 文件格式转换暂时不支持自动检测版本 - var impVersions = VersionHelper.Versions.ToDictionary(); + var impVersions = VersionHelper.Names.ToDictionary(); impVersions.Remove(Spine.Version.Auto); comboBox_SourceVersion.DataSource = impVersions.ToList(); @@ -77,13 +77,13 @@ namespace SpineViewer.Dialogs if (!SkeletonConverter.ImplementedVersions.Contains(sourceVersion)) { - MessageBox.Show($"{sourceVersion.String()} 版本尚未实现(咕咕咕~)", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show($"{sourceVersion.GetName()} 版本尚未实现(咕咕咕~)", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!SkeletonConverter.ImplementedVersions.Contains(targetVersion)) { - MessageBox.Show($"{targetVersion.String()} 版本尚未实现(咕咕咕~)", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show($"{targetVersion.GetName()} 版本尚未实现(咕咕咕~)", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } diff --git a/SpineViewer/Dialogs/OpenSpineDialog.cs b/SpineViewer/Dialogs/OpenSpineDialog.cs index fdfd61e..0812188 100644 --- a/SpineViewer/Dialogs/OpenSpineDialog.cs +++ b/SpineViewer/Dialogs/OpenSpineDialog.cs @@ -17,7 +17,7 @@ namespace SpineViewer.Dialogs public OpenSpineDialog() { InitializeComponent(); - comboBox_Version.DataSource = VersionHelper.Versions.ToList(); + comboBox_Version.DataSource = VersionHelper.Names.ToList(); comboBox_Version.DisplayMember = "Value"; comboBox_Version.ValueMember = "Key"; comboBox_Version.SelectedValue = Spine.Version.Auto; @@ -78,7 +78,7 @@ namespace SpineViewer.Dialogs if (version != Spine.Version.Auto && !Spine.Spine.ImplementedVersions.Contains(version)) { - MessageBox.Show($"{version.String()} 版本尚未实现(咕咕咕~)", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show($"{version.GetName()} 版本尚未实现(咕咕咕~)", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } diff --git a/SpineViewer/Spine/TypeConverter.cs b/SpineViewer/Spine/TypeConverter.cs index 0271828..88a84d5 100644 --- a/SpineViewer/Spine/TypeConverter.cs +++ b/SpineViewer/Spine/TypeConverter.cs @@ -18,7 +18,7 @@ namespace SpineViewer.Spine if (destinationType == typeof(string) && value is Version version) { // 调用自定义的 String() 方法 - return version.String(); + return version.GetName(); } return base.ConvertTo(context, culture, value, destinationType); diff --git a/SpineViewer/Spine/Version.cs b/SpineViewer/Spine/Version.cs index ab0e47f..77f21c3 100644 --- a/SpineViewer/Spine/Version.cs +++ b/SpineViewer/Spine/Version.cs @@ -12,10 +12,15 @@ namespace SpineViewer.Spine public static class VersionHelper { /// - /// 描述缓存 + /// 版本名称 /// - public static readonly ReadOnlyDictionary Versions; - private static readonly Dictionary versions = []; + public static readonly ReadOnlyDictionary Names; + private static readonly Dictionary names = []; + + /// + /// Runtime 版本字符串 + /// + private static readonly Dictionary runtimes = []; static VersionHelper() { @@ -24,17 +29,33 @@ namespace SpineViewer.Spine { var field = typeof(Version).GetField(value.ToString()); var attribute = field?.GetCustomAttribute(); - versions[(Version)value] = attribute?.Description ?? value.ToString(); + names[(Version)value] = attribute?.Description ?? value.ToString(); } - Versions = versions.AsReadOnly(); + Names = names.AsReadOnly(); + + runtimes[Version.V21] = Assembly.GetAssembly(typeof(SpineRuntime21.Skeleton)).GetCustomAttribute()?.InformationalVersion; + runtimes[Version.V36] = Assembly.GetAssembly(typeof(SpineRuntime36.Skeleton)).GetCustomAttribute()?.InformationalVersion; + runtimes[Version.V37] = Assembly.GetAssembly(typeof(SpineRuntime37.Skeleton)).GetCustomAttribute()?.InformationalVersion; + runtimes[Version.V38] = Assembly.GetAssembly(typeof(SpineRuntime38.Skeleton)).GetCustomAttribute()?.InformationalVersion; + runtimes[Version.V40] = Assembly.GetAssembly(typeof(SpineRuntime40.Skeleton)).GetCustomAttribute()?.InformationalVersion; + runtimes[Version.V41] = Assembly.GetAssembly(typeof(SpineRuntime41.Skeleton)).GetCustomAttribute()?.InformationalVersion; + runtimes[Version.V42] = Assembly.GetAssembly(typeof(SpineRuntime42.Skeleton)).GetCustomAttribute()?.InformationalVersion; } /// - /// 版本号字符串 + /// 版本字符串名称 /// - public static string String(this Version version) + public static string GetName(this Version version) { - return Versions.TryGetValue(version, out var description) ? description : version.ToString(); + return Names.TryGetValue(version, out var val) ? val : version.ToString(); + } + + /// + /// Runtime 版本字符串名称 + /// + public static string GetRuntime(this Version version) + { + return runtimes.TryGetValue(version, out var val) ? val : GetName(version); } }