Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## v0.16.13

- 增加 FFmpeg 下载页面跳转菜单项
- 增加 WorkerW 调试菜单功能
- 完善动画选择框功能, 允许滚轮和方向键快速切换
- 修改项目输出路径结构

## v0.16.12

- 修复 label 控件文字显示问题
Expand Down
2 changes: 1 addition & 1 deletion Spine/Spine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<BaseOutputPath>$(SolutionDir)out</BaseOutputPath>
<OutputPath>$(BaseOutputPath)\$(Configuration)\$(PlatformTarget)</OutputPath>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<Version>0.16.11</Version>
<Version>0.16.13</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
79 changes: 7 additions & 72 deletions SpineViewer/Models/SpineObjectModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,6 @@ public SpineObjectModel(SpineObjectWorkspaceConfigModel cfg)
_isShown = cfg.IsShown;
}

public event EventHandler<SkinStatusChangedEventArgs>? SkinStatusChanged;

public event EventHandler<SlotVisibleChangedEventArgs>? SlotVisibleChanged;

public event EventHandler<SlotAttachmentChangedEventArgs>? SlotAttachmentChanged;

public event EventHandler<TrackPropertyChangedEventArgs>? TrackPropertyChanged;

#region 参数面板实现

public SpineVersion Version => _spineObject.Version;
Expand Down Expand Up @@ -202,10 +194,7 @@ public bool GetSkinStatus(string skinName)

public bool SetSkinStatus(string skinName, bool status)
{
bool changed = false;
lock (_lock) changed = _spineObject.SetSkinStatus(skinName, status);
if (changed) SkinStatusChanged?.Invoke(this, new(skinName, status));
return changed;
lock (_lock) return _spineObject.SetSkinStatus(skinName, status);
}

public FrozenDictionary<string, ImmutableArray<string>> SlotAttachments => _slotAttachments;
Expand All @@ -217,10 +206,7 @@ public bool GetSlotVisible(string slotName)

public bool SetSlotVisible(string slotName, bool visible)
{
bool changed = false;
lock (_lock) changed = _spineObject.SetSlotVisible(slotName, visible);
if (changed) SlotVisibleChanged?.Invoke(this, new(slotName, visible));
return changed;
lock (_lock) return _spineObject.SetSlotVisible(slotName, visible);
}

public string? GetAttachment(string slotName)
Expand All @@ -230,10 +216,7 @@ public bool SetSlotVisible(string slotName, bool visible)

public bool SetAttachment(string slotName, string? attachmentName)
{
bool changed = false;
lock (_lock) changed = _spineObject.SetAttachment(slotName, attachmentName);
if (changed) SlotAttachmentChanged?.Invoke(this, new(slotName, attachmentName));
return changed;
lock (_lock) return _spineObject.SetAttachment(slotName, attachmentName);
}

public ImmutableArray<string> Animations => _animations;
Expand All @@ -255,7 +238,6 @@ public float GetAnimationDuration(string name)
/// </summary>
public void SetAnimation(int index, string name)
{
bool changed = false;
float lastTimeScale = 1f;
float lastAlpha = 1f;
lock (_lock)
Expand All @@ -277,10 +259,8 @@ public void SetAnimation(int index, string name)
{
_spineObject.Skeleton.SetSlotsToSetupPose();
}
changed = true;
}
}
if (changed) TrackPropertyChanged?.Invoke(this, new(index, nameof(TrackPropertyChangedEventArgs.AnimationName)));
}

public float GetTrackTimeScale(int index)
Expand All @@ -295,7 +275,6 @@ public void SetTrackTimeScale(int index, float scale)
if (_spineObject.AnimationState.GetCurrent(index) is ITrackEntry entry)
{
entry.TimeScale = Math.Clamp(scale, 0.01f, 100f);
TrackPropertyChanged?.Invoke(this, new(index, nameof(TrackPropertyChangedEventArgs.TimeScale)));
}
}
}
Expand All @@ -312,7 +291,6 @@ public void SetTrackAlpha(int index, float alpha)
if (_spineObject.AnimationState.GetCurrent(index) is ITrackEntry entry)
{
entry.Alpha = Math.Clamp(alpha, 0f, 1f);
TrackPropertyChanged?.Invoke(this, new(index, nameof(TrackPropertyChangedEventArgs.Alpha)));
}
}
}
Expand All @@ -335,7 +313,6 @@ public int[] GetTrackIndices()
public void ClearTrack(int index)
{
lock (_lock) _spineObject.AnimationState.ClearTrack(index);
TrackPropertyChanged?.Invoke(this, new(index, nameof(TrackPropertyChangedEventArgs.AnimationName)));
}

public void ResetAnimationsTime()
Expand Down Expand Up @@ -521,25 +498,21 @@ public void ApplyObjectConfig(SpineObjectConfigModel m, SpineObjectConfigApplyFl
if (flag == SpineObjectConfigApplyFlag.All || flag == SpineObjectConfigApplyFlag.Skin)
{
foreach (var name in _spineObject.Data.Skins.Select(v => v.Name).Except(m.LoadedSkins))
if (_spineObject.SetSkinStatus(name, false))
SkinStatusChanged?.Invoke(this, new(name, false));
_spineObject.SetSkinStatus(name, false);
foreach (var name in m.LoadedSkins)
if (_spineObject.SetSkinStatus(name, true))
SkinStatusChanged?.Invoke(this, new(name, true));
_spineObject.SetSkinStatus(name, true);
}

if (flag == SpineObjectConfigApplyFlag.SlotAttachement)
{
foreach (var (slotName, attachmentName) in m.SlotAttachment)
if (_spineObject.SetAttachment(slotName, attachmentName))
SlotAttachmentChanged?.Invoke(this, new(slotName, attachmentName));
_spineObject.SetAttachment(slotName, attachmentName);
}

if (flag == SpineObjectConfigApplyFlag.SlotVisibility)
{
foreach (var slotName in m.DisabledSlots)
if (_spineObject.SetSlotVisible(slotName, false))
SlotVisibleChanged?.Invoke(this, new(slotName, false));
_spineObject.SetSlotVisible(slotName, false);
}

if (flag == SpineObjectConfigApplyFlag.All)
Expand All @@ -554,7 +527,6 @@ public void ApplyObjectConfig(SpineObjectConfigModel m, SpineObjectConfigApplyFl
var tr = _spineObject.AnimationState.SetAnimation(trackIndex, trConfig.AnimationName, true);
tr.TimeScale = trConfig.TimeScale;
tr.Alpha = trConfig.Alpha;
TrackPropertyChanged?.Invoke(this, new(trackIndex, nameof(TrackPropertyChangedEventArgs.AnimationName)));
}
trackIndex++;
}
Expand Down Expand Up @@ -644,43 +616,6 @@ public enum SpineObjectConfigApplyFlag
SlotVisibility,
}

public class SkinStatusChangedEventArgs(string name, bool status) : EventArgs
{
public string Name { get; } = name;
public bool Status { get; } = status;
}

public class SlotVisibleChangedEventArgs(string slotName, bool visible) : EventArgs
{
public string SlotName { get; } = slotName;
public bool Visible { get; } = visible;
}

public class SlotAttachmentChangedEventArgs(string slotName, string? attachmentName) : EventArgs
{
public string SlotName { get; } = slotName;
public string? AttachmentName { get; } = attachmentName;
}

/// <summary>
/// 模型动画轨道属性变化事件参数, 需要检索 <c><see cref="PropertyName"/></c> 来确定发生变化的属性是什么
/// </summary>
/// <param name="trackIndex">发生属性变化的轨道索引</param>
/// <param name="propertyName">使用 <c>nameof</c> 设置发生改变的属性名</param>
public class TrackPropertyChangedEventArgs(int trackIndex, string propertyName) : EventArgs
{
public int TrackIndex { get; } = trackIndex;

/// <summary>
/// 发生变化的属性名, 将会使用 <c>nameof</c> 设置为属性名称字符串
/// </summary>
public string PropertyName { get; } = propertyName;

public string? AnimationName { get; }
public float TimeScale { get; } = 1f;
public float Alpha { get; } = 1f;
}

public class SpineObjectLoadOptions
{
public bool IsShown { get; set; } = true;
Expand Down
5 changes: 4 additions & 1 deletion SpineViewer/Resources/Theme.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
<ResourceDictionary x:Class="SpineViewer.Resources.Theme"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:o="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
Expand Down Expand Up @@ -45,13 +46,15 @@
</Style>
</Setter.Value>
</Setter>
<EventSetter Event="MouseLeftButtonDown" Handler="ListBox_MouseLeftButtonDown"/>
</Style>

<Style x:Key="MyListViewBaseStyle" TargetType="ListView" BasedOn="{StaticResource ListViewBaseStyle}">
<Setter Property="SelectionMode" Value="Extended"/>
<!--<Setter Property="VirtualizingPanel.IsVirtualizing" Value="False"/>-->
<Setter Property="Background" Value="Transparent"/>
<Setter Property="ItemContainerStyle" Value="{StaticResource ListViewItemBaseStyle.Small}"/>
<EventSetter Event="MouseLeftButtonDown" Handler="ListView_MouseLeftButtonDown"/>
</Style>

<Style x:Key="MyGroupBoxBaseStyle" TargetType="GroupBox" BasedOn="{StaticResource GroupBoxTab}">
Expand Down
29 changes: 29 additions & 0 deletions SpineViewer/Resources/Theme.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using SpineViewer.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace SpineViewer.Resources
{
public partial class Theme : ResourceDictionary
{
private void ListView_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var list = (ListView)sender;
if (((DependencyObject)e.OriginalSource)?.GetParent<ListViewItem>(true) is null)
list.SelectedItems.Clear();
}

private void ListBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var list = (ListBox)sender;
if (((DependencyObject)e.OriginalSource)?.GetParent<ListBoxItem>(true) is null)
list.SelectedItems.Clear();
}
}
}
2 changes: 1 addition & 1 deletion SpineViewer/SpineViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<BaseOutputPath>$(SolutionDir)out</BaseOutputPath>
<OutputPath>$(BaseOutputPath)\$(Configuration)\$(PlatformTarget)</OutputPath>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<Version>0.16.13-beta</Version>
<Version>0.16.13</Version>
<OutputType>WinExe</OutputType>
<UseWPF>true</UseWPF>
</PropertyGroup>
Expand Down
28 changes: 28 additions & 0 deletions SpineViewer/Utils/VisualTreeExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace SpineViewer.Utils
{
public static class VisualTreeExtension
{
/// <summary>
/// 向上查找指定类型的对象 (含源节点)
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source">源节点</param>
/// <param name="includeSource">是否包含源节点</param>
public static T? GetParent<T>(this DependencyObject source, bool includeSource = false) where T : DependencyObject
{
if (!includeSource)
source = VisualTreeHelper.GetParent(source);
while (source is not null && source is not T)
source = VisualTreeHelper.GetParent(source);
return source as T;
}
}
}
6 changes: 6 additions & 0 deletions SpineViewer/Utils/WorkerWDebugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Win32Natives;
Expand Down Expand Up @@ -42,8 +43,13 @@ public static void LogWorkerWSearchInfo()
// Send 0x052C to Progman. This message directs Progman to spawn a
// WorkerW behind the desktop icons. If it is already there, nothing
// happens.
Marshal.SetLastPInvokeError(0);
var ret = User32.SendMessageTimeout(progman, User32.WM_SPAWN_WORKER, 0, 0, User32.SMTO_NORMAL, 1000, out _);
var lastErr = Marshal.GetLastPInvokeError();
var lastErrMsg = Marshal.GetLastPInvokeErrorMessage();

_logger.Debug("SendMessageTimeout returned 0x{0:x8}", ret);
_logger.Debug("ErrCode: 0x{0:x8}, ErrMsg: {1}", lastErr, lastErrMsg);

// Spy++ output
// .....
Expand Down
Loading
Loading