TextureAtlasEditor - Animated Tiles now play in the selected tile picture box and AnimationEditor can now accept Animation in constructor aswell as blend the frames with a given color

This commit is contained in:
miku-666
2023-08-03 17:51:17 +02:00
parent afb01e6e32
commit a878e3734b
9 changed files with 532 additions and 375 deletions

View File

@@ -15,7 +15,12 @@ namespace PckStudio.Extensions
return new Vector4(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f);
}
internal static byte BlendValues(float source, float overlay, BlendMode blendType)
internal static byte BlendValues(byte source, byte overlay, BlendMode blendType)
{
return (byte)MathExtensions.Clamp(BlendValues(source / 255f, overlay / 255f, blendType) * 255, 0, 255);
}
internal static float BlendValues(float source, float overlay, BlendMode blendType)
{
source = MathExtensions.Clamp(source, 0.0f, 1.0f);
overlay = MathExtensions.Clamp(overlay, 0.0f, 1.0f);
@@ -30,7 +35,7 @@ namespace PckStudio.Extensions
BlendMode.Screen => 1f - (1f - source) * (1f - overlay),
_ => 0.0f
};
return (byte)MathExtensions.Clamp(resultValue * 255, 0, 255);
return MathExtensions.Clamp(resultValue, 0.0f, 1.0f);
}
internal static byte Mix(double ratio, byte val1, byte val2)

View File

@@ -159,14 +159,12 @@ namespace PckStudio.Extensions
byte[] baseImageBuffer = new byte[baseImageData.Stride * baseImageData.Height];
Marshal.Copy(baseImageData.Scan0, baseImageBuffer, 0, baseImageBuffer.Length);
var normalized = overlayColor.Normalize();
for (int k = 0; k < baseImageBuffer.Length; k += 4)
{
baseImageBuffer[k + 0] = ColorExtensions.BlendValues(baseImageBuffer[k + 0] / 255f, normalized.X, mode);
baseImageBuffer[k + 1] = ColorExtensions.BlendValues(baseImageBuffer[k + 1] / 255f, normalized.Y, mode);
baseImageBuffer[k + 2] = ColorExtensions.BlendValues(baseImageBuffer[k + 2] / 255f, normalized.Z, mode);
baseImageBuffer[k + 0] = ColorExtensions.BlendValues(baseImageBuffer[k + 0], overlayColor.B, mode);
baseImageBuffer[k + 1] = ColorExtensions.BlendValues(baseImageBuffer[k + 1], overlayColor.G, mode);
baseImageBuffer[k + 2] = ColorExtensions.BlendValues(baseImageBuffer[k + 2], overlayColor.R, mode);
}
Bitmap bitmapResult = new Bitmap(baseImage.Width, baseImage.Height, PixelFormat.Format32bppArgb);
@@ -201,9 +199,9 @@ namespace PckStudio.Extensions
for (int k = 0; k < baseImageBuffer.Length && k < overlayImageBuffer.Length; k += 4)
{
baseImageBuffer[k + 0] = ColorExtensions.BlendValues(baseImageBuffer[k + 0] / 255f, overlayImageBuffer[k + 0] / 255f, mode);
baseImageBuffer[k + 1] = ColorExtensions.BlendValues(baseImageBuffer[k + 1] / 255f, overlayImageBuffer[k + 1] / 255f, mode);
baseImageBuffer[k + 2] = ColorExtensions.BlendValues(baseImageBuffer[k + 2] / 255f, overlayImageBuffer[k + 2] / 255f, mode);
baseImageBuffer[k + 0] = ColorExtensions.BlendValues(baseImageBuffer[k + 0], overlayImageBuffer[k + 0], mode);
baseImageBuffer[k + 1] = ColorExtensions.BlendValues(baseImageBuffer[k + 1], overlayImageBuffer[k + 1], mode);
baseImageBuffer[k + 2] = ColorExtensions.BlendValues(baseImageBuffer[k + 2], overlayImageBuffer[k + 2], mode);
}
Bitmap bitmapResult = new Bitmap(baseImage.Width, baseImage.Height, PixelFormat.Format32bppArgb);

View File

@@ -28,349 +28,351 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AnimationEditor));
this.frameTreeView = new System.Windows.Forms.TreeView();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.addFrameToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.removeFrameToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.TextureIcons = new System.Windows.Forms.ImageList(this.components);
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.importToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.importAnimationTextureToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.importJavaAnimationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.importGifToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exportAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exportJavaAnimationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.gifToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.bulkAnimationSpeedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.changeTileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.howToInterpolation = new System.Windows.Forms.ToolStripMenuItem();
this.editorControlsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.setBulkSpedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.javaAnimationSupportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.InterpolationCheckbox = new MetroFramework.Controls.MetroCheckBox();
this.AnimationStartStopBtn = new MetroFramework.Controls.MetroButton();
this.tileLabel = new MetroFramework.Controls.MetroLabel();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.animationPictureBox = new PckStudio.Forms.Editor.AnimationPictureBox();
this.frameTimeandTicksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.contextMenuStrip1.SuspendLayout();
this.menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.animationPictureBox)).BeginInit();
this.SuspendLayout();
//
// frameTreeView
//
this.frameTreeView.AllowDrop = true;
this.frameTreeView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AnimationEditor));
this.frameTreeView = new System.Windows.Forms.TreeView();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.addFrameToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.removeFrameToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.TextureIcons = new System.Windows.Forms.ImageList(this.components);
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.importToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.importAnimationTextureToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.importJavaAnimationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.importGifToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exportAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exportJavaAnimationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.gifToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.bulkAnimationSpeedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.changeTileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.frameTimeandTicksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.howToInterpolation = new System.Windows.Forms.ToolStripMenuItem();
this.editorControlsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.setBulkSpedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.javaAnimationSupportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.InterpolationCheckbox = new MetroFramework.Controls.MetroCheckBox();
this.AnimationStartStopBtn = new MetroFramework.Controls.MetroButton();
this.tileLabel = new MetroFramework.Controls.MetroLabel();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.animationPictureBox = new PckStudio.Forms.Editor.AnimationPictureBox();
this.contextMenuStrip1.SuspendLayout();
this.menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.animationPictureBox)).BeginInit();
this.SuspendLayout();
//
// frameTreeView
//
this.frameTreeView.AllowDrop = true;
this.frameTreeView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.frameTreeView.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.frameTreeView.ContextMenuStrip = this.contextMenuStrip1;
this.frameTreeView.ForeColor = System.Drawing.Color.White;
this.frameTreeView.ImageIndex = 0;
this.frameTreeView.ImageList = this.TextureIcons;
this.frameTreeView.Location = new System.Drawing.Point(20, 88);
this.frameTreeView.Margin = new System.Windows.Forms.Padding(0);
this.frameTreeView.Name = "frameTreeView";
this.frameTreeView.SelectedImageIndex = 0;
this.frameTreeView.ShowLines = false;
this.frameTreeView.ShowRootLines = false;
this.frameTreeView.Size = new System.Drawing.Size(134, 253);
this.frameTreeView.TabIndex = 15;
this.frameTreeView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.frameTreeView_ItemDrag);
this.frameTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.frameTreeView_AfterSelect);
this.frameTreeView.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeView1_doubleClick);
this.frameTreeView.DragDrop += new System.Windows.Forms.DragEventHandler(this.frameTreeView_DragDrop);
this.frameTreeView.DragEnter += new System.Windows.Forms.DragEventHandler(this.frameTreeView_DragEnter);
this.frameTreeView.DragOver += new System.Windows.Forms.DragEventHandler(this.frameTreeView_DragOver);
//
// contextMenuStrip1
//
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.frameTreeView.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.frameTreeView.ContextMenuStrip = this.contextMenuStrip1;
this.frameTreeView.ForeColor = System.Drawing.Color.White;
this.frameTreeView.ImageIndex = 0;
this.frameTreeView.ImageList = this.TextureIcons;
this.frameTreeView.Location = new System.Drawing.Point(20, 88);
this.frameTreeView.Margin = new System.Windows.Forms.Padding(0);
this.frameTreeView.Name = "frameTreeView";
this.frameTreeView.SelectedImageIndex = 0;
this.frameTreeView.ShowLines = false;
this.frameTreeView.ShowRootLines = false;
this.frameTreeView.Size = new System.Drawing.Size(134, 253);
this.frameTreeView.TabIndex = 15;
this.frameTreeView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.frameTreeView_ItemDrag);
this.frameTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.frameTreeView_AfterSelect);
this.frameTreeView.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeView1_doubleClick);
this.frameTreeView.DragDrop += new System.Windows.Forms.DragEventHandler(this.frameTreeView_DragDrop);
this.frameTreeView.DragEnter += new System.Windows.Forms.DragEventHandler(this.frameTreeView_DragEnter);
this.frameTreeView.DragOver += new System.Windows.Forms.DragEventHandler(this.frameTreeView_DragOver);
//
// contextMenuStrip1
//
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.addFrameToolStripMenuItem,
this.removeFrameToolStripMenuItem});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(154, 48);
//
// addFrameToolStripMenuItem
//
this.addFrameToolStripMenuItem.Name = "addFrameToolStripMenuItem";
this.addFrameToolStripMenuItem.Size = new System.Drawing.Size(153, 22);
this.addFrameToolStripMenuItem.Text = "Add Frame";
this.addFrameToolStripMenuItem.Click += new System.EventHandler(this.addFrameToolStripMenuItem_Click);
//
// removeFrameToolStripMenuItem
//
this.removeFrameToolStripMenuItem.Name = "removeFrameToolStripMenuItem";
this.removeFrameToolStripMenuItem.Size = new System.Drawing.Size(153, 22);
this.removeFrameToolStripMenuItem.Text = "Remove Frame";
this.removeFrameToolStripMenuItem.Click += new System.EventHandler(this.removeFrameToolStripMenuItem_Click);
//
// TextureIcons
//
this.TextureIcons.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
this.TextureIcons.ImageSize = new System.Drawing.Size(32, 32);
this.TextureIcons.TransparentColor = System.Drawing.Color.Transparent;
//
// menuStrip
//
this.menuStrip.AutoSize = false;
this.menuStrip.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(154, 48);
//
// addFrameToolStripMenuItem
//
this.addFrameToolStripMenuItem.Name = "addFrameToolStripMenuItem";
this.addFrameToolStripMenuItem.Size = new System.Drawing.Size(153, 22);
this.addFrameToolStripMenuItem.Text = "Add Frame";
this.addFrameToolStripMenuItem.Click += new System.EventHandler(this.addFrameToolStripMenuItem_Click);
//
// removeFrameToolStripMenuItem
//
this.removeFrameToolStripMenuItem.Name = "removeFrameToolStripMenuItem";
this.removeFrameToolStripMenuItem.Size = new System.Drawing.Size(153, 22);
this.removeFrameToolStripMenuItem.Text = "Remove Frame";
this.removeFrameToolStripMenuItem.Click += new System.EventHandler(this.removeFrameToolStripMenuItem_Click);
//
// TextureIcons
//
this.TextureIcons.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
this.TextureIcons.ImageSize = new System.Drawing.Size(32, 32);
this.TextureIcons.TransparentColor = System.Drawing.Color.Transparent;
//
// menuStrip
//
this.menuStrip.AutoSize = false;
this.menuStrip.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem,
this.editToolStripMenuItem,
this.helpToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(20, 60);
this.menuStrip.Name = "menuStrip";
this.menuStrip.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional;
this.menuStrip.Size = new System.Drawing.Size(372, 24);
this.menuStrip.TabIndex = 14;
this.menuStrip.Text = "menuStrip1";
//
// fileToolStripMenuItem
//
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuStrip.Location = new System.Drawing.Point(20, 60);
this.menuStrip.Name = "menuStrip";
this.menuStrip.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional;
this.menuStrip.Size = new System.Drawing.Size(372, 24);
this.menuStrip.TabIndex = 14;
this.menuStrip.Text = "menuStrip1";
//
// fileToolStripMenuItem
//
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.saveToolStripMenuItem1,
this.toolStripSeparator1,
this.importToolStripMenuItem,
this.exportAsToolStripMenuItem});
this.fileToolStripMenuItem.ForeColor = System.Drawing.Color.White;
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
this.fileToolStripMenuItem.Text = "File";
//
// saveToolStripMenuItem1
//
this.saveToolStripMenuItem1.Image = ((System.Drawing.Image)(resources.GetObject("saveToolStripMenuItem1.Image")));
this.saveToolStripMenuItem1.Name = "saveToolStripMenuItem1";
this.saveToolStripMenuItem1.Size = new System.Drawing.Size(122, 22);
this.saveToolStripMenuItem1.Text = "Save";
this.saveToolStripMenuItem1.Click += new System.EventHandler(this.saveToolStripMenuItem1_Click);
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(119, 6);
//
// importToolStripMenuItem
//
this.importToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem.ForeColor = System.Drawing.Color.White;
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
this.fileToolStripMenuItem.Text = "File";
//
// saveToolStripMenuItem1
//
this.saveToolStripMenuItem1.Image = ((System.Drawing.Image)(resources.GetObject("saveToolStripMenuItem1.Image")));
this.saveToolStripMenuItem1.Name = "saveToolStripMenuItem1";
this.saveToolStripMenuItem1.Size = new System.Drawing.Size(122, 22);
this.saveToolStripMenuItem1.Text = "Save";
this.saveToolStripMenuItem1.Click += new System.EventHandler(this.saveToolStripMenuItem1_Click);
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(119, 6);
//
// importToolStripMenuItem
//
this.importToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.importAnimationTextureToolStripMenuItem,
this.importJavaAnimationToolStripMenuItem,
this.importGifToolStripMenuItem});
this.importToolStripMenuItem.Name = "importToolStripMenuItem";
this.importToolStripMenuItem.Size = new System.Drawing.Size(122, 22);
this.importToolStripMenuItem.Text = "Import";
//
// importAnimationTextureToolStripMenuItem
//
this.importAnimationTextureToolStripMenuItem.Name = "importAnimationTextureToolStripMenuItem";
this.importAnimationTextureToolStripMenuItem.Size = new System.Drawing.Size(171, 22);
this.importAnimationTextureToolStripMenuItem.Text = "Animation Texture";
this.importAnimationTextureToolStripMenuItem.Click += new System.EventHandler(this.importAnimationTextureToolStripMenuItem_Click);
//
// importJavaAnimationToolStripMenuItem
//
this.importJavaAnimationToolStripMenuItem.Name = "importJavaAnimationToolStripMenuItem";
this.importJavaAnimationToolStripMenuItem.Size = new System.Drawing.Size(171, 22);
this.importJavaAnimationToolStripMenuItem.Text = "Java Animation";
this.importJavaAnimationToolStripMenuItem.Click += new System.EventHandler(this.importJavaAnimationToolStripMenuItem_Click);
//
// importGifToolStripMenuItem
//
this.importGifToolStripMenuItem.Name = "importGifToolStripMenuItem";
this.importGifToolStripMenuItem.Size = new System.Drawing.Size(171, 22);
this.importGifToolStripMenuItem.Text = "Gif";
this.importGifToolStripMenuItem.Click += new System.EventHandler(this.importGifToolStripMenuItem_Click);
//
// exportAsToolStripMenuItem
//
this.exportAsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.importToolStripMenuItem.Name = "importToolStripMenuItem";
this.importToolStripMenuItem.Size = new System.Drawing.Size(122, 22);
this.importToolStripMenuItem.Text = "Import";
//
// importAnimationTextureToolStripMenuItem
//
this.importAnimationTextureToolStripMenuItem.Name = "importAnimationTextureToolStripMenuItem";
this.importAnimationTextureToolStripMenuItem.Size = new System.Drawing.Size(171, 22);
this.importAnimationTextureToolStripMenuItem.Text = "Animation Texture";
this.importAnimationTextureToolStripMenuItem.Click += new System.EventHandler(this.importAnimationTextureToolStripMenuItem_Click);
//
// importJavaAnimationToolStripMenuItem
//
this.importJavaAnimationToolStripMenuItem.Name = "importJavaAnimationToolStripMenuItem";
this.importJavaAnimationToolStripMenuItem.Size = new System.Drawing.Size(171, 22);
this.importJavaAnimationToolStripMenuItem.Text = "Java Animation";
this.importJavaAnimationToolStripMenuItem.Click += new System.EventHandler(this.importJavaAnimationToolStripMenuItem_Click);
//
// importGifToolStripMenuItem
//
this.importGifToolStripMenuItem.Name = "importGifToolStripMenuItem";
this.importGifToolStripMenuItem.Size = new System.Drawing.Size(171, 22);
this.importGifToolStripMenuItem.Text = "Gif";
this.importGifToolStripMenuItem.Click += new System.EventHandler(this.importGifToolStripMenuItem_Click);
//
// exportAsToolStripMenuItem
//
this.exportAsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.exportJavaAnimationToolStripMenuItem,
this.gifToolStripMenuItem});
this.exportAsToolStripMenuItem.Name = "exportAsToolStripMenuItem";
this.exportAsToolStripMenuItem.Size = new System.Drawing.Size(122, 22);
this.exportAsToolStripMenuItem.Text = "Export as";
//
// exportJavaAnimationToolStripMenuItem
//
this.exportJavaAnimationToolStripMenuItem.Name = "exportJavaAnimationToolStripMenuItem";
this.exportJavaAnimationToolStripMenuItem.Size = new System.Drawing.Size(155, 22);
this.exportJavaAnimationToolStripMenuItem.Text = "Java Animation";
this.exportJavaAnimationToolStripMenuItem.Click += new System.EventHandler(this.exportJavaAnimationToolStripMenuItem_Click);
//
// gifToolStripMenuItem
//
this.gifToolStripMenuItem.Name = "gifToolStripMenuItem";
this.gifToolStripMenuItem.Size = new System.Drawing.Size(155, 22);
this.gifToolStripMenuItem.Text = "Gif";
this.gifToolStripMenuItem.Click += new System.EventHandler(this.gifToolStripMenuItem_Click);
//
// editToolStripMenuItem
//
this.editToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.exportAsToolStripMenuItem.Name = "exportAsToolStripMenuItem";
this.exportAsToolStripMenuItem.Size = new System.Drawing.Size(122, 22);
this.exportAsToolStripMenuItem.Text = "Export as";
//
// exportJavaAnimationToolStripMenuItem
//
this.exportJavaAnimationToolStripMenuItem.Name = "exportJavaAnimationToolStripMenuItem";
this.exportJavaAnimationToolStripMenuItem.Size = new System.Drawing.Size(155, 22);
this.exportJavaAnimationToolStripMenuItem.Text = "Java Animation";
this.exportJavaAnimationToolStripMenuItem.Click += new System.EventHandler(this.exportJavaAnimationToolStripMenuItem_Click);
//
// gifToolStripMenuItem
//
this.gifToolStripMenuItem.Name = "gifToolStripMenuItem";
this.gifToolStripMenuItem.Size = new System.Drawing.Size(155, 22);
this.gifToolStripMenuItem.Text = "Gif";
this.gifToolStripMenuItem.Click += new System.EventHandler(this.gifToolStripMenuItem_Click);
//
// editToolStripMenuItem
//
this.editToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.bulkAnimationSpeedToolStripMenuItem,
this.changeTileToolStripMenuItem});
this.editToolStripMenuItem.ForeColor = System.Drawing.Color.White;
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
this.editToolStripMenuItem.Size = new System.Drawing.Size(46, 20);
this.editToolStripMenuItem.Text = "Tools";
//
// bulkAnimationSpeedToolStripMenuItem
//
this.bulkAnimationSpeedToolStripMenuItem.Name = "bulkAnimationSpeedToolStripMenuItem";
this.bulkAnimationSpeedToolStripMenuItem.Size = new System.Drawing.Size(210, 22);
this.bulkAnimationSpeedToolStripMenuItem.Text = "Set Bulk Animation Speed";
this.bulkAnimationSpeedToolStripMenuItem.Click += new System.EventHandler(this.bulkAnimationSpeedToolStripMenuItem_Click);
//
// changeTileToolStripMenuItem
//
this.changeTileToolStripMenuItem.Name = "changeTileToolStripMenuItem";
this.changeTileToolStripMenuItem.Size = new System.Drawing.Size(210, 22);
this.changeTileToolStripMenuItem.Text = "Change Tile";
this.changeTileToolStripMenuItem.Click += new System.EventHandler(this.changeTileToolStripMenuItem_Click);
//
// helpToolStripMenuItem
//
this.helpToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.editToolStripMenuItem.ForeColor = System.Drawing.Color.White;
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
this.editToolStripMenuItem.Size = new System.Drawing.Size(46, 20);
this.editToolStripMenuItem.Text = "Tools";
//
// bulkAnimationSpeedToolStripMenuItem
//
this.bulkAnimationSpeedToolStripMenuItem.Name = "bulkAnimationSpeedToolStripMenuItem";
this.bulkAnimationSpeedToolStripMenuItem.Size = new System.Drawing.Size(210, 22);
this.bulkAnimationSpeedToolStripMenuItem.Text = "Set Bulk Animation Speed";
this.bulkAnimationSpeedToolStripMenuItem.Click += new System.EventHandler(this.bulkAnimationSpeedToolStripMenuItem_Click);
//
// changeTileToolStripMenuItem
//
this.changeTileToolStripMenuItem.Name = "changeTileToolStripMenuItem";
this.changeTileToolStripMenuItem.Size = new System.Drawing.Size(210, 22);
this.changeTileToolStripMenuItem.Text = "Change Tile";
this.changeTileToolStripMenuItem.Click += new System.EventHandler(this.changeTileToolStripMenuItem_Click);
//
// helpToolStripMenuItem
//
this.helpToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.frameTimeandTicksToolStripMenuItem,
this.howToInterpolation,
this.editorControlsToolStripMenuItem,
this.setBulkSpedToolStripMenuItem,
this.javaAnimationSupportToolStripMenuItem});
this.helpToolStripMenuItem.ForeColor = System.Drawing.Color.White;
this.helpToolStripMenuItem.Name = "helpToolStripMenuItem";
this.helpToolStripMenuItem.Size = new System.Drawing.Size(44, 20);
this.helpToolStripMenuItem.Text = "Help";
//
// howToInterpolation
//
this.howToInterpolation.Name = "howToInterpolation";
this.howToInterpolation.Size = new System.Drawing.Size(200, 22);
this.howToInterpolation.Text = "Interpolation";
this.howToInterpolation.Click += new System.EventHandler(this.howToInterpolation_Click);
//
// editorControlsToolStripMenuItem
//
this.editorControlsToolStripMenuItem.Name = "editorControlsToolStripMenuItem";
this.editorControlsToolStripMenuItem.Size = new System.Drawing.Size(200, 22);
this.editorControlsToolStripMenuItem.Text = "Editor Controls";
this.editorControlsToolStripMenuItem.Click += new System.EventHandler(this.editorControlsToolStripMenuItem_Click);
//
// setBulkSpedToolStripMenuItem
//
this.setBulkSpedToolStripMenuItem.Name = "setBulkSpedToolStripMenuItem";
this.setBulkSpedToolStripMenuItem.Size = new System.Drawing.Size(200, 22);
this.setBulkSpedToolStripMenuItem.Text = "Set Bulk Speed";
this.setBulkSpedToolStripMenuItem.Click += new System.EventHandler(this.setBulkSpeedToolStripMenuItem_Click);
//
// javaAnimationSupportToolStripMenuItem
//
this.javaAnimationSupportToolStripMenuItem.Name = "javaAnimationSupportToolStripMenuItem";
this.javaAnimationSupportToolStripMenuItem.Size = new System.Drawing.Size(200, 22);
this.javaAnimationSupportToolStripMenuItem.Text = "Java Animation Support";
this.javaAnimationSupportToolStripMenuItem.Click += new System.EventHandler(this.javaAnimationSupportToolStripMenuItem_Click);
//
// InterpolationCheckbox
//
this.InterpolationCheckbox.AutoSize = true;
this.InterpolationCheckbox.Location = new System.Drawing.Point(161, 63);
this.InterpolationCheckbox.Name = "InterpolationCheckbox";
this.InterpolationCheckbox.Size = new System.Drawing.Size(129, 15);
this.InterpolationCheckbox.TabIndex = 17;
this.InterpolationCheckbox.Text = "Enable Interpolation";
this.InterpolationCheckbox.Theme = MetroFramework.MetroThemeStyle.Dark;
this.InterpolationCheckbox.UseSelectable = true;
this.InterpolationCheckbox.CheckedChanged += new System.EventHandler(this.InterpolationCheckbox_CheckedChanged);
//
// AnimationStartStopBtn
//
this.AnimationStartStopBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
this.helpToolStripMenuItem.ForeColor = System.Drawing.Color.White;
this.helpToolStripMenuItem.Name = "helpToolStripMenuItem";
this.helpToolStripMenuItem.Size = new System.Drawing.Size(44, 20);
this.helpToolStripMenuItem.Text = "Help";
//
// frameTimeandTicksToolStripMenuItem
//
this.frameTimeandTicksToolStripMenuItem.Name = "frameTimeandTicksToolStripMenuItem";
this.frameTimeandTicksToolStripMenuItem.Size = new System.Drawing.Size(200, 22);
this.frameTimeandTicksToolStripMenuItem.Text = "Frame Time (and Ticks)";
this.frameTimeandTicksToolStripMenuItem.Click += new System.EventHandler(this.frameTimeandTicksToolStripMenuItem_Click);
//
// howToInterpolation
//
this.howToInterpolation.Name = "howToInterpolation";
this.howToInterpolation.Size = new System.Drawing.Size(200, 22);
this.howToInterpolation.Text = "Interpolation";
this.howToInterpolation.Click += new System.EventHandler(this.howToInterpolation_Click);
//
// editorControlsToolStripMenuItem
//
this.editorControlsToolStripMenuItem.Name = "editorControlsToolStripMenuItem";
this.editorControlsToolStripMenuItem.Size = new System.Drawing.Size(200, 22);
this.editorControlsToolStripMenuItem.Text = "Editor Controls";
this.editorControlsToolStripMenuItem.Click += new System.EventHandler(this.editorControlsToolStripMenuItem_Click);
//
// setBulkSpedToolStripMenuItem
//
this.setBulkSpedToolStripMenuItem.Name = "setBulkSpedToolStripMenuItem";
this.setBulkSpedToolStripMenuItem.Size = new System.Drawing.Size(200, 22);
this.setBulkSpedToolStripMenuItem.Text = "Set Bulk Speed";
this.setBulkSpedToolStripMenuItem.Click += new System.EventHandler(this.setBulkSpeedToolStripMenuItem_Click);
//
// javaAnimationSupportToolStripMenuItem
//
this.javaAnimationSupportToolStripMenuItem.Name = "javaAnimationSupportToolStripMenuItem";
this.javaAnimationSupportToolStripMenuItem.Size = new System.Drawing.Size(200, 22);
this.javaAnimationSupportToolStripMenuItem.Text = "Java Animation Support";
this.javaAnimationSupportToolStripMenuItem.Click += new System.EventHandler(this.javaAnimationSupportToolStripMenuItem_Click);
//
// InterpolationCheckbox
//
this.InterpolationCheckbox.AutoSize = true;
this.InterpolationCheckbox.Location = new System.Drawing.Point(161, 63);
this.InterpolationCheckbox.Name = "InterpolationCheckbox";
this.InterpolationCheckbox.Size = new System.Drawing.Size(129, 15);
this.InterpolationCheckbox.TabIndex = 17;
this.InterpolationCheckbox.Text = "Enable Interpolation";
this.InterpolationCheckbox.Theme = MetroFramework.MetroThemeStyle.Dark;
this.InterpolationCheckbox.UseSelectable = true;
this.InterpolationCheckbox.CheckedChanged += new System.EventHandler(this.InterpolationCheckbox_CheckedChanged);
//
// AnimationStartStopBtn
//
this.AnimationStartStopBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.AnimationStartStopBtn.Location = new System.Drawing.Point(157, 317);
this.AnimationStartStopBtn.Name = "AnimationStartStopBtn";
this.AnimationStartStopBtn.Size = new System.Drawing.Size(232, 24);
this.AnimationStartStopBtn.Style = MetroFramework.MetroColorStyle.White;
this.AnimationStartStopBtn.TabIndex = 18;
this.AnimationStartStopBtn.Text = "Play Animation";
this.AnimationStartStopBtn.Theme = MetroFramework.MetroThemeStyle.Dark;
this.AnimationStartStopBtn.UseSelectable = true;
this.AnimationStartStopBtn.Click += new System.EventHandler(this.AnimationStartStopBtn_Click);
//
// tileLabel
//
this.tileLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.tileLabel.AutoSize = true;
this.tileLabel.Location = new System.Drawing.Point(20, 341);
this.tileLabel.MinimumSize = new System.Drawing.Size(170, 19);
this.tileLabel.Name = "tileLabel";
this.tileLabel.Size = new System.Drawing.Size(57, 19);
this.tileLabel.TabIndex = 20;
this.tileLabel.Text = "tileLabel";
this.tileLabel.Theme = MetroFramework.MetroThemeStyle.Dark;
//
// pictureBox1
//
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
this.AnimationStartStopBtn.Location = new System.Drawing.Point(157, 317);
this.AnimationStartStopBtn.Name = "AnimationStartStopBtn";
this.AnimationStartStopBtn.Size = new System.Drawing.Size(232, 24);
this.AnimationStartStopBtn.Style = MetroFramework.MetroColorStyle.White;
this.AnimationStartStopBtn.TabIndex = 18;
this.AnimationStartStopBtn.Text = "Play Animation";
this.AnimationStartStopBtn.Theme = MetroFramework.MetroThemeStyle.Dark;
this.AnimationStartStopBtn.UseSelectable = true;
this.AnimationStartStopBtn.Click += new System.EventHandler(this.AnimationStartStopBtn_Click);
//
// tileLabel
//
this.tileLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.tileLabel.AutoSize = true;
this.tileLabel.Location = new System.Drawing.Point(20, 341);
this.tileLabel.MinimumSize = new System.Drawing.Size(170, 19);
this.tileLabel.Name = "tileLabel";
this.tileLabel.Size = new System.Drawing.Size(57, 19);
this.tileLabel.TabIndex = 20;
this.tileLabel.Text = "tileLabel";
this.tileLabel.Theme = MetroFramework.MetroThemeStyle.Dark;
//
// pictureBox1
//
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox1.Location = new System.Drawing.Point(154, 60);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(238, 24);
this.pictureBox1.TabIndex = 21;
this.pictureBox1.TabStop = false;
//
// animationPictureBox
//
this.animationPictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
this.pictureBox1.Location = new System.Drawing.Point(154, 60);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(238, 24);
this.pictureBox1.TabIndex = 21;
this.pictureBox1.TabStop = false;
//
// animationPictureBox
//
this.animationPictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.animationPictureBox.Location = new System.Drawing.Point(157, 88);
this.animationPictureBox.Name = "animationPictureBox";
this.animationPictureBox.Size = new System.Drawing.Size(235, 223);
this.animationPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.animationPictureBox.TabIndex = 16;
this.animationPictureBox.TabStop = false;
//
// frameTimeandTicksToolStripMenuItem
//
this.frameTimeandTicksToolStripMenuItem.Name = "frameTimeandTicksToolStripMenuItem";
this.frameTimeandTicksToolStripMenuItem.Size = new System.Drawing.Size(200, 22);
this.frameTimeandTicksToolStripMenuItem.Text = "Frame Time (and Ticks)";
this.frameTimeandTicksToolStripMenuItem.Click += new System.EventHandler(this.frameTimeandTicksToolStripMenuItem_Click);
//
// AnimationEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(412, 362);
this.Controls.Add(this.InterpolationCheckbox);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.AnimationStartStopBtn);
this.Controls.Add(this.tileLabel);
this.Controls.Add(this.animationPictureBox);
this.Controls.Add(this.frameTreeView);
this.Controls.Add(this.menuStrip);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MinimumSize = new System.Drawing.Size(412, 362);
this.Name = "AnimationEditor";
this.Style = MetroFramework.MetroColorStyle.Silver;
this.Text = "Animation Editor";
this.Theme = MetroFramework.MetroThemeStyle.Dark;
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.AnimationEditor_FormClosing);
this.contextMenuStrip1.ResumeLayout(false);
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.animationPictureBox)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
this.animationPictureBox.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
this.animationPictureBox.Location = new System.Drawing.Point(157, 88);
this.animationPictureBox.Name = "animationPictureBox";
this.animationPictureBox.Size = new System.Drawing.Size(235, 223);
this.animationPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.animationPictureBox.TabIndex = 16;
this.animationPictureBox.TabStop = false;
//
// AnimationEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(412, 362);
this.Controls.Add(this.InterpolationCheckbox);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.AnimationStartStopBtn);
this.Controls.Add(this.tileLabel);
this.Controls.Add(this.animationPictureBox);
this.Controls.Add(this.frameTreeView);
this.Controls.Add(this.menuStrip);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MinimumSize = new System.Drawing.Size(412, 362);
this.Name = "AnimationEditor";
this.Style = MetroFramework.MetroColorStyle.Silver;
this.Text = "Animation Editor";
this.Theme = MetroFramework.MetroThemeStyle.Dark;
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.AnimationEditor_FormClosing);
this.Load += new System.EventHandler(this.AnimationEditor_Load);
this.contextMenuStrip1.ResumeLayout(false);
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.animationPictureBox)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}

View File

@@ -27,42 +27,75 @@ namespace PckStudio.Forms.Editor
private string TileName = string.Empty;
private readonly bool hasBlendColor = false;
private Color blendColor;
private bool IsSpecialTile(string tileName)
{
return tileName == "clock" || tileName == "compass";
}
public AnimationEditor(PckFile.FileData file)
private AnimationEditor()
{
InitializeComponent();
animationFile = file;
InitializeComponent();
toolStripSeparator1.Visible = saveToolStripMenuItem1.Visible = !Settings.Default.AutoSaveChanges;
}
TileName = Path.GetFileNameWithoutExtension(animationFile.Filename);
internal AnimationEditor(Animation animation, string tileName)
: this()
{
currentAnimation = animation;
TileName = tileName;
}
bulkAnimationSpeedToolStripMenuItem.Enabled =
importToolStripMenuItem.Enabled =
exportAsToolStripMenuItem.Enabled =
InterpolationCheckbox.Visible = !IsSpecialTile(TileName);
public AnimationEditor(PckFile.FileData file)
: this()
{
animationFile = file;
TileName = Path.GetFileNameWithoutExtension(animationFile.Filename);
}
toolStripSeparator1.Visible = saveToolStripMenuItem1.Visible = !Settings.Default.AutoSaveChanges;
public AnimationEditor(PckFile.FileData file, Color blendColor)
: this(file)
{
hasBlendColor = true;
this.blendColor = blendColor;
}
currentAnimation = new Animation(Array.Empty<Image>());
if (animationFile.Size > 0)
{
using MemoryStream textureMem = new MemoryStream(animationFile.Data);
var texture = new Bitmap(textureMem);
var frameTextures = texture.CreateImageList(ImageLayoutDirection.Vertical);
currentAnimation = animationFile.Properties.HasProperty("ANIM")
? new Animation(frameTextures, animationFile.Properties.GetPropertyValue("ANIM"))
: new Animation(frameTextures, string.Empty);
}
private void AnimationEditor_Load(object sender, EventArgs e)
{
bulkAnimationSpeedToolStripMenuItem.Enabled =
importToolStripMenuItem.Enabled =
exportAsToolStripMenuItem.Enabled =
InterpolationCheckbox.Visible = !IsSpecialTile(TileName);
if (currentAnimation is null)
CreateAnimation();
SetTileLabel();
LoadAnimationTreeView();
}
private void CreateAnimation()
{
currentAnimation = new Animation(Array.Empty<Image>());
if (animationFile is not null && animationFile.Size > 0)
{
using MemoryStream textureMem = new MemoryStream(animationFile.Data);
var texture = new Bitmap(textureMem);
var frameTextures = texture.CreateImageList(ImageLayoutDirection.Vertical);
if (hasBlendColor)
{
frameTextures = frameTextures.Select(frameTexture => frameTexture.Blend(blendColor, BlendMode.Multiply));
}
currentAnimation = animationFile.Properties.HasProperty("ANIM")
? new Animation(frameTextures, animationFile.Properties.GetPropertyValue("ANIM"))
: new Animation(frameTextures, string.Empty);
}
currentAnimation.Category = animationFile.Filename.Split('/').Contains("items")
? Animation.AnimationCategory.Items
: Animation.AnimationCategory.Blocks;
SetTileLabel();
LoadAnimationTreeView();
}
}
private void LoadAnimationTreeView()
{
@@ -131,7 +164,7 @@ namespace PckStudio.Forms.Editor
private void saveToolStripMenuItem1_Click(object sender, EventArgs e)
{
if (!IsSpecialTile(TileName) && currentAnimation is not null)
if (!IsSpecialTile(TileName) && currentAnimation is not null && animationFile is not null)
{
string anim = currentAnimation.BuildAnim();
animationFile.Properties.SetProperty("ANIM", anim);
@@ -546,5 +579,5 @@ namespace PckStudio.Forms.Editor
"All time related functions in Minecraft use ticks, notably redstone repeaters. There are 20 ticks in 1 second, so " +
"1 tick is 1/20 of a second. To find how long your frame is, divide the frame time by 20", "Frame Time and Ticks");
}
}
}
}

View File

@@ -28,7 +28,7 @@ using PckStudio.Internal;
namespace PckStudio.Forms.Editor
{
internal class AnimationPictureBox : PictureBox
internal class AnimationPictureBox : PictureBoxWithInterpolationMode
{
public bool IsPlaying => _isPlaying;
@@ -39,6 +39,7 @@ namespace PckStudio.Forms.Editor
private Animation.Frame currentFrame;
private Animation _animation;
private CancellationTokenSource cts = new CancellationTokenSource();
private object l_dispose = new object();
public void Start(Animation animation)
{
@@ -97,7 +98,8 @@ namespace PckStudio.Forms.Editor
continue;
}
SetAnimationFrame(currentFrame);
await Task.Delay(TickInMillisecond * currentFrame.Ticks);
if (!await DelayAsync(TickInMillisecond * currentFrame.Ticks, cts.Token))
break;
}
_isPlaying = false;
}
@@ -107,15 +109,35 @@ namespace PckStudio.Forms.Editor
for (int tick = 0; tick < currentFrame.Ticks && !cts.IsCancellationRequested; tick++)
{
double delta = 1.0f - tick / (double)currentFrame.Ticks;
Invoke(() =>
{
if (!Disposing)
Image = currentFrame.Texture.Interpolate(nextFrame.Texture, delta);
});
await Task.Delay(TickInMillisecond);
if (!IsHandleCreated)
break;
lock (l_dispose)
{
Invoke(() =>
{
Image = currentFrame.Texture.Interpolate(nextFrame.Texture, delta);
});
}
if (!await DelayAsync(TickInMillisecond, cts.Token))
break;
}
}
private async Task<bool> DelayAsync(int millisecondsDelay, CancellationToken cancellationToken, [CallerMemberName] string caller = default!)
{
try
{
await Task.Delay(millisecondsDelay, cancellationToken);
}
catch
{
Debug.WriteLine($"Stoping {caller}");
return false;
}
return true;
}
private Animation.Frame SetAnimationFrame(int frameIndex)
{
var frame = _animation.GetFrame(frameIndex);
@@ -125,7 +147,23 @@ namespace PckStudio.Forms.Editor
private void SetAnimationFrame(Animation.Frame frame)
{
Invoke(() => Image = frame.Texture);
if (!IsHandleCreated)
return;
lock (l_dispose)
{
Invoke(() =>
{
Image = frame.Texture;
});
}
}
protected override void Dispose(bool disposing)
{
lock(l_dispose)
{
base.Dispose(disposing);
}
}
}
}

View File

@@ -37,7 +37,7 @@
this.extractTileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.originalPictureBox = new PckStudio.PictureBoxWithInterpolationMode();
this.selectTilePictureBox = new PckStudio.PictureBoxWithInterpolationMode();
this.selectTilePictureBox = new PckStudio.Forms.Editor.AnimationPictureBox();
this.infoTextBox = new System.Windows.Forms.RichTextBox();
this.replaceButton = new MetroFramework.Controls.MetroButton();
this.animationButton = new MetroFramework.Controls.MetroButton();
@@ -243,7 +243,7 @@
#endregion
private PictureBoxWithInterpolationMode selectTilePictureBox;
private PckStudio.Forms.Editor.AnimationPictureBox selectTilePictureBox;
private MetroFramework.Controls.MetroButton prevButton;
private MetroFramework.Controls.MetroButton nextButton;
private System.Windows.Forms.MenuStrip menuStrip1;

View File

@@ -22,9 +22,12 @@ using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using MetroFramework.Forms;
using OMI.Formats.Color;
using OMI.Formats.Pck;
using OMI.Workers.Color;
using PckStudio.Extensions;
using PckStudio.Forms.Editor;
using PckStudio.Forms.Utilities;
@@ -49,13 +52,15 @@ namespace PckStudio
internal readonly string Name;
internal readonly string TextureName;
internal readonly Rectangle Area;
internal readonly AnimationResources.TileInfo Tile;
public SelectedTile(int index, string name, string textureName, Rectangle area)
public SelectedTile(int index, string name, string textureName, Rectangle area, AnimationResources.TileInfo tile)
{
Index = index;
Name = name;
TextureName = textureName;
Area = area;
Tile = tile;
}
}
@@ -68,6 +73,8 @@ namespace PckStudio
private readonly List<AnimationResources.TileInfo> _textureInfos;
private SelectedTile _selectedItem = new SelectedTile();
private ColorContainer _colourTable;
private int SelectedIndex
{
set => SetImageDisplayed(value);
@@ -78,6 +85,8 @@ namespace PckStudio
public TextureAtlasEditor(PckFile pckFile, string path, Image atlas, Size areaSize)
{
InitializeComponent();
AcquireColorTable(pckFile);
_areaSize = areaSize;
_pckFile = pckFile;
_rowCount = atlas.Width / areaSize.Width;
@@ -94,8 +103,24 @@ namespace PckStudio
SelectedIndex = 0;
}
private bool AcquireColorTable(PckFile pckFile)
{
if (pckFile.TryGetFile("colours.col", PckFile.FileData.FileType.ColourTableFile, out var colFile) &&
colFile.Size > 0)
{
using var ms = new MemoryStream(colFile.Data);
var reader = new COLFileReader();
_colourTable = reader.FromStream(ms);
return true;
}
_colourTable = null;
return false;
}
private void SetImageDisplayed(int index)
{
if (selectTilePictureBox.IsPlaying)
selectTilePictureBox.Stop();
prevButton.Enabled = index > 0;
nextButton.Enabled = index < _textures.Count - 1;
infoTextBox.Text = string.Empty;
@@ -105,20 +130,33 @@ namespace PckStudio
var info = _textureInfos[index];
var pos = GetSelectedPoint(index, _rowCount, _columnCount, _imageLayout);
var selectedArea = new Rectangle(pos.X * _areaSize.Width, pos.Y * _areaSize.Height, _areaSize.Width, _areaSize.Height);
_selectedItem = new SelectedTile(index, info.DisplayName, info.InternalName, selectedArea);
_selectedItem = new SelectedTile(index, info.DisplayName, info.InternalName, selectedArea, info);
infoTextBox.Text = $"{_selectedItem.Name}\n{_selectedItem.TextureName}";
animationButton.Text =
_pckFile.Files.Contains($"res/textures/{_atlasType}/{_selectedItem.TextureName}.png", PckFile.FileData.FileType.TextureFile)
? "Open Animation"
: "Create Animation";
bool hasAnimation = _pckFile.Files.TryGetValue($"res/textures/{_atlasType}/{_selectedItem.TextureName}.png", PckFile.FileData.FileType.TextureFile, out var animationFile);
animationButton.Text = hasAnimation ? "Edit Animation" : "Create Animation";
if (hasAnimation && animationFile.Size > 0)
{
using var ms = new MemoryStream(animationFile.Data);
var img = Image.FromStream(ms);
var textures = img.CreateImageList(ImageLayoutDirection.Vertical);
selectTilePictureBox.Start(new Internal.Animation(textures, animationFile.Properties.GetPropertyValue("ANIM")));
return;
}
}
if (_textures.IndexInRange(index))
{
selectTilePictureBox.Image = _textures[index];
var img = _textures[index];
if (_selectedItem.Tile.HasColourEntry &&
!string.IsNullOrWhiteSpace(_selectedItem.Tile.ColourEntryName) &&
_colourTable is not null &&
_colourTable.Colors.FirstOrDefault(entry => entry.Name == _selectedItem.Tile.ColourEntryName) is ColorContainer.Color color)
{
img = img.Blend(color.ColorPallette, BlendMode.Multiply);
}
selectTilePictureBox.Image = img;
}
}
private void prevButton_Click(object sender, EventArgs e)
@@ -292,7 +330,29 @@ namespace PckStudio
{
file = new PckFile.FileData($"res/textures/{_atlasType}/{_selectedItem.TextureName}.png", PckFile.FileData.FileType.TextureFile);
}
var animationEditor = new AnimationEditor(file);
AnimationEditor animationEditor;
if (_selectedItem.Tile.HasColourEntry &&
!string.IsNullOrWhiteSpace(_selectedItem.Tile.ColourEntryName) &&
_colourTable is not null)
{
Color blenColor = Color.White;
if (_selectedItem.Tile.IsWaterColour &&
_colourTable.WaterColors.FirstOrDefault(entry => entry.Name == _selectedItem.Tile.ColourEntryName) is ColorContainer.WaterColor waterColor)
{
blenColor = waterColor.SurfaceColor;
}
else if (_colourTable.Colors.FirstOrDefault(entry => entry.Name == _selectedItem.Tile.ColourEntryName) is ColorContainer.Color color)
{
blenColor = color.ColorPallette;
}
animationEditor = new AnimationEditor(file, blenColor);
}
else
{
animationEditor = new AnimationEditor(file);
}
if (animationEditor.ShowDialog() == DialogResult.OK && isNewFile)
{
_pckFile.Files.Add(file);

View File

@@ -34,6 +34,15 @@ namespace PckStudio.Forms.Utilities
[JsonProperty("internalName")]
public string InternalName { get; set; }
[JsonProperty("hasColourEntry", DefaultValueHandling = DefaultValueHandling.Populate)]
public bool HasColourEntry { get; set; }
[JsonProperty("isWaterColour", DefaultValueHandling = DefaultValueHandling.Populate)]
public bool IsWaterColour { get; set; }
[JsonProperty("colourEntryName", DefaultValueHandling = DefaultValueHandling.Populate)]
public string ColourEntryName { get; set; }
public TileInfo(string displayName, string internalName)
{
DisplayName = displayName;

View File

@@ -4,7 +4,10 @@
"blocks": [
{
"internalName": "grass_top",
"displayName": "Grass Block (Top)"
"displayName": "Grass Block (Top)",
"hasColourEntry": true,
"isWaterColour": false,
"colourEntryName": "Grass_Common"
},
{
"internalName": "stone",
@@ -156,7 +159,10 @@
},
{
"internalName": "grass_side_overlay",
"displayName": "Grass Side (Overlay)"
"displayName": "Grass Side (Overlay)",
"hasColourEntry": true,
"isWaterColour": false,
"colourEntryName": "Grass_Common"
},
{
"internalName": "tallgrass",
@@ -824,11 +830,17 @@
},
{
"internalName": "water",
"displayName": "Water"
"displayName": "Water",
"hasColourEntry": true,
"isWaterColour": true,
"colourEntryName": "default"
},
{
"internalName": "water_flow",
"displayName": "Flowing Water"
"displayName": "Flowing Water",
"hasColourEntry": true,
"isWaterColour": true,
"colourEntryName": "default"
},
{
"internalName": "",