diff --git a/SpriteLibrary/SpriteDatabase.cs b/SpriteLibrary/SpriteDatabase.cs index ba93380..90b0bc3 100644 --- a/SpriteLibrary/SpriteDatabase.cs +++ b/SpriteLibrary/SpriteDatabase.cs @@ -140,18 +140,7 @@ namespace SpriteLibrary { if (SI.SpriteName == SpriteName) { - //This is the sprite. Pull out the image resource. then pull out the sprite. - ResourceManager rm = myResourceManager; - Image myImage = (Bitmap)rm.GetObject(SI.ImageName); - if (myImage == null) return null; //break out if we do not have the image defined for this - DestSprite = new Sprite(SI.StartPoint, theController, myImage, SI.Width, SI.Height, SI.AnimSpeed, SI.NumAnimations); - int sizepercent = SI.ViewPercent; - if (sizepercent < 5) sizepercent = 100; - if (sizepercent > 300) sizepercent = 100; - double delta = (double)sizepercent / 100.0; //turn it into a double, and into something we can multiply. - DestSprite.SetSize(new Size((int)(DestSprite.GetSize.Width * delta), (int)(DestSprite.GetSize.Height * delta))); - DestSprite.SetName(SpriteName); - //We have created a new sprite. Now, return a duplicate of that sprite. + SI.CreateSprite(theController, this); return theController.DuplicateSprite(SpriteName); } } diff --git a/SpriteLibrary/SpriteEntryForm.Designer.cs b/SpriteLibrary/SpriteEntryForm.Designer.cs index ff299c1..0759e7d 100644 --- a/SpriteLibrary/SpriteEntryForm.Designer.cs +++ b/SpriteLibrary/SpriteEntryForm.Designer.cs @@ -52,8 +52,9 @@ // // pbImageField // - this.pbImageField.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + this.pbImageField.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); + this.pbImageField.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.pbImageField.Location = new System.Drawing.Point(5, 10); this.pbImageField.Name = "pbImageField"; this.pbImageField.Size = new System.Drawing.Size(213, 253); @@ -130,6 +131,7 @@ // // btnCancel // + this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.btnCancel.Location = new System.Drawing.Point(353, 259); this.btnCancel.Name = "btnCancel"; this.btnCancel.Size = new System.Drawing.Size(75, 23); diff --git a/SpriteLibrary/SpriteEntryForm.resx b/SpriteLibrary/SpriteEntryForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SpriteLibrary/SpriteEntryForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SpriteLibrary/SpriteInfo.cs b/SpriteLibrary/SpriteInfo.cs index 89550b8..eea3962 100644 --- a/SpriteLibrary/SpriteInfo.cs +++ b/SpriteLibrary/SpriteInfo.cs @@ -4,11 +4,19 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; +using System.Resources; + namespace SpriteLibrary { + internal enum AnimationType { SpriteDefinition=0, Rotation=1, Mirror=2 } internal class AnimationInfo { + public AnimationType FieldsToUse = AnimationType.SpriteDefinition; + public int AnimationToUse = 0; + public int RotationDegrees=0; + public bool MirrorHorizontally = false; + public bool MirrorVertically = false; public Point StartPoint = new Point(-1, -1); public string ImageName = ""; public int Width = -1; @@ -41,5 +49,45 @@ namespace SpriteLibrary { return SpriteDatabase.CloneByXMLSerializing(this); } + + public Sprite CreateSprite(SpriteController ControllerToUse, SpriteDatabase TheDatabaseToUse) + { + Sprite DestSprite = null; + for (int index = 0; index < Animations.Count; index++) + { + AnimationInfo CurrentAnimation = Animations[index]; + Image myImage = TheDatabaseToUse.GetImageFromName(CurrentAnimation.ImageName, true); + if (myImage == null) return null; //break out if we do not have the image defined for this + AnimationType AT = CurrentAnimation.FieldsToUse; + if (index == 0) AT = AnimationType.SpriteDefinition; //the first one MUST be this. + switch(AT) + { + case AnimationType.SpriteDefinition: + if(DestSprite == null)//Creating the sprite from scratch + { + DestSprite = new Sprite(CurrentAnimation.StartPoint, ControllerToUse, myImage, CurrentAnimation.Width, CurrentAnimation.Height, CurrentAnimation.AnimSpeed, CurrentAnimation.NumFrames); + } + else + { + DestSprite.AddAnimation(CurrentAnimation.StartPoint, myImage, CurrentAnimation.Width, CurrentAnimation.Height, CurrentAnimation.AnimSpeed, CurrentAnimation.NumFrames); + } + break; + case AnimationType.Rotation: + DestSprite.AddAnimation(CurrentAnimation.AnimationToUse, CurrentAnimation.RotationDegrees); + break; + case AnimationType.Mirror: + DestSprite.AddAnimation(CurrentAnimation.AnimationToUse, CurrentAnimation.MirrorHorizontally,CurrentAnimation.MirrorVertically); + break; + } + } + int sizepercent = ViewPercent; + if (sizepercent < 5) sizepercent = 100; + if (sizepercent > 300) sizepercent = 100; + double delta = (double)sizepercent / 100.0; //turn it into a double, and into something we can multiply. + DestSprite.SetSize(new Size((int)(DestSprite.GetSize.Width * delta), (int)(DestSprite.GetSize.Height * delta))); + DestSprite.SetName(SpriteName); + //We have created a new sprite. Now, return a duplicate of that sprite. + return DestSprite; + } } } diff --git a/SpriteLibrary/SpriteLibrary.csproj b/SpriteLibrary/SpriteLibrary.csproj index a3eb328..eda7b56 100644 --- a/SpriteLibrary/SpriteLibrary.csproj +++ b/SpriteLibrary/SpriteLibrary.csproj @@ -78,6 +78,9 @@ Resources.Designer.cs Designer + + SpriteEntryForm.cs +