From 2a4d354d28e98610aa84e2fa6b9ca2157f4d968b Mon Sep 17 00:00:00 2001 From: EternalModz <86510009+EternalModz@users.noreply.github.com> Date: Sat, 15 Mar 2025 13:12:00 -0700 Subject: [PATCH] Animation editor will now flow the same design as MainForm. --- .../Forms/Editor/AnimationEditor.Designer.cs | 30 +- PCK-Studio/Forms/Editor/AnimationEditor.cs | 565 +++++++++--------- 2 files changed, 295 insertions(+), 300 deletions(-) diff --git a/PCK-Studio/Forms/Editor/AnimationEditor.Designer.cs b/PCK-Studio/Forms/Editor/AnimationEditor.Designer.cs index 522972a7..1084b520 100644 --- a/PCK-Studio/Forms/Editor/AnimationEditor.Designer.cs +++ b/PCK-Studio/Forms/Editor/AnimationEditor.Designer.cs @@ -66,20 +66,19 @@ // 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.Dock = System.Windows.Forms.DockStyle.Left; this.frameTreeView.ForeColor = System.Drawing.Color.White; this.frameTreeView.ImageIndex = 0; this.frameTreeView.ImageList = this.TextureIcons; - this.frameTreeView.Location = new System.Drawing.Point(24, 101); + this.frameTreeView.Location = new System.Drawing.Point(0, 28); 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(155, 292); + this.frameTreeView.Size = new System.Drawing.Size(155, 390); 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); @@ -120,16 +119,15 @@ // this.menuStrip.AutoSize = false; this.menuStrip.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); - this.menuStrip.Dock = System.Windows.Forms.DockStyle.None; this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem, this.editToolStripMenuItem, this.helpToolStripMenuItem}); - this.menuStrip.Location = new System.Drawing.Point(24, 69); + this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Padding = new System.Windows.Forms.Padding(7, 2, 0, 2); this.menuStrip.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional; - this.menuStrip.Size = new System.Drawing.Size(157, 28); + this.menuStrip.Size = new System.Drawing.Size(480, 28); this.menuStrip.TabIndex = 14; this.menuStrip.Text = "menuStrip1"; // @@ -279,8 +277,8 @@ // InterpolationCheckbox // this.InterpolationCheckbox.AutoSize = true; - this.InterpolationCheckbox.Location = new System.Drawing.Point(188, 72); - this.InterpolationCheckbox.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.InterpolationCheckbox.Location = new System.Drawing.Point(351, 8); + this.InterpolationCheckbox.Margin = new System.Windows.Forms.Padding(4); this.InterpolationCheckbox.Name = "InterpolationCheckbox"; this.InterpolationCheckbox.Size = new System.Drawing.Size(129, 15); this.InterpolationCheckbox.TabIndex = 17; @@ -293,8 +291,8 @@ // 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(183, 366); - this.AnimationStartStopBtn.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.AnimationStartStopBtn.Location = new System.Drawing.Point(183, 341); + this.AnimationStartStopBtn.Margin = new System.Windows.Forms.Padding(4); this.AnimationStartStopBtn.Name = "AnimationStartStopBtn"; this.AnimationStartStopBtn.Size = new System.Drawing.Size(270, 28); this.AnimationStartStopBtn.Style = MetroFramework.MetroColorStyle.White; @@ -308,11 +306,11 @@ // 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(24, 394); + this.tileLabel.Location = new System.Drawing.Point(183, 50); this.tileLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.tileLabel.MinimumSize = new System.Drawing.Size(199, 22); this.tileLabel.Name = "tileLabel"; - this.tileLabel.Size = new System.Drawing.Size(57, 19); + this.tileLabel.Size = new System.Drawing.Size(199, 22); this.tileLabel.TabIndex = 20; this.tileLabel.Text = "tileLabel"; this.tileLabel.Theme = MetroFramework.MetroThemeStyle.Dark; @@ -326,8 +324,8 @@ this.animationPictureBox.BlendMode = PckStudio.Extensions.BlendMode.Multiply; this.animationPictureBox.Image = null; this.animationPictureBox.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; - this.animationPictureBox.Location = new System.Drawing.Point(183, 101); - this.animationPictureBox.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.animationPictureBox.Location = new System.Drawing.Point(183, 76); + this.animationPictureBox.Margin = new System.Windows.Forms.Padding(4); this.animationPictureBox.Name = "animationPictureBox"; this.animationPictureBox.Size = new System.Drawing.Size(274, 258); this.animationPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; @@ -350,7 +348,7 @@ this.ForeColor = System.Drawing.Color.White; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Location = new System.Drawing.Point(0, 0); - this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.Margin = new System.Windows.Forms.Padding(4); this.MinimumSize = new System.Drawing.Size(478, 411); this.Name = "AnimationEditor"; this.Text = "Animation Editor"; diff --git a/PCK-Studio/Forms/Editor/AnimationEditor.cs b/PCK-Studio/Forms/Editor/AnimationEditor.cs index c155f7bf..f1ad3c12 100644 --- a/PCK-Studio/Forms/Editor/AnimationEditor.cs +++ b/PCK-Studio/Forms/Editor/AnimationEditor.cs @@ -15,70 +15,67 @@ * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. **/ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using PckStudio.Extensions; +using PckStudio.Forms.Additional_Popups.Animation; +using PckStudio.Internal; +using PckStudio.Internal.Deserializer; +using PckStudio.Internal.Serializer; +using PckStudio.Properties; +using PckStudio.ToolboxItems; using System; +using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Windows.Forms; -using System.Collections.Generic; -using System.Diagnostics; -using MetroFramework.Forms; - -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -using PckStudio.Forms.Additional_Popups.Animation; -using PckStudio.Extensions; -using PckStudio.Properties; -using PckStudio.Internal; -using PckStudio.Internal.Deserializer; -using PckStudio.Internal.Serializer; -using PckStudio.ToolboxItems; namespace PckStudio.Forms.Editor { public partial class AnimationEditor : ThemeForm - { + { public Animation Result => _animation; - private Animation _animation; - private bool _isSpecialTile; + private Animation _animation; + private bool _isSpecialTile; - private AnimationEditor() - { + private AnimationEditor() + { InitializeComponent(); toolStripSeparator1.Visible = saveToolStripMenuItem1.Visible = !Settings.Default.AutoSaveChanges; } internal AnimationEditor(Animation animation, string displayName, bool isSpecialTile = false) - : this() - { - _ = animation ?? throw new ArgumentNullException(nameof(animation)); - _animation = animation; + : this() + { + _ = animation ?? throw new ArgumentNullException(nameof(animation)); + _animation = animation; tileLabel.Text = displayName; _isSpecialTile = isSpecialTile; animationPictureBox.Image = animation.CreateAnimationImage(); } internal AnimationEditor(Animation animation, string displayName, Color blendColor) - : this(animation, displayName) + : this(animation, displayName) { - animationPictureBox.UseBlendColor = true; - animationPictureBox.BlendColor = blendColor; + animationPictureBox.UseBlendColor = true; + animationPictureBox.BlendColor = blendColor; } - private void ValidateToolStrip() + private void ValidateToolStrip() { - bulkAnimationSpeedToolStripMenuItem.Enabled = - importToolStripMenuItem.Enabled = - exportAsToolStripMenuItem.Enabled = - InterpolationCheckbox.Visible = !_isSpecialTile; - } + bulkAnimationSpeedToolStripMenuItem.Enabled = + importToolStripMenuItem.Enabled = + exportAsToolStripMenuItem.Enabled = + InterpolationCheckbox.Visible = !_isSpecialTile; + } private void AnimationEditor_Load(object sender, EventArgs e) { - ValidateToolStrip(); + ValidateToolStrip(); LoadAnimationTreeView(); } @@ -95,11 +92,11 @@ namespace PckStudio.Forms.Editor TextureIcons.Images.AddRange(_animation.GetTextures().ToArray()); UpdateTreeView(); - animationPictureBox.Image ??= _animation.CreateAnimationImage(); + animationPictureBox.Image ??= _animation.CreateAnimationImage(); if (_animation.FrameCount > 0) { - animationPictureBox.Image.SelectActiveFrame(FrameDimension.Page, 0); + animationPictureBox.Image.SelectActiveFrame(FrameDimension.Page, 0); } } @@ -115,152 +112,152 @@ namespace PckStudio.Forms.Editor }) .ToArray() ); - } + } private void frameTreeView_AfterSelect(object sender, TreeViewEventArgs e) - { - if (animationPictureBox.IsPlaying) - { - StopAnimation(); - } - animationPictureBox.Image = _animation.GetFrame(frameTreeView.SelectedNode.Index).Texture; - } - - private void StopAnimation() { - animationPictureBox.Stop(); - AnimationStartStopBtn.Text = "Play Animation"; - } + if (animationPictureBox.IsPlaying) + { + StopAnimation(); + } + animationPictureBox.Image = _animation.GetFrame(frameTreeView.SelectedNode.Index).Texture; + } - private void AnimationStartStopBtn_Click(object sender, EventArgs e) - { - if (animationPictureBox.IsPlaying) - { - StopAnimation(); - return; - } + private void StopAnimation() + { + animationPictureBox.Stop(); + AnimationStartStopBtn.Text = "Play Animation"; + } + + private void AnimationStartStopBtn_Click(object sender, EventArgs e) + { + if (animationPictureBox.IsPlaying) + { + StopAnimation(); + return; + } if (_animation.FrameCount > 1) - { - animationPictureBox.Image = _animation.CreateAnimationImage(); + { + animationPictureBox.Image = _animation.CreateAnimationImage(); animationPictureBox.Start(); - AnimationStartStopBtn.Text = "Stop Animation"; - } - } + AnimationStartStopBtn.Text = "Stop Animation"; + } + } - private void frameTreeView_KeyDown(object sender, KeyEventArgs e) - { - if (e.KeyData == Keys.Delete) - removeFrameToolStripMenuItem_Click(sender, e); - } + private void frameTreeView_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyData == Keys.Delete) + removeFrameToolStripMenuItem_Click(sender, e); + } - private TreeNode FindNodeByName(TreeNode treeNode, string name) - { - foreach (TreeNode node in treeNode.Nodes) - { - if (node.Text.ToLower() == name.ToLower()) - return node; - return FindNodeByName(node, name); - } - return null; - } + private TreeNode FindNodeByName(TreeNode treeNode, string name) + { + foreach (TreeNode node in treeNode.Nodes) + { + if (node.Text.ToLower() == name.ToLower()) + return node; + return FindNodeByName(node, name); + } + return null; + } - private void saveToolStripMenuItem1_Click(object sender, EventArgs e) - { - if (!_isSpecialTile && _animation is not null && _animation.FrameCount > 0) - { - DialogResult = DialogResult.OK; - return; - } - DialogResult = DialogResult.Cancel; - } + private void saveToolStripMenuItem1_Click(object sender, EventArgs e) + { + if (!_isSpecialTile && _animation is not null && _animation.FrameCount > 0) + { + DialogResult = DialogResult.OK; + return; + } + DialogResult = DialogResult.Cancel; + } - // Most of the code below is modified code from this link: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.treeview.itemdrag?view=windowsdesktop-6.0 - // - MattNL + // Most of the code below is modified code from this link: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.treeview.itemdrag?view=windowsdesktop-6.0 + // - MattNL - private void frameTreeView_ItemDrag(object sender, ItemDragEventArgs e) - { - // Move the dragged node when the left mouse button is used. - if (e.Button == MouseButtons.Left) - { - DoDragDrop(e.Item, DragDropEffects.Move); - } - } + private void frameTreeView_ItemDrag(object sender, ItemDragEventArgs e) + { + // Move the dragged node when the left mouse button is used. + if (e.Button == MouseButtons.Left) + { + DoDragDrop(e.Item, DragDropEffects.Move); + } + } - // Set the target drop effect to the effect - // specified in the ItemDrag event handler. - private void frameTreeView_DragEnter(object sender, DragEventArgs e) - { - e.Effect = e.AllowedEffect; - } + // Set the target drop effect to the effect + // specified in the ItemDrag event handler. + private void frameTreeView_DragEnter(object sender, DragEventArgs e) + { + e.Effect = e.AllowedEffect; + } - // Select the node under the mouse pointer to indicate the - // expected drop location. - private void frameTreeView_DragOver(object sender, DragEventArgs e) - { - // Retrieve the client coordinates of the mouse position. - Point targetPoint = frameTreeView.PointToClient(new Point(e.X, e.Y)); + // Select the node under the mouse pointer to indicate the + // expected drop location. + private void frameTreeView_DragOver(object sender, DragEventArgs e) + { + // Retrieve the client coordinates of the mouse position. + Point targetPoint = frameTreeView.PointToClient(new Point(e.X, e.Y)); - // Select the node at the mouse position. - frameTreeView.SelectedNode = frameTreeView.GetNodeAt(targetPoint); - } + // Select the node at the mouse position. + frameTreeView.SelectedNode = frameTreeView.GetNodeAt(targetPoint); + } - private void frameTreeView_DragDrop(object sender, DragEventArgs e) - { - // Retrieve the client coordinates of the drop location. - Point targetPoint = frameTreeView.PointToClient(new Point(e.X, e.Y)); + private void frameTreeView_DragDrop(object sender, DragEventArgs e) + { + // Retrieve the client coordinates of the drop location. + Point targetPoint = frameTreeView.PointToClient(new Point(e.X, e.Y)); - // Retrieve the node at the drop location. - TreeNode targetNode = frameTreeView.GetNodeAt(targetPoint); + // Retrieve the node at the drop location. + TreeNode targetNode = frameTreeView.GetNodeAt(targetPoint); - // Retrieve the node that was dragged. - TreeNode draggedNode = (TreeNode)e.Data.GetData(typeof(TreeNode)); + // Retrieve the node that was dragged. + TreeNode draggedNode = (TreeNode)e.Data.GetData(typeof(TreeNode)); - // Confirm that the node at the drop location is not - // the dragged node or a descendant of the dragged node. - if (targetNode == null) - { - draggedNode.Remove(); - frameTreeView.Nodes.Add(draggedNode); - } - else if (!draggedNode.Equals(targetNode) && !ContainsNode(draggedNode, targetNode)) - { - // If it is a move operation, remove the node from its current - // location and add it to the node at the drop location. + // Confirm that the node at the drop location is not + // the dragged node or a descendant of the dragged node. + if (targetNode == null) + { + draggedNode.Remove(); + frameTreeView.Nodes.Add(draggedNode); + } + else if (!draggedNode.Equals(targetNode) && !ContainsNode(draggedNode, targetNode)) + { + // If it is a move operation, remove the node from its current + // location and add it to the node at the drop location. - if (e.Effect == DragDropEffects.Move) - { - int draggedIndex = draggedNode.Index; - int targetIndex = targetNode.Index; - _animation.SwapFrames(draggedIndex, targetIndex); - UpdateTreeView(); - } - } - } + if (e.Effect == DragDropEffects.Move) + { + int draggedIndex = draggedNode.Index; + int targetIndex = targetNode.Index; + _animation.SwapFrames(draggedIndex, targetIndex); + UpdateTreeView(); + } + } + } - // Determine whether one node is a parent - // or ancestor of a second node. - private bool ContainsNode(TreeNode node1, TreeNode node2) - { - // Check the parent node of the second node. - if (node2.Parent == null) - return false; - if (node2.Parent.Equals(node1)) - return true; + // Determine whether one node is a parent + // or ancestor of a second node. + private bool ContainsNode(TreeNode node1, TreeNode node2) + { + // Check the parent node of the second node. + if (node2.Parent == null) + return false; + if (node2.Parent.Equals(node1)) + return true; - // If the parent node is not null or equal to the first node, - // call the ContainsNode method recursively using the parent of - // the second node. - return ContainsNode(node1, node2.Parent); - } + // If the parent node is not null or equal to the first node, + // call the ContainsNode method recursively using the parent of + // the second node. + return ContainsNode(node1, node2.Parent); + } - private void treeView1_doubleClick(object sender, EventArgs e) - { + private void treeView1_doubleClick(object sender, EventArgs e) + { Animation.Frame frame = _animation.GetFrame(frameTreeView.SelectedNode.Index); using FrameEditor diag = new FrameEditor(frame.Ticks, _animation.GetTextureIndex(frame.Texture), TextureIcons); - if (diag.ShowDialog(this) == DialogResult.OK) + if (diag.ShowDialog(this) == DialogResult.OK) { - /* Found a bug here. When passing the frame variable, + /* Found a bug here. When passing the frame variable, * it would replace the first instance of that frame and time * rather than the actual frame that was clicked. * I've just switched to passing the index to fix this for now. @@ -272,48 +269,48 @@ namespace PckStudio.Forms.Editor } } - private void addFrameToolStripMenuItem_Click(object sender, EventArgs e) - { + private void addFrameToolStripMenuItem_Click(object sender, EventArgs e) + { using FrameEditor diag = new FrameEditor(TextureIcons); - diag.SaveButton.Text = "Add"; - if (diag.ShowDialog(this) == DialogResult.OK) - { + diag.SaveButton.Text = "Add"; + if (diag.ShowDialog(this) == DialogResult.OK) + { _animation.AddFrame(diag.FrameTextureIndex, _isSpecialTile ? Animation.MinimumFrameTime : diag.FrameTime); UpdateTreeView(); - } - } + } + } - private void removeFrameToolStripMenuItem_Click(object sender, EventArgs e) - { - if (frameTreeView.SelectedNode is TreeNode t && _animation.RemoveFrame(t.Index)) - { - frameTreeView.SelectedNode.Remove(); - } - } + private void removeFrameToolStripMenuItem_Click(object sender, EventArgs e) + { + if (frameTreeView.SelectedNode is TreeNode t && _animation.RemoveFrame(t.Index)) + { + frameTreeView.SelectedNode.Remove(); + } + } - private void bulkAnimationSpeedToolStripMenuItem_Click(object sender, EventArgs e) - { - SetBulkSpeed diag = new SetBulkSpeed(); - if (diag.ShowDialog(this) == DialogResult.OK) - { - if (animationPictureBox.IsPlaying) - animationPictureBox.Stop(); + private void bulkAnimationSpeedToolStripMenuItem_Click(object sender, EventArgs e) + { + SetBulkSpeed diag = new SetBulkSpeed(); + if (diag.ShowDialog(this) == DialogResult.OK) + { + if (animationPictureBox.IsPlaying) + animationPictureBox.Stop(); _animation.SetFrameTicks(diag.Ticks); - UpdateTreeView(); - } - diag.Dispose(); - } + UpdateTreeView(); + } + diag.Dispose(); + } - private void importJavaAnimationToolStripMenuItem_Click(object sender, EventArgs e) - { - if (MessageBox.Show( - this, - "This feature will replace the existing animation data. " + - "It might fail if the selected animation script is invalid. " + - "Are you sure that you want to continue?", - "Warning", - MessageBoxButtons.YesNo) == DialogResult.No) - return; + private void importJavaAnimationToolStripMenuItem_Click(object sender, EventArgs e) + { + if (MessageBox.Show( + this, + "This feature will replace the existing animation data. " + + "It might fail if the selected animation script is invalid. " + + "Are you sure that you want to continue?", + "Warning", + MessageBoxButtons.YesNo) == DialogResult.No) + return; OpenFileDialog fileDialog = new OpenFileDialog { @@ -324,122 +321,122 @@ namespace PckStudio.Forms.Editor Filter = "Animation Scripts (*.mcmeta)|*.png.mcmeta" }; if (fileDialog.ShowDialog(this) != DialogResult.OK) - return; - Debug.WriteLine("Selected Animation Script: " + fileDialog.FileName); + return; + Debug.WriteLine("Selected Animation Script: " + fileDialog.FileName); - string textureFile = fileDialog.FileName.Substring(0, fileDialog.FileName.Length - ".mcmeta".Length); + string textureFile = fileDialog.FileName.Substring(0, fileDialog.FileName.Length - ".mcmeta".Length); if (!File.Exists(textureFile)) - { - MessageBox.Show(this, textureFile + " was not found", "Texture not found"); - return; - } + { + MessageBox.Show(this, textureFile + " was not found", "Texture not found"); + return; + } try - { - var img = Image.FromFile(textureFile); - JObject mcmeta = JObject.Parse(File.ReadAllText(fileDialog.FileName)); + { + var img = Image.FromFile(textureFile); + JObject mcmeta = JObject.Parse(File.ReadAllText(fileDialog.FileName)); Animation javaAnimation = AnimationDeserializer.DefaultDeserializer.DeserializeJavaAnimation(mcmeta, img); - _animation = javaAnimation; - LoadAnimationTreeView(); - } - catch (JsonException j_ex) - { - MessageBox.Show(this, j_ex.Message, "Invalid animation"); - return; - } - } + _animation = javaAnimation; + LoadAnimationTreeView(); + } + catch (JsonException j_ex) + { + MessageBox.Show(this, j_ex.Message, "Invalid animation"); + return; + } + } - private void exportJavaAnimationToolStripMenuItem_Click(object sender, EventArgs e) - { - SaveFileDialog fileDialog = new SaveFileDialog(); - fileDialog.Title = "Please choose where you want to save your new animation"; - fileDialog.Filter = "Animation Scripts (*.mcmeta)|*.png.mcmeta"; - if (fileDialog.ShowDialog(this) == DialogResult.OK) + private void exportJavaAnimationToolStripMenuItem_Click(object sender, EventArgs e) + { + SaveFileDialog fileDialog = new SaveFileDialog(); + fileDialog.Title = "Please choose where you want to save your new animation"; + fileDialog.Filter = "Animation Scripts (*.mcmeta)|*.png.mcmeta"; + if (fileDialog.ShowDialog(this) == DialogResult.OK) { JObject mcmeta = AnimationSerializer.SerializeJavaAnimation(_animation); string jsondata = JsonConvert.SerializeObject(mcmeta, Formatting.Indented); string filename = fileDialog.FileName; File.WriteAllText(filename, jsondata); Image finalTexture = AnimationSerializer.SerializeTexture(_animation); - // removes ".mcmeta" from filename - string texturePath = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename)); + // removes ".mcmeta" from filename + string texturePath = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename)); finalTexture.Save(texturePath); MessageBox.Show(this, "Animation was successfully exported as " + Path.GetFileName(filename), "Export successful!"); } } private void howToInterpolation_Click(object sender, EventArgs e) - { - MessageBox.Show(this, "The Interpolation effect is when the animtion smoothly translates between the frames instead of simply displaying the next one. This can be seen with some vanilla Minecraft textures such as Magma and Prismarine.", "Interpolation"); - } + { + MessageBox.Show(this, "The Interpolation effect is when the animtion smoothly translates between the frames instead of simply displaying the next one. This can be seen with some vanilla Minecraft textures such as Magma and Prismarine.", "Interpolation"); + } - private void editorControlsToolStripMenuItem_Click(object sender, EventArgs e) - { - MessageBox.Show(this, "Simply drag and drop frames in the tree to rearrange your animation.\n\n" + - "You can also preview your animation at any time by simply pressing the button under the animation display.", "Editor Controls"); - } + private void editorControlsToolStripMenuItem_Click(object sender, EventArgs e) + { + MessageBox.Show(this, "Simply drag and drop frames in the tree to rearrange your animation.\n\n" + + "You can also preview your animation at any time by simply pressing the button under the animation display.", "Editor Controls"); + } - private void setBulkSpeedToolStripMenuItem_Click(object sender, EventArgs e) - { - MessageBox.Show(this, "You can edit the frame and its speed by double clicking a frame in the tree. If you'd like to change the entire animation's speed, you can do so with the \"Set Bulk Animation Speed\" button in the \"Tools\" tab", "How to use Bulk Animation tool"); - } + private void setBulkSpeedToolStripMenuItem_Click(object sender, EventArgs e) + { + MessageBox.Show(this, "You can edit the frame and its speed by double clicking a frame in the tree. If you'd like to change the entire animation's speed, you can do so with the \"Set Bulk Animation Speed\" button in the \"Tools\" tab", "How to use Bulk Animation tool"); + } - private void javaAnimationSupportToolStripMenuItem_Click(object sender, EventArgs e) - { - MessageBox.Show(this, "You can import any valid Java Edition tile animations into your pck by opening an mcmeta.\n\n" + - "You can also export your animation as an Java Edition tile animation. It will also export the actual texture in the same spot.", "Java Edition Support"); - } + private void javaAnimationSupportToolStripMenuItem_Click(object sender, EventArgs e) + { + MessageBox.Show(this, "You can import any valid Java Edition tile animations into your pck by opening an mcmeta.\n\n" + + "You can also export your animation as an Java Edition tile animation. It will also export the actual texture in the same spot.", "Java Edition Support"); + } - private void InterpolationCheckbox_CheckedChanged(object sender, EventArgs e) - { - if (_animation is not null) - _animation.Interpolate = InterpolationCheckbox.Checked; - } + private void InterpolationCheckbox_CheckedChanged(object sender, EventArgs e) + { + if (_animation is not null) + _animation.Interpolate = InterpolationCheckbox.Checked; + } private void AnimationEditor_FormClosing(object sender, FormClosingEventArgs e) { - if (animationPictureBox.IsPlaying) - { + if (animationPictureBox.IsPlaying) + { animationPictureBox.Stop(); - } - if (Settings.Default.AutoSaveChanges) - { - saveToolStripMenuItem1_Click(sender, EventArgs.Empty); - } + } + if (Settings.Default.AutoSaveChanges) + { + saveToolStripMenuItem1_Click(sender, EventArgs.Empty); + } } private void importGifToolStripMenuItem_Click(object sender, EventArgs e) { - OpenFileDialog fileDialog = new OpenFileDialog() - { - Filter = "GIF file|*.gif" - }; - if (fileDialog.ShowDialog(this) != DialogResult.OK) - return; + OpenFileDialog fileDialog = new OpenFileDialog() + { + Filter = "GIF file|*.gif" + }; + if (fileDialog.ShowDialog(this) != DialogResult.OK) + return; - var gif = Image.FromFile(fileDialog.FileName); - if (!gif.RawFormat.Equals(ImageFormat.Gif)) - { - MessageBox.Show(this, "Selected file is not a gif", "Invalid file", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } + var gif = Image.FromFile(fileDialog.FileName); + if (!gif.RawFormat.Equals(ImageFormat.Gif)) + { + MessageBox.Show(this, "Selected file is not a gif", "Invalid file", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } - var oldResolution = _animation.GetFrame(0).Texture.Width; + var oldResolution = _animation.GetFrame(0).Texture.Width; FrameDimension dimension = new FrameDimension(gif.FrameDimensionsList[0]); int frameCount = gif.GetFrameCount(dimension); - var textures = new List(frameCount); + var textures = new List(frameCount); - for (int i = 0; i < frameCount; i++) - { - gif.SelectActiveFrame(dimension, i); + for (int i = 0; i < frameCount; i++) + { + gif.SelectActiveFrame(dimension, i); - textures.Add(new Bitmap(gif, oldResolution, oldResolution)); - } + textures.Add(new Bitmap(gif, oldResolution, oldResolution)); + } _animation = new Animation(textures, initFramesFromTextures: true); _animation.Interpolate = InterpolationCheckbox.Checked; - LoadAnimationTreeView(); + LoadAnimationTreeView(); } private void importAnimationTextureToolStripMenuItem_Click(object sender, EventArgs e) @@ -453,27 +450,27 @@ namespace PckStudio.Forms.Editor return; using Image img = Image.FromFile(ofd.FileName); IEnumerable textures = img.Split(ImageLayoutDirection.Vertical); - _animation = new Animation(textures, initFramesFromTextures: true); - LoadAnimationTreeView(); + _animation = new Animation(textures, initFramesFromTextures: true); + LoadAnimationTreeView(); } - private void gifToolStripMenuItem_Click(object sender, EventArgs e) + private void gifToolStripMenuItem_Click(object sender, EventArgs e) { - var fileDialog = new SaveFileDialog() - { - FileName = tileLabel.Text, - Filter = "GIF file|*.gif" - }; - if (fileDialog.ShowDialog(this) != DialogResult.OK) - return; - _animation.CreateAnimationImage().Save(fileDialog.FileName); - } + var fileDialog = new SaveFileDialog() + { + FileName = tileLabel.Text, + Filter = "GIF file|*.gif" + }; + if (fileDialog.ShowDialog(this) != DialogResult.OK) + return; + _animation.CreateAnimationImage().Save(fileDialog.FileName); + } - private void frameTimeandTicksToolStripMenuItem_Click(object sender, EventArgs e) - { - MessageBox.Show(this, "The frame time is the time that the current frame is displayed for. This unit is measured in ticks. " + - "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"); - } + private void frameTimeandTicksToolStripMenuItem_Click(object sender, EventArgs e) + { + MessageBox.Show(this, "The frame time is the time that the current frame is displayed for. This unit is measured in ticks. " + + "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"); + } } }