From aaa80bd65492e21e9289d52ec1daed5ab05e29c7 Mon Sep 17 00:00:00 2001 From: quinnvoker Date: Wed, 26 Dec 2018 21:07:21 -0800 Subject: [PATCH] Added: SelectionState; New Undoable Mods: AddAnimation, RemoveAnimation, AddFrame, RemoveFrame, RemoveSprite --- AnimationEditor/AnimationEditor.csproj | 16 +++ AnimationEditor/Form1.Designer.cs | 100 +++++++++++------- AnimationEditor/Form1.cs | 91 ++++++++-------- AnimationEditor/Modifications/AddAnimation.cs | 65 ++++++++++++ AnimationEditor/Modifications/AddFrame.cs | 98 +++++++++++++++++ AnimationEditor/Modifications/History.cs | 94 ++++++++++++++++ .../Modifications/IModification.cs | 19 ++++ AnimationEditor/Modifications/ModHelper.cs | 59 +++++++++++ .../Modifications/RemoveAnimation.cs | 88 +++++++++++++++ AnimationEditor/Modifications/RemoveFrame.cs | 89 ++++++++++++++++ AnimationEditor/Modifications/RemoveSprite.cs | 82 ++++++++++++++ .../Modifications/SelectionState.cs | 23 ++++ .../Properties/Resources.Designer.cs | 44 ++++---- AnimationEditor/Properties/Resources.resx | 13 ++- AnimationEditor/Resources/13test.png | Bin 0 -> 987 bytes AnimationEditor/Resources/15test.png | Bin 0 -> 991 bytes 16 files changed, 761 insertions(+), 120 deletions(-) create mode 100644 AnimationEditor/Modifications/AddAnimation.cs create mode 100644 AnimationEditor/Modifications/AddFrame.cs create mode 100644 AnimationEditor/Modifications/History.cs create mode 100644 AnimationEditor/Modifications/IModification.cs create mode 100644 AnimationEditor/Modifications/ModHelper.cs create mode 100644 AnimationEditor/Modifications/RemoveAnimation.cs create mode 100644 AnimationEditor/Modifications/RemoveFrame.cs create mode 100644 AnimationEditor/Modifications/RemoveSprite.cs create mode 100644 AnimationEditor/Modifications/SelectionState.cs create mode 100644 AnimationEditor/Resources/13test.png create mode 100644 AnimationEditor/Resources/15test.png diff --git a/AnimationEditor/AnimationEditor.csproj b/AnimationEditor/AnimationEditor.csproj index dacf2d5..41887ef 100644 --- a/AnimationEditor/AnimationEditor.csproj +++ b/AnimationEditor/AnimationEditor.csproj @@ -66,6 +66,13 @@ + + + + + + + Component @@ -75,6 +82,8 @@ Form1.cs + + @@ -136,6 +145,7 @@ True Resources.resx + True @@ -157,5 +167,11 @@ QURO + + + + + + \ No newline at end of file diff --git a/AnimationEditor/Form1.Designer.cs b/AnimationEditor/Form1.Designer.cs index 06577a6..1092a98 100644 --- a/AnimationEditor/Form1.Designer.cs +++ b/AnimationEditor/Form1.Designer.cs @@ -33,7 +33,6 @@ this.spriteListBox = new System.Windows.Forms.ListBox(); this.frameListBox = new System.Windows.Forms.ListBox(); this.addSpriteToFrameListButton = new System.Windows.Forms.Button(); - this.spritePreview = new System.Windows.Forms.PictureBox(); this.frameTrackBar = new System.Windows.Forms.TrackBar(); this.delayInputBox = new System.Windows.Forms.NumericUpDown(); this.animationBox = new System.Windows.Forms.ComboBox(); @@ -53,6 +52,8 @@ this.loadAnimationSetToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveAnimationSetToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.undoToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.redoToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.updateAnimationSpritesFromSpriteMapToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.animationLoopCheckBox = new System.Windows.Forms.CheckBox(); this.saveAnimationDialog = new System.Windows.Forms.SaveFileDialog(); @@ -70,8 +71,6 @@ 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(); @@ -91,7 +90,9 @@ this.animationLabel = new System.Windows.Forms.Label(); this.animationPreview = new AnimationEditor.AnimationPreview(); this.loadAnimationSetDialog = new System.Windows.Forms.OpenFileDialog(); - ((System.ComponentModel.ISupportInitialize)(this.spritePreview)).BeginInit(); + this.moveSpriteUpButton = new System.Windows.Forms.Button(); + this.moveSpriteDownButton = new System.Windows.Forms.Button(); + this.spritePreview = new System.Windows.Forms.PictureBox(); ((System.ComponentModel.ISupportInitialize)(this.frameTrackBar)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.delayInputBox)).BeginInit(); this.mainMenuStrip.SuspendLayout(); @@ -102,6 +103,7 @@ ((System.ComponentModel.ISupportInitialize)(this.spriteXPosBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.importDelayBox)).BeginInit(); this.animationPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.spritePreview)).BeginInit(); this.SuspendLayout(); // // loadSpriteSheetDialog @@ -153,17 +155,6 @@ this.addSpriteToFrameListButton.UseVisualStyleBackColor = true; this.addSpriteToFrameListButton.Click += new System.EventHandler(this.addSpriteToFrameListButton_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; - // // frameTrackBar // this.frameTrackBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) @@ -331,12 +322,28 @@ // editToolStripMenuItem // this.editToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.undoToolStripMenuItem, + this.redoToolStripMenuItem, this.updateAnimationSpritesFromSpriteMapToolStripMenuItem}); this.editToolStripMenuItem.Enabled = false; this.editToolStripMenuItem.Name = "editToolStripMenuItem"; this.editToolStripMenuItem.Size = new System.Drawing.Size(39, 20); this.editToolStripMenuItem.Text = "Edit"; // + // undoToolStripMenuItem + // + this.undoToolStripMenuItem.Name = "undoToolStripMenuItem"; + this.undoToolStripMenuItem.Size = new System.Drawing.Size(304, 22); + this.undoToolStripMenuItem.Text = "Undo"; + this.undoToolStripMenuItem.Click += new System.EventHandler(this.undoToolStripMenuItem_Click); + // + // redoToolStripMenuItem + // + this.redoToolStripMenuItem.Name = "redoToolStripMenuItem"; + this.redoToolStripMenuItem.Size = new System.Drawing.Size(304, 22); + this.redoToolStripMenuItem.Text = "Redo"; + this.redoToolStripMenuItem.Click += new System.EventHandler(this.redoToolStripMenuItem_Click); + // // updateAnimationSpritesFromSpriteMapToolStripMenuItem // this.updateAnimationSpritesFromSpriteMapToolStripMenuItem.Enabled = false; @@ -543,30 +550,6 @@ 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))); @@ -779,6 +762,41 @@ 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); @@ -791,7 +809,6 @@ this.MinimumSize = new System.Drawing.Size(780, 345); this.Name = "Form1"; this.Text = "QUROGames Animation Studio"; - ((System.ComponentModel.ISupportInitialize)(this.spritePreview)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.frameTrackBar)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.delayInputBox)).EndInit(); this.mainMenuStrip.ResumeLayout(false); @@ -807,6 +824,7 @@ ((System.ComponentModel.ISupportInitialize)(this.importDelayBox)).EndInit(); this.animationPanel.ResumeLayout(false); this.animationPanel.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.spritePreview)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -877,6 +895,8 @@ private System.Windows.Forms.Button duplicateFrameButton; private System.Windows.Forms.Button replaceSpriteButton; private System.Windows.Forms.Panel spritePosPanel; + private System.Windows.Forms.ToolStripMenuItem undoToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem redoToolStripMenuItem; } } diff --git a/AnimationEditor/Form1.cs b/AnimationEditor/Form1.cs index 538e81f..a0fdbd9 100644 --- a/AnimationEditor/Form1.cs +++ b/AnimationEditor/Form1.cs @@ -14,12 +14,15 @@ using Microsoft.Xna.Framework.Graphics; using QURO.Animation; using QURO; using System.Xml; +using AnimationEditor.Modifications; using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate; namespace AnimationEditor { public partial class Form1 : Form { + private History undoHistory; + private Texture2D _spriteSheet; //property ensures animationPreview holds a copy of whatever spriteSheet the editor is using private Texture2D spriteSheet @@ -48,6 +51,7 @@ namespace AnimationEditor public Form1() { InitializeComponent(); + undoHistory = new History(); frameRate = 60; importDelayBox.Value = 0; animationPreview.FrameChanged += animationPreview_FrameChanged; @@ -101,30 +105,10 @@ namespace AnimationEditor private void AddFrame(Frame frameToAdd) { - int newSelectedIndex; - - //if only frame in animation is uninitiated and input is not empty, clear the list - if (frameToAdd.Name != "empty" && - frames.Count == 1 && - frames[0].Sprites.Count == 1 && - frames[0].Sprites[0].Name == "empty") - { - frames.Clear(); - } - - if (frameListBox.SelectedItem == null || frameListBox.SelectedIndex == frames.Count - 1) - { - frames.Add(frameToAdd); - frameTrackBar.Maximum = frames.Count - 1; - newSelectedIndex = frames.Count - 1; - } - else - { - frames.Insert(frameListBox.SelectedIndex + 1, frameToAdd); - newSelectedIndex = frameListBox.SelectedIndex + 1; - } + var modification = new AddFrame(frames, frameListBox, frameToAdd); + ModHelper.DoModificationWithSelectionTracking(modification, animationBox, frameListBox, frameSpriteListBox); + undoHistory.Add(modification); UpdateAnimation(); - frameListBox_SetSingleSelection(newSelectedIndex); } private void UpdateAnimation() @@ -235,6 +219,7 @@ namespace AnimationEditor if (animationPreview.PreviewSprite != null && !animationPreview.Playing) { animationPreview.PreviewSprite.CurrentFrameIndex = frameListBox.SelectedIndex; + frameTrackBar.Maximum = frames.Count - 1; frameTrackBar.Value = frameListBox.SelectedIndex; } @@ -409,12 +394,10 @@ namespace AnimationEditor { if(frameListBox.SelectedIndices.Count == 1 && frameListBox.SelectedIndex > -1 && frameListBox.SelectedIndex < frames.Count) { - frames.RemoveAt(frameListBox.SelectedIndex); + var mod = new RemoveFrame(frames, frameListBox, frameListBox.SelectedIndex); + ModHelper.DoModificationWithSelectionTracking(mod, animationBox, frameListBox, spriteListBox); + undoHistory.Add(mod); UpdateAnimation(); - if(frames.Count > 0 && frameListBox.SelectedIndex > frames.Count - 1) - { - frameListBox_SetSingleSelection(frames.Count - 1); - } } } @@ -452,14 +435,20 @@ namespace AnimationEditor EnableAnimationEditingControls(); InitiateAnimationList(); } - animations.Add(loadedAnimation); - animationBox.SelectedIndex = animations.Count - 1; + AddAnimation(loadedAnimation); currentAnimation = animations[animationBox.SelectedIndex]; ReadAnimationInfo(); UpdateAnimation(); } } + private void AddAnimation(Animation anim) + { + var mod = new AddAnimation(animations, animationBox, anim); + ModHelper.DoModificationWithSelectionTracking(mod, animationBox, frameListBox, frameSpriteListBox); + undoHistory.Add(mod); + } + private void animationBox_SelectedIndexChanged(object sender, EventArgs e) { currentAnimation = animations[animationBox.SelectedIndex]; @@ -469,29 +458,18 @@ namespace AnimationEditor private void addAnimationButton_Click(object sender, EventArgs e) { - animations.Add(new Animation()); - animationBox.SelectedIndex = animations.Count - 1; + AddAnimation(new Animation()); } private void removeAnimationButton_Click(object sender, EventArgs e) { - if (animationBox.SelectedIndex > -1 && animationBox.SelectedIndex < animations.Count - 1) + if (animationBox.SelectedIndex > -1 && animationBox.SelectedIndex < animations.Count) { - if (animations.Count == 1) - { - currentAnimation = new Animation(); - animations[animationBox.SelectedIndex] = currentAnimation; - ReadAnimationInfo(); - UpdateAnimation(); - } - else - { - animations.RemoveAt(animationBox.SelectedIndex); - if(animationBox.SelectedIndex > animations.Count - 1) - { - animationBox.SelectedIndex--; - } - } + var mod = new RemoveAnimation(animations, animationBox, animationBox.SelectedIndex); + ModHelper.DoModificationWithSelectionTracking(mod, animationBox, frameListBox, frameSpriteListBox); + undoHistory.Add(mod); + ReadAnimationInfo(); + UpdateAnimation(); } } @@ -545,6 +523,7 @@ namespace AnimationEditor { if (loadAnimationSetDialog.ShowDialog() == DialogResult.OK) { + undoHistory = new History(); AnimationSet loadedAnimSet; using (XmlReader xmlRead = XmlReader.Create(loadAnimationSetDialog.FileName)) @@ -740,7 +719,9 @@ namespace AnimationEditor { if (frameSpriteListBox.SelectedIndex > -1 && frameSpriteListBox.SelectedIndex < frameSprites.Count) { - frameSprites.RemoveAt(frameSpriteListBox.SelectedIndex); + var mod = new RemoveSprite(frameSprites, frameSpriteListBox, frameSpriteListBox.SelectedIndex); + ModHelper.DoModificationWithSelectionTracking(mod, animationBox, frameListBox, frameSpriteListBox); + undoHistory.Add(mod); UpdateAnimation(); } } @@ -766,5 +747,17 @@ namespace AnimationEditor spr.Name = replacement.Name; UpdateAnimation(); } + + private void undoToolStripMenuItem_Click(object sender, EventArgs e) + { + undoHistory.Undo(animationBox, frameListBox, frameSpriteListBox); + UpdateAnimation(); + } + + private void redoToolStripMenuItem_Click(object sender, EventArgs e) + { + undoHistory.Redo(animationBox, frameListBox, frameSpriteListBox); + UpdateAnimation(); + } } } diff --git a/AnimationEditor/Modifications/AddAnimation.cs b/AnimationEditor/Modifications/AddAnimation.cs new file mode 100644 index 0000000..d87a56f --- /dev/null +++ b/AnimationEditor/Modifications/AddAnimation.cs @@ -0,0 +1,65 @@ +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; + +namespace AnimationEditor.Modifications +{ + class AddAnimation : IModification + { + private SelectionState preChangeSelection; + private SelectionState postChangeSelection; + + private BindingList animations; + private ComboBox animationBox; + private Animation animationToAdd; + + public AddAnimation(BindingList animList, ComboBox animBox, Animation anim = null) + { + animations = animList; + animationBox = animBox; + if (anim != null) + animationToAdd = anim; + else animationToAdd = new Animation(); + } + + public void Do() + { + animations.Add(animationToAdd); + animationBox.SelectedIndex = animations.Count - 1; + } + + public void Undo() + { + animations.RemoveAt(animations.Count - 1); + } + + 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 "Add Animation"; + } + } +} diff --git a/AnimationEditor/Modifications/AddFrame.cs b/AnimationEditor/Modifications/AddFrame.cs new file mode 100644 index 0000000..e676bf8 --- /dev/null +++ b/AnimationEditor/Modifications/AddFrame.cs @@ -0,0 +1,98 @@ +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; + +namespace AnimationEditor.Modifications +{ + class AddFrame : IModification + { + private SelectionState preChangeSelection; + private SelectionState postChangeSelection; + + private BindingList frames; + private ListBox frameListBox; + private Frame frameToAdd; + + public AddFrame(BindingList frameList, ListBox frameBox, Frame frame = null) + { + frames = frameList; + frameListBox = frameBox; + if (frame != null) + frameToAdd = frame; + else frameToAdd = new Frame(); + } + + public void Do() + { + int newSelectedIndex; + + //if only frame in animation is uninitiated and input is not empty, clear the list + if (frameToAdd.Name != "empty" && + frames.Count == 1 && + frames[0].Sprites.Count == 1 && + frames[0].Sprites[0].Name == "empty") + { + frames.Clear(); + } + + if (frameListBox.SelectedItem == null || frameListBox.SelectedIndex == frames.Count - 1) + { + frames.Add(frameToAdd); + newSelectedIndex = frames.Count - 1; + } + else + { + frames.Insert(frameListBox.SelectedIndex + 1, frameToAdd); + newSelectedIndex = frameListBox.SelectedIndex + 1; + } + ModHelper.SetSingleSelection(frameListBox, newSelectedIndex); + } + + public void Undo() + { + if(frames.Count < 2) + { + frames.Clear(); + frames.Add(new Frame()); + } + else if(postChangeSelection!= null) + { + int addedFrameIndex = postChangeSelection.SelectedFrames[0]; + frames.RemoveAt(addedFrameIndex); + if(addedFrameIndex > 0) + { + ModHelper.SetSingleSelection(frameListBox, addedFrameIndex - 1); + } + } + } + + 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 "Add Frame"; + } + } +} diff --git a/AnimationEditor/Modifications/History.cs b/AnimationEditor/Modifications/History.cs new file mode 100644 index 0000000..760a63e --- /dev/null +++ b/AnimationEditor/Modifications/History.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AnimationEditor.Modifications +{ + class History + { + private List changes; + private int position; + + public bool CanUndo + { + get { return position >= 0 && changes.Count > 0; } + } + + public bool CanRedo + { + get { return position < changes.Count - 1; } + } + + public History() + { + changes = new List(); + } + + public void Add(IModification change) + { + if (position < changes.Count - 1) + { + changes.RemoveRange(position + 1, changes.Count - 1 - position); + } + changes.Add(change); + position = changes.Count - 1; + } + + public void Undo() + { + if (CanUndo) + { + changes[position].Undo(); + position--; + } + } + + public void Undo(ComboBox animBox, ListBox frameBox, ListBox spriteBox) + { + if (CanUndo) + { + Console.Write("Hist.Pos(" + position + "): "); + ModHelper.UndoAndRestoreSelection(changes[position], animBox, frameBox, spriteBox); + position--; + } + } + + public void Redo() + { + if (CanRedo) + { + changes[position + 1].Do(); + position++; + } + } + + public void Redo(ComboBox animBox, ListBox frameBox, ListBox spriteBox) + { + if (CanRedo) + { + Console.Write("Hist.Pos(" + position + "): "); + ModHelper.RedoAndRestoreSelection(changes[position + 1], animBox, frameBox, spriteBox); + position++; + } + } + + public string NextUndoString() + { + if (!CanUndo) + return "Undo..."; + else + return "Undo " + changes[position]; + } + + public string NextRedoString() + { + if (!CanRedo) + return "Redo..."; + else + return "Redo " + changes[position + 1]; + } + } +} diff --git a/AnimationEditor/Modifications/IModification.cs b/AnimationEditor/Modifications/IModification.cs new file mode 100644 index 0000000..62bc1ec --- /dev/null +++ b/AnimationEditor/Modifications/IModification.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AnimationEditor.Modifications +{ + public interface IModification + { + void Do(); + void Undo(); + SelectionState GetPreChangeSelection(); + void SetPreChangeSelection(SelectionState currentSelection); + SelectionState GetPostChangeSelection(); + void SetPostChangeSelection(SelectionState currentSelection); + } +} diff --git a/AnimationEditor/Modifications/ModHelper.cs b/AnimationEditor/Modifications/ModHelper.cs new file mode 100644 index 0000000..e010ce7 --- /dev/null +++ b/AnimationEditor/Modifications/ModHelper.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.ComponentModel; +using QURO; + +namespace AnimationEditor.Modifications +{ + public static class ModHelper + { + public static void DoModificationWithSelectionTracking(IModification mod, ComboBox animBox, ListBox frameBox, ListBox frameSpriteBox) + { + mod.SetPreChangeSelection(new SelectionState(animBox, frameBox, frameSpriteBox)); + mod.Do(); + mod.SetPostChangeSelection(new SelectionState (animBox, frameBox, frameSpriteBox)); + Console.WriteLine("Perform: " + mod); + } + + public static void UndoAndRestoreSelection(IModification mod, ComboBox animBox, ListBox frameBox, ListBox frameSpriteBox) + { + mod.Undo(); + RestoreSelection(mod.GetPreChangeSelection(), animBox, frameBox, frameSpriteBox); + Console.WriteLine("Undo: " + mod); + } + + public static void RedoAndRestoreSelection(IModification mod, ComboBox animBox, ListBox frameBox, ListBox frameSpriteBox) + { + mod.Do(); + RestoreSelection(mod.GetPostChangeSelection(), animBox, frameBox, frameSpriteBox); + Console.WriteLine("Redo: " + mod); + } + + public static void RestoreSelection(SelectionState selection, ComboBox animBox, ListBox frameBox, ListBox frameSpriteBox) + { + animBox.SelectedIndex = selection.SelectedAnimation; + + frameBox.SelectedIndices.Clear(); + foreach(int index in selection.SelectedFrames) + { + frameBox.SelectedIndex = index; + } + + frameSpriteBox.SelectedIndices.Clear(); + foreach(int index in selection.SelectedFrameSprites) + { + frameSpriteBox.SelectedIndex = index; + } + } + + public static void SetSingleSelection(ListBox lb, int index) + { + lb.SelectedIndices.Clear(); + lb.SelectedIndex = index; + } + } +} diff --git a/AnimationEditor/Modifications/RemoveAnimation.cs b/AnimationEditor/Modifications/RemoveAnimation.cs new file mode 100644 index 0000000..e549b46 --- /dev/null +++ b/AnimationEditor/Modifications/RemoveAnimation.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 Microsoft.Xna.Framework; +using QURO; +using QURO.Animation; +using System.Windows.Forms; + +namespace AnimationEditor.Modifications +{ + class RemoveAnimation : IModification + { + private SelectionState preChangeSelection; + private SelectionState postChangeSelection; + + private BindingList animations; + private ComboBox animationBox; + private int removeIndex; + + private Animation removedAnim; + + public RemoveAnimation(BindingList anims, ComboBox animBox, int index) + { + animations = anims; + animationBox = animBox; + removeIndex = index; + } + + public void Do() + { + if (removeIndex > -1 && removeIndex < animations.Count) + { + removedAnim = animations[removeIndex]; + if (animations.Count == 1) + { + animations[removeIndex] = new Animation(); + } + else + { + animations.RemoveAt(removeIndex); + if (animationBox.SelectedIndex > animations.Count - 1) + { + animationBox.SelectedIndex--; + } + } + } + } + + public void Undo() + { + if(removedAnim != null) + { + if (animations.Count == 1 && removeIndex == 0 && animations[0].Frames.Length == 1 && animations[0].Frames[0].Sprites[0].Bounds == Rectangle.Empty) + { + animations[0] = removedAnim; + } + else + animations.Insert(removeIndex, removedAnim); + } + } + + 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 "Remove Animation"; + } + } +} diff --git a/AnimationEditor/Modifications/RemoveFrame.cs b/AnimationEditor/Modifications/RemoveFrame.cs new file mode 100644 index 0000000..db2266c --- /dev/null +++ b/AnimationEditor/Modifications/RemoveFrame.cs @@ -0,0 +1,89 @@ +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; + +namespace AnimationEditor.Modifications +{ + class RemoveFrame : IModification + { + private SelectionState preChangeSelection; + private SelectionState postChangeSelection; + + private BindingList frames; + private ListBox frameListBox; + private int removeIndex; + + private Frame removedFrame; + + public RemoveFrame(BindingList frameList, ListBox frameBox, int index) + { + frames = frameList; + frameListBox = frameBox; + removeIndex = index; + } + + public void Do() + { + if(removeIndex > -1 && removeIndex < frames.Count) + { + removedFrame = frames[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); + } + } + } + + public void Undo() + { + if(removedFrame != null) + { + if(frames.Count == 1 && removeIndex == 0) + { + frames.Clear(); + frames.Add(removedFrame); + } + else + frames.Insert(removeIndex, removedFrame); + } + } + + 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 "Remove Sprite"; + } + } +} diff --git a/AnimationEditor/Modifications/RemoveSprite.cs b/AnimationEditor/Modifications/RemoveSprite.cs new file mode 100644 index 0000000..01137c0 --- /dev/null +++ b/AnimationEditor/Modifications/RemoveSprite.cs @@ -0,0 +1,82 @@ +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; + +namespace AnimationEditor.Modifications +{ + class RemoveSprite : IModification + { + private SelectionState preChangeSelection; + private SelectionState postChangeSelection; + + private BindingList sprites; + private ListBox spriteListBox; + private int removeIndex; + + private Sprite removedSprite; + + public RemoveSprite(BindingList spriteList, ListBox spriteBox, int index) + { + sprites = spriteList; + spriteListBox = spriteBox; + removeIndex = index; + } + + public void Do() + { + if(removeIndex > -1 && removeIndex < sprites.Count) + { + removedSprite = sprites[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); + } + } + } + + public void Undo() + { + if(removedSprite != null) + { + sprites.Insert(removeIndex, removedSprite); + } + } + + 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 "Remove Frame"; + } + } +} diff --git a/AnimationEditor/Modifications/SelectionState.cs b/AnimationEditor/Modifications/SelectionState.cs new file mode 100644 index 0000000..88bc655 --- /dev/null +++ b/AnimationEditor/Modifications/SelectionState.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AnimationEditor.Modifications +{ + public class SelectionState + { + public int SelectedAnimation { get; set; } + public List SelectedFrames { get; set; } + public List SelectedFrameSprites { get; set; } + + public SelectionState(ComboBox animationComboBox, ListBox frameListBox, ListBox frameSpriteListBox) + { + SelectedAnimation = animationComboBox.SelectedIndex; + SelectedFrames = frameListBox.SelectedIndices.Cast().ToList(); + SelectedFrameSprites = frameSpriteListBox.SelectedIndices.Cast().ToList(); + } + } +} diff --git a/AnimationEditor/Properties/Resources.Designer.cs b/AnimationEditor/Properties/Resources.Designer.cs index 1e3b8b7..6f23e8f 100644 --- a/AnimationEditor/Properties/Resources.Designer.cs +++ b/AnimationEditor/Properties/Resources.Designer.cs @@ -8,10 +8,10 @@ // //------------------------------------------------------------------------------ -namespace AnimationEditor.Properties -{ - - +namespace AnimationEditor.Properties { + using System; + + /// /// A strongly-typed resource class, for looking up localized strings, etc. /// @@ -19,51 +19,43 @@ namespace AnimationEditor.Properties // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - + internal class Resources { + private static global::System.Resources.ResourceManager resourceMan; - + private static global::System.Globalization.CultureInfo resourceCulture; - + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { + internal Resources() { } - + /// /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AnimationEditor.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } - + /// /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { + internal static global::System.Globalization.CultureInfo Culture { + get { return resourceCulture; } - set - { + set { resourceCulture = value; } } diff --git a/AnimationEditor/Properties/Resources.resx b/AnimationEditor/Properties/Resources.resx index af7dbeb..1af7de1 100644 --- a/AnimationEditor/Properties/Resources.resx +++ b/AnimationEditor/Properties/Resources.resx @@ -46,7 +46,7 @@ mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with - : System.Serialization.Formatters.Binary.BinaryFormatter + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 @@ -60,6 +60,7 @@ : and then encoded with base64 encoding. --> + @@ -68,9 +69,10 @@ - + + @@ -85,9 +87,10 @@ - + + @@ -109,9 +112,9 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 \ No newline at end of file diff --git a/AnimationEditor/Resources/13test.png b/AnimationEditor/Resources/13test.png new file mode 100644 index 0000000000000000000000000000000000000000..1e5486188cb93e1527d36d7d5411703bf42ca408 GIT binary patch literal 987 zcmaJ=zi-n(6h2Xks){l(v|Tt{sbV0$b4b$I#FQj(oxbmTKkoTawQ^@^adi;@uw-m& zwZtax!W{qV*~=AfR+!#ob=qbFD`!FQ+!%D+G?Afv-Y~F%} zSm6R5VHS+NeLqrSRT$|i+)s{?07nqkQ-#x_nr0Q2X-HsJ#3>u+B$&&HQU=Qz`8rHv z2_q?u@J33)N_IoR5*$AQ&lWmurKW9-bMZ(Ox{L)1LW99T9NZ9T*g=vk%Lu1YI-TN( zRCM4oD^B^*+C)JkksZ1LbEyv#MXN>oOci*gr!9EFRMwBiW8wotu@xXm#7RpNplSXe z>UmRi#A@WM-hT>5je~%o8i{B>wE4xg*OF9$QVxm5XxN~1e=@~tmogf4X#mUhtSG@< z*LUb38sSY-G5m;GzD*2G6}W=vx{e}atZ6x1#Bx3(NxGcZBwWg8wlLOs(o*E!>sW^$8N@B*G$BcXerI9nn0;HYKAon1?QrrwzA%&tYA$wj;vlw9mz7d<)R z+mpD{wdKKd@rlp3J>+ZsogClfzr=;=PDAH*I2^wC`s@ey&aqmhJ_IMP@m(GvLn}7o zZ>_!C^G_DQ&#NClEU(X<6v??7zfDjBw zj0hwa286@{0}Db7Fff#%>>!X>7!hJYVnE@XCMg5KlKtL0ec$(f?)i4Tw!ScbVIBam zP~9*Z+%6{X+zkJony%mv$yGT+L1z{P< za*88T(V@?*IORu6V+DgmcIXDor9Mm)tqwh4n!qbPX~7F7vVJrg6CW6gtpG_PPFflR zP4oXy&zqnl)*z?#{!=(=9R>t7NJI}pn_t|{Qj#iA^^jPMhAm3>$5X6#DWg%B22gKi zL?2sN}NhaJveMxb*I--oT@kCI@4<@P30n93`#Ec zuZtcZ@$E_6$=dQ@viQX3+aB_@KKfRE%72O3`ev)l?O-r?{Ndqe?ww(cT5|xtzQC7x zv{E&St@vYS`_kDvN8s)Hy&3!F^4-Pzw|-d9gVovNqw8B2&9w)=x<4PiTs;2$1i&{y V?1IkwPhYNaI;fUw#