Added: SelectionState; New Undoable Mods: AddAnimation, RemoveAnimation, AddFrame, RemoveFrame, RemoveSprite

This commit is contained in:
quinnvoker
2018-12-26 21:07:21 -08:00
parent 2e72c46b7b
commit aaa80bd654
16 changed files with 761 additions and 120 deletions
+16
View File
@@ -66,6 +66,13 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Modifications\AddAnimation.cs" />
<Compile Include="Modifications\RemoveAnimation.cs" />
<Compile Include="Modifications\RemoveSprite.cs" />
<Compile Include="Modifications\RemoveFrame.cs" />
<Compile Include="Modifications\AddFrame.cs" />
<Compile Include="Modifications\History.cs" />
<Compile Include="Modifications\IModification.cs" />
<Compile Include="AnimationPreview.cs">
<SubType>Component</SubType>
</Compile>
@@ -75,6 +82,8 @@
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Modifications\ModHelper.cs" />
<Compile Include="Modifications\SelectionState.cs" />
<Compile Include="MonoGame.Framework.Content.Pipeline\ContentIdentity.cs" />
<Compile Include="MonoGame.Framework.Content.Pipeline\InvalidContentException.cs" />
<Compile Include="MonoGame.Framework.Content.Pipeline\NamedValueDictionary.cs" />
@@ -136,6 +145,7 @@
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
@@ -157,5 +167,11 @@
<Name>QURO</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Resources\15test.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\13test.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
+60 -40
View File
@@ -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;
}
}
+42 -49
View File
@@ -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();
}
}
}
@@ -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<Animation> animations;
private ComboBox animationBox;
private Animation animationToAdd;
public AddAnimation(BindingList<Animation> 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";
}
}
}
+98
View File
@@ -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<Frame> frames;
private ListBox frameListBox;
private Frame frameToAdd;
public AddFrame(BindingList<Frame> 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";
}
}
}
+94
View File
@@ -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<IModification> 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<IModification>();
}
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];
}
}
}
@@ -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);
}
}
@@ -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;
}
}
}
@@ -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<Animation> animations;
private ComboBox animationBox;
private int removeIndex;
private Animation removedAnim;
public RemoveAnimation(BindingList<Animation> 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";
}
}
}
@@ -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<Frame> frames;
private ListBox frameListBox;
private int removeIndex;
private Frame removedFrame;
public RemoveFrame(BindingList<Frame> 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";
}
}
}
@@ -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<Sprite> sprites;
private ListBox spriteListBox;
private int removeIndex;
private Sprite removedSprite;
public RemoveSprite(BindingList<Sprite> 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";
}
}
}
@@ -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<int> SelectedFrames { get; set; }
public List<int> SelectedFrameSprites { get; set; }
public SelectionState(ComboBox animationComboBox, ListBox frameListBox, ListBox frameSpriteListBox)
{
SelectedAnimation = animationComboBox.SelectedIndex;
SelectedFrames = frameListBox.SelectedIndices.Cast<int>().ToList();
SelectedFrameSprites = frameSpriteListBox.SelectedIndices.Cast<int>().ToList();
}
}
}
+18 -26
View File
@@ -8,10 +8,10 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace AnimationEditor.Properties
{
namespace AnimationEditor.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
@@ -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() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[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;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[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;
}
}
+8 -5
View File
@@ -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.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
@@ -68,9 +69,10 @@
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
@@ -85,9 +87,10 @@
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
@@ -109,9 +112,9 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
Binary file not shown.

After

Width:  |  Height:  |  Size: 987 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 991 B