增加骨骼文件重载功能
This commit is contained in:
@@ -19,6 +19,7 @@ namespace SpineViewer.Resources
|
||||
public static string Str_GeneratePreviewsTitle => Get<string>("Str_GeneratePreviewsTitle");
|
||||
public static string Str_DeletePreviewsTitle => Get<string>("Str_DeletePreviewsTitle");
|
||||
public static string Str_AddSpineObjectsTitle => Get<string>("Str_AddSpineObjectsTitle");
|
||||
public static string Str_ReloadSpineObjectsTitle => Get<string>("Str_ReloadSpineObjectsTitle");
|
||||
public static string Str_CustomFFmpegExporterTitle => Get<string>("Str_CustomFFmpegExporterTitle");
|
||||
|
||||
public static string Str_InfoPopup => Get<string>("Str_InfoPopup");
|
||||
|
||||
@@ -36,9 +36,10 @@
|
||||
<s:String x:Key="Str_ListViewStatusBar">{0} items, {1} selected</s:String>
|
||||
<s:String x:Key="Str_AddSpineObject">Add...</s:String>
|
||||
<s:String x:Key="Str_RemoveSpineObject">Remove</s:String>
|
||||
<s:String x:Key="Str_AddSpineObjectFromClipboard">Add from Clipboard</s:String>
|
||||
<s:String x:Key="Str_Reload">Reload</s:String>
|
||||
<s:String x:Key="Str_MoveUpSpineObject">Move Up</s:String>
|
||||
<s:String x:Key="Str_MoveDownSpineObject">Move Down</s:String>
|
||||
<s:String x:Key="Str_AddSpineObjectFromClipboard">Add from Clipboard</s:String>
|
||||
<s:String x:Key="Str_CopySpineObjectConfig">Copy Config</s:String>
|
||||
<s:String x:Key="Str_ApplySpineObjectConfig">Apply Config</s:String>
|
||||
<s:String x:Key="Str_SaveSpineObjectConfigToFile">Save Config to File...</s:String>
|
||||
@@ -120,6 +121,7 @@
|
||||
<s:String x:Key="Str_GeneratePreviewsTitle">Generate Previews</s:String>
|
||||
<s:String x:Key="Str_DeletePreviewsTitle">Delete Previews</s:String>
|
||||
<s:String x:Key="Str_AddSpineObjectsTitle">Batch Add Spine Files</s:String>
|
||||
<s:String x:Key="Str_ReloadSpineObjectsTitle">Reload Spine Files</s:String>
|
||||
|
||||
<s:String x:Key="Str_InfoPopup">Information</s:String>
|
||||
<s:String x:Key="Str_WarnPopup">Warning</s:String>
|
||||
|
||||
@@ -36,9 +36,10 @@
|
||||
<s:String x:Key="Str_ListViewStatusBar">全{0}件、選択中{1}件</s:String>
|
||||
<s:String x:Key="Str_AddSpineObject">追加...</s:String>
|
||||
<s:String x:Key="Str_RemoveSpineObject">削除</s:String>
|
||||
<s:String x:Key="Str_AddSpineObjectFromClipboard">クリップボードから追加</s:String>
|
||||
<s:String x:Key="Str_Reload">再読み込み</s:String>
|
||||
<s:String x:Key="Str_MoveUpSpineObject">上へ移動</s:String>
|
||||
<s:String x:Key="Str_MoveDownSpineObject">下へ移動</s:String>
|
||||
<s:String x:Key="Str_AddSpineObjectFromClipboard">クリップボードから追加</s:String>
|
||||
<s:String x:Key="Str_CopySpineObjectConfig">パラメーターをコピー</s:String>
|
||||
<s:String x:Key="Str_ApplySpineObjectConfig">パラメーターを適用</s:String>
|
||||
<s:String x:Key="Str_SaveSpineObjectConfigToFile">パラメータファイルを保存...</s:String>
|
||||
@@ -120,6 +121,7 @@
|
||||
<s:String x:Key="Str_GeneratePreviewsTitle">プレビューを生成</s:String>
|
||||
<s:String x:Key="Str_DeletePreviewsTitle">プレビューを削除</s:String>
|
||||
<s:String x:Key="Str_AddSpineObjectsTitle">一括でスケルトンファイルを追加</s:String>
|
||||
<s:String x:Key="Str_ReloadSpineObjectsTitle">スケルトンファイルの再読み込み</s:String>
|
||||
|
||||
<s:String x:Key="Str_InfoPopup">情報</s:String>
|
||||
<s:String x:Key="Str_WarnPopup">警告</s:String>
|
||||
|
||||
@@ -36,9 +36,10 @@
|
||||
<s:String x:Key="Str_ListViewStatusBar">共 {0} 项,已选择 {1} 项</s:String>
|
||||
<s:String x:Key="Str_AddSpineObject">添加...</s:String>
|
||||
<s:String x:Key="Str_RemoveSpineObject">移除</s:String>
|
||||
<s:String x:Key="Str_AddSpineObjectFromClipboard">从剪贴板添加</s:String>
|
||||
<s:String x:Key="Str_Reload">重新加载</s:String>
|
||||
<s:String x:Key="Str_MoveUpSpineObject">上移</s:String>
|
||||
<s:String x:Key="Str_MoveDownSpineObject">下移</s:String>
|
||||
<s:String x:Key="Str_AddSpineObjectFromClipboard">从剪贴板添加</s:String>
|
||||
<s:String x:Key="Str_CopySpineObjectConfig">复制参数</s:String>
|
||||
<s:String x:Key="Str_ApplySpineObjectConfig">应用参数</s:String>
|
||||
<s:String x:Key="Str_SaveSpineObjectConfigToFile">保存参数文件...</s:String>
|
||||
@@ -120,6 +121,7 @@
|
||||
<s:String x:Key="Str_GeneratePreviewsTitle">生成预览图</s:String>
|
||||
<s:String x:Key="Str_DeletePreviewsTitle">删除预览图</s:String>
|
||||
<s:String x:Key="Str_AddSpineObjectsTitle">批量添加骨骼文件</s:String>
|
||||
<s:String x:Key="Str_ReloadSpineObjectsTitle">重新加载骨骼文件</s:String>
|
||||
|
||||
<s:String x:Key="Str_InfoPopup">提示信息</s:String>
|
||||
<s:String x:Key="Str_WarnPopup">警告信息</s:String>
|
||||
|
||||
@@ -15,6 +15,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Shell;
|
||||
|
||||
namespace SpineViewer.ViewModels.MainWindow
|
||||
@@ -111,7 +112,7 @@ namespace SpineViewer.ViewModels.MainWindow
|
||||
|
||||
private void RemoveSpineObject_Execute(IList? args)
|
||||
{
|
||||
if (args is null) return;
|
||||
if (!RemoveSpineObject_CanExecute(args)) return;
|
||||
|
||||
if (args.Count > 1)
|
||||
{
|
||||
@@ -137,6 +138,121 @@ namespace SpineViewer.ViewModels.MainWindow
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从剪贴板文件列表添加模型
|
||||
/// </summary>
|
||||
public RelayCommand Cmd_AddSpineObjectFromClipboard => _cmd_AddSpineObjectFromClipboard ??= new(AddSpineObjectFromClipboard_Execute);
|
||||
private RelayCommand? _cmd_AddSpineObjectFromClipboard;
|
||||
|
||||
private void AddSpineObjectFromClipboard_Execute()
|
||||
{
|
||||
if (!Clipboard.ContainsFileDropList()) return;
|
||||
AddSpineObjectFromFileList(Clipboard.GetFileDropList().Cast<string>().ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重新加载模型
|
||||
/// </summary>
|
||||
public RelayCommand<IList?> Cmd_ReloadSpineObject => _cmd_ReloadSpineObject ??= new(ReloadSpineObject_Execute, ReloadSpineObject_CanExecute);
|
||||
private RelayCommand<IList?>? _cmd_ReloadSpineObject;
|
||||
|
||||
private void ReloadSpineObject_Execute(IList? args)
|
||||
{
|
||||
if (!ReloadSpineObject_CanExecute(args)) return;
|
||||
|
||||
if (args.Count <= 1)
|
||||
{
|
||||
lock (_spineObjectModels.Lock)
|
||||
{
|
||||
var sp = (SpineObjectModel)args[0];
|
||||
var idx = _spineObjectModels.IndexOf(sp);
|
||||
if (idx < 0) return;
|
||||
|
||||
try
|
||||
{
|
||||
var spNew = new SpineObjectModel(sp.SkelPath, sp.AtlasPath);
|
||||
spNew.Load(sp.Dump());
|
||||
_spineObjectModels[idx] = spNew;
|
||||
sp.Dispose();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error("Failed to reload spine {0}, {1}", sp.SkelPath, ex.Message);
|
||||
_logger.Trace(ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ProgressService.RunAsync((pr, ct) => ReloadSpineObjectsTask(
|
||||
args.Cast<SpineObjectModel>().ToArray(), pr, ct),
|
||||
AppResource.Str_ReloadSpineObjectsTitle
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private bool ReloadSpineObject_CanExecute(IList? args)
|
||||
{
|
||||
if (args is null) return false;
|
||||
if (args.Count <= 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ReloadSpineObjectsTask(SpineObjectModel[] spines, IProgressReporter reporter, CancellationToken ct)
|
||||
{
|
||||
int totalCount = spines.Length;
|
||||
int success = 0;
|
||||
int error = 0;
|
||||
|
||||
_vmMain.ProgressState = TaskbarItemProgressState.Normal;
|
||||
_vmMain.ProgressValue = 0;
|
||||
|
||||
reporter.Total = totalCount;
|
||||
reporter.Done = 0;
|
||||
reporter.ProgressText = $"[0/{totalCount}]";
|
||||
for (int i = 0; i < totalCount; i++)
|
||||
{
|
||||
if (ct.IsCancellationRequested) break;
|
||||
|
||||
var sp = spines[i];
|
||||
reporter.ProgressText = $"[{i}/{totalCount}] {sp.Name}";
|
||||
|
||||
lock (_spineObjectModels.Lock)
|
||||
{
|
||||
var idx = _spineObjectModels.IndexOf(sp);
|
||||
if (idx >= 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
var spNew = new SpineObjectModel(sp.SkelPath, sp.AtlasPath);
|
||||
spNew.Load(sp.Dump());
|
||||
_spineObjectModels[idx] = spNew;
|
||||
sp.Dispose();
|
||||
success++;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error++;
|
||||
_logger.Error("Failed to reload spine {0}, {1}", sp.SkelPath, ex.Message);
|
||||
_logger.Trace(ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reporter.Done = i + 1;
|
||||
reporter.ProgressText = $"[{i + 1}/{totalCount}] {sp.Name}";
|
||||
_vmMain.ProgressValue = (i + 1f) / totalCount;
|
||||
}
|
||||
_vmMain.ProgressState = TaskbarItemProgressState.None;
|
||||
|
||||
if (error > 0)
|
||||
_logger.Warn("Batch reload {0} successfully, {1} failed", success, error);
|
||||
else
|
||||
_logger.Info("{0} skel reloaded successfully", success);
|
||||
|
||||
_logger.LogCurrentProcessMemoryUsage();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 模型上移一位
|
||||
/// </summary>
|
||||
@@ -145,8 +261,7 @@ namespace SpineViewer.ViewModels.MainWindow
|
||||
|
||||
private void MoveUpSpineObject_Execute(IList? args)
|
||||
{
|
||||
if (args is null) return;
|
||||
if (args.Count != 1) return;
|
||||
if (!MoveUpSpineObject_CanExecute(args)) return;
|
||||
var sp = (SpineObjectModel)args[0];
|
||||
lock (_spineObjectModels.Lock)
|
||||
{
|
||||
@@ -171,8 +286,7 @@ namespace SpineViewer.ViewModels.MainWindow
|
||||
|
||||
private void MoveDownSpineObject_Execute(IList? args)
|
||||
{
|
||||
if (args is null) return;
|
||||
if (args.Count != 1) return;
|
||||
if (!MoveDownSpineObject_CanExecute(args)) return;
|
||||
var sp = (SpineObjectModel)args[0];
|
||||
lock (_spineObjectModels.Lock)
|
||||
{
|
||||
@@ -189,18 +303,6 @@ namespace SpineViewer.ViewModels.MainWindow
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从剪贴板文件列表添加模型
|
||||
/// </summary>
|
||||
public RelayCommand Cmd_AddSpineObjectFromClipboard => _cmd_AddSpineObjectFromClipboard ??= new(AddSpineObjectFromClipboard_Execute);
|
||||
private RelayCommand? _cmd_AddSpineObjectFromClipboard;
|
||||
|
||||
private void AddSpineObjectFromClipboard_Execute()
|
||||
{
|
||||
if (!Clipboard.ContainsFileDropList()) return;
|
||||
AddSpineObjectFromFileList(Clipboard.GetFileDropList().Cast<string>().ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 复制模型参数
|
||||
/// </summary>
|
||||
@@ -209,8 +311,7 @@ namespace SpineViewer.ViewModels.MainWindow
|
||||
|
||||
private void CopySpineObjectConfig_Execute(IList? args)
|
||||
{
|
||||
if (args is null) return;
|
||||
if (args.Count != 1) return;
|
||||
if (!CopySpineObjectConfig_CanExecute(args)) return;
|
||||
var sp = (SpineObjectModel)args[0];
|
||||
_copiedSpineObjectConfigModel = sp.Dump();
|
||||
_logger.Info("Copy config from model: {0}", sp.Name);
|
||||
@@ -231,9 +332,7 @@ namespace SpineViewer.ViewModels.MainWindow
|
||||
|
||||
private void ApplySpineObjectConfig_Execute(IList? args)
|
||||
{
|
||||
if (_copiedSpineObjectConfigModel is null) return;
|
||||
if (args is null) return;
|
||||
if (args.Count <= 0) return;
|
||||
if (!ApplySpineObjectConfig_CanExecute(args)) return;
|
||||
foreach (SpineObjectModel sp in args)
|
||||
{
|
||||
sp.Load(_copiedSpineObjectConfigModel);
|
||||
|
||||
@@ -63,6 +63,7 @@ namespace SpineViewer.ViewModels
|
||||
|
||||
private void Cancel_Execute()
|
||||
{
|
||||
if (!Cancel_CanExecute()) return;
|
||||
if (!MessagePopupService.Quest(AppResource.Str_CancelQuest)) return;
|
||||
_cts.Cancel();
|
||||
Cmd_Cancel.NotifyCanExecuteChanged();
|
||||
|
||||
@@ -246,9 +246,10 @@
|
||||
<ListView.InputBindings>
|
||||
<KeyBinding Gesture="Ctrl+O" Command="{Binding Cmd_AddSpineObject}"/>
|
||||
<KeyBinding Gesture="Delete" Command="{Binding Cmd_RemoveSpineObject}" CommandParameter="{Binding SelectedItems, ElementName=_spinesListView}"/>
|
||||
<KeyBinding Gesture="Ctrl+V" Command="{Binding Cmd_AddSpineObjectFromClipboard}"/>
|
||||
<KeyBinding Gesture="Ctrl+R" Command="{Binding Cmd_ReloadSpineObject}" CommandParameter="{Binding SelectedItems, ElementName=_spinesListView}"/>
|
||||
<KeyBinding Gesture="Alt+W" Command="{Binding Cmd_MoveUpSpineObject}" CommandParameter="{Binding SelectedItems, ElementName=_spinesListView}"/>
|
||||
<KeyBinding Gesture="Alt+S" Command="{Binding Cmd_MoveDownSpineObject}" CommandParameter="{Binding SelectedItems, ElementName=_spinesListView}"/>
|
||||
<KeyBinding Gesture="Ctrl+V" Command="{Binding Cmd_AddSpineObjectFromClipboard}"/>
|
||||
<KeyBinding Gesture="Ctrl+Shift+C" Command="{Binding Cmd_CopySpineObjectConfig}" CommandParameter="{Binding SelectedItems, ElementName=_spinesListView}"/>
|
||||
<KeyBinding Gesture="Ctrl+Shift+V" Command="{Binding Cmd_ApplySpineObjectConfig}" CommandParameter="{Binding SelectedItems, ElementName=_spinesListView}"/>
|
||||
</ListView.InputBindings>
|
||||
@@ -262,6 +263,13 @@
|
||||
InputGestureText="Delete"
|
||||
Command="{Binding Cmd_RemoveSpineObject}"
|
||||
CommandParameter="{Binding PlacementTarget.SelectedItems, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"/>
|
||||
<MenuItem Header="{DynamicResource Str_AddSpineObjectFromClipboard}"
|
||||
InputGestureText="Ctrl+V"
|
||||
Command="{Binding Cmd_AddSpineObjectFromClipboard}"/>
|
||||
<MenuItem Header="{DynamicResource Str_Reload}"
|
||||
InputGestureText="Ctrl+R"
|
||||
Command="{Binding Cmd_ReloadSpineObject}"
|
||||
CommandParameter="{Binding PlacementTarget.SelectedItems, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="{DynamicResource Str_MoveUpSpineObject}"
|
||||
InputGestureText="Alt+W"
|
||||
@@ -272,10 +280,6 @@
|
||||
Command="{Binding Cmd_MoveDownSpineObject}"
|
||||
CommandParameter="{Binding PlacementTarget.SelectedItems, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="{DynamicResource Str_AddSpineObjectFromClipboard}"
|
||||
InputGestureText="Ctrl+V"
|
||||
Command="{Binding Cmd_AddSpineObjectFromClipboard}"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="{DynamicResource Str_CopySpineObjectConfig}"
|
||||
InputGestureText="Ctrl+Shift+C"
|
||||
Command="{Binding Cmd_CopySpineObjectConfig}"
|
||||
|
||||
Reference in New Issue
Block a user