From 20518ac9da1432170434e3550e978dd2d785454b Mon Sep 17 00:00:00 2001 From: MattNL Date: Wed, 15 Mar 2023 17:09:21 -0400 Subject: [PATCH] Made special conditions when editing compass and clock textures --- PCK-Studio/Forms/Editor/AnimationEditor.cs | 35 +++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/PCK-Studio/Forms/Editor/AnimationEditor.cs b/PCK-Studio/Forms/Editor/AnimationEditor.cs index cadbd94a..9e22f9a1 100644 --- a/PCK-Studio/Forms/Editor/AnimationEditor.cs +++ b/PCK-Studio/Forms/Editor/AnimationEditor.cs @@ -156,15 +156,22 @@ namespace PckStudio.Forms.Editor return animationData.TrimEnd(','); } - public Image BuildTexture() + public Image BuildTexture(AnimationEditor ae) { int width = frameTextures[0].Width; int height = frameTextures[0].Height; if (width != height) throw new Exception("Invalid size"); - var img = new Bitmap(width, height * FrameTextureCount); + + bool isClockOrCompass = ae.TileName == "clock" || ae.TileName == "compass"; + + List linearImages = new List(); + foreach (TreeNode n in ae.frameTreeView.Nodes) linearImages.Add(frameTextures[n.ImageIndex]); + + var img = new Bitmap(width, height * (isClockOrCompass ? linearImages.Count : FrameTextureCount)); int pos_y = 0; + using (var g = Graphics.FromImage(img)) - frameTextures.ForEach(texture => + (isClockOrCompass ? linearImages : frameTextures).ForEach(texture => { g.DrawImage(texture, 0, pos_y); pos_y += height; @@ -244,6 +251,13 @@ namespace PckStudio.Forms.Editor isItem = file.Filename.Split('/').Contains("items"); TileName = Path.GetFileNameWithoutExtension(file.Filename); + + InterpolationCheckbox.Visible = !(TileName == "clock" || TileName == "compass"); + InterpolationCheckbox.Checked = InterpolationCheckbox.Visible; + bulkAnimationSpeedToolStripMenuItem.Enabled = InterpolationCheckbox.Visible; + importJavaAnimationToolStripMenuItem.Enabled = InterpolationCheckbox.Visible; + exportJavaAnimationToolStripMenuItem.Enabled = InterpolationCheckbox.Visible; + animationFile = file; using MemoryStream textureMem = new MemoryStream(animationFile.Data); @@ -326,10 +340,10 @@ namespace PckStudio.Forms.Editor { string anim = currentAnimation.BuildAnim(); - animationFile.Properties.SetProperty("ANIM", anim); + animationFile.Properties.SetProperty("ANIM", TileName == "clock" || TileName == "compass" ? "" : anim); using (var stream = new MemoryStream()) { - currentAnimation.BuildTexture().Save(stream, ImageFormat.Png); + currentAnimation.BuildTexture(this).Save(stream, ImageFormat.Png); animationFile.SetData(stream.ToArray()); } //Reusing this for the tile path @@ -435,7 +449,7 @@ namespace PckStudio.Forms.Editor diag.SaveBtn.Text = "Add"; if (diag.ShowDialog(this) == DialogResult.OK) { - currentAnimation.AddFrame(diag.FrameTextureIndex, diag.FrameTime); + currentAnimation.AddFrame(diag.FrameTextureIndex, TileName == "clock" || TileName == "compass" ? 1 : diag.FrameTime); LoadAnimationTreeView(); } } @@ -551,6 +565,13 @@ namespace PckStudio.Forms.Editor Console.WriteLine(diag.SelectedTile); if (TileName != diag.SelectedTile) isItem = diag.IsItem; TileName = diag.SelectedTile; + + InterpolationCheckbox.Visible = !(TileName == "clock" || TileName == "compass"); + InterpolationCheckbox.Checked = InterpolationCheckbox.Visible; + bulkAnimationSpeedToolStripMenuItem.Enabled = InterpolationCheckbox.Visible; + importJavaAnimationToolStripMenuItem.Enabled = InterpolationCheckbox.Visible; + exportJavaAnimationToolStripMenuItem.Enabled = InterpolationCheckbox.Visible; + foreach (JObject content in AnimationUtil.tileData[animationSection].Children()) { var first = content.Properties().FirstOrDefault(p => p.Name == TileName); @@ -583,7 +604,7 @@ namespace PckStudio.Forms.Editor mcmeta["animation"] = animation; File.WriteAllText(fileDialog.FileName, JsonConvert.SerializeObject(mcmeta, Formatting.Indented)); string fn = fileDialog.FileName; - currentAnimation.BuildTexture().Save(fn.Remove(fn.Length - 7)); + currentAnimation.BuildTexture(this).Save(fn.Remove(fn.Length - 7)); MessageBox.Show("Your animation was successfully exported at " + fn, "Successful export"); }