diff --git a/AnimationEditor/AnimationEditor.csproj b/AnimationEditor/AnimationEditor.csproj
index ef1d283..c296a09 100644
--- a/AnimationEditor/AnimationEditor.csproj
+++ b/AnimationEditor/AnimationEditor.csproj
@@ -118,6 +118,7 @@
+
Form1.cs
diff --git a/AnimationEditor/AnimationPreview.cs b/AnimationEditor/AnimationPreview.cs
index d2fbf00..309daa1 100644
--- a/AnimationEditor/AnimationPreview.cs
+++ b/AnimationEditor/AnimationPreview.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -12,28 +13,83 @@ namespace AnimationEditor
{
class AnimationPreview : UpdateWindow
{
- public Texture2D SpriteSheet { get; set; }
public AnimatedSprite PreviewSprite { get; set; }
- public Animation CurrentAnimation { get; set; }
+ public float ZoomLevel { get; set; }
+
+ private EventHandler onFrameChanged;
+ public event EventHandler FrameChanged
+ {
+ add
+ {
+ onFrameChanged += value;
+ }
+ remove
+ {
+ onFrameChanged -= value;
+ }
+ }
+
+ private EventHandler onAnimationEnded;
+ public event EventHandler AnimationEnded
+ {
+ add
+ {
+ onAnimationEnded += value;
+ }
+ remove
+ {
+ onAnimationEnded -= value;
+ }
+ }
+
+ public bool Playing { get; set; }
protected override void Initialize()
{
base.Initialize();
+ ZoomLevel = 1;
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
- PreviewSprite?.Update(gameTime);
+ if (Playing && PreviewSprite != null)
+ {
+ if (!PreviewSprite.CurrentAnimation.IsLooping && PreviewSprite.CurrentFrameIndex == PreviewSprite.CurrentAnimation.Frames.Count() - 1)
+ {
+ OnAnimationEnded(new EventArgs());
+ }
+ else
+ {
+ PreviewSprite.Update(gameTime);
+ OnFrameChanged(new EventArgs());
+ }
+ }
+ }
+
+ protected virtual void OnFrameChanged(EventArgs e)
+ {
+ onFrameChanged?.Invoke(this, e);
+ }
+
+ protected virtual void OnAnimationEnded(EventArgs e)
+ {
+ onAnimationEnded?.Invoke(this, e);
}
protected override void Draw()
{
base.Draw();
+ Matrix scaleMatrix = Matrix.CreateScale(ZoomLevel);
- Editor.spriteBatch.Begin();
- PreviewSprite?.Draw(Editor.spriteBatch, new Vector2(10, 10), Color.White);
+ Editor.graphics.Clear(Color.DimGray);
+
+ if (ZoomLevel >= 1)
+ Editor.spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: scaleMatrix);
+ else
+ Editor.spriteBatch.Begin(transformMatrix: scaleMatrix);
+ PreviewSprite?.Draw(Editor.spriteBatch, new Vector2((Editor.graphics.PresentationParameters.BackBufferWidth / 2) / ZoomLevel, (Editor.graphics.PresentationParameters.BackBufferHeight / 2) / ZoomLevel), Color.White);
Editor.spriteBatch.End();
}
}
diff --git a/AnimationEditor/Form1.Designer.cs b/AnimationEditor/Form1.Designer.cs
index 53c7e32..d863f58 100644
--- a/AnimationEditor/Form1.Designer.cs
+++ b/AnimationEditor/Form1.Designer.cs
@@ -28,42 +28,64 @@
///
private void InitializeComponent()
{
- this.loadSpriteSheetButton = new System.Windows.Forms.Button();
this.loadSpriteSheetDialog = new System.Windows.Forms.OpenFileDialog();
- this.loadSpriteMapButton = new System.Windows.Forms.Button();
this.loadSpriteMapDialog = new System.Windows.Forms.OpenFileDialog();
this.spriteListBox = new System.Windows.Forms.ListBox();
- this.animationPreview = new AnimationEditor.AnimationPreview();
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();
+ this.animationNameBox = new System.Windows.Forms.TextBox();
+ this.playAnimationButton = new System.Windows.Forms.Button();
+ this.removeFrameButton = new System.Windows.Forms.Button();
+ this.moveFrameUpButton = new System.Windows.Forms.Button();
+ this.moveFrameDownButton = new System.Windows.Forms.Button();
+ this.mainMenuStrip = new System.Windows.Forms.MenuStrip();
+ this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.loadSpriteSheetToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.loadSpriteMapToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripSeparator();
+ this.loadAnimationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.saveAnimationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
+ this.loadAnimationSetToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.saveAnimationSetToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.animationLoopCheckBox = new System.Windows.Forms.CheckBox();
+ this.saveAnimationDialog = new System.Windows.Forms.SaveFileDialog();
+ this.saveAnimationSetDialog = new System.Windows.Forms.SaveFileDialog();
+ this.loadAnimationDialog = new System.Windows.Forms.OpenFileDialog();
+ this.addAnimationButton = new System.Windows.Forms.Button();
+ this.removeAnimationButton = new System.Windows.Forms.Button();
+ this.frameEditorPanel = new System.Windows.Forms.Panel();
+ this.importDelayLabel = new System.Windows.Forms.Label();
+ this.importValuesLabel = new System.Windows.Forms.Label();
+ this.importDelayBox = new System.Windows.Forms.NumericUpDown();
+ this.delayLabel = new System.Windows.Forms.Label();
+ this.frameInfoLabel = new System.Windows.Forms.Label();
+ this.frameBoxLabel = new System.Windows.Forms.Label();
+ this.spriteBoxLabel = new System.Windows.Forms.Label();
+ 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();
+ ((System.ComponentModel.ISupportInitialize)(this.spritePreview)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.frameTrackBar)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.delayInputBox)).BeginInit();
+ this.mainMenuStrip.SuspendLayout();
+ this.frameEditorPanel.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.importDelayBox)).BeginInit();
+ this.animationPanel.SuspendLayout();
this.SuspendLayout();
//
- // loadSpriteSheetButton
- //
- this.loadSpriteSheetButton.Location = new System.Drawing.Point(28, 36);
- this.loadSpriteSheetButton.Name = "loadSpriteSheetButton";
- this.loadSpriteSheetButton.Size = new System.Drawing.Size(119, 23);
- this.loadSpriteSheetButton.TabIndex = 1;
- this.loadSpriteSheetButton.Text = "Load Sprite Sheet...";
- this.loadSpriteSheetButton.UseVisualStyleBackColor = true;
- this.loadSpriteSheetButton.Click += new System.EventHandler(this.loadSpriteSheetButton_Click);
- //
// loadSpriteSheetDialog
//
this.loadSpriteSheetDialog.DefaultExt = "png";
this.loadSpriteSheetDialog.FileName = "openFileDialog1";
this.loadSpriteSheetDialog.Filter = "PNG files|*png";
//
- // loadSpriteMapButton
- //
- this.loadSpriteMapButton.Enabled = false;
- this.loadSpriteMapButton.Location = new System.Drawing.Point(28, 65);
- this.loadSpriteMapButton.Name = "loadSpriteMapButton";
- this.loadSpriteMapButton.Size = new System.Drawing.Size(119, 23);
- this.loadSpriteMapButton.TabIndex = 2;
- this.loadSpriteMapButton.Text = "Load Sprite Map...";
- this.loadSpriteMapButton.UseVisualStyleBackColor = true;
- this.loadSpriteMapButton.Click += new System.EventHandler(this.loadSpriteMapButton_Click);
- //
// loadSpriteMapDialog
//
this.loadSpriteMapDialog.DefaultExt = "xml";
@@ -72,56 +94,483 @@
//
// spriteListBox
//
+ this.spriteListBox.BackColor = System.Drawing.SystemColors.Window;
+ this.spriteListBox.Enabled = false;
this.spriteListBox.FormattingEnabled = true;
- this.spriteListBox.Location = new System.Drawing.Point(28, 104);
+ this.spriteListBox.Location = new System.Drawing.Point(5, 62);
this.spriteListBox.Name = "spriteListBox";
- this.spriteListBox.Size = new System.Drawing.Size(119, 264);
+ this.spriteListBox.Size = new System.Drawing.Size(119, 303);
this.spriteListBox.TabIndex = 3;
- this.spriteListBox.MouseDown += new System.Windows.Forms.MouseEventHandler(this.spriteListBox_MouseDown);
- //
- // animationPreview
- //
- this.animationPreview.Location = new System.Drawing.Point(413, 74);
- this.animationPreview.Name = "animationPreview";
- this.animationPreview.Size = new System.Drawing.Size(253, 198);
- this.animationPreview.SpriteSheet = null;
- this.animationPreview.TabIndex = 0;
- this.animationPreview.Text = "animationPreview1";
+ this.spriteListBox.SelectedIndexChanged += new System.EventHandler(this.spriteListBox_SelectedIndexChanged);
//
// frameListBox
//
this.frameListBox.AllowDrop = true;
+ this.frameListBox.BackColor = System.Drawing.SystemColors.Window;
+ this.frameListBox.Enabled = false;
this.frameListBox.FormattingEnabled = true;
- this.frameListBox.Location = new System.Drawing.Point(166, 104);
+ this.frameListBox.Location = new System.Drawing.Point(163, 62);
this.frameListBox.Name = "frameListBox";
- this.frameListBox.Size = new System.Drawing.Size(120, 264);
+ this.frameListBox.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
+ this.frameListBox.Size = new System.Drawing.Size(120, 303);
this.frameListBox.TabIndex = 4;
+ this.frameListBox.SelectedIndexChanged += new System.EventHandler(this.frameListBox_SelectedIndexChanged);
+ //
+ // addSpriteToFrameListButton
+ //
+ this.addSpriteToFrameListButton.Enabled = false;
+ this.addSpriteToFrameListButton.Location = new System.Drawing.Point(130, 212);
+ this.addSpriteToFrameListButton.Name = "addSpriteToFrameListButton";
+ this.addSpriteToFrameListButton.Size = new System.Drawing.Size(27, 23);
+ this.addSpriteToFrameListButton.TabIndex = 5;
+ this.addSpriteToFrameListButton.Text = "→";
+ 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.Enabled = false;
+ 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.Enabled = false;
+ this.frameTrackBar.Location = new System.Drawing.Point(3, 359);
+ this.frameTrackBar.Name = "frameTrackBar";
+ this.frameTrackBar.Size = new System.Drawing.Size(466, 45);
+ this.frameTrackBar.TabIndex = 7;
+ this.frameTrackBar.Scroll += new System.EventHandler(this.frameTrackBar_Scroll);
+ //
+ // delayInputBox
+ //
+ this.delayInputBox.Enabled = false;
+ this.delayInputBox.Location = new System.Drawing.Point(198, 393);
+ this.delayInputBox.Name = "delayInputBox";
+ this.delayInputBox.Size = new System.Drawing.Size(83, 20);
+ this.delayInputBox.TabIndex = 8;
+ this.delayInputBox.ValueChanged += new System.EventHandler(this.delayInputBox_ValueChanged);
+ //
+ // animationBox
+ //
+ this.animationBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.animationBox.Enabled = false;
+ this.animationBox.FormattingEnabled = true;
+ this.animationBox.Location = new System.Drawing.Point(71, 0);
+ this.animationBox.Name = "animationBox";
+ this.animationBox.Size = new System.Drawing.Size(121, 21);
+ this.animationBox.TabIndex = 9;
+ this.animationBox.SelectedIndexChanged += new System.EventHandler(this.animationBox_SelectedIndexChanged);
+ //
+ // animationNameBox
+ //
+ this.animationNameBox.Enabled = false;
+ this.animationNameBox.Location = new System.Drawing.Point(313, 0);
+ 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);
+ //
+ // playAnimationButton
+ //
+ this.playAnimationButton.Enabled = false;
+ this.playAnimationButton.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.playAnimationButton.Location = new System.Drawing.Point(200, 391);
+ this.playAnimationButton.Name = "playAnimationButton";
+ this.playAnimationButton.Size = new System.Drawing.Size(75, 23);
+ this.playAnimationButton.TabIndex = 11;
+ this.playAnimationButton.Text = "| | / ►";
+ this.playAnimationButton.UseVisualStyleBackColor = true;
+ this.playAnimationButton.Click += new System.EventHandler(this.playAnimationButton_Click);
+ //
+ // removeFrameButton
+ //
+ this.removeFrameButton.Enabled = false;
+ this.removeFrameButton.Location = new System.Drawing.Point(256, 26);
+ this.removeFrameButton.Name = "removeFrameButton";
+ this.removeFrameButton.Size = new System.Drawing.Size(27, 23);
+ this.removeFrameButton.TabIndex = 12;
+ this.removeFrameButton.Text = "X";
+ this.removeFrameButton.UseVisualStyleBackColor = true;
+ this.removeFrameButton.Click += new System.EventHandler(this.removeFrameButton_Click);
+ //
+ // moveFrameUpButton
+ //
+ this.moveFrameUpButton.Enabled = false;
+ this.moveFrameUpButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.moveFrameUpButton.Location = new System.Drawing.Point(223, 26);
+ this.moveFrameUpButton.Name = "moveFrameUpButton";
+ this.moveFrameUpButton.Size = new System.Drawing.Size(27, 23);
+ this.moveFrameUpButton.TabIndex = 13;
+ this.moveFrameUpButton.Text = "↑";
+ this.moveFrameUpButton.UseVisualStyleBackColor = true;
+ this.moveFrameUpButton.Click += new System.EventHandler(this.moveFrameUpButton_Click);
+ //
+ // moveFrameDownButton
+ //
+ this.moveFrameDownButton.Enabled = false;
+ this.moveFrameDownButton.Location = new System.Drawing.Point(190, 26);
+ this.moveFrameDownButton.Name = "moveFrameDownButton";
+ this.moveFrameDownButton.Size = new System.Drawing.Size(27, 23);
+ this.moveFrameDownButton.TabIndex = 14;
+ this.moveFrameDownButton.Text = "↓";
+ this.moveFrameDownButton.UseVisualStyleBackColor = true;
+ this.moveFrameDownButton.Click += new System.EventHandler(this.moveFrameDownButton_Click);
+ //
+ // mainMenuStrip
+ //
+ this.mainMenuStrip.BackColor = System.Drawing.SystemColors.Control;
+ this.mainMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.fileToolStripMenuItem});
+ this.mainMenuStrip.Location = new System.Drawing.Point(0, 0);
+ this.mainMenuStrip.Name = "mainMenuStrip";
+ this.mainMenuStrip.Size = new System.Drawing.Size(763, 24);
+ this.mainMenuStrip.TabIndex = 15;
+ this.mainMenuStrip.Text = "menuStrip1";
+ //
+ // fileToolStripMenuItem
+ //
+ this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.loadSpriteSheetToolStripMenuItem,
+ this.loadSpriteMapToolStripMenuItem,
+ this.toolStripMenuItem3,
+ this.loadAnimationToolStripMenuItem,
+ this.saveAnimationToolStripMenuItem,
+ this.toolStripMenuItem2,
+ this.loadAnimationSetToolStripMenuItem,
+ this.saveAnimationSetToolStripMenuItem});
+ this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
+ this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
+ this.fileToolStripMenuItem.Text = "File";
+ //
+ // loadSpriteSheetToolStripMenuItem
+ //
+ this.loadSpriteSheetToolStripMenuItem.Name = "loadSpriteSheetToolStripMenuItem";
+ this.loadSpriteSheetToolStripMenuItem.Size = new System.Drawing.Size(187, 22);
+ this.loadSpriteSheetToolStripMenuItem.Text = "Load Sprite Sheet...";
+ this.loadSpriteSheetToolStripMenuItem.Click += new System.EventHandler(this.loadSpriteSheetToolStripMenuItem_Click);
+ //
+ // loadSpriteMapToolStripMenuItem
+ //
+ this.loadSpriteMapToolStripMenuItem.Enabled = false;
+ this.loadSpriteMapToolStripMenuItem.Name = "loadSpriteMapToolStripMenuItem";
+ this.loadSpriteMapToolStripMenuItem.Size = new System.Drawing.Size(187, 22);
+ this.loadSpriteMapToolStripMenuItem.Text = "Load Sprite Map...";
+ this.loadSpriteMapToolStripMenuItem.Click += new System.EventHandler(this.loadSpriteMapToolStripMenuItem_Click);
+ //
+ // toolStripMenuItem3
+ //
+ this.toolStripMenuItem3.Name = "toolStripMenuItem3";
+ this.toolStripMenuItem3.Size = new System.Drawing.Size(184, 6);
+ //
+ // loadAnimationToolStripMenuItem
+ //
+ this.loadAnimationToolStripMenuItem.Enabled = false;
+ this.loadAnimationToolStripMenuItem.Name = "loadAnimationToolStripMenuItem";
+ this.loadAnimationToolStripMenuItem.Size = new System.Drawing.Size(187, 22);
+ this.loadAnimationToolStripMenuItem.Text = "Load Animation...";
+ this.loadAnimationToolStripMenuItem.Click += new System.EventHandler(this.loadAnimationToolStripMenuItem_Click);
+ //
+ // saveAnimationToolStripMenuItem
+ //
+ this.saveAnimationToolStripMenuItem.Enabled = false;
+ this.saveAnimationToolStripMenuItem.Name = "saveAnimationToolStripMenuItem";
+ this.saveAnimationToolStripMenuItem.Size = new System.Drawing.Size(187, 22);
+ this.saveAnimationToolStripMenuItem.Text = "Save Animation...";
+ this.saveAnimationToolStripMenuItem.Click += new System.EventHandler(this.saveAnimationToolStripMenuItem_Click);
+ //
+ // toolStripMenuItem2
+ //
+ this.toolStripMenuItem2.Name = "toolStripMenuItem2";
+ this.toolStripMenuItem2.Size = new System.Drawing.Size(184, 6);
+ //
+ // loadAnimationSetToolStripMenuItem
+ //
+ this.loadAnimationSetToolStripMenuItem.Enabled = false;
+ this.loadAnimationSetToolStripMenuItem.Name = "loadAnimationSetToolStripMenuItem";
+ this.loadAnimationSetToolStripMenuItem.Size = new System.Drawing.Size(187, 22);
+ this.loadAnimationSetToolStripMenuItem.Text = "Load Animation Set...";
+ this.loadAnimationSetToolStripMenuItem.Click += new System.EventHandler(this.loadAnimationSetToolStripMenuItem_Click);
+ //
+ // saveAnimationSetToolStripMenuItem
+ //
+ this.saveAnimationSetToolStripMenuItem.Enabled = false;
+ this.saveAnimationSetToolStripMenuItem.Name = "saveAnimationSetToolStripMenuItem";
+ this.saveAnimationSetToolStripMenuItem.Size = new System.Drawing.Size(187, 22);
+ this.saveAnimationSetToolStripMenuItem.Text = "Save Animation Set...";
+ this.saveAnimationSetToolStripMenuItem.Click += new System.EventHandler(this.saveAnimationSetToolStripMenuItem_Click);
+ //
+ // animationLoopCheckBox
+ //
+ this.animationLoopCheckBox.AutoSize = true;
+ this.animationLoopCheckBox.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
+ this.animationLoopCheckBox.Enabled = false;
+ this.animationLoopCheckBox.Location = new System.Drawing.Point(419, 2);
+ this.animationLoopCheckBox.Name = "animationLoopCheckBox";
+ this.animationLoopCheckBox.Size = new System.Drawing.Size(50, 17);
+ this.animationLoopCheckBox.TabIndex = 16;
+ this.animationLoopCheckBox.Text = "Loop";
+ this.animationLoopCheckBox.UseVisualStyleBackColor = true;
+ this.animationLoopCheckBox.CheckedChanged += new System.EventHandler(this.animationLoopCheckBox_CheckedChanged);
+ //
+ // saveAnimationDialog
+ //
+ this.saveAnimationDialog.DefaultExt = "xml";
+ this.saveAnimationDialog.Filter = "Xml Files|*.xml";
+ //
+ // saveAnimationSetDialog
+ //
+ this.saveAnimationSetDialog.DefaultExt = "xml";
+ this.saveAnimationSetDialog.Filter = "Xml files|*.xml";
+ //
+ // loadAnimationDialog
+ //
+ this.loadAnimationDialog.FileName = "openFileDialog1";
+ //
+ // addAnimationButton
+ //
+ this.addAnimationButton.Enabled = false;
+ this.addAnimationButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.addAnimationButton.Location = new System.Drawing.Point(199, -1);
+ this.addAnimationButton.Name = "addAnimationButton";
+ this.addAnimationButton.Size = new System.Drawing.Size(27, 23);
+ this.addAnimationButton.TabIndex = 18;
+ this.addAnimationButton.Text = "+";
+ this.addAnimationButton.UseVisualStyleBackColor = true;
+ this.addAnimationButton.Click += new System.EventHandler(this.addAnimationButton_Click);
+ //
+ // removeAnimationButton
+ //
+ this.removeAnimationButton.Enabled = false;
+ this.removeAnimationButton.Location = new System.Drawing.Point(232, -1);
+ this.removeAnimationButton.Name = "removeAnimationButton";
+ this.removeAnimationButton.Size = new System.Drawing.Size(27, 23);
+ this.removeAnimationButton.TabIndex = 17;
+ this.removeAnimationButton.Text = "-";
+ this.removeAnimationButton.UseVisualStyleBackColor = true;
+ this.removeAnimationButton.Click += new System.EventHandler(this.removeAnimationButton_Click);
+ //
+ // frameEditorPanel
+ //
+ this.frameEditorPanel.Controls.Add(this.importDelayLabel);
+ this.frameEditorPanel.Controls.Add(this.importValuesLabel);
+ this.frameEditorPanel.Controls.Add(this.importDelayBox);
+ this.frameEditorPanel.Controls.Add(this.delayLabel);
+ this.frameEditorPanel.Controls.Add(this.frameInfoLabel);
+ this.frameEditorPanel.Controls.Add(this.frameBoxLabel);
+ this.frameEditorPanel.Controls.Add(this.spriteBoxLabel);
+ this.frameEditorPanel.Controls.Add(this.frameListBox);
+ this.frameEditorPanel.Controls.Add(this.spriteListBox);
+ this.frameEditorPanel.Controls.Add(this.addSpriteToFrameListButton);
+ this.frameEditorPanel.Controls.Add(this.spritePreview);
+ this.frameEditorPanel.Controls.Add(this.moveFrameDownButton);
+ this.frameEditorPanel.Controls.Add(this.delayInputBox);
+ this.frameEditorPanel.Controls.Add(this.moveFrameUpButton);
+ this.frameEditorPanel.Controls.Add(this.removeFrameButton);
+ this.frameEditorPanel.Location = new System.Drawing.Point(0, 27);
+ this.frameEditorPanel.Name = "frameEditorPanel";
+ this.frameEditorPanel.Size = new System.Drawing.Size(290, 423);
+ this.frameEditorPanel.TabIndex = 19;
+ //
+ // importDelayLabel
+ //
+ this.importDelayLabel.AutoSize = true;
+ this.importDelayLabel.Location = new System.Drawing.Point(4, 395);
+ this.importDelayLabel.Name = "importDelayLabel";
+ this.importDelayLabel.Size = new System.Drawing.Size(34, 13);
+ this.importDelayLabel.TabIndex = 21;
+ this.importDelayLabel.Text = "Delay";
+ //
+ // importValuesLabel
+ //
+ this.importValuesLabel.AutoSize = true;
+ this.importValuesLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.importValuesLabel.Location = new System.Drawing.Point(4, 372);
+ this.importValuesLabel.Name = "importValuesLabel";
+ this.importValuesLabel.Size = new System.Drawing.Size(84, 13);
+ this.importValuesLabel.TabIndex = 20;
+ this.importValuesLabel.Text = "Import Values";
+ //
+ // importDelayBox
+ //
+ this.importDelayBox.Enabled = false;
+ this.importDelayBox.Location = new System.Drawing.Point(41, 393);
+ this.importDelayBox.Name = "importDelayBox";
+ this.importDelayBox.Size = new System.Drawing.Size(83, 20);
+ this.importDelayBox.TabIndex = 19;
+ this.importDelayBox.ValueChanged += new System.EventHandler(this.importDelayBox_ValueChanged);
+ //
+ // delayLabel
+ //
+ this.delayLabel.AutoSize = true;
+ this.delayLabel.Location = new System.Drawing.Point(160, 395);
+ this.delayLabel.Name = "delayLabel";
+ this.delayLabel.Size = new System.Drawing.Size(34, 13);
+ this.delayLabel.TabIndex = 18;
+ this.delayLabel.Text = "Delay";
+ //
+ // frameInfoLabel
+ //
+ this.frameInfoLabel.AutoSize = true;
+ this.frameInfoLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.frameInfoLabel.Location = new System.Drawing.Point(160, 372);
+ this.frameInfoLabel.Name = "frameInfoLabel";
+ this.frameInfoLabel.Size = new System.Drawing.Size(121, 13);
+ this.frameInfoLabel.TabIndex = 17;
+ this.frameInfoLabel.Text = "Selected Frame Info";
+ //
+ // frameBoxLabel
+ //
+ this.frameBoxLabel.AutoSize = true;
+ this.frameBoxLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.frameBoxLabel.Location = new System.Drawing.Point(160, 3);
+ this.frameBoxLabel.Name = "frameBoxLabel";
+ this.frameBoxLabel.Size = new System.Drawing.Size(65, 13);
+ this.frameBoxLabel.TabIndex = 16;
+ this.frameBoxLabel.Text = "Frame List";
+ //
+ // spriteBoxLabel
+ //
+ this.spriteBoxLabel.AutoSize = true;
+ this.spriteBoxLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.spriteBoxLabel.Location = new System.Drawing.Point(3, 3);
+ this.spriteBoxLabel.Name = "spriteBoxLabel";
+ this.spriteBoxLabel.Size = new System.Drawing.Size(97, 13);
+ this.spriteBoxLabel.TabIndex = 15;
+ this.spriteBoxLabel.Text = "Sprite Selection";
+ //
+ // animationPanel
+ //
+ this.animationPanel.Controls.Add(this.animationNameLabel);
+ this.animationPanel.Controls.Add(this.animationLabel);
+ this.animationPanel.Controls.Add(this.playAnimationButton);
+ this.animationPanel.Controls.Add(this.animationPreview);
+ this.animationPanel.Controls.Add(this.frameTrackBar);
+ this.animationPanel.Controls.Add(this.addAnimationButton);
+ this.animationPanel.Controls.Add(this.animationBox);
+ this.animationPanel.Controls.Add(this.removeAnimationButton);
+ this.animationPanel.Controls.Add(this.animationNameBox);
+ this.animationPanel.Controls.Add(this.animationLoopCheckBox);
+ this.animationPanel.Location = new System.Drawing.Point(289, 27);
+ this.animationPanel.Name = "animationPanel";
+ this.animationPanel.Size = new System.Drawing.Size(474, 423);
+ this.animationPanel.TabIndex = 20;
+ //
+ // animationNameLabel
+ //
+ this.animationNameLabel.AutoSize = true;
+ this.animationNameLabel.Location = new System.Drawing.Point(272, 3);
+ this.animationNameLabel.Name = "animationNameLabel";
+ this.animationNameLabel.Size = new System.Drawing.Size(35, 13);
+ this.animationNameLabel.TabIndex = 23;
+ this.animationNameLabel.Text = "Name";
+ //
+ // animationLabel
+ //
+ this.animationLabel.AutoSize = true;
+ this.animationLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.animationLabel.Location = new System.Drawing.Point(3, 3);
+ this.animationLabel.Name = "animationLabel";
+ this.animationLabel.Size = new System.Drawing.Size(62, 13);
+ this.animationLabel.TabIndex = 22;
+ this.animationLabel.Text = "Animation";
+ //
+ // animationPreview
+ //
+ this.animationPreview.BackColor = System.Drawing.SystemColors.ControlDarkDark;
+ this.animationPreview.Enabled = false;
+ this.animationPreview.Location = new System.Drawing.Point(3, 26);
+ this.animationPreview.Name = "animationPreview";
+ this.animationPreview.Playing = false;
+ this.animationPreview.PreviewSprite = null;
+ this.animationPreview.Size = new System.Drawing.Size(466, 326);
+ this.animationPreview.TabIndex = 0;
+ this.animationPreview.Text = "animationPreview1";
+ this.animationPreview.ZoomLevel = 0F;
+ this.animationPreview.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.animationPreview_MouseWheel);
+ //
+ // loadAnimationSetDialog
+ //
+ this.loadAnimationSetDialog.FileName = "openFileDialog1";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
- this.Controls.Add(this.frameListBox);
- this.Controls.Add(this.spriteListBox);
- this.Controls.Add(this.loadSpriteMapButton);
- this.Controls.Add(this.loadSpriteSheetButton);
- this.Controls.Add(this.animationPreview);
+ this.BackColor = System.Drawing.SystemColors.Control;
+ this.ClientSize = new System.Drawing.Size(763, 450);
+ this.Controls.Add(this.animationPanel);
+ this.Controls.Add(this.frameEditorPanel);
+ this.Controls.Add(this.mainMenuStrip);
+ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "Form1";
- this.Text = "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);
+ this.mainMenuStrip.PerformLayout();
+ this.frameEditorPanel.ResumeLayout(false);
+ this.frameEditorPanel.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.importDelayBox)).EndInit();
+ this.animationPanel.ResumeLayout(false);
+ this.animationPanel.PerformLayout();
this.ResumeLayout(false);
+ this.PerformLayout();
}
#endregion
private AnimationPreview animationPreview;
- private System.Windows.Forms.Button loadSpriteSheetButton;
private System.Windows.Forms.OpenFileDialog loadSpriteSheetDialog;
- private System.Windows.Forms.Button loadSpriteMapButton;
private System.Windows.Forms.OpenFileDialog loadSpriteMapDialog;
private System.Windows.Forms.ListBox spriteListBox;
private System.Windows.Forms.ListBox frameListBox;
+ private System.Windows.Forms.Button addSpriteToFrameListButton;
+ private System.Windows.Forms.PictureBox spritePreview;
+ private System.Windows.Forms.TrackBar frameTrackBar;
+ private System.Windows.Forms.NumericUpDown delayInputBox;
+ private System.Windows.Forms.ComboBox animationBox;
+ private System.Windows.Forms.TextBox animationNameBox;
+ private System.Windows.Forms.Button playAnimationButton;
+ private System.Windows.Forms.Button removeFrameButton;
+ private System.Windows.Forms.Button moveFrameUpButton;
+ private System.Windows.Forms.Button moveFrameDownButton;
+ private System.Windows.Forms.MenuStrip mainMenuStrip;
+ private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem loadSpriteSheetToolStripMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem loadSpriteMapToolStripMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem loadAnimationSetToolStripMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem saveAnimationSetToolStripMenuItem;
+ private System.Windows.Forms.ToolStripSeparator toolStripMenuItem3;
+ private System.Windows.Forms.ToolStripMenuItem loadAnimationToolStripMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem saveAnimationToolStripMenuItem;
+ private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
+ private System.Windows.Forms.CheckBox animationLoopCheckBox;
+ private System.Windows.Forms.SaveFileDialog saveAnimationDialog;
+ private System.Windows.Forms.SaveFileDialog saveAnimationSetDialog;
+ private System.Windows.Forms.OpenFileDialog loadAnimationDialog;
+ private System.Windows.Forms.Button addAnimationButton;
+ private System.Windows.Forms.Button removeAnimationButton;
+ private System.Windows.Forms.Panel frameEditorPanel;
+ private System.Windows.Forms.Label frameBoxLabel;
+ private System.Windows.Forms.Label spriteBoxLabel;
+ private System.Windows.Forms.Label importDelayLabel;
+ private System.Windows.Forms.Label importValuesLabel;
+ private System.Windows.Forms.NumericUpDown importDelayBox;
+ private System.Windows.Forms.Label delayLabel;
+ private System.Windows.Forms.Label frameInfoLabel;
+ private System.Windows.Forms.Panel animationPanel;
+ private System.Windows.Forms.Label animationLabel;
+ private System.Windows.Forms.Label animationNameLabel;
+ private System.Windows.Forms.OpenFileDialog loadAnimationSetDialog;
}
}
diff --git a/AnimationEditor/Form1.cs b/AnimationEditor/Form1.cs
index 7ce412b..cac86e9 100644
--- a/AnimationEditor/Form1.cs
+++ b/AnimationEditor/Form1.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
-//using System.Drawing;
+using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -20,29 +20,203 @@ namespace AnimationEditor
{
public partial class Form1 : Form
{
- private SpriteMapRegion draggedSprite;
+ public Texture2D SpriteSheet { get; set; }
+ public int FrameRate { get; set; }
+
public BindingList Sprites { get; set; }
+ public BindingList Frames { get; set; }
+ public BindingList Animations { get; set; }
+
+ public Animation CurrentAnimation { get; set; }
+ public Frame CurrentFrame { get; set; }
+
+ private bool reading = false;
+ private float importDelay = 0;
public Form1()
{
InitializeComponent();
+ FrameRate = 60;
+ importDelayBox.Value = 0;
+ animationPreview.FrameChanged += animationPreview_FrameChanged;
+ animationPreview.AnimationEnded += animationPreview_AnimationEnded;
}
- private void loadSpriteSheetButton_Click(object sender, EventArgs e)
+ private void frameListBox_SetSingleSelection(int index)
{
- if(loadSpriteSheetDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+ frameListBox.SelectedIndices.Clear();
+ frameListBox.SelectedIndex = index;
+ }
+
+ private void EnableMapAndAnimationLoadingControls()
+ {
+ loadSpriteMapToolStripMenuItem.Enabled = true;
+ loadAnimationToolStripMenuItem.Enabled = true;
+ loadAnimationSetToolStripMenuItem.Enabled = true;
+ }
+
+ private void EnableSpriteMapControls()
+ {
+ spriteListBox.Enabled = true;
+ addSpriteToFrameListButton.Enabled = true;
+ spritePreview.Enabled = true;
+ importDelayBox.Enabled = true;
+ }
+
+ private void EnableAnimationEditingControls()
+ {
+ saveAnimationToolStripMenuItem.Enabled = true;
+ saveAnimationSetToolStripMenuItem.Enabled = true;
+
+ frameListBox.Enabled = true;
+ moveFrameDownButton.Enabled = true;
+ moveFrameUpButton.Enabled = true;
+ removeFrameButton.Enabled = true;
+ delayInputBox.Enabled = true;
+
+ animationBox.Enabled = true;
+ addAnimationButton.Enabled = true;
+ removeAnimationButton.Enabled = true;
+ removeFrameButton.Enabled = true;
+ animationNameBox.Enabled = true;
+ animationLoopCheckBox.Enabled = true;
+ frameTrackBar.Enabled = true;
+ playAnimationButton.Enabled = true;
+ animationPreview.Enabled = true;
+ }
+
+ private void InitiateAnimationList()
+ {
+ Animations = new BindingList();
+ animationBox.DataSource = Animations;
+ animationBox.DisplayMember = "Name";
+ }
+
+ private void addSpriteToFrameListButton_Click(object sender, EventArgs e)
+ {
+ if (spriteListBox.SelectedItem != null)
{
- FileStream fileStream = new FileStream(loadSpriteSheetDialog.FileName, FileMode.Open);
- animationPreview.SpriteSheet = Texture2D.FromStream(animationPreview.Editor.graphics, fileStream);
- loadSpriteMapButton.Enabled = true;
+ int newSelectedIndex;
+
+ if (Frames.Count == 1 && Frames[0].Bounds == Microsoft.Xna.Framework.Rectangle.Empty)
+ {
+ Frames.Clear();
+ }
+
+ if (frameListBox.SelectedItem == null || frameListBox.SelectedIndex == Frames.Count - 1)
+ {
+ Frames.Add(new Frame((SpriteMapRegion)spriteListBox.SelectedItem, importDelay));
+ frameTrackBar.Maximum = Frames.Count - 1;
+ newSelectedIndex = Frames.Count - 1;
+ }
+ else
+ {
+ Frames.Insert(frameListBox.SelectedIndex + 1, new Frame((SpriteMapRegion)spriteListBox.SelectedItem, 0.25f));
+ newSelectedIndex = frameListBox.SelectedIndex + 1;
+ }
+ UpdateAnimation();
+ frameListBox_SetSingleSelection(newSelectedIndex);
}
}
- private void loadSpriteMapButton_Click(object sender, EventArgs e)
+ private void UpdateAnimation()
{
- if (loadSpriteMapDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+ if(Frames?.Count > 0)
{
+ if(CurrentAnimation == null)
+ CurrentAnimation = new Animation("unnamed", Frames.ToArray(), true);
+ else
+ {
+ CurrentAnimation.Name = animationNameBox.Text;
+ CurrentAnimation.Frames = Frames.ToArray();
+ CurrentAnimation.IsLooping = animationLoopCheckBox.Checked;
+ }
+ if (animationPreview.PreviewSprite == null)
+ animationPreview.PreviewSprite = new AnimatedSprite(SpriteSheet, CurrentAnimation);
+ else
+ animationPreview.PreviewSprite.CurrentAnimation = CurrentAnimation;
+ frameTrackBar.Maximum = CurrentAnimation.Frames.Count() - 1;
+ if(Animations.Count < 1)
+ {
+ Animations.Add(CurrentAnimation);
+ animationBox.DataSource = Animations;
+ animationBox.DisplayMember = "Name";
+ }
+ }
+ else
+ {
+ animationPreview.PreviewSprite = null;
+ }
+ }
+ private void ReadAnimationInfo()
+ {
+ reading = true;
+ frameTrackBar.Maximum = CurrentAnimation.Frames.Count() - 1;
+ Frames = new BindingList(CurrentAnimation.Frames.ToList());
+ frameListBox.DataSource = Frames;
+ frameListBox.DisplayMember = "Name";
+ animationNameBox.Text = CurrentAnimation.Name;
+ animationLoopCheckBox.Checked = CurrentAnimation.IsLooping;
+ reading = false;
+ }
+
+ private void spriteListBox_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ if (spriteListBox.SelectedItem != null)
+ {
+ var currentSprite = (SpriteMapRegion)spriteListBox.SelectedItem;
+ Stream texture2DToImageStream = new MemoryStream();
+ Texture2DRegionExtractor.GetTexture2DFromRegion(SpriteSheet, SpriteSheet.GraphicsDevice, currentSprite.Bounds)
+ .SaveAsPng(texture2DToImageStream, currentSprite.Bounds.Width, currentSprite.Bounds.Height);
+ spritePreview.Image = Image.FromStream(texture2DToImageStream);
+ texture2DToImageStream.Close();
+ }
+ }
+
+ private void frameListBox_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ if (frameListBox.SelectedIndices.Count == 1 && frameListBox.SelectedItem != null)
+ {
+ CurrentFrame = (Frame)frameListBox.SelectedItem;
+ if (animationPreview.PreviewSprite != null && !animationPreview.Playing)
+ {
+ animationPreview.PreviewSprite.CurrentFrameIndex = frameListBox.SelectedIndex;
+ frameTrackBar.Value = frameListBox.SelectedIndex;
+ }
+ UpdateFrameInformation();
+ }
+ }
+
+ private void UpdateFrameInformation()
+ {
+ delayInputBox.Value = (int)(CurrentFrame.Delay * FrameRate);
+ }
+
+ private void delayInputBox_ValueChanged(object sender, EventArgs e)
+ {
+ foreach(int index in frameListBox.SelectedIndices)
+ {
+ var currentFrame = Frames[index];
+ currentFrame.Delay = (float)delayInputBox.Value / FrameRate;
+ }
+ }
+
+
+ private void loadSpriteSheetToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ if (loadSpriteSheetDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+ {
+ FileStream fileStream = new FileStream(loadSpriteSheetDialog.FileName, FileMode.Open);
+ SpriteSheet = Texture2D.FromStream(animationPreview.Editor.graphics, fileStream);
+ EnableMapAndAnimationLoadingControls();
+ }
+ }
+
+ private void loadSpriteMapToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ if (loadSpriteMapDialog.ShowDialog() == DialogResult.OK)
+ {
Dictionary loadedSpriteMap;
using (XmlReader xmlRead = XmlReader.Create(loadSpriteMapDialog.FileName))
{
@@ -58,18 +232,246 @@ namespace AnimationEditor
spriteListBox.DataSource = Sprites;
spriteListBox.DisplayMember = "Name";
spriteListBox.ValueMember = "Bounds";
- Rectangle[] frames = new Rectangle[] { Sprites[0].Bounds, Sprites[1].Bounds, Sprites[2].Bounds };
- animationPreview.CurrentAnimation = new Animation("Test", frames, 1f / 60f, true);
- animationPreview.PreviewSprite = new AnimatedSprite(animationPreview.SpriteSheet, animationPreview.CurrentAnimation);
+
+ if (CurrentAnimation == null)
+ {
+ Frames = new BindingList();
+ frameListBox.DataSource = Frames;
+ frameListBox.DisplayMember = "Name";
+ }
+
+ EnableSpriteMapControls();
+ EnableAnimationEditingControls();
}
}
- private void spriteListBox_MouseDown(object sender, MouseEventArgs e)
+ private void animationPreview_FrameChanged(object sender, EventArgs e)
{
- if (spriteListBox.SelectedItem == null)
- return;
- spriteListBox.DoDragDrop(spriteListBox.SelectedItem, DragDropEffects.Copy);
- draggedSprite = (SpriteMapRegion)spriteListBox.SelectedItem;
+ frameTrackBar.Value = animationPreview.PreviewSprite.CurrentFrameIndex;
+ }
+
+ private void animationPreview_AnimationEnded(object sender, EventArgs e)
+ {
+ animationPreview.Playing = false;
+ frameTrackBar.Enabled = true;
+ }
+
+ private void animationLoopCheckBox_CheckedChanged(object sender, EventArgs e)
+ {
+ CurrentAnimation.IsLooping = animationLoopCheckBox.Checked;
+ }
+
+ private void playAnimationButton_Click(object sender, EventArgs e)
+ {
+ if (CurrentAnimation.Frames.Count() > 0)
+ {
+ animationPreview.Playing = !animationPreview.Playing;
+ if (!animationPreview.Playing)
+ {
+ frameTrackBar.Enabled = true;
+ }
+ else
+ {
+ animationPreview.PreviewSprite.CurrentAnimation = CurrentAnimation;
+ frameTrackBar.Enabled = false;
+ }
+ }
+ }
+
+ private void frameTrackBar_Scroll(object sender, EventArgs e)
+ {
+ if (!animationPreview.Playing)
+ {
+ animationPreview.PreviewSprite.CurrentFrameIndex = frameTrackBar.Value;
+ frameListBox_SetSingleSelection(frameTrackBar.Value);
+ }
+ }
+
+ private void moveFrameDownButton_Click(object sender, EventArgs e)
+ {
+ if (frameListBox.SelectedIndices.Count == 1 && frameListBox.SelectedIndex < Frames.Count - 1)
+ {
+ var frameBelow = Frames[frameListBox.SelectedIndex + 1];
+ Frames[frameListBox.SelectedIndex + 1] = CurrentFrame;
+ Frames[frameListBox.SelectedIndex] = frameBelow;
+ UpdateAnimation();
+ frameListBox_SetSingleSelection(frameListBox.SelectedIndex + 1);
+ }
+ }
+
+ private void moveFrameUpButton_Click(object sender, EventArgs e)
+ {
+ if (frameListBox.SelectedIndices.Count == 1 && frameListBox.SelectedIndex > 0)
+ {
+ var frameAbove = Frames[frameListBox.SelectedIndex - 1];
+ Frames[frameListBox.SelectedIndex - 1] = CurrentFrame;
+ Frames[frameListBox.SelectedIndex] = frameAbove;
+ UpdateAnimation();
+ frameListBox_SetSingleSelection(frameListBox.SelectedIndex - 1);
+ }
+ }
+
+ private void removeFrameButton_Click(object sender, EventArgs e)
+ {
+ if(frameListBox.SelectedIndices.Count == 1 && frameListBox.SelectedIndex > -1 && frameListBox.SelectedIndex < Frames.Count)
+ {
+ Frames.RemoveAt(frameListBox.SelectedIndex);
+ UpdateAnimation();
+ if(Frames.Count > 0 && frameListBox.SelectedIndex > Frames.Count - 1)
+ {
+ frameListBox_SetSingleSelection(Frames.Count - 1);
+ }
+ }
+ }
+
+ private void animationNameBox_TextChanged(object sender, EventArgs e)
+ {
+ if (!reading)
+ {
+ CurrentAnimation.Name = animationNameBox.Text;
+ Animations.ResetBindings();
+ }
+ }
+
+ private void saveAnimationToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ if (saveAnimationDialog.ShowDialog() == DialogResult.OK)
+ {
+ using (XmlWriter writer = XmlWriter.Create(saveAnimationDialog.FileName))
+ {
+ IntermediateSerializer.Serialize(writer, CurrentAnimation, null);
+ }
+ }
+ }
+
+ private void loadAnimationToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ if (loadAnimationDialog.ShowDialog() == DialogResult.OK)
+ {
+ Animation loadedAnimation;
+ using (XmlReader xmlRead = XmlReader.Create(loadAnimationDialog.FileName))
+ {
+ loadedAnimation = IntermediateSerializer.Deserialize(xmlRead, null);
+ }
+ if (animationBox.Enabled == false)
+ {
+ EnableAnimationEditingControls();
+ InitiateAnimationList();
+ }
+ Animations.Add(loadedAnimation);
+ animationBox.SelectedIndex = Animations.Count - 1;
+ CurrentAnimation = Animations[animationBox.SelectedIndex];
+ ReadAnimationInfo();
+ UpdateAnimation();
+ }
+ }
+
+ private void animationBox_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ CurrentAnimation = Animations[animationBox.SelectedIndex];
+ ReadAnimationInfo();
+ UpdateAnimation();
+ }
+
+ private void addAnimationButton_Click(object sender, EventArgs e)
+ {
+ Animations.Add(new Animation());
+ animationBox.SelectedIndex = Animations.Count - 1;
+ }
+
+ private void removeAnimationButton_Click(object sender, EventArgs e)
+ {
+ if (animationBox.SelectedIndex > -1 && animationBox.SelectedIndex < Animations.Count - 1)
+ {
+ 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--;
+ }
+ }
+ }
+ }
+
+ private void importDelayBox_ValueChanged(object sender, EventArgs e)
+ {
+ importDelay = (float)importDelayBox.Value / FrameRate;
+ }
+
+ private void animationPreview_MouseWheel(object sender, MouseEventArgs e)
+ {
+ if(Math.Sign(e.Delta) > 0)
+ {
+ animationPreview.ZoomLevel++;
+ }
+ else if (animationPreview.ZoomLevel > 1)
+ {
+ animationPreview.ZoomLevel--;
+ }
+ }
+
+ private void saveAnimationSetToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var animSet = new Dictionary();
+ foreach(Animation anim in Animations)
+ {
+ if (animSet.ContainsKey(anim.Name))
+ {
+ string errorMessage = "Duplicate names found! Please ensure all animations have unique names.";
+ string caption = "Save Aborted";
+ MessageBoxButtons saveError = MessageBoxButtons.OK;
+
+ MessageBox.Show(errorMessage, caption, saveError);
+ return;
+ }
+ else
+ {
+ animSet.Add(anim.Name, anim);
+ }
+ }
+
+ if (saveAnimationSetDialog.ShowDialog() == DialogResult.OK)
+ {
+ using (XmlWriter writer = XmlWriter.Create(saveAnimationSetDialog.FileName))
+ {
+ IntermediateSerializer.Serialize(writer, animSet, null);
+ }
+ }
+ }
+
+ private void loadAnimationSetToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ if (loadAnimationSetDialog.ShowDialog() == DialogResult.OK)
+ {
+ Dictionary loadedAnimSet;
+
+ using (XmlReader xmlRead = XmlReader.Create(loadAnimationSetDialog.FileName))
+ {
+ loadedAnimSet = IntermediateSerializer.Deserialize>(xmlRead, null);
+ }
+
+ if (animationBox.Enabled == false)
+ {
+ EnableAnimationEditingControls();
+ }
+ InitiateAnimationList();
+ foreach(KeyValuePair currentEntry in loadedAnimSet)
+ {
+ Animations.Add(currentEntry.Value);
+ }
+ animationBox.SelectedIndex = 0;
+ CurrentAnimation = Animations[animationBox.SelectedIndex];
+ ReadAnimationInfo();
+ UpdateAnimation();
+ }
}
}
}
diff --git a/AnimationEditor/Form1.resx b/AnimationEditor/Form1.resx
index 3daccba..1b1975c 100644
--- a/AnimationEditor/Form1.resx
+++ b/AnimationEditor/Form1.resx
@@ -123,4 +123,19 @@
190, 17
+
+ 357, 17
+
+
+ 492, 17
+
+
+ 659, 17
+
+
+ 843, 17
+
+
+ 1010, 17
+
\ No newline at end of file
diff --git a/AnimationEditor/Texture2DRegionExtractor.cs b/AnimationEditor/Texture2DRegionExtractor.cs
new file mode 100644
index 0000000..da12c03
--- /dev/null
+++ b/AnimationEditor/Texture2DRegionExtractor.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace AnimationEditor
+{
+ static class Texture2DRegionExtractor
+ {
+ public static Texture2D GetTexture2DFromRegion(Texture2D source, GraphicsDevice graphics, Rectangle region)
+ {
+ var outputTex = new Texture2D(graphics, region.Width, region.Height);
+ int pixelCount = region.Width * region.Height;
+ Color[] pixelData = new Color[pixelCount];
+ source.GetData(0, region, pixelData, 0, pixelCount);
+ outputTex.SetData(pixelData);
+ return outputTex;
+ }
+ }
+}
diff --git a/QURO.AnimationLibrary/Animation.cs b/QURO.AnimationLibrary/Animation.cs
index 0c1f378..b8a76a3 100644
--- a/QURO.AnimationLibrary/Animation.cs
+++ b/QURO.AnimationLibrary/Animation.cs
@@ -11,7 +11,12 @@ namespace QURO.AnimationLibrary
public bool IsStillImage => Frames.Length <= 1;
- public Animation() { }
+ public Animation()
+ {
+ Name = "unnamed";
+ Frames = new Frame[] { new Frame() };
+ IsLooping = false;
+ }
public Animation(string name, Frame[] frames, bool loop)
{
diff --git a/QURO.AnimationLibrary/Frame.cs b/QURO.AnimationLibrary/Frame.cs
index 5e5e25f..b6a99ae 100644
--- a/QURO.AnimationLibrary/Frame.cs
+++ b/QURO.AnimationLibrary/Frame.cs
@@ -9,8 +9,8 @@ namespace QURO.AnimationLibrary
public Frame()
{
- Name = "unnamed";
- Bounds = new Rectangle(0, 0, 8, 8);
+ Name = "empty";
+ Bounds = Rectangle.Empty;
Origin = Vector2.Zero;
Delay = 0;
}