diff --git a/AnimationEditor/AnimationEditor.csproj b/AnimationEditor/AnimationEditor.csproj index 41887ef..3e76b53 100644 --- a/AnimationEditor/AnimationEditor.csproj +++ b/AnimationEditor/AnimationEditor.csproj @@ -67,6 +67,7 @@ + diff --git a/AnimationEditor/Form1.cs b/AnimationEditor/Form1.cs index a0fdbd9..86b0480 100644 --- a/AnimationEditor/Form1.cs +++ b/AnimationEditor/Form1.cs @@ -608,8 +608,8 @@ namespace AnimationEditor private void ReadSpriteOffset() { reading = true; - spriteXPosBox.Value = (int)currentFrame.Sprites[frameSpriteListBox.SelectedIndex].Offset.X; - spriteYPosBox.Value = (int)currentFrame.Sprites[frameSpriteListBox.SelectedIndex].Offset.Y; + spriteXPosBox.Value = (int)frameSprites[frameSpriteListBox.SelectedIndex].Offset.X; + spriteYPosBox.Value = (int)frameSprites[frameSpriteListBox.SelectedIndex].Offset.Y; reading = false; } @@ -638,10 +638,10 @@ namespace AnimationEditor private void addSpriteToFrameSpritesButton_Click(object sender, EventArgs e) { var spriteToAdd = spriteSet[spriteListBox.SelectedIndex].Clone(); - if (currentFrame.Sprites == null) - currentFrame.Sprites = new List(); - currentFrame.Sprites.Add(spriteToAdd); - frameSprites.ResetBindings(); + + var mod = new AddSprite(frameSprites, frameSpriteListBox, currentFrame, spriteToAdd); + ModHelper.DoModificationWithSelectionTracking(mod, animationBox, frameListBox, frameSpriteListBox); + undoHistory.Add(mod); } private void addEmptyFrameButton_Click(object sender, EventArgs e) diff --git a/AnimationEditor/Modifications/AddFrame.cs b/AnimationEditor/Modifications/AddFrame.cs index e676bf8..d7a33d3 100644 --- a/AnimationEditor/Modifications/AddFrame.cs +++ b/AnimationEditor/Modifications/AddFrame.cs @@ -7,6 +7,7 @@ using System.ComponentModel; using QURO; using QURO.Animation; using System.Windows.Forms; +using Microsoft.Xna.Framework; namespace AnimationEditor.Modifications { @@ -36,7 +37,7 @@ namespace AnimationEditor.Modifications if (frameToAdd.Name != "empty" && frames.Count == 1 && frames[0].Sprites.Count == 1 && - frames[0].Sprites[0].Name == "empty") + frames[0].Sprites[0].Bounds == Rectangle.Empty) { frames.Clear(); } diff --git a/AnimationEditor/Modifications/AddSprite.cs b/AnimationEditor/Modifications/AddSprite.cs new file mode 100644 index 0000000..2583d51 --- /dev/null +++ b/AnimationEditor/Modifications/AddSprite.cs @@ -0,0 +1,75 @@ +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 AddSprite : IModification + { + private SelectionState preChangeSelection; + private SelectionState postChangeSelection; + + private BindingList sprites; + private Frame currentFrame; + private ListBox spriteBox; + private Sprite spriteToAdd; + + public AddSprite(BindingList spriteList, ListBox sprBox, Frame currFrame, Sprite sprite = null) + { + sprites = spriteList; + spriteBox = sprBox; + currentFrame = currFrame; + if (sprite != null) + spriteToAdd = sprite; + else spriteToAdd = new Sprite(); + } + + public void Do() + { + if (sprites.Count == 1 && sprites[0].Bounds == Rectangle.Empty) + sprites.Clear(); + + sprites.Add(spriteToAdd); + currentFrame.Sprites = sprites.ToList(); + ModHelper.SetSingleSelection(spriteBox, sprites.Count - 1); + } + + public void Undo() + { + sprites.RemoveAt(sprites.Count - 1); + if (sprites.Count == 0) + sprites.Add(new Sprite()); + currentFrame.Sprites = sprites.ToList(); + } + + 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 Sprite"; + } + } +} diff --git a/AnimationEditor/Modifications/RemoveFrame.cs b/AnimationEditor/Modifications/RemoveFrame.cs index db2266c..dfa84dd 100644 --- a/AnimationEditor/Modifications/RemoveFrame.cs +++ b/AnimationEditor/Modifications/RemoveFrame.cs @@ -7,6 +7,7 @@ using System.ComponentModel; using QURO; using QURO.Animation; using System.Windows.Forms; +using Microsoft.Xna.Framework; namespace AnimationEditor.Modifications { @@ -53,7 +54,7 @@ namespace AnimationEditor.Modifications { if(removedFrame != null) { - if(frames.Count == 1 && removeIndex == 0) + if (frames.Count == 1 && removeIndex == 0 && (frames[0].Sprites == null || frames[0].Sprites[0].Bounds == Rectangle.Empty)) { frames.Clear(); frames.Add(removedFrame);