增加语言设置

This commit is contained in:
ww-rm
2025-06-14 01:57:39 +08:00
parent b3010360b4
commit 7ec938b415
14 changed files with 265 additions and 137 deletions

View File

@@ -6,6 +6,7 @@ using SpineViewer.Models;
using SpineViewer.Services;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Text;
@@ -105,7 +106,8 @@ namespace SpineViewer.ViewModels.MainWindow
DebugBoundingBoxes = DebugBoundingBoxes,
DebugPaths = DebugPaths,
DebugPoints = DebugPoints,
DebugClippings = DebugClippings
DebugClippings = DebugClippings,
AppLanguage = AppLanguage,
};
}
set
@@ -124,6 +126,7 @@ namespace SpineViewer.ViewModels.MainWindow
DebugPaths = value.DebugPaths;
DebugPoints = value.DebugPoints;
DebugClippings = value.DebugClippings;
AppLanguage = value.AppLanguage;
}
}
@@ -149,42 +152,88 @@ namespace SpineViewer.ViewModels.MainWindow
#endregion
// TODO: 是否自动记忆模型参数
#region
public bool UsePma { get => _usePma; set => SetProperty(ref _usePma, value); }
private bool _usePma;
// TODO: 是否自动记忆模型参数
public bool DebugTexture { get => _debugTexture; set => SetProperty(ref _debugTexture, value); }
private bool _debugTexture = true;
public bool UsePma
{
get => SpineObjectListViewModel.LoadOptions.UsePma;
set => SetProperty(SpineObjectListViewModel.LoadOptions.UsePma, value, v => SpineObjectListViewModel.LoadOptions.UsePma = v);
}
public bool DebugBounds { get => _debugBounds; set => SetProperty(ref _debugBounds, value); }
private bool _debugBounds;
public bool DebugTexture
{
get => SpineObjectListViewModel.LoadOptions.DebugTexture;
set => SetProperty(SpineObjectListViewModel.LoadOptions.DebugTexture, value, v => SpineObjectListViewModel.LoadOptions.DebugTexture = v);
}
public bool DebugBones { get => _debugBones; set => SetProperty(ref _debugBones, value); }
private bool _debugBones;
public bool DebugBounds
{
get => SpineObjectListViewModel.LoadOptions.DebugBounds;
set => SetProperty(SpineObjectListViewModel.LoadOptions.DebugBounds, value, v => SpineObjectListViewModel.LoadOptions.DebugBounds = v);
}
public bool DebugRegions { get => _debugRegions; set => SetProperty(ref _debugRegions, value); }
private bool _debugRegions;
public bool DebugBones
{
get => SpineObjectListViewModel.LoadOptions.DebugBones;
set => SetProperty(SpineObjectListViewModel.LoadOptions.DebugBones, value, v => SpineObjectListViewModel.LoadOptions.DebugBones = v);
}
public bool DebugMeshHulls { get => _debugMeshHulls; set => SetProperty(ref _debugMeshHulls, value); }
private bool _debugMeshHulls;
public bool DebugRegions
{
get => SpineObjectListViewModel.LoadOptions.DebugRegions;
set => SetProperty(SpineObjectListViewModel.LoadOptions.DebugRegions, value, v => SpineObjectListViewModel.LoadOptions.DebugRegions = v);
}
public bool DebugMeshes { get => _debugMeshes; set => SetProperty(ref _debugMeshes, value); }
private bool _debugMeshes;
public bool DebugMeshHulls
{
get => SpineObjectListViewModel.LoadOptions.DebugMeshHulls;
set => SetProperty(SpineObjectListViewModel.LoadOptions.DebugMeshHulls, value, v => SpineObjectListViewModel.LoadOptions.DebugMeshHulls = v);
}
public bool DebugBoundingBoxes { get => _debugBoundingBoxes; set => SetProperty(ref _debugBoundingBoxes, value); }
private bool _debugBoundingBoxes;
public bool DebugMeshes
{
get => SpineObjectListViewModel.LoadOptions.DebugMeshes;
set => SetProperty(SpineObjectListViewModel.LoadOptions.DebugMeshes, value, v => SpineObjectListViewModel.LoadOptions.DebugMeshes = v);
}
public bool DebugPaths { get => _debugPaths; set => SetProperty(ref _debugPaths, value); }
private bool _debugPaths;
public bool DebugBoundingBoxes
{
get => SpineObjectListViewModel.LoadOptions.DebugBoundingBoxes;
set => SetProperty(SpineObjectListViewModel.LoadOptions.DebugBoundingBoxes, value, v => SpineObjectListViewModel.LoadOptions.DebugBoundingBoxes = v);
}
public bool DebugPoints { get => _debugPoints; set => SetProperty(ref _debugPoints, value); }
private bool _debugPoints;
public bool DebugPaths
{
get => SpineObjectListViewModel.LoadOptions.DebugPaths;
set => SetProperty(SpineObjectListViewModel.LoadOptions.DebugPaths, value, v => SpineObjectListViewModel.LoadOptions.DebugPaths = v);
}
public bool DebugClippings { get => _debugClippings; set => SetProperty(ref _debugClippings, value); }
private bool _debugClippings;
public bool DebugPoints
{
get => SpineObjectListViewModel.LoadOptions.DebugPoints;
set => SetProperty(SpineObjectListViewModel.LoadOptions.DebugPoints, value, v => SpineObjectListViewModel.LoadOptions.DebugPoints = v);
}
public bool DebugClippings
{
get => SpineObjectListViewModel.LoadOptions.DebugClippings;
set => SetProperty(SpineObjectListViewModel.LoadOptions.DebugClippings, value, v => SpineObjectListViewModel.LoadOptions.DebugClippings = v);
}
#endregion
#region
public static ImmutableArray<AppLanguage> AppLanguageOptions { get; } = Enum.GetValues<AppLanguage>().ToImmutableArray();
public AppLanguage AppLanguage
{
get => ((App)App.Current).Language;
set => SetProperty(((App)App.Current).Language, value, v => ((App)App.Current).Language = v);
}
#endregion
}

View File

@@ -21,6 +21,12 @@ namespace SpineViewer.ViewModels.MainWindow
{
public class SpineObjectListViewModel : ObservableObject
{
/// <summary>
/// 加载选项
/// </summary>
public static SpineLoadOptions LoadOptions => _loadOptions;
private static readonly SpineLoadOptions _loadOptions = new();
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
/// <summary>
@@ -249,41 +255,6 @@ namespace SpineViewer.ViewModels.MainWindow
return true;
}
/// <summary>
/// 安全地在末尾添加一个模型, 发生错误会输出日志
/// </summary>
/// <returns>是否添加成功</returns>
public bool AddSpineObject(string skelPath, string? atlasPath = null)
{
try
{
// TODO: 判断是否记忆参数
var pre = _vmMain.PreferenceViewModel;
var sp = new SpineObjectModel(skelPath, atlasPath)
{
UsePma = pre.UsePma,
DebugTexture = pre.DebugTexture,
DebugBounds = pre.DebugBounds,
DebugRegions = pre.DebugRegions,
DebugMeshHulls = pre.DebugMeshHulls,
DebugMeshes = pre.DebugMeshes,
DebugBoundingBoxes = pre.DebugBoundingBoxes,
DebugPaths = pre.DebugPaths,
DebugPoints = pre.DebugPoints,
DebugClippings = pre.DebugClippings
};
lock (_spineObjectModels.Lock) _spineObjectModels.Add(sp);
return true;
}
catch (Exception ex)
{
_logger.Trace(ex.ToString());
_logger.Error("Failed to load: {0}, {1}", skelPath, ex.Message);
}
return false;
}
/// <summary>
/// 从路径列表添加对象
/// </summary>
@@ -369,5 +340,54 @@ namespace SpineViewer.ViewModels.MainWindow
_logger.LogCurrentProcessMemoryUsage();
}
/// <summary>
/// 安全地在末尾添加一个模型, 发生错误会输出日志
/// </summary>
/// <returns>是否添加成功</returns>
public bool AddSpineObject(string skelPath, string? atlasPath = null)
{
try
{
var sp = new SpineObjectModel(skelPath, atlasPath)
{
UsePma = _loadOptions.UsePma,
DebugTexture = _loadOptions.DebugTexture,
DebugBounds = _loadOptions.DebugBounds,
DebugRegions = _loadOptions.DebugRegions,
DebugMeshHulls = _loadOptions.DebugMeshHulls,
DebugMeshes = _loadOptions.DebugMeshes,
DebugBoundingBoxes = _loadOptions.DebugBoundingBoxes,
DebugPaths = _loadOptions.DebugPaths,
DebugPoints = _loadOptions.DebugPoints,
DebugClippings = _loadOptions.DebugClippings
};
lock (_spineObjectModels.Lock) _spineObjectModels.Add(sp);
return true;
}
catch (Exception ex)
{
_logger.Trace(ex.ToString());
_logger.Error("Failed to load: {0}, {1}", skelPath, ex.Message);
}
return false;
}
public class SpineLoadOptions
{
// TODO: 判断是否记忆参数
public bool UsePma { get; set; }
public bool DebugTexture { get; set; } = true;
public bool DebugBounds { get; set; }
public bool DebugBones { get; set; }
public bool DebugRegions { get; set; }
public bool DebugMeshHulls { get; set; }
public bool DebugMeshes { get; set; }
public bool DebugBoundingBoxes { get; set; }
public bool DebugPaths { get; set; }
public bool DebugPoints { get; set; }
public bool DebugClippings { get; set; }
}
}
}