From 145f4f3265eb1ef6b4ab3ffdd79636a95937ca8d Mon Sep 17 00:00:00 2001 From: ww-rm Date: Wed, 19 Mar 2025 13:12:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A9=BA=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SpineViewer/Spine/Implementations/Spine/Spine21.cs | 13 +++++++++++-- SpineViewer/Spine/Implementations/Spine/Spine36.cs | 13 +++++++++++-- SpineViewer/Spine/Implementations/Spine/Spine37.cs | 13 +++++++++++-- SpineViewer/Spine/Implementations/Spine/Spine38.cs | 13 +++++++++++-- SpineViewer/Spine/Implementations/Spine/Spine40.cs | 13 +++++++++++-- SpineViewer/Spine/Implementations/Spine/Spine41.cs | 13 +++++++++++-- SpineViewer/Spine/Implementations/Spine/Spine42.cs | 13 +++++++++++-- SpineViewer/Spine/Spine.cs | 7 ++++++- SpineViewer/Spine/TypeConverter.cs | 4 ---- 9 files changed, 83 insertions(+), 19 deletions(-) diff --git a/SpineViewer/Spine/Implementations/Spine/Spine21.cs b/SpineViewer/Spine/Implementations/Spine/Spine21.cs index 38fe6cf..49f127a 100644 --- a/SpineViewer/Spine/Implementations/Spine/Spine21.cs +++ b/SpineViewer/Spine/Implementations/Spine/Spine21.cs @@ -13,6 +13,8 @@ namespace SpineViewer.Spine.Implementations.Spine [SpineImplementation(Version.V21)] internal class Spine21 : SpineViewer.Spine.Spine { + private static readonly Animation EmptyAnimation = new(EMPTY_ANIMATION, [], 0); + private class TextureLoader : SpineRuntime21.TextureLoader { public void Load(AtlasPage page, string path) @@ -172,8 +174,15 @@ namespace SpineViewer.Spine.Implementations.Spine public override string CurrentAnimation { - get => animationState.GetCurrent(0)?.Animation.Name ?? DefaultAnimationName; - set { if (animationNames.Contains(value)) { animationState.SetAnimation(0, value, true); Update(0); } } + get => animationState.GetCurrent(0)?.Animation.Name ?? EMPTY_ANIMATION; + set + { + if (value == EMPTY_ANIMATION) + animationState.SetAnimation(0, EmptyAnimation, false); + else if (animationNames.Contains(value)) + animationState.SetAnimation(0, value, true); + Update(0); + } } public override RectangleF Bounds diff --git a/SpineViewer/Spine/Implementations/Spine/Spine36.cs b/SpineViewer/Spine/Implementations/Spine/Spine36.cs index 892ed7b..1163300 100644 --- a/SpineViewer/Spine/Implementations/Spine/Spine36.cs +++ b/SpineViewer/Spine/Implementations/Spine/Spine36.cs @@ -13,6 +13,8 @@ namespace SpineViewer.Spine.Implementations.Spine [SpineImplementation(Version.V36)] internal class Spine36 : SpineViewer.Spine.Spine { + private static readonly Animation EmptyAnimation = new(EMPTY_ANIMATION, [], 0); + private class TextureLoader : SpineRuntime36.TextureLoader { public void Load(AtlasPage page, string path) @@ -170,8 +172,15 @@ namespace SpineViewer.Spine.Implementations.Spine public override string CurrentAnimation { - get => animationState.GetCurrent(0)?.Animation.Name ?? DefaultAnimationName; - set { if (animationNames.Contains(value)) { animationState.SetAnimation(0, value, true); Update(0); } } + get => animationState.GetCurrent(0)?.Animation.Name ?? EMPTY_ANIMATION; + set + { + if (value == EMPTY_ANIMATION) + animationState.SetAnimation(0, EmptyAnimation, false); + else if (animationNames.Contains(value)) + animationState.SetAnimation(0, value, true); + Update(0); + } } public override RectangleF Bounds diff --git a/SpineViewer/Spine/Implementations/Spine/Spine37.cs b/SpineViewer/Spine/Implementations/Spine/Spine37.cs index 90b7b3b..db74c92 100644 --- a/SpineViewer/Spine/Implementations/Spine/Spine37.cs +++ b/SpineViewer/Spine/Implementations/Spine/Spine37.cs @@ -10,6 +10,8 @@ namespace SpineViewer.Spine.Implementations.Spine [SpineImplementation(Version.V37)] internal class Spine37 : SpineViewer.Spine.Spine { + private static readonly Animation EmptyAnimation = new(EMPTY_ANIMATION, [], 0); + private class TextureLoader : SpineRuntime37.TextureLoader { public void Load(AtlasPage page, string path) @@ -177,8 +179,15 @@ namespace SpineViewer.Spine.Implementations.Spine public override string CurrentAnimation { - get => animationState.GetCurrent(0)?.Animation.Name ?? DefaultAnimationName; - set { if (animationNames.Contains(value)) { animationState.SetAnimation(0, value, true); Update(0); } } + get => animationState.GetCurrent(0)?.Animation.Name ?? EMPTY_ANIMATION; + set + { + if (value == EMPTY_ANIMATION) + animationState.SetAnimation(0, EmptyAnimation, false); + else if (animationNames.Contains(value)) + animationState.SetAnimation(0, value, true); + Update(0); + } } public override RectangleF Bounds diff --git a/SpineViewer/Spine/Implementations/Spine/Spine38.cs b/SpineViewer/Spine/Implementations/Spine/Spine38.cs index 8606f39..0feaea1 100644 --- a/SpineViewer/Spine/Implementations/Spine/Spine38.cs +++ b/SpineViewer/Spine/Implementations/Spine/Spine38.cs @@ -13,6 +13,8 @@ namespace SpineViewer.Spine.Implementations.Spine [SpineImplementation(Version.V38)] internal class Spine38 : SpineViewer.Spine.Spine { + private static readonly Animation EmptyAnimation = new(EMPTY_ANIMATION, [], 0); + private class TextureLoader : SpineRuntime38.TextureLoader { public void Load(AtlasPage page, string path) @@ -180,8 +182,15 @@ namespace SpineViewer.Spine.Implementations.Spine public override string CurrentAnimation { - get => animationState.GetCurrent(0)?.Animation.Name ?? DefaultAnimationName; - set { if (animationNames.Contains(value)) { animationState.SetAnimation(0, value, true); Update(0); } } + get => animationState.GetCurrent(0)?.Animation.Name ?? EMPTY_ANIMATION; + set + { + if (value == EMPTY_ANIMATION) + animationState.SetAnimation(0, EmptyAnimation, false); + else if (animationNames.Contains(value)) + animationState.SetAnimation(0, value, true); + Update(0); + } } public override RectangleF Bounds diff --git a/SpineViewer/Spine/Implementations/Spine/Spine40.cs b/SpineViewer/Spine/Implementations/Spine/Spine40.cs index 152f456..016e324 100644 --- a/SpineViewer/Spine/Implementations/Spine/Spine40.cs +++ b/SpineViewer/Spine/Implementations/Spine/Spine40.cs @@ -12,6 +12,8 @@ namespace SpineViewer.Spine.Implementations.Spine [SpineImplementation(Version.V40)] internal class Spine40 : SpineViewer.Spine.Spine { + private static readonly Animation EmptyAnimation = new(EMPTY_ANIMATION, [], 0); + private class TextureLoader : SpineRuntime40.TextureLoader { public void Load(AtlasPage page, string path) @@ -179,8 +181,15 @@ namespace SpineViewer.Spine.Implementations.Spine public override string CurrentAnimation { - get => animationState.GetCurrent(0)?.Animation.Name ?? DefaultAnimationName; - set { if (animationNames.Contains(value)) { animationState.SetAnimation(0, value, true); Update(0); } } + get => animationState.GetCurrent(0)?.Animation.Name ?? EMPTY_ANIMATION; + set + { + if (value == EMPTY_ANIMATION) + animationState.SetAnimation(0, EmptyAnimation, false); + else if (animationNames.Contains(value)) + animationState.SetAnimation(0, value, true); + Update(0); + } } public override RectangleF Bounds diff --git a/SpineViewer/Spine/Implementations/Spine/Spine41.cs b/SpineViewer/Spine/Implementations/Spine/Spine41.cs index 44b4f3c..b6ba485 100644 --- a/SpineViewer/Spine/Implementations/Spine/Spine41.cs +++ b/SpineViewer/Spine/Implementations/Spine/Spine41.cs @@ -12,6 +12,8 @@ namespace SpineViewer.Spine.Implementations.Spine [SpineImplementation(Version.V41)] internal class Spine41 : SpineViewer.Spine.Spine { + private static readonly Animation EmptyAnimation = new(EMPTY_ANIMATION, [], 0); + private class TextureLoader : SpineRuntime41.TextureLoader { public void Load(AtlasPage page, string path) @@ -179,8 +181,15 @@ namespace SpineViewer.Spine.Implementations.Spine public override string CurrentAnimation { - get => animationState.GetCurrent(0)?.Animation.Name ?? DefaultAnimationName; - set { if (animationNames.Contains(value)) { animationState.SetAnimation(0, value, true); Update(0); } } + get => animationState.GetCurrent(0)?.Animation.Name ?? EMPTY_ANIMATION; + set + { + if (value == EMPTY_ANIMATION) + animationState.SetAnimation(0, EmptyAnimation, false); + else if (animationNames.Contains(value)) + animationState.SetAnimation(0, value, true); + Update(0); + } } public override RectangleF Bounds diff --git a/SpineViewer/Spine/Implementations/Spine/Spine42.cs b/SpineViewer/Spine/Implementations/Spine/Spine42.cs index 5b0a316..babf205 100644 --- a/SpineViewer/Spine/Implementations/Spine/Spine42.cs +++ b/SpineViewer/Spine/Implementations/Spine/Spine42.cs @@ -12,6 +12,8 @@ namespace SpineViewer.Spine.Implementations.Spine [SpineImplementation(Version.V42)] internal class Spine42 : SpineViewer.Spine.Spine { + private static readonly Animation EmptyAnimation = new(EMPTY_ANIMATION, [], 0); + private class TextureLoader : SpineRuntime42.TextureLoader { public void Load(AtlasPage page, string path) @@ -179,8 +181,15 @@ namespace SpineViewer.Spine.Implementations.Spine public override string CurrentAnimation { - get => animationState.GetCurrent(0)?.Animation.Name ?? DefaultAnimationName; - set { if (animationNames.Contains(value)) { animationState.SetAnimation(0, value, true); Update(0); } } + get => animationState.GetCurrent(0)?.Animation.Name ?? EMPTY_ANIMATION; + set + { + if (value == EMPTY_ANIMATION) + animationState.SetAnimation(0, EmptyAnimation, false); + else if (animationNames.Contains(value)) + animationState.SetAnimation(0, value, true); + Update(0); + } } public override RectangleF Bounds diff --git a/SpineViewer/Spine/Spine.cs b/SpineViewer/Spine/Spine.cs index 686dd7d..9e0a2d7 100644 --- a/SpineViewer/Spine/Spine.cs +++ b/SpineViewer/Spine/Spine.cs @@ -36,6 +36,11 @@ namespace SpineViewer.Spine /// public abstract class Spine : SFML.Graphics.Drawable, IDisposable { + /// + /// 空动画标记 + /// + public const string EMPTY_ANIMATION = ""; + /// /// 实现类缓存 /// @@ -199,7 +204,7 @@ namespace SpineViewer.Spine /// [Browsable(false)] public ReadOnlyCollection AnimationNames { get => animationNames.AsReadOnly(); } - protected List animationNames = []; + protected List animationNames = [EMPTY_ANIMATION]; /// /// 默认动画名称 diff --git a/SpineViewer/Spine/TypeConverter.cs b/SpineViewer/Spine/TypeConverter.cs index 48110d0..0271828 100644 --- a/SpineViewer/Spine/TypeConverter.cs +++ b/SpineViewer/Spine/TypeConverter.cs @@ -42,11 +42,7 @@ namespace SpineViewer.Spine public override StandardValuesCollection? GetStandardValues(ITypeDescriptorContext? context) { if (context?.Instance is Spine obj) - { - // 返回 AnimationNames 作为下拉选项 return new StandardValuesCollection(obj.AnimationNames); - } - return base.GetStandardValues(context); } }