From 73bbbf9ddad46e2d34afa63a21b847557f31db83 Mon Sep 17 00:00:00 2001 From: quinnvoker Date: Sat, 29 Dec 2018 17:31:39 -0800 Subject: [PATCH] Added mods: ChangeFrameDelay, MoveSprite(NC), RenameAnimation, RenameFrame, ReorderSprite, ReplaceFrame, SetSpritePosition(NC); Changed: Removed opening conditionals from several mods --- AnimationEditor/AnimationEditor.csproj | 7 + AnimationEditor/Form1.Designer.cs | 102 +++++----- AnimationEditor/Form1.cs | 174 ++++++++++-------- AnimationEditor/Modifications/AddFrame.cs | 10 +- .../Modifications/ChangeFrameDelay.cs | 88 +++++++++ AnimationEditor/Modifications/ModHelper.cs | 4 +- AnimationEditor/Modifications/MoveSprite.cs | 81 ++++++++ .../Modifications/RemoveAnimation.cs | 21 +-- AnimationEditor/Modifications/RemoveFrame.cs | 25 ++- AnimationEditor/Modifications/RemoveSprite.cs | 25 ++- .../Modifications/RenameAnimation.cs | 67 +++++++ AnimationEditor/Modifications/RenameFrame.cs | 88 +++++++++ AnimationEditor/Modifications/ReorderFrame.cs | 8 +- .../Modifications/ReorderSprite.cs | 71 +++++++ .../Modifications/ReplaceSprite.cs | 69 +++++++ .../Modifications/SetSpritePosition.cs | 67 +++++++ 16 files changed, 734 insertions(+), 173 deletions(-) create mode 100644 AnimationEditor/Modifications/ChangeFrameDelay.cs create mode 100644 AnimationEditor/Modifications/MoveSprite.cs create mode 100644 AnimationEditor/Modifications/RenameAnimation.cs create mode 100644 AnimationEditor/Modifications/RenameFrame.cs create mode 100644 AnimationEditor/Modifications/ReorderSprite.cs create mode 100644 AnimationEditor/Modifications/ReplaceSprite.cs create mode 100644 AnimationEditor/Modifications/SetSpritePosition.cs diff --git a/AnimationEditor/AnimationEditor.csproj b/AnimationEditor/AnimationEditor.csproj index 908c3c9..657515d 100644 --- a/AnimationEditor/AnimationEditor.csproj +++ b/AnimationEditor/AnimationEditor.csproj @@ -68,6 +68,13 @@ + + + + + + + diff --git a/AnimationEditor/Form1.Designer.cs b/AnimationEditor/Form1.Designer.cs index 1092a98..7470189 100644 --- a/AnimationEditor/Form1.Designer.cs +++ b/AnimationEditor/Form1.Designer.cs @@ -71,6 +71,8 @@ this.spriteYPosBox = new System.Windows.Forms.NumericUpDown(); this.spriteXPosBox = new System.Windows.Forms.NumericUpDown(); this.removeSpriteButton = new System.Windows.Forms.Button(); + this.moveSpriteUpButton = new System.Windows.Forms.Button(); + this.moveSpriteDownButton = new System.Windows.Forms.Button(); this.frameSpriteListBox = new System.Windows.Forms.ListBox(); this.frameSpriteListLabel = new System.Windows.Forms.Label(); this.replaceSpriteButton = new System.Windows.Forms.Button(); @@ -83,16 +85,14 @@ this.frameInfoLabel = new System.Windows.Forms.Label(); this.frameBoxLabel = new System.Windows.Forms.Label(); this.spriteBoxLabel = new System.Windows.Forms.Label(); + this.spritePreview = new System.Windows.Forms.PictureBox(); this.duplicateFrameButton = new System.Windows.Forms.Button(); this.addEmptyFrameButton = new System.Windows.Forms.Button(); this.animationPanel = new System.Windows.Forms.Panel(); this.animationNameLabel = new System.Windows.Forms.Label(); this.animationLabel = new System.Windows.Forms.Label(); - this.animationPreview = new AnimationEditor.AnimationPreview(); this.loadAnimationSetDialog = new System.Windows.Forms.OpenFileDialog(); - this.moveSpriteUpButton = new System.Windows.Forms.Button(); - this.moveSpriteDownButton = new System.Windows.Forms.Button(); - this.spritePreview = new System.Windows.Forms.PictureBox(); + this.animationPreview = new AnimationEditor.AnimationPreview(); ((System.ComponentModel.ISupportInitialize)(this.frameTrackBar)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.delayInputBox)).BeginInit(); this.mainMenuStrip.SuspendLayout(); @@ -102,8 +102,8 @@ ((System.ComponentModel.ISupportInitialize)(this.spriteYPosBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.spriteXPosBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.importDelayBox)).BeginInit(); - this.animationPanel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.spritePreview)).BeginInit(); + this.animationPanel.SuspendLayout(); this.SuspendLayout(); // // loadSpriteSheetDialog @@ -147,6 +147,7 @@ // addSpriteToFrameListButton // this.addSpriteToFrameListButton.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.addSpriteToFrameListButton.Enabled = false; this.addSpriteToFrameListButton.Location = new System.Drawing.Point(130, 130); this.addSpriteToFrameListButton.Name = "addSpriteToFrameListButton"; this.addSpriteToFrameListButton.Size = new System.Drawing.Size(27, 23); @@ -190,7 +191,8 @@ this.animationNameBox.Name = "animationNameBox"; this.animationNameBox.Size = new System.Drawing.Size(100, 20); this.animationNameBox.TabIndex = 10; - this.animationNameBox.TextChanged += new System.EventHandler(this.animationNameBox_TextChanged); + this.animationNameBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.animationNameBox_KeyPress); + this.animationNameBox.Leave += new System.EventHandler(this.animationNameBox_Leave); // // playAnimationButton // @@ -440,6 +442,8 @@ this.frameNameBox.Size = new System.Drawing.Size(83, 20); this.frameNameBox.TabIndex = 25; this.frameNameBox.TextChanged += new System.EventHandler(this.frameNameBox_TextChanged); + this.frameNameBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.frameNameBox_KeyPress); + this.frameNameBox.Leave += new System.EventHandler(this.frameNameBox_Leave); // // frameSpritePanel // @@ -550,6 +554,30 @@ this.removeSpriteButton.UseVisualStyleBackColor = true; this.removeSpriteButton.Click += new System.EventHandler(this.removeSpriteButton_Click); // + // moveSpriteUpButton + // + this.moveSpriteUpButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.moveSpriteUpButton.Location = new System.Drawing.Point(109, 0); + this.moveSpriteUpButton.Margin = new System.Windows.Forms.Padding(0, 3, 0, 3); + this.moveSpriteUpButton.Name = "moveSpriteUpButton"; + this.moveSpriteUpButton.Size = new System.Drawing.Size(23, 23); + this.moveSpriteUpButton.TabIndex = 26; + this.moveSpriteUpButton.Text = "↑"; + this.moveSpriteUpButton.UseVisualStyleBackColor = true; + this.moveSpriteUpButton.Click += new System.EventHandler(this.moveSpriteUpButton_Click); + // + // moveSpriteDownButton + // + this.moveSpriteDownButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.moveSpriteDownButton.Location = new System.Drawing.Point(86, 0); + this.moveSpriteDownButton.Margin = new System.Windows.Forms.Padding(3, 3, 0, 3); + this.moveSpriteDownButton.Name = "moveSpriteDownButton"; + this.moveSpriteDownButton.Size = new System.Drawing.Size(23, 23); + this.moveSpriteDownButton.TabIndex = 26; + this.moveSpriteDownButton.Text = "↓"; + this.moveSpriteDownButton.UseVisualStyleBackColor = true; + this.moveSpriteDownButton.Click += new System.EventHandler(this.moveSpriteDownButton_Click); + // // frameSpriteListBox // this.frameSpriteListBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); @@ -575,6 +603,7 @@ // replaceSpriteButton // this.replaceSpriteButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.replaceSpriteButton.Enabled = false; this.replaceSpriteButton.Location = new System.Drawing.Point(1, 56); this.replaceSpriteButton.Name = "replaceSpriteButton"; this.replaceSpriteButton.Size = new System.Drawing.Size(27, 23); @@ -587,6 +616,7 @@ // addSpriteToFrameSpritesButton // this.addSpriteToFrameSpritesButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.addSpriteToFrameSpritesButton.Enabled = false; this.addSpriteToFrameSpritesButton.Location = new System.Drawing.Point(1, 36); this.addSpriteToFrameSpritesButton.Name = "addSpriteToFrameSpritesButton"; this.addSpriteToFrameSpritesButton.Size = new System.Drawing.Size(27, 23); @@ -676,6 +706,17 @@ this.spriteBoxLabel.TabIndex = 15; this.spriteBoxLabel.Text = "Sprite Selection"; // + // spritePreview + // + this.spritePreview.BackColor = System.Drawing.SystemColors.ControlDark; + this.spritePreview.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; + this.spritePreview.Location = new System.Drawing.Point(5, 19); + this.spritePreview.Name = "spritePreview"; + this.spritePreview.Size = new System.Drawing.Size(119, 43); + this.spritePreview.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.spritePreview.TabIndex = 6; + this.spritePreview.TabStop = false; + // // duplicateFrameButton // this.duplicateFrameButton.Location = new System.Drawing.Point(130, 18); @@ -736,6 +777,12 @@ this.animationLabel.TabIndex = 22; this.animationLabel.Text = "Animation"; // + // loadAnimationSetDialog + // + this.loadAnimationSetDialog.DefaultExt = "animset"; + this.loadAnimationSetDialog.FileName = "openFileDialog1"; + this.loadAnimationSetDialog.Filter = "QUROGames AnimationSet|*.animSet"; + // // animationPreview // this.animationPreview.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -756,47 +803,6 @@ this.animationPreview.ZoomLevel = 0F; this.animationPreview.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.animationPreview_MouseWheel); // - // loadAnimationSetDialog - // - this.loadAnimationSetDialog.DefaultExt = "animset"; - this.loadAnimationSetDialog.FileName = "openFileDialog1"; - this.loadAnimationSetDialog.Filter = "QUROGames AnimationSet|*.animSet"; - // - // moveSpriteUpButton - // - this.moveSpriteUpButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.moveSpriteUpButton.Location = new System.Drawing.Point(109, 0); - this.moveSpriteUpButton.Margin = new System.Windows.Forms.Padding(0, 3, 0, 3); - this.moveSpriteUpButton.Name = "moveSpriteUpButton"; - this.moveSpriteUpButton.Size = new System.Drawing.Size(23, 23); - this.moveSpriteUpButton.TabIndex = 26; - this.moveSpriteUpButton.Text = "↑"; - this.moveSpriteUpButton.UseVisualStyleBackColor = true; - this.moveSpriteUpButton.Click += new System.EventHandler(this.moveSpriteUpButton_Click); - // - // moveSpriteDownButton - // - this.moveSpriteDownButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.moveSpriteDownButton.Location = new System.Drawing.Point(86, 0); - this.moveSpriteDownButton.Margin = new System.Windows.Forms.Padding(3, 3, 0, 3); - this.moveSpriteDownButton.Name = "moveSpriteDownButton"; - this.moveSpriteDownButton.Size = new System.Drawing.Size(23, 23); - this.moveSpriteDownButton.TabIndex = 26; - this.moveSpriteDownButton.Text = "↓"; - this.moveSpriteDownButton.UseVisualStyleBackColor = true; - this.moveSpriteDownButton.Click += new System.EventHandler(this.moveSpriteDownButton_Click); - // - // spritePreview - // - this.spritePreview.BackColor = System.Drawing.SystemColors.ControlDark; - this.spritePreview.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; - this.spritePreview.Location = new System.Drawing.Point(5, 19); - this.spritePreview.Name = "spritePreview"; - this.spritePreview.Size = new System.Drawing.Size(119, 43); - this.spritePreview.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; - this.spritePreview.TabIndex = 6; - this.spritePreview.TabStop = false; - // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -822,9 +828,9 @@ ((System.ComponentModel.ISupportInitialize)(this.spriteYPosBox)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.spriteXPosBox)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.importDelayBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.spritePreview)).EndInit(); this.animationPanel.ResumeLayout(false); this.animationPanel.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.spritePreview)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); diff --git a/AnimationEditor/Form1.cs b/AnimationEditor/Form1.cs index 350404c..2b390c3 100644 --- a/AnimationEditor/Form1.cs +++ b/AnimationEditor/Form1.cs @@ -44,6 +44,7 @@ namespace AnimationEditor private Animation currentAnimation; private Frame currentFrame; + private bool frameNameBoxEdited; private bool tracking; private bool reading; private float importDelay = 0; @@ -128,7 +129,8 @@ namespace AnimationEditor else animationPreview.PreviewSprite.CurrentAnimation = currentAnimation; frameTrackBar.Maximum = currentAnimation.Frames.Count() - 1; - frameListBox_SetSingleSelection(frameTrackBar.Value); + if(frameListBox.SelectedIndices.Count < 2 && frameListBox.SelectedIndex != frameTrackBar.Value) + frameListBox_SetSingleSelection(frameTrackBar.Value); if(animations.Count < 1) { animations.Add(currentAnimation); @@ -156,7 +158,7 @@ namespace AnimationEditor //update per-sprite controls spritePosPanel.Enabled = singleSpriteSelected; - replaceSpriteButton.Enabled = singleSpriteSelected; + replaceSpriteButton.Enabled = singleSpriteSelected && spriteSet != null; moveSpriteDownButton.Enabled = singleSpriteSelected; moveSpriteUpButton.Enabled = singleSpriteSelected; removeSpriteButton.Enabled = singleSpriteSelected; @@ -241,6 +243,10 @@ namespace AnimationEditor } } + //ensure at least one sprite is selected + if (frameSprites.Count > 0 && frameSpriteListBox.SelectedIndices.Count < 1) + frameSpriteListBox.SelectedIndex = 0; + //update forms fields to match selected frame's informations UpdateFrameInformation(); } @@ -262,11 +268,11 @@ namespace AnimationEditor private void delayInputBox_ValueChanged(object sender, EventArgs e) { - foreach(int index in frameListBox.SelectedIndices) - { - var currentFrame = frames[index]; - currentFrame.Delay = (float)delayInputBox.Value / frameRate; - } + if (reading || tracking) + return; + var mod = new ChangeFrameDelay(frames, frameListBox, (float)delayInputBox.Value / frameRate); + ModHelper.DoModificationWithSelectionTracking(mod, animationBox, frameListBox, frameSpriteListBox); + undoHistory.Add(mod); } private void loadSpriteSheetToolStripMenuItem_Click(object sender, EventArgs e) @@ -305,6 +311,11 @@ namespace AnimationEditor spriteListBox.DisplayMember = "Name"; spriteListBox.ValueMember = "Bounds"; + //enable spriteMap-required controls + addSpriteToFrameListButton.Enabled = true; + addSpriteToFrameSpritesButton.Enabled = true; + replaceSpriteButton.Enabled = true; + if (currentAnimation == null) { frames = new BindingList(); @@ -370,14 +381,7 @@ namespace AnimationEditor { if (frameListBox.SelectedIndices.Count == 1 && frameListBox.SelectedIndex < frames.Count - 1) { - MoveListItem(frames, frameListBox, 1); - /* - var frameBelow = frames[frameListBox.SelectedIndex + 1]; - frames[frameListBox.SelectedIndex + 1] = currentFrame; - frames[frameListBox.SelectedIndex] = frameBelow; - UpdateAnimation(); - frameListBox_SetSingleSelection(frameListBox.SelectedIndex + 1); - */ + MoveFrame(frames, frameListBox, 1); } } @@ -385,18 +389,11 @@ namespace AnimationEditor { if (frameListBox.SelectedIndices.Count == 1 && frameListBox.SelectedIndex > 0) { - MoveListItem(frames, frameListBox, -1); - /* - var frameAbove = frames[frameListBox.SelectedIndex - 1]; - frames[frameListBox.SelectedIndex - 1] = currentFrame; - frames[frameListBox.SelectedIndex] = frameAbove; - UpdateAnimation(); - frameListBox_SetSingleSelection(frameListBox.SelectedIndex - 1); - */ + MoveFrame(frames, frameListBox, -1); } } - private void MoveListItem(BindingList frameList, ListBox frameBox, int dir) + private void MoveFrame(BindingList frameList, ListBox frameBox, int dir) { var mod = new ReorderFrame(frameList, frameBox, dir); ModHelper.DoModificationWithSelectionTracking(mod, animationBox, frameListBox, frameSpriteListBox); @@ -415,15 +412,6 @@ namespace AnimationEditor } } - private void animationNameBox_TextChanged(object sender, EventArgs e) - { - if (reading || currentAnimation.Name == animationNameBox.Text) - return; - - currentAnimation.Name = animationNameBox.Text; - animations.ResetBindings(); - } - private void saveAnimationToolStripMenuItem_Click(object sender, EventArgs e) { if (saveAnimationDialog.ShowDialog() == DialogResult.OK) @@ -633,9 +621,13 @@ namespace AnimationEditor if (reading || frameSpriteListBox.SelectedIndex >= currentFrame.Sprites.Count) return; + SetSpritePosition(); + currentFrame.Sprites = frameSprites.ToList(); + /* var newPos = currentFrame.Sprites[frameSpriteListBox.SelectedIndex].Offset; newPos.X = (float)spriteXPosBox.Value; currentFrame.Sprites[frameSpriteListBox.SelectedIndex].Offset = newPos; + */ } //update Y offset of selected sprite with position entered into spriteYPosBox @@ -644,9 +636,20 @@ namespace AnimationEditor if (reading || frameSpriteListBox.SelectedIndex >= currentFrame.Sprites.Count) return; + SetSpritePosition(); + currentFrame.Sprites = frameSprites.ToList(); + /* var newPos = currentFrame.Sprites[frameSpriteListBox.SelectedIndex].Offset; newPos.Y = (float)spriteYPosBox.Value; currentFrame.Sprites[frameSpriteListBox.SelectedIndex].Offset = newPos; + */ + } + + private void SetSpritePosition() + { + var mod = new SetSpritePosition(frameSprites, frameSpriteListBox, new Vector2((float)spriteXPosBox.Value, (float)spriteYPosBox.Value)); + ModHelper.DoModificationWithSelectionTracking(mod, animationBox, frameListBox, frameSpriteListBox); + undoHistory.Add(mod); } private void addSpriteToFrameSpritesButton_Click(object sender, EventArgs e) @@ -663,39 +666,24 @@ namespace AnimationEditor AddFrame(new Frame()); } - private void frameNameBox_TextChanged(object sender, EventArgs e) + private void RenameFrames() { - if (reading) - return; - bool changed = false; foreach(int index in frameListBox.SelectedIndices) { if (frames[index].Name != frameNameBox.Text) { - frames[index].Name = frameNameBox.Text; changed = true; + break; } } if (changed) { - //store current frame selection data - List selection = new List(); - foreach (int index in frameListBox.SelectedIndices) - { - selection.Add(index); - } - //refresh list so name changes are reflected in form - frames.ResetBindings(); - //restore selection - reading = true; - foreach(int index in selection) - { - frameListBox.SelectedIndex = index; - } - reading = false; + var mod = new RenameFrame(frames, frameListBox, frameNameBox.Text); + ModHelper.DoModificationWithSelectionTracking(mod, animationBox, frameListBox, frameSpriteListBox); + undoHistory.Add(mod); } } @@ -703,14 +691,7 @@ namespace AnimationEditor { if (frameSpriteListBox.SelectedIndex < currentFrame.Sprites.Count - 1) { - var index = frameSpriteListBox.SelectedIndex; - - var currentSprite = frameSprites[index]; - var spriteBelow = frameSprites[index + 1]; - frameSprites[index + 1] = currentSprite; - frameSprites[index] = spriteBelow; - UpdateAnimation(); - frameSpriteListBox.SelectedIndex = index + 1; + MoveSprite(frameSprites, frameSpriteListBox, 1); } } @@ -718,17 +699,18 @@ namespace AnimationEditor { if (frameSpriteListBox.SelectedIndex > 0) { - var index = frameSpriteListBox.SelectedIndex; - - var currentSprite = frameSprites[index]; - var spriteAbove = frameSprites[index - 1]; - frameSprites[index - 1] = currentSprite; - frameSprites[index] = spriteAbove; - UpdateAnimation(); - frameSpriteListBox.SelectedIndex = index - 1; + MoveSprite(frameSprites, frameSpriteListBox, -1); } } + private void MoveSprite(BindingList spriteList, ListBox spriteBox, int dir) + { + var mod = new ReorderSprite(spriteList, spriteBox, dir); + ModHelper.DoModificationWithSelectionTracking(mod, animationBox, frameListBox, frameSpriteListBox); + undoHistory.Add(mod); + UpdateAnimation(); + } + private void removeSpriteButton_Click(object sender, EventArgs e) { if (frameSpriteListBox.SelectedIndex > -1 && frameSpriteListBox.SelectedIndex < frameSprites.Count) @@ -753,12 +735,9 @@ namespace AnimationEditor private void replaceSpriteButton_Click(object sender, EventArgs e) { - var spr = frameSprites[frameSpriteListBox.SelectedIndex]; - var replacement = spriteSet[spriteListBox.SelectedIndex]; - - spr.Bounds = replacement.Bounds; - spr.Origin = replacement.Origin; - spr.Name = replacement.Name; + var mod = new ReplaceSprite(frameSprites, frameSpriteListBox.SelectedIndex, spriteSet[spriteListBox.SelectedIndex]); + ModHelper.DoModificationWithSelectionTracking(mod, animationBox, frameListBox, frameSpriteListBox); + undoHistory.Add(mod); UpdateAnimation(); } @@ -773,5 +752,50 @@ namespace AnimationEditor undoHistory.Redo(animationBox, frameListBox, frameSpriteListBox); UpdateAnimation(); } + + private void UpdateAnimationName() + { + var mod = new RenameAnimation(animations, animationBox.SelectedIndex, animationNameBox.Text); + ModHelper.DoModificationWithSelectionTracking(mod, animationBox, frameListBox, frameSpriteListBox); + undoHistory.Add(mod); + } + + private void animationNameBox_Leave(object sender, EventArgs e) + { + if (animations[animationBox.SelectedIndex].Name != animationNameBox.Text) + { + UpdateAnimationName(); + } + } + + private void animationNameBox_KeyPress(object sender, KeyPressEventArgs e) + { + if (e.KeyChar == (char)Keys.Return && animations[animationBox.SelectedIndex].Name != animationNameBox.Text) + { + UpdateAnimationName(); + } + } + + private void frameNameBox_Leave(object sender, EventArgs e) + { + if (frameNameBoxEdited) + RenameFrames(); + frameNameBoxEdited = false; + } + + private void frameNameBox_KeyPress(object sender, KeyPressEventArgs e) + { + if (e.KeyChar == (char)Keys.Return && frameNameBoxEdited) + RenameFrames(); + frameNameBoxEdited = false; + } + + private void frameNameBox_TextChanged(object sender, EventArgs e) + { + if(!reading && !tracking) + { + frameNameBoxEdited = true; + } + } } } diff --git a/AnimationEditor/Modifications/AddFrame.cs b/AnimationEditor/Modifications/AddFrame.cs index d7a33d3..ecc0774 100644 --- a/AnimationEditor/Modifications/AddFrame.cs +++ b/AnimationEditor/Modifications/AddFrame.cs @@ -18,7 +18,8 @@ namespace AnimationEditor.Modifications private BindingList frames; private ListBox frameListBox; - private Frame frameToAdd; + private Frame frameToAdd; + private int index; public AddFrame(BindingList frameList, ListBox frameBox, Frame frame = null) { @@ -27,6 +28,7 @@ namespace AnimationEditor.Modifications if (frame != null) frameToAdd = frame; else frameToAdd = new Frame(); + index = frameListBox.SelectedIndex; } public void Do() @@ -42,15 +44,15 @@ namespace AnimationEditor.Modifications frames.Clear(); } - if (frameListBox.SelectedItem == null || frameListBox.SelectedIndex == frames.Count - 1) + if (frameListBox.SelectedItem == null || index == frames.Count - 1) { frames.Add(frameToAdd); newSelectedIndex = frames.Count - 1; } else { - frames.Insert(frameListBox.SelectedIndex + 1, frameToAdd); - newSelectedIndex = frameListBox.SelectedIndex + 1; + frames.Insert(index + 1, frameToAdd); + newSelectedIndex = index + 1; } ModHelper.SetSingleSelection(frameListBox, newSelectedIndex); } diff --git a/AnimationEditor/Modifications/ChangeFrameDelay.cs b/AnimationEditor/Modifications/ChangeFrameDelay.cs new file mode 100644 index 0000000..afe4ba1 --- /dev/null +++ b/AnimationEditor/Modifications/ChangeFrameDelay.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel; +using QURO; +using QURO.Animation; +using System.Windows.Forms; +using Microsoft.Xna.Framework; + +namespace AnimationEditor.Modifications +{ + class ChangeFrameDelay : IModification + { + private SelectionState preChangeSelection; + private SelectionState postChangeSelection; + + private BindingList frames; + private ListBox listBox; + private List indices; + private Dictionary originalDelays; + private float newDelay; + + public ChangeFrameDelay(BindingList frameList, ListBox frameListBox, float delay) + { + frames = frameList; + listBox = frameListBox; + indices = new List(); + originalDelays = new Dictionary(); + foreach (int i in frameListBox.SelectedIndices) + { + indices.Add(i); + originalDelays.Add(i, frames[i].Delay); + } + newDelay = delay; + } + + public void Do() + { + foreach (int index in indices) + { + frames[index].Delay = newDelay; + } + frames.ResetBindings(); + listBox.SelectedIndices.Clear(); + foreach (int index in indices) + { + listBox.SelectedIndices.Add(index); + } + } + + public void Undo() + { + foreach (int index in indices) + { + frames[index].Delay = originalDelays[index]; + } + frames.ResetBindings(); + } + + public SelectionState GetPreChangeSelection() + { + return preChangeSelection; + } + public void SetPreChangeSelection(SelectionState currentSelection) + { + preChangeSelection = currentSelection; + } + public SelectionState GetPostChangeSelection() + { + return postChangeSelection; + } + public void SetPostChangeSelection(SelectionState currentSelection) + { + postChangeSelection = currentSelection; + } + + public override string ToString() + { + if (indices.Count == 1) + return "Change Frame Delay"; + else + return "Change Frame Delays"; + } + } +} + diff --git a/AnimationEditor/Modifications/ModHelper.cs b/AnimationEditor/Modifications/ModHelper.cs index e010ce7..4aed7c4 100644 --- a/AnimationEditor/Modifications/ModHelper.cs +++ b/AnimationEditor/Modifications/ModHelper.cs @@ -40,13 +40,13 @@ namespace AnimationEditor.Modifications frameBox.SelectedIndices.Clear(); foreach(int index in selection.SelectedFrames) { - frameBox.SelectedIndex = index; + frameBox.SelectedIndices.Add(index); } frameSpriteBox.SelectedIndices.Clear(); foreach(int index in selection.SelectedFrameSprites) { - frameSpriteBox.SelectedIndex = index; + frameSpriteBox.SelectedIndices.Add(index); } } diff --git a/AnimationEditor/Modifications/MoveSprite.cs b/AnimationEditor/Modifications/MoveSprite.cs new file mode 100644 index 0000000..8a8ca96 --- /dev/null +++ b/AnimationEditor/Modifications/MoveSprite.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel; +using QURO; +using QURO.Animation; +using System.Windows.Forms; +using Microsoft.Xna.Framework; + +namespace AnimationEditor.Modifications +{ + class MoveSprite : IModification + { + private SelectionState preChangeSelection; + private SelectionState postChangeSelection; + + private BindingList sprites; + private ListBox listBox; + private List indices; + private Dictionary originalPositions; + private Vector2 dist; + + public MoveSprite(BindingList spriteList, ListBox spriteListBox, Vector2 distance) + { + sprites = spriteList; + listBox = spriteListBox; + indices = new List(); + originalPositions = new Dictionary(); + foreach (int i in spriteListBox.SelectedIndices) + { + indices.Add(i); + originalPositions.Add(i, sprites[i].Offset); + } + dist = distance; + } + + public void Do() + { + foreach (int index in indices) + { + sprites[index].Offset += dist; + } + } + + public void Undo() + { + foreach (int index in indices) + { + sprites[index].Offset = originalPositions[index]; + } + } + + public SelectionState GetPreChangeSelection() + { + return preChangeSelection; + } + public void SetPreChangeSelection(SelectionState currentSelection) + { + preChangeSelection = currentSelection; + } + public SelectionState GetPostChangeSelection() + { + return postChangeSelection; + } + public void SetPostChangeSelection(SelectionState currentSelection) + { + postChangeSelection = currentSelection; + } + + public override string ToString() + { + if (indices.Count == 1) + return "Move Sprite"; + else + return "Move Sprites"; + } + } +} + diff --git a/AnimationEditor/Modifications/RemoveAnimation.cs b/AnimationEditor/Modifications/RemoveAnimation.cs index e549b46..bd36187 100644 --- a/AnimationEditor/Modifications/RemoveAnimation.cs +++ b/AnimationEditor/Modifications/RemoveAnimation.cs @@ -31,20 +31,17 @@ namespace AnimationEditor.Modifications public void Do() { - if (removeIndex > -1 && removeIndex < animations.Count) + removedAnim = animations[removeIndex]; + if (animations.Count == 1) { - removedAnim = animations[removeIndex]; - if (animations.Count == 1) + animations[removeIndex] = new Animation(); + } + else + { + animations.RemoveAt(removeIndex); + if (animationBox.SelectedIndex > animations.Count - 1) { - animations[removeIndex] = new Animation(); - } - else - { - animations.RemoveAt(removeIndex); - if (animationBox.SelectedIndex > animations.Count - 1) - { - animationBox.SelectedIndex--; - } + animationBox.SelectedIndex--; } } } diff --git a/AnimationEditor/Modifications/RemoveFrame.cs b/AnimationEditor/Modifications/RemoveFrame.cs index dfa84dd..a9adf00 100644 --- a/AnimationEditor/Modifications/RemoveFrame.cs +++ b/AnimationEditor/Modifications/RemoveFrame.cs @@ -31,22 +31,19 @@ namespace AnimationEditor.Modifications public void Do() { - if(removeIndex > -1 && removeIndex < frames.Count) + removedFrame = frames[removeIndex]; + + if(frames.Count == 1) { - removedFrame = frames[removeIndex]; + frames.Clear(); + frames.Add(new Frame()); + } + else + frames.RemoveAt(removeIndex); - if(frames.Count == 1) - { - frames.Clear(); - frames.Add(new Frame()); - } - else - frames.RemoveAt(removeIndex); - - if (frames.Count > -1 && frameListBox.SelectedIndex > frames.Count - 1) - { - ModHelper.SetSingleSelection(frameListBox, frames.Count - 1); - } + if (frames.Count > -1 && frameListBox.SelectedIndex > frames.Count - 1) + { + ModHelper.SetSingleSelection(frameListBox, frames.Count - 1); } } diff --git a/AnimationEditor/Modifications/RemoveSprite.cs b/AnimationEditor/Modifications/RemoveSprite.cs index 01137c0..d353d0a 100644 --- a/AnimationEditor/Modifications/RemoveSprite.cs +++ b/AnimationEditor/Modifications/RemoveSprite.cs @@ -30,21 +30,18 @@ namespace AnimationEditor.Modifications public void Do() { - if(removeIndex > -1 && removeIndex < sprites.Count) + removedSprite = sprites[removeIndex]; + + if(sprites.Count == 1) { - removedSprite = sprites[removeIndex]; + sprites.Clear(); + } + else + sprites.RemoveAt(removeIndex); - if(sprites.Count == 1) - { - sprites.Clear(); - } - else - sprites.RemoveAt(removeIndex); - - if (sprites.Count > -1 && spriteListBox.SelectedIndex > sprites.Count - 1) - { - ModHelper.SetSingleSelection(spriteListBox, sprites.Count - 1); - } + if (sprites.Count > -1 && spriteListBox.SelectedIndex > sprites.Count - 1) + { + ModHelper.SetSingleSelection(spriteListBox, sprites.Count - 1); } } @@ -76,7 +73,7 @@ namespace AnimationEditor.Modifications public override string ToString() { - return "Remove Frame"; + return "Remove Sprite"; } } } diff --git a/AnimationEditor/Modifications/RenameAnimation.cs b/AnimationEditor/Modifications/RenameAnimation.cs new file mode 100644 index 0000000..2c6b250 --- /dev/null +++ b/AnimationEditor/Modifications/RenameAnimation.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel; +using QURO; +using QURO.Animation; +using System.Windows.Forms; +using Microsoft.Xna.Framework; + +namespace AnimationEditor.Modifications +{ + class RenameAnimation : IModification + { + private SelectionState preChangeSelection; + private SelectionState postChangeSelection; + + private BindingList anims; + private int index; + private string originalName; + private string newName; + + public RenameAnimation(BindingList animList, int index, string name) + { + anims = animList; + this.index = index; + originalName = anims[index].Name; + newName = name; + } + + public void Do() + { + anims[index].Name = newName; + anims.ResetBindings(); + } + + public void Undo() + { + anims[index].Name = originalName; + anims.ResetBindings(); + } + + public SelectionState GetPreChangeSelection() + { + return preChangeSelection; + } + public void SetPreChangeSelection(SelectionState currentSelection) + { + preChangeSelection = currentSelection; + } + public SelectionState GetPostChangeSelection() + { + return postChangeSelection; + } + public void SetPostChangeSelection(SelectionState currentSelection) + { + postChangeSelection = currentSelection; + } + + public override string ToString() + { + return "Rename Animation"; + } + } +} + diff --git a/AnimationEditor/Modifications/RenameFrame.cs b/AnimationEditor/Modifications/RenameFrame.cs new file mode 100644 index 0000000..f5f7c65 --- /dev/null +++ b/AnimationEditor/Modifications/RenameFrame.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel; +using QURO; +using QURO.Animation; +using System.Windows.Forms; +using Microsoft.Xna.Framework; + +namespace AnimationEditor.Modifications +{ + class RenameFrame : IModification + { + private SelectionState preChangeSelection; + private SelectionState postChangeSelection; + + private BindingList frames; + private ListBox listBox; + private List indices; + private Dictionary originalNames; + private string newName; + + public RenameFrame(BindingList frameList, ListBox frameListBox, string name) + { + frames = frameList; + listBox = frameListBox; + indices = new List(); + originalNames = new Dictionary(); + foreach(int i in frameListBox.SelectedIndices) + { + indices.Add(i); + originalNames.Add(i, frames[i].Name); + } + newName = name; + } + + public void Do() + { + foreach (int index in indices) + { + frames[index].Name = newName; + } + frames.ResetBindings(); + listBox.SelectedIndices.Clear(); + foreach (int index in indices) + { + listBox.SelectedIndices.Add(index); + } + } + + public void Undo() + { + foreach (int index in indices) + { + frames[index].Name = originalNames[index]; + } + frames.ResetBindings(); + } + + public SelectionState GetPreChangeSelection() + { + return preChangeSelection; + } + public void SetPreChangeSelection(SelectionState currentSelection) + { + preChangeSelection = currentSelection; + } + public SelectionState GetPostChangeSelection() + { + return postChangeSelection; + } + public void SetPostChangeSelection(SelectionState currentSelection) + { + postChangeSelection = currentSelection; + } + + public override string ToString() + { + if (indices.Count == 1) + return "Rename Frame"; + else + return "Rename Frames"; + } + } +} + diff --git a/AnimationEditor/Modifications/ReorderFrame.cs b/AnimationEditor/Modifications/ReorderFrame.cs index abd0920..94529be 100644 --- a/AnimationEditor/Modifications/ReorderFrame.cs +++ b/AnimationEditor/Modifications/ReorderFrame.cs @@ -16,10 +16,10 @@ namespace AnimationEditor.Modifications private SelectionState preChangeSelection; private SelectionState postChangeSelection; - private BindingList frames; - private ListBox listBox; - private int index; - private int dir; + private readonly BindingList frames; + private readonly ListBox listBox; + private readonly int index; + private readonly int dir; public ReorderFrame(BindingList frameList, ListBox frameListBox, int direction) { diff --git a/AnimationEditor/Modifications/ReorderSprite.cs b/AnimationEditor/Modifications/ReorderSprite.cs new file mode 100644 index 0000000..c9aa3c7 --- /dev/null +++ b/AnimationEditor/Modifications/ReorderSprite.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel; +using QURO; +using QURO.Animation; +using System.Windows.Forms; +using Microsoft.Xna.Framework; + +namespace AnimationEditor.Modifications +{ + class ReorderSprite : IModification + { + private SelectionState preChangeSelection; + private SelectionState postChangeSelection; + + private BindingList sprites; + private ListBox listBox; + private int index; + private int dir; + + public ReorderSprite(BindingList spriteList, ListBox spriteListBox, int direction) + { + sprites = spriteList; + listBox = spriteListBox; + index = spriteListBox.SelectedIndex; + dir = Math.Sign(direction); + } + + public void Do() + { + var movingFrame = sprites[index]; + sprites[index] = sprites[index + dir]; + sprites[index + dir] = movingFrame; + ModHelper.SetSingleSelection(listBox, index + dir); + } + + public void Undo() + { + var movingFrame = sprites[index + dir]; + sprites[index + dir] = sprites[index]; + sprites[index] = movingFrame; + ModHelper.SetSingleSelection(listBox, index); + } + + public SelectionState GetPreChangeSelection() + { + return preChangeSelection; + } + public void SetPreChangeSelection(SelectionState currentSelection) + { + preChangeSelection = currentSelection; + } + public SelectionState GetPostChangeSelection() + { + return postChangeSelection; + } + public void SetPostChangeSelection(SelectionState currentSelection) + { + postChangeSelection = currentSelection; + } + + + public override string ToString() + { + return "Move Sprite"; + } + } +} diff --git a/AnimationEditor/Modifications/ReplaceSprite.cs b/AnimationEditor/Modifications/ReplaceSprite.cs new file mode 100644 index 0000000..39fe750 --- /dev/null +++ b/AnimationEditor/Modifications/ReplaceSprite.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel; +using QURO; +using QURO.Animation; +using System.Windows.Forms; +using Microsoft.Xna.Framework; + +namespace AnimationEditor.Modifications +{ + class ReplaceSprite : IModification + { + private SelectionState preChangeSelection; + private SelectionState postChangeSelection; + + private BindingList sprites; + private int index; + private Sprite original; + private Sprite replacement; + + public ReplaceSprite(BindingList spriteList, int origIndex, Sprite newSprite) + { + sprites = spriteList; + index = origIndex; + original = sprites[index].Clone(); + replacement = newSprite; + } + + public void Do() + { + sprites[index].Name = replacement.Name; + sprites[index].Bounds = replacement.Bounds; + sprites[index].Origin = replacement.Origin; + } + + public void Undo() + { + sprites[index].Name = original.Name; + sprites[index].Bounds = original.Bounds; + sprites[index].Origin = original.Origin; + } + + public SelectionState GetPreChangeSelection() + { + return preChangeSelection; + } + public void SetPreChangeSelection(SelectionState currentSelection) + { + preChangeSelection = currentSelection; + } + public SelectionState GetPostChangeSelection() + { + return postChangeSelection; + } + public void SetPostChangeSelection(SelectionState currentSelection) + { + postChangeSelection = currentSelection; + } + + + public override string ToString() + { + return "Replace Sprite"; + } + } +} diff --git a/AnimationEditor/Modifications/SetSpritePosition.cs b/AnimationEditor/Modifications/SetSpritePosition.cs new file mode 100644 index 0000000..4f2918e --- /dev/null +++ b/AnimationEditor/Modifications/SetSpritePosition.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel; +using QURO; +using QURO.Animation; +using System.Windows.Forms; +using Microsoft.Xna.Framework; + +namespace AnimationEditor.Modifications +{ + class SetSpritePosition : IModification + { + private SelectionState preChangeSelection; + private SelectionState postChangeSelection; + + private BindingList sprites; + private ListBox listBox; + private int index; + private Vector2 originalPosition; + private Vector2 newPosition; + + public SetSpritePosition(BindingList spriteList, ListBox spriteListBox, Vector2 newPos) + { + sprites = spriteList; + listBox = spriteListBox; + index = spriteListBox.SelectedIndex; + originalPosition = sprites[index].Offset; + newPosition = newPos; + } + + public void Do() + { + sprites[index].Offset = newPosition; + } + + public void Undo() + { + sprites[index].Offset = originalPosition; + } + + public SelectionState GetPreChangeSelection() + { + return preChangeSelection; + } + public void SetPreChangeSelection(SelectionState currentSelection) + { + preChangeSelection = currentSelection; + } + public SelectionState GetPostChangeSelection() + { + return postChangeSelection; + } + public void SetPostChangeSelection(SelectionState currentSelection) + { + postChangeSelection = currentSelection; + } + + public override string ToString() + { + return "Set Sprite Position"; + } + } +} +