Updated AnimatedSprite to support offsets and subsprites simultaneously
This commit is contained in:
Generated
+20
-7
@@ -80,8 +80,9 @@
|
||||
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();
|
||||
this.animationPreview = new AnimationEditor.AnimationPreview();
|
||||
this.addEmptyFrameButton = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.spritePreview)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.frameTrackBar)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.delayInputBox)).BeginInit();
|
||||
@@ -216,7 +217,7 @@
|
||||
// moveFrameUpButton
|
||||
//
|
||||
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, 19);
|
||||
this.moveFrameUpButton.Location = new System.Drawing.Point(225, 19);
|
||||
this.moveFrameUpButton.Name = "moveFrameUpButton";
|
||||
this.moveFrameUpButton.Size = new System.Drawing.Size(27, 23);
|
||||
this.moveFrameUpButton.TabIndex = 13;
|
||||
@@ -226,7 +227,7 @@
|
||||
//
|
||||
// moveFrameDownButton
|
||||
//
|
||||
this.moveFrameDownButton.Location = new System.Drawing.Point(190, 19);
|
||||
this.moveFrameDownButton.Location = new System.Drawing.Point(194, 19);
|
||||
this.moveFrameDownButton.Name = "moveFrameDownButton";
|
||||
this.moveFrameDownButton.Size = new System.Drawing.Size(27, 23);
|
||||
this.moveFrameDownButton.TabIndex = 14;
|
||||
@@ -404,6 +405,7 @@
|
||||
this.frameEditorPanel.Controls.Add(this.moveFrameDownButton);
|
||||
this.frameEditorPanel.Controls.Add(this.delayInputBox);
|
||||
this.frameEditorPanel.Controls.Add(this.moveFrameUpButton);
|
||||
this.frameEditorPanel.Controls.Add(this.addEmptyFrameButton);
|
||||
this.frameEditorPanel.Controls.Add(this.removeFrameButton);
|
||||
this.frameEditorPanel.Enabled = false;
|
||||
this.frameEditorPanel.Location = new System.Drawing.Point(0, 27);
|
||||
@@ -638,6 +640,12 @@
|
||||
this.animationLabel.TabIndex = 22;
|
||||
this.animationLabel.Text = "Animation";
|
||||
//
|
||||
// loadAnimationSetDialog
|
||||
//
|
||||
this.loadAnimationSetDialog.DefaultExt = "animset";
|
||||
this.loadAnimationSetDialog.FileName = "openFileDialog1";
|
||||
this.loadAnimationSetDialog.Filter = "QUROGames AnimationSet|*.animSet";
|
||||
//
|
||||
// animationPreview
|
||||
//
|
||||
this.animationPreview.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
@@ -654,11 +662,15 @@
|
||||
this.animationPreview.ZoomLevel = 0F;
|
||||
this.animationPreview.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.animationPreview_MouseWheel);
|
||||
//
|
||||
// loadAnimationSetDialog
|
||||
// addEmptyFrameButton
|
||||
//
|
||||
this.loadAnimationSetDialog.DefaultExt = "animset";
|
||||
this.loadAnimationSetDialog.FileName = "openFileDialog1";
|
||||
this.loadAnimationSetDialog.Filter = "QUROGames AnimationSet|*.animSet";
|
||||
this.addEmptyFrameButton.Location = new System.Drawing.Point(163, 19);
|
||||
this.addEmptyFrameButton.Name = "addEmptyFrameButton";
|
||||
this.addEmptyFrameButton.Size = new System.Drawing.Size(27, 23);
|
||||
this.addEmptyFrameButton.TabIndex = 12;
|
||||
this.addEmptyFrameButton.Text = "+";
|
||||
this.addEmptyFrameButton.UseVisualStyleBackColor = true;
|
||||
this.addEmptyFrameButton.Click += new System.EventHandler(this.addEmptyFrameButton_Click);
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
@@ -747,6 +759,7 @@
|
||||
private System.Windows.Forms.NumericUpDown subSpriteXPosBox;
|
||||
private System.Windows.Forms.Panel subSpritePanel;
|
||||
private System.Windows.Forms.Label subSpritePositionLabel;
|
||||
private System.Windows.Forms.Button addEmptyFrameButton;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+26
-14
@@ -31,17 +31,7 @@ namespace AnimationEditor
|
||||
private Animation currentAnimation;
|
||||
private Frame currentFrame;
|
||||
|
||||
private bool r;
|
||||
|
||||
private bool reading
|
||||
{
|
||||
get { return r; }
|
||||
set
|
||||
{
|
||||
r = value;
|
||||
Console.WriteLine("Reading: " + r);
|
||||
}
|
||||
}
|
||||
private bool reading;
|
||||
private float importDelay = 0;
|
||||
|
||||
public Form1()
|
||||
@@ -91,6 +81,12 @@ namespace AnimationEditor
|
||||
private void addSpriteToFrameListButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (spriteListBox.SelectedItem != null)
|
||||
{
|
||||
AddFrame(new Frame((SpriteMapRegion)spriteListBox.SelectedItem, importDelay));
|
||||
}
|
||||
}
|
||||
|
||||
private void AddFrame(Frame frameToAdd)
|
||||
{
|
||||
int newSelectedIndex;
|
||||
|
||||
@@ -101,19 +97,18 @@ namespace AnimationEditor
|
||||
|
||||
if (frameListBox.SelectedItem == null || frameListBox.SelectedIndex == frames.Count - 1)
|
||||
{
|
||||
frames.Add(new Frame((SpriteMapRegion)spriteListBox.SelectedItem, importDelay));
|
||||
frames.Add(frameToAdd);
|
||||
frameTrackBar.Maximum = frames.Count - 1;
|
||||
newSelectedIndex = frames.Count - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
frames.Insert(frameListBox.SelectedIndex + 1, new Frame((SpriteMapRegion)spriteListBox.SelectedItem, 0.25f));
|
||||
frames.Insert(frameListBox.SelectedIndex + 1, frameToAdd);
|
||||
newSelectedIndex = frameListBox.SelectedIndex + 1;
|
||||
}
|
||||
UpdateAnimation();
|
||||
frameListBox_SetSingleSelection(newSelectedIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateAnimation()
|
||||
{
|
||||
@@ -510,6 +505,18 @@ namespace AnimationEditor
|
||||
frame.Sprite = loadedSpriteMap[frame.Name];
|
||||
updateCounter++;
|
||||
}
|
||||
if (frame.SubSprites != null)
|
||||
{
|
||||
for (int index = 0; index < frame.SubSprites.Count; index++)
|
||||
{
|
||||
var subSprite = frame.SubSprites[index];
|
||||
if (loadedSpriteMap.ContainsKey(subSprite.Name))
|
||||
{
|
||||
frame.SubSprites[index] = loadedSpriteMap[subSprite.Name];
|
||||
updateCounter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -560,5 +567,10 @@ namespace AnimationEditor
|
||||
currentFrame.SubSprites.Add(spriteToAdd);
|
||||
subSprites.Add(spriteToAdd);
|
||||
}
|
||||
|
||||
private void addEmptyFrameButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
AddFrame(new Frame());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,21 +76,37 @@ namespace QURO.AnimationLibrary
|
||||
{
|
||||
spriteBatch.Draw(SpriteSheet, position - CurrentFrame.Origin, CurrentFrame.Bounds, tint);
|
||||
if (CurrentFrame.SubSprites != null)
|
||||
DrawSubSprites(spriteBatch, position, tint);
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, Vector2 position, Vector2 spriteMapOffset, Color tint, bool offsetSubSprites = false)
|
||||
{
|
||||
Rectangle sourceRect = CurrentFrame.Bounds;
|
||||
sourceRect.Offset(spriteMapOffset);
|
||||
|
||||
spriteBatch.Draw(SpriteSheet, position, sourceRect, tint);
|
||||
if (CurrentFrame.SubSprites != null)
|
||||
DrawSubSprites(spriteBatch, position, tint, offsetSubSprites? (Vector2?)spriteMapOffset : null);
|
||||
}
|
||||
|
||||
public void DrawSubSprites(SpriteBatch spriteBatch, Vector2 position, Color tint, Vector2? spriteMapOffset = null)
|
||||
{
|
||||
if (CurrentFrame.SubSprites.Count != CurrentFrame.SubSpritePositions.Count)
|
||||
{
|
||||
System.Console.WriteLine("SubSpriteCount and SubSpritePositionCount are not equal! Skipping subsprites...");
|
||||
return;
|
||||
}
|
||||
for (int index = 0; index < CurrentFrame.SubSprites.Count; index++)
|
||||
{
|
||||
var subSprite = CurrentFrame.SubSprites[index];
|
||||
spriteBatch.Draw(SpriteSheet, position - subSprite.Origin + CurrentFrame.SubSpritePositions[index], subSprite.Bounds, tint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, Vector2 position, Vector2 spriteOffset, Color tint)
|
||||
{
|
||||
Rectangle sourceRect = CurrentFrame.Bounds;
|
||||
sourceRect.Offset(spriteOffset);
|
||||
Rectangle sourceRect = subSprite.Bounds;
|
||||
|
||||
spriteBatch.Draw(SpriteSheet, position, sourceRect, tint);
|
||||
if (spriteMapOffset != null)
|
||||
sourceRect.Offset((Vector2)spriteMapOffset);
|
||||
|
||||
spriteBatch.Draw(SpriteSheet, position - subSprite.Origin + CurrentFrame.SubSpritePositions[index], sourceRect, tint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user