Skip to content

Commit

Permalink
Common: Support Skeleton Skins.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kagamia committed Jul 8, 2017
1 parent 6248c91 commit 22093e7
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 21 deletions.
1 change: 1 addition & 0 deletions WzComparerR2.Common/Animation/SpineAnimationData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ private SpineAnimationData()

public bool PremultipliedAlpha { get; set; }
public SkeletonData SkeletonData { get; private set; }
public string DefaultSkin { get; set; }

public static SpineAnimationData CreateFromNode(Wz_Node atlasNode, bool? useJson, GraphicsDevice graphicsDevice, GlobalFindNodeFunction findNode)
{
Expand Down
22 changes: 20 additions & 2 deletions WzComparerR2.Common/Animation/SpineAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public SpineAnimator(SpineAnimationData data)

public ReadOnlyCollection<string> Animations { get; private set; }

public ReadOnlyCollection<string> Skins { get; private set; }

public int SelectedAnimationIndex
{
get
Expand Down Expand Up @@ -75,6 +77,12 @@ public string SelectedAnimationName
}
}

public string SelectedSkin
{
get { return this.Skeleton.Skin?.Name; }
set { this.Skeleton.SetSkin(value); }
}

public int CurrentTime
{
get { return (int)((this._animationState?.GetCurrent(0)?.Time ?? 0) * 1000); }
Expand Down Expand Up @@ -269,10 +277,20 @@ private LinkedList<KeyFrame> GetTimeLineKeyFrames(Timeline timeLine)
private void Load()
{
this.Skeleton = new Skeleton(this.Data.SkeletonData);
IList<string> aniNames = this.Data.SkeletonData.Animations.Select(ani => ani.Name).ToArray();
IList<string> aniNames = this.Data.SkeletonData.Animations.Select(ani => ani.Name).ToList();
this.Animations = new ReadOnlyCollection<string>(aniNames);
this._animationState = new AnimationState(new AnimationStateData(this.Data.SkeletonData));

this.Skins = new ReadOnlyCollection<string>(this.Data.SkeletonData.Skins.Select(skin => skin.Name).ToList());

if (!string.IsNullOrEmpty(this.Data.DefaultSkin))
{
var skin = this.Skeleton.Data.FindSkin(this.Data.DefaultSkin);
if (skin != null)
{
this.Skeleton.SetSkin(skin);
}
}

if (this.Animations.Count > 0)
{
this.SelectedAnimationIndex = 0;
Expand Down
51 changes: 32 additions & 19 deletions WzComparerR2/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions WzComparerR2/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,20 @@ private void cmbItemAniNames_SelectedIndexChanged(object sender, EventArgs e)
}
}

private void cmbItemSkins_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.cmbItemSkins.SelectedIndex > -1 && this.pictureBoxEx1.Items.Count > 0)
{
var aniItem = this.pictureBoxEx1.Items[0] as Animation.SpineAnimator;
if (aniItem != null)
{
string skinName = this.cmbItemSkins.SelectedItem as string;
aniItem.SelectedSkin = skinName;
this.cmbItemSkins.Tooltip = skinName;
}
}
}

private void buttonItemSaveImage_Click(object sender, EventArgs e)
{
if (this.pictureBoxEx1.Items.Count <= 0)
Expand Down Expand Up @@ -474,10 +488,16 @@ private void buttonItemGif_Click(object sender, EventArgs e)
{
this.pictureBoxEx1.ShowAnimation(spineData);
var aniItem = this.pictureBoxEx1.Items[0] as Animation.SpineAnimator;

this.cmbItemAniNames.Items.Clear();
this.cmbItemAniNames.Items.Add("");
this.cmbItemAniNames.Items.AddRange(aniItem.Animations.ToArray());
this.cmbItemAniNames.SelectedIndex = 0;

this.cmbItemSkins.Visible = true;
this.cmbItemSkins.Items.Clear();
this.cmbItemSkins.Items.AddRange(aniItem.Skins.ToArray());
this.cmbItemSkins.SelectedIndex = aniItem.Skins.IndexOf(aniItem.SelectedSkin);
}
}
else
Expand All @@ -488,6 +508,7 @@ private void buttonItemGif_Click(object sender, EventArgs e)
{
this.pictureBoxEx1.ShowAnimation(frameData);
this.cmbItemAniNames.Items.Clear();
this.cmbItemSkins.Visible = false;
}
}
this.pictureBoxEx1.PictureName = aniName;
Expand Down Expand Up @@ -2942,6 +2963,8 @@ private void btnItemOptions_Click(object sender, System.EventArgs e)
UpdateWzLoadingSettings();
}
}


}

#region 内部用扩展方法
Expand Down

0 comments on commit 22093e7

Please sign in to comment.