feat: spineview localize
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using SpineViewer.Spine;
|
||||
using SpineViewer.Utils;
|
||||
using SpineViewer.Utils.Localize;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@@ -20,7 +21,7 @@ namespace SpineViewer.Spine.SpineView
|
||||
/// <summary>
|
||||
/// 全轨道动画最大时长
|
||||
/// </summary>
|
||||
[DisplayName("全轨道最大时长")]
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "maximumTrackLength")]
|
||||
public float AnimationTracksMaxDuration => Spine.GetTrackIndices().Select(i => Spine.GetAnimationDuration(Spine.GetAnimation(i))).Max();
|
||||
|
||||
/// <summary>
|
||||
@@ -144,8 +145,8 @@ namespace SpineViewer.Spine.SpineView
|
||||
[Browsable(false)]
|
||||
public int Index { get; } = i;
|
||||
|
||||
[DisplayName("时长")]
|
||||
public float Duration => spine.GetAnimationDuration(spine.GetAnimation(Index));
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "duration")]
|
||||
public float Duration => spine.GetAnimationDuration(spine.GetAnimation(Index));
|
||||
|
||||
/// <summary>
|
||||
/// 实现了默认的转为字符串的方式
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using SpineViewer.Spine;
|
||||
using SpineViewer.Utils;
|
||||
using SpineViewer.Utils.Localize;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@@ -21,37 +22,37 @@ namespace SpineViewer.Spine.SpineView
|
||||
/// 获取所属版本
|
||||
/// </summary>
|
||||
[TypeConverter(typeof(SpineVersionConverter))]
|
||||
[DisplayName("运行时版本")]
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "runtimeVersion")]
|
||||
public SpineVersion Version => Spine.Version;
|
||||
|
||||
/// <summary>
|
||||
/// 资源所在完整目录
|
||||
/// </summary>
|
||||
[DisplayName("资源目录")]
|
||||
public string AssetsDir => Spine.AssetsDir;
|
||||
/// <summary>
|
||||
/// 资源所在完整目录
|
||||
/// </summary>
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "resourcesPath")]
|
||||
public string AssetsDir => Spine.AssetsDir;
|
||||
|
||||
/// <summary>
|
||||
/// skel 文件完整路径
|
||||
/// </summary>
|
||||
[DisplayName("skel文件路径")]
|
||||
public string SkelPath => Spine.SkelPath;
|
||||
/// <summary>
|
||||
/// skel 文件完整路径
|
||||
/// </summary>
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "skelPath")]
|
||||
public string SkelPath => Spine.SkelPath;
|
||||
|
||||
/// <summary>
|
||||
/// atlas 文件完整路径
|
||||
/// </summary>
|
||||
[DisplayName("atlas文件路径")]
|
||||
public string AtlasPath => Spine.AtlasPath;
|
||||
/// <summary>
|
||||
/// atlas 文件完整路径
|
||||
/// </summary>
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "atlasPath")]
|
||||
public string AtlasPath => Spine.AtlasPath;
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
[DisplayName("名称")]
|
||||
public string Name => Spine.Name;
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "name")]
|
||||
public string Name => Spine.Name;
|
||||
|
||||
/// <summary>
|
||||
/// 获取所属文件版本
|
||||
/// </summary>
|
||||
[DisplayName("文件版本")]
|
||||
public string FileVersion => Spine.FileVersion;
|
||||
/// <summary>
|
||||
/// 获取所属文件版本
|
||||
/// </summary>
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "fileVersion")]
|
||||
public string FileVersion => Spine.FileVersion;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SpineViewer.Spine;
|
||||
using SpineViewer.Utils.Localize;
|
||||
|
||||
namespace SpineViewer.Spine.SpineView
|
||||
{
|
||||
@@ -14,28 +15,28 @@ namespace SpineViewer.Spine.SpineView
|
||||
[Browsable(false)]
|
||||
public SpineObject Spine { get; } = spine;
|
||||
|
||||
[DisplayName("基本信息")]
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "basicInfo")]
|
||||
public SpineBaseInfoProperty BaseInfo { get; } = new(spine);
|
||||
|
||||
[DisplayName("渲染")]
|
||||
public SpineRenderProperty Render { get; } = new(spine);
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "render")]
|
||||
public SpineRenderProperty Render { get; } = new(spine);
|
||||
|
||||
[DisplayName("变换")]
|
||||
public SpineTransformProperty Transform { get; } = new(spine);
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "transform")]
|
||||
public SpineTransformProperty Transform { get; } = new(spine);
|
||||
|
||||
[TypeConverter(typeof(ExpandableObjectConverter))]
|
||||
[DisplayName("皮肤")]
|
||||
public SpineSkinProperty Skin { get; } = new(spine);
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "skin")]
|
||||
public SpineSkinProperty Skin { get; } = new(spine);
|
||||
|
||||
[TypeConverter(typeof(ExpandableObjectConverter))]
|
||||
[DisplayName("插槽")]
|
||||
public SpineSlotProperty Slot { get; } = new(spine);
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "slot")]
|
||||
public SpineSlotProperty Slot { get; } = new(spine);
|
||||
|
||||
[TypeConverter(typeof(ExpandableObjectConverter))]
|
||||
[DisplayName("动画")]
|
||||
public SpineAnimationProperty Animation { get; } = new(spine);
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "animation")]
|
||||
public SpineAnimationProperty Animation { get; } = new(spine);
|
||||
|
||||
[DisplayName("调试")]
|
||||
public SpineDebugProperty Debug { get; } = new(spine);
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "debug")]
|
||||
public SpineDebugProperty Debug { get; } = new(spine);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SpineViewer.Spine;
|
||||
using SpineViewer.Utils.Localize;
|
||||
|
||||
namespace SpineViewer.Spine.SpineView
|
||||
{
|
||||
@@ -16,16 +17,16 @@ namespace SpineViewer.Spine.SpineView
|
||||
[Browsable(false)]
|
||||
public SpineObject Spine { get; } = spine;
|
||||
|
||||
/// <summary>
|
||||
/// 是否被隐藏, 被隐藏的模型将仅仅在列表显示, 不参与其他行为
|
||||
/// </summary>
|
||||
[DisplayName("是否隐藏")]
|
||||
/// <summary>
|
||||
/// 是否被隐藏, 被隐藏的模型将仅仅在列表显示, 不参与其他行为
|
||||
/// </summary>
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "isHidden")]
|
||||
public bool IsHidden { get => Spine.IsHidden; set => Spine.IsHidden = value; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否使用预乘Alpha
|
||||
/// </summary>
|
||||
[DisplayName("预乘Alpha通道")]
|
||||
public bool UsePremultipliedAlpha { get => Spine.UsePma; set => Spine.UsePma = value; }
|
||||
/// <summary>
|
||||
/// 是否使用预乘Alpha
|
||||
/// </summary>
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "usePremultipliedAlpha")]
|
||||
public bool UsePremultipliedAlpha { get => Spine.UsePma; set => Spine.UsePma = value; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SpineViewer.Spine;
|
||||
using SpineViewer.Utils;
|
||||
using SpineViewer.Utils.Localize;
|
||||
|
||||
namespace SpineViewer.Spine.SpineView
|
||||
{
|
||||
@@ -17,29 +18,29 @@ namespace SpineViewer.Spine.SpineView
|
||||
[Browsable(false)]
|
||||
public SpineObject Spine { get; } = spine;
|
||||
|
||||
/// <summary>
|
||||
/// 缩放比例
|
||||
/// </summary>
|
||||
[DisplayName("缩放比例")]
|
||||
/// <summary>
|
||||
/// 缩放比例
|
||||
/// </summary>
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "scale")]
|
||||
public float Scale { get => Spine.Scale; set => Spine.Scale = value; }
|
||||
|
||||
/// <summary>
|
||||
/// 位置
|
||||
/// </summary>
|
||||
[TypeConverter(typeof(PointFConverter))]
|
||||
[DisplayName("位置")]
|
||||
public PointF Position { get => Spine.Position; set => Spine.Position = value; }
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "position")]
|
||||
public PointF Position { get => Spine.Position; set => Spine.Position = value; }
|
||||
|
||||
/// <summary>
|
||||
/// 水平翻转
|
||||
/// </summary>
|
||||
[DisplayName("水平翻转")]
|
||||
public bool FlipX { get => Spine.FlipX; set => Spine.FlipX = value; }
|
||||
/// <summary>
|
||||
/// 水平翻转
|
||||
/// </summary>
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "flipX")]
|
||||
public bool FlipX { get => Spine.FlipX; set => Spine.FlipX = value; }
|
||||
|
||||
/// <summary>
|
||||
/// 垂直翻转
|
||||
/// </summary>
|
||||
[DisplayName("垂直翻转")]
|
||||
public bool FlipY { get => Spine.FlipY; set => Spine.FlipY = value; }
|
||||
/// <summary>
|
||||
/// 垂直翻转
|
||||
/// </summary>
|
||||
[LocalizedDisplayName(typeof(Properties.Resources), "flipY")]
|
||||
public bool FlipY { get => Spine.FlipY; set => Spine.FlipY = value; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,10 @@ namespace SpineViewer.Utils.Localize
|
||||
{
|
||||
public static class LocalizeConfiguration
|
||||
{
|
||||
static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public static void UpdateLocalizeSetting(string newCulture)
|
||||
{
|
||||
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
||||
|
||||
if (config.AppSettings.Settings["localize"] != null)
|
||||
config.AppSettings.Settings["localize"].Value = newCulture;
|
||||
else
|
||||
@@ -29,15 +28,14 @@ namespace SpineViewer.Utils.Localize
|
||||
public static void SetCulture()
|
||||
{
|
||||
string cultureName = ConfigurationManager.AppSettings["localize"];
|
||||
logger.Info($"Culture name: {cultureName}");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(cultureName))
|
||||
{
|
||||
Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-CN");
|
||||
Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-CN");
|
||||
cultureName = "zh-CN";
|
||||
}
|
||||
try
|
||||
{
|
||||
|
||||
var culture = new CultureInfo(cultureName);
|
||||
Thread.CurrentThread.CurrentCulture = culture;
|
||||
Thread.CurrentThread.CurrentUICulture = culture;
|
||||
@@ -47,6 +45,8 @@ namespace SpineViewer.Utils.Localize
|
||||
Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-CN");
|
||||
Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-CN");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ namespace SpineViewer.Utils
|
||||
if (s.Length == 4) // #RGB
|
||||
return ParseShortHexColor(s, includeAlpha: false);
|
||||
|
||||
throw new FormatException("无法解析颜色,请使用 #RRGGBBAA、#RRGGBB、#RGBA 或 #RGB 格式");
|
||||
throw new FormatException(Properties.Resources.formatExceptionParseColor);
|
||||
}
|
||||
|
||||
// 处理 R,G,B,A 和 R,G,B 格式
|
||||
@@ -207,11 +207,11 @@ namespace SpineViewer.Utils
|
||||
if (color.IsKnownColor || color.IsNamedColor)
|
||||
return new SFML.Graphics.Color(color.R, color.G, color.B, color.A);
|
||||
|
||||
throw new FormatException("无法解析颜色,请使用已知的颜色名称");
|
||||
throw new FormatException(Properties.Resources.formatExceptionUnknownColor);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new FormatException("无法解析颜色,请检查格式", ex);
|
||||
throw new FormatException(Properties.Resources.formatExceptionParseColorError, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user