Skip to content

Commit

Permalink
[HaRepacker] Page up, down to swap between spine skins
Browse files Browse the repository at this point in the history
  • Loading branch information
lastbattle committed Feb 16, 2021
1 parent fbac03f commit 100dbf3
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions HaSharedLibrary/GUI/SpineAnimationWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class SpineAnimationWindow : Microsoft.Xna.Framework.Game
private SpriteFont font;


//
private int spineSkinIndex = 0;

/// <summary>
/// Constructor
/// </summary>
Expand All @@ -69,7 +72,7 @@ public SpineAnimationWindow(WzSpineAnimationItem spineAnimationItem, string titl
SupportedOrientations = DisplayOrientation.Default,
PreferredBackBufferWidth = 1366,
PreferredBackBufferHeight = 768,
PreferredBackBufferFormat = SurfaceFormat.Color,
PreferredBackBufferFormat = SurfaceFormat.Color /*RGBA8888*/ | SurfaceFormat.Bgr32 | SurfaceFormat.Dxt1 | SurfaceFormat.Dxt5 ,
PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8,
};
graphicsDeviceMgr.ApplyChanges();
Expand Down Expand Up @@ -111,7 +114,10 @@ protected override void LoadContent()
// Skin
Skin skin = wzSpineObject.spineAnimationItem.SkeletonData.Skins.FirstOrDefault(); // just set the first skin
if (skin != null)
{
wzSpineObject.skeleton.SetSkin(skin.Name);
}
this.spineSkinIndex = 0;

// Define mixing between animations.
wzSpineObject.stateData = new AnimationStateData(wzSpineObject.skeleton.Data);
Expand Down Expand Up @@ -201,6 +207,26 @@ protected override void Update(GameTime gameTime)
if (bIsRightKeyPressed)
wzSpineObject.skeleton.X -= MOVE_XY_POSITION;

// Swap between skins
if (Keyboard.GetState().IsKeyDown(Keys.PageUp))
{
if (this.spineSkinIndex != 0)
this.spineSkinIndex--;
else
this.spineSkinIndex = wzSpineObject.spineAnimationItem.SkeletonData.Skins.Count() - 1;

wzSpineObject.skeleton.SetSkin(wzSpineObject.spineAnimationItem.SkeletonData.Skins[this.spineSkinIndex]);
}
else if (Keyboard.GetState().IsKeyDown(Keys.PageDown))
{
if (this.spineSkinIndex + 1 < wzSpineObject.spineAnimationItem.SkeletonData.Skins.Count())
this.spineSkinIndex++;
else
this.spineSkinIndex = 0;

wzSpineObject.skeleton.SetSkin(wzSpineObject.spineAnimationItem.SkeletonData.Skins[this.spineSkinIndex]);
}

base.Update(gameTime);
}

Expand Down Expand Up @@ -236,7 +262,12 @@ protected override void Draw(GameTime gameTime)

spriteBatch.Begin();
if (gameTime.TotalGameTime.TotalSeconds < 3)
spriteBatch.DrawString(font, "Press [Left] [Right] [Up] [Down] [Shift] for navigation.", new Vector2(20, 10), Color.White);
spriteBatch.DrawString(font,
string.Format("Press [Left] [Right] [Up] [Down] [Shift] for navigation.{0}{1}",
Environment.NewLine,
wzSpineObject.spineAnimationItem.SkeletonData.Skins.Count() > 1 ? "[Page up] [Page down] to swap between skins." : string.Empty),
new Vector2(20, 10),
Color.White);

spriteBatch.End();

Expand Down

0 comments on commit 100dbf3

Please sign in to comment.