Skip to content

Commit

Permalink
Merge pull request #106 from lastbattle/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
lastbattle authored Feb 16, 2021
2 parents 5057b71 + c2d4b10 commit 22f62e7
Show file tree
Hide file tree
Showing 10 changed files with 341 additions and 125 deletions.
6 changes: 4 additions & 2 deletions HaCreator/GUI/EditorPanels/BackgroundPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,11 @@ private void bgItem_Click(object sender, MouseEventArgs e)
Thread thread = new Thread(() =>
{
WzSpineAnimationItem item = new WzSpineAnimationItem(stringObj);


string path_title = stringObj.Parent?.FullPath ?? "Animate";

// Create xna window
SpineAnimationWindow Window = new SpineAnimationWindow(item);
SpineAnimationWindow Window = new SpineAnimationWindow(item, path_title);
Window.Run();
});
thread.Start();
Expand Down
3 changes: 3 additions & 0 deletions HaCreator/GUI/Load.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ private void LoadButton_Click(object sender, EventArgs e)
}
else if (WZSelect.Checked)
{
if (mapBrowser.SelectedItem == null)
return; // racing event

string selectedName = mapBrowser.SelectedItem;

if (selectedName.StartsWith("MapLogin")) // MapLogin, MapLogin1, MapLogin2, MapLogin3
Expand Down
2 changes: 1 addition & 1 deletion HaCreator/MapSimulator/MapSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ private void DoScreenshot()
GraphicsDevice.GetBackBufferData(backBuffer);

//Copy to texture
using (Texture2D texture = new Texture2D(GraphicsDevice, RenderWidth, RenderHeight, false, SurfaceFormat.Color))
using (Texture2D texture = new Texture2D(GraphicsDevice, RenderWidth, RenderHeight, false, SurfaceFormat.Color /*RGBA8888*/))
{
texture.SetData(backBuffer);

Expand Down
4 changes: 2 additions & 2 deletions HaRepacker/GUI/Panels/ImageAnimationPreviewWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class ImageAnimationPreviewWindow : Microsoft.Xna.Framework.Game
/// Constructor
/// </summary>
/// <param name="selectedAnimationNodes"></param>
public ImageAnimationPreviewWindow(List<WzNode> selectedAnimationNodes)
public ImageAnimationPreviewWindow(List<WzNode> selectedAnimationNodes, string title_path)
{
this.selectedAnimationNodes = selectedAnimationNodes;

Expand All @@ -56,7 +56,7 @@ public ImageAnimationPreviewWindow(List<WzNode> selectedAnimationNodes)
//Window.AllowUserResizing = true;
//Window.IsBorderless = true;
//Window.Position = new Point(0, 0);
Window.Title = "Animation preview";
Window.Title = title_path;
IsFixedTimeStep = false; // dont cap fps
Content.RootDirectory = "Content";

Expand Down
10 changes: 8 additions & 2 deletions HaRepacker/GUI/Panels/MainPanel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Xna.Framework;
using Spine;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
Expand Down Expand Up @@ -634,11 +635,13 @@ public void StartAnimateSelectedCanvas()
selectedNodes.Add(node);
}

string path_title = ((WzNode)DataTree.SelectedNodes[0]).Parent?.FullPath ?? "Animate";

Thread thread = new Thread(() =>
{
try
{
ImageAnimationPreviewWindow previewWnd = new ImageAnimationPreviewWindow(selectedNodes);
ImageAnimationPreviewWindow previewWnd = new ImageAnimationPreviewWindow(selectedNodes, path_title);
previewWnd.Run();
}
catch (Exception ex)
Expand Down Expand Up @@ -1441,14 +1444,17 @@ private void ShowObjectValue(WzObject obj)
textEditor.SetHighlightingDefinitionIndex(20); // json
textEditor.textEditor.Text = obj.ToString();


string path_title = stringObj.Parent?.FullPath ?? "Animate";

Thread thread = new Thread(() =>
{
try
{
WzSpineAnimationItem item = new WzSpineAnimationItem(stringObj);

// Create xna window
SpineAnimationWindow Window = new SpineAnimationWindow(item);
SpineAnimationWindow Window = new SpineAnimationWindow(item, path_title);
Window.Run();
}
catch (Exception e)
Expand Down
53 changes: 43 additions & 10 deletions HaSharedLibrary/GUI/SpineAnimationWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using Microsoft.Xna.Framework.Input;
using Spine;
using System;
using System.Linq;

namespace HaSharedLibrary.GUI
{
Expand All @@ -43,19 +44,23 @@ public class SpineAnimationWindow : Microsoft.Xna.Framework.Game
private SpriteFont font;


//
private int spineSkinIndex = 0;

/// <summary>
/// Constructor
/// </summary>
/// <param name="spineAnimationItem"></param>
/// <param name="skeletonData"></param>
public SpineAnimationWindow(WzSpineAnimationItem spineAnimationItem)
/// <param name="title_path">The path of the spine animation to set as title</param>
public SpineAnimationWindow(WzSpineAnimationItem spineAnimationItem, string title_path)
{
IsMouseVisible = true;

//Window.IsBorderless = true;
//Window.Position = new Point(0, 0);
Window.Title = "Spine";
Window.Title = title_path;
IsFixedTimeStep = false; // dont cap fps
Content.RootDirectory = "Content";

graphicsDeviceMgr = new GraphicsDeviceManager(this)
{
Expand All @@ -67,7 +72,7 @@ public SpineAnimationWindow(WzSpineAnimationItem spineAnimationItem)
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 @@ -101,15 +106,18 @@ protected override void LoadContent()
wzSpineObject.spineAnimationItem.LoadResources(graphicsDeviceMgr.GraphicsDevice); // load spine resources (this must happen after window is loaded)
wzSpineObject.skeleton = new Skeleton(wzSpineObject.spineAnimationItem.SkeletonData);

skeletonRenderer = new SkeletonMeshRenderer(GraphicsDevice);
skeletonRenderer.PremultipliedAlpha = wzSpineObject.spineAnimationItem.PremultipliedAlpha;
skeletonRenderer = new SkeletonMeshRenderer(GraphicsDevice)
{
PremultipliedAlpha = wzSpineObject.spineAnimationItem.PremultipliedAlpha
};

// Skin
foreach (Skin skin in wzSpineObject.spineAnimationItem.SkeletonData.Skins)
Skin skin = wzSpineObject.spineAnimationItem.SkeletonData.Skins.FirstOrDefault(); // just set the first skin
if (skin != null)
{
wzSpineObject.skeleton.SetSkin(skin.Name); // just set the first skin
break;
wzSpineObject.skeleton.SetSkin(skin.Name);
}
this.spineSkinIndex = 0;

// Define mixing between animations.
wzSpineObject.stateData = new AnimationStateData(wzSpineObject.skeleton.Data);
Expand Down Expand Up @@ -199,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 @@ -234,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
13 changes: 11 additions & 2 deletions MapleLib/WzLib/Spine/WzSpineAnimationItem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018~2020, LastBattle https://github.com/lastbattle
* Copyright (c) 2018~2021, LastBattle https://github.com/lastbattle
* Copyright (c) 2010~2013, haha01haha http://forum.ragezone.com/f701/release-universal-harepacker-version-892005/
Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -38,7 +38,16 @@ namespace MapleLib.WzLib.Spine
public class WzSpineAnimationItem
{
// Spine

/// <summary>
/// Whether the renderer will assume that colors have premultiplied alpha.
///
/// A variation of a bitmap image or alpha blending calculation in which the RGB color values are assumed
/// to be already multiplied by an alpha channel, to reduce computations during Alpha blending;
/// uses the blend operation: dst *= (1 - alpha) + src; capable of mixing alpha blending with additive blending effects
/// </summary>
public bool PremultipliedAlpha { get; set; }

public SkeletonData SkeletonData { get; private set; }

// pre-loading
Expand Down Expand Up @@ -75,7 +84,7 @@ public void LoadResources(GraphicsDevice graphicsDevice)
pma = ((WzImage)wzSpineAtlasPropertyNode.parent)["PMA"].ReadValue(0) > 0;

this.SkeletonData = skeletonData;
this.PremultipliedAlpha = pma;
this.PremultipliedAlpha = pma; // whether the renderer will assume that colors have premultiplied alpha. Default is true.

}
}
Expand Down
67 changes: 47 additions & 20 deletions MapleLib/WzLib/Spine/WzSpineTextureLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using Texture2D = Microsoft.Xna.Framework.Graphics.Texture2D;

namespace MapleLib.WzLib.Spine
{
public class WzSpineTextureLoader : TextureLoader
{
public WzObject ParentNode { get; private set; }
private GraphicsDevice graphicsDevice;
private readonly GraphicsDevice graphicsDevice;


public WzSpineTextureLoader(WzObject ParentNode, GraphicsDevice graphicsDevice)
Expand Down Expand Up @@ -79,29 +78,57 @@ public void Load(AtlasPage page, string path)

if (canvasProperty != null)
{
Bitmap bitmap = canvasProperty.GetLinkedWzCanvasBitmap();
if (bitmap != null && graphicsDevice != null)
{
Texture2D tex = new Texture2D(graphicsDevice, bitmap.Width, bitmap.Height, true, SurfaceFormat.Color);
BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat);

int bufferSize = data.Height * data.Stride;
WzCanvasProperty linkImgProperty = (WzCanvasProperty) canvasProperty.GetLinkedWzImageProperty();

//create data buffer
byte[] bytes = new byte[bufferSize];
WzPngProperty pngProperty = linkImgProperty.PngProperty;
SurfaceFormat surfaceFormat = linkImgProperty.PngProperty.GetXNASurfaceFormat();

// copy bitmap data into buffer
Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);

// copy our buffer to the texture
tex.SetData(bytes);
if (graphicsDevice != null)
{
Texture2D tex;
tex = new Texture2D(graphicsDevice,
pngProperty.Width, pngProperty.Height,
false, surfaceFormat);
/*switch (surfaceFormat)
{
case SurfaceFormat.Bgra4444:
tex = new Texture2D(graphicsDevice,
pngProperty.Width * 2, pngProperty.Height * 2,
false, surfaceFormat);
break;
case SurfaceFormat.Bgra32:
tex = new Texture2D(graphicsDevice,
pngProperty.Width * 4, pngProperty.Height * 4,
false, surfaceFormat);
break;
case SurfaceFormat.Bgr565:
tex = new Texture2D(graphicsDevice,
pngProperty.Width * 2, pngProperty.Height * 2,
false, surfaceFormat);
break;
case SurfaceFormat.Dxt3:
tex = new Texture2D(graphicsDevice,
pngProperty.Width * 4, pngProperty.Height * 4,
false, surfaceFormat);
break;
case SurfaceFormat.Dxt5:
tex = new Texture2D(graphicsDevice,
pngProperty.Width * 4, pngProperty.Height * 4,
false, surfaceFormat);
break;
default:
tex = new Texture2D(graphicsDevice,
pngProperty.Width, pngProperty.Height,
false, surfaceFormat);
break;
}
*/
pngProperty.ParsePng(true, tex);

// unlock the bitmap data
bitmap.UnlockBits(data);

page.rendererObject = tex;
page.width = bitmap.Width;
page.height = bitmap.Height;
page.width = pngProperty.Width;
page.height = pngProperty.Height;
}
}
}
Expand Down
22 changes: 17 additions & 5 deletions MapleLib/WzLib/WzProperties/WzCanvasProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ public override void WriteValue(MapleLib.WzLib.Util.WzBinaryWriter writer)
// Image info
writer.WriteCompressedInt(PngProperty.Width);
writer.WriteCompressedInt(PngProperty.Height);
writer.WriteCompressedInt(PngProperty.format);
writer.Write((byte)PngProperty.format2);
writer.WriteCompressedInt(PngProperty.Format);
writer.Write((byte)PngProperty.Format2);
writer.Write((Int32)0);

// Write image
Expand Down Expand Up @@ -284,6 +284,18 @@ public bool HaveOutlinkProperty()
/// </summary>
/// <returns></returns>
public Bitmap GetLinkedWzCanvasBitmap()
{
return GetLinkedWzImageProperty().GetBitmap();
}

/// <summary>
/// Gets the '_inlink' WzCanvasProperty of this.
///
/// '_inlink' is not implemented as part of WzCanvasProperty as I dont want to override existing Wz structure.
/// It will be handled via HaRepackerMainPanel instead.
/// </summary>
/// <returns></returns>
public WzImageProperty GetLinkedWzImageProperty()
{
string _inlink = ((WzStringProperty)this[InlinkPropertyName])?.Value; // could get nexon'd here. In case they place an _inlink that's not WzStringProperty
string _outlink = ((WzStringProperty)this[OutlinkPropertyName])?.Value; // could get nexon'd here. In case they place an _outlink that's not WzStringProperty
Expand All @@ -300,7 +312,7 @@ public Bitmap GetLinkedWzCanvasBitmap()
WzImageProperty foundProperty = wzImageParent.GetFromPath(_inlink);
if (foundProperty != null && foundProperty is WzImageProperty property)
{
return property.GetBitmap();
return property;
}
}
}
Expand All @@ -316,11 +328,11 @@ public Bitmap GetLinkedWzCanvasBitmap()
WzObject foundProperty = wzFileParent.GetObjectFromPath(_outlink);
if (foundProperty != null && foundProperty is WzImageProperty property)
{
return property.GetBitmap();
return property;
}
}
}
return this.GetBitmap();
return this;
}

/// <summary>
Expand Down
Loading

0 comments on commit 22f62e7

Please sign in to comment.