diff --git a/AnimationEditor/AnimationEditor.csproj b/AnimationEditor/AnimationEditor.csproj index 3e76b53..908c3c9 100644 --- a/AnimationEditor/AnimationEditor.csproj +++ b/AnimationEditor/AnimationEditor.csproj @@ -68,6 +68,7 @@ + diff --git a/AnimationEditor/Form1.cs b/AnimationEditor/Form1.cs index 86b0480..350404c 100644 --- a/AnimationEditor/Form1.cs +++ b/AnimationEditor/Form1.cs @@ -370,11 +370,14 @@ 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); + */ } } @@ -382,14 +385,25 @@ 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); + */ } } + private void MoveListItem(BindingList frameList, ListBox frameBox, int dir) + { + var mod = new ReorderFrame(frameList, frameBox, dir); + ModHelper.DoModificationWithSelectionTracking(mod, animationBox, frameListBox, frameSpriteListBox); + undoHistory.Add(mod); + UpdateAnimation(); + } + private void removeFrameButton_Click(object sender, EventArgs e) { if(frameListBox.SelectedIndices.Count == 1 && frameListBox.SelectedIndex > -1 && frameListBox.SelectedIndex < frames.Count) diff --git a/AnimationEditor/Modifications/ReorderFrame.cs b/AnimationEditor/Modifications/ReorderFrame.cs new file mode 100644 index 0000000..abd0920 --- /dev/null +++ b/AnimationEditor/Modifications/ReorderFrame.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 ReorderFrame : IModification + { + private SelectionState preChangeSelection; + private SelectionState postChangeSelection; + + private BindingList frames; + private ListBox listBox; + private int index; + private int dir; + + public ReorderFrame(BindingList frameList, ListBox frameListBox, int direction) + { + frames = frameList; + listBox = frameListBox; + index = frameListBox.SelectedIndex; + dir = Math.Sign(direction); + } + + public void Do() + { + var movingFrame = frames[index]; + frames[index] = frames[index + dir]; + frames[index + dir] = movingFrame; + ModHelper.SetSingleSelection(listBox, index + dir); + } + + public void Undo() + { + var movingFrame = frames[index + dir]; + frames[index + dir] = frames[index]; + frames[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 Frame"; + } + } +}