initial saving working (possibly)

This commit is contained in:
Tim Young 2017-09-16 08:23:47 -05:00
parent 4f2d190b6c
commit e9f1a9a3ed
4 changed files with 22 additions and 9 deletions

View File

@ -22,11 +22,12 @@ namespace SpriteLibrary
/// </summary> /// </summary>
public class SpriteDatabase public class SpriteDatabase
{ {
List<SpriteInfo> SpriteInfoList = new List<SpriteInfo>(); public List<SpriteInfo> SpriteInfoList = new List<SpriteInfo>();
List<ImageStruct> TheImages = new List<ImageStruct>(); List<ImageStruct> TheImages = new List<ImageStruct>();
ResourceManager myResourceManager = null; ResourceManager myResourceManager = null;
string Filename = ""; string Filename = "";
Size SnapGridSize = new Size(5, 5); Size SnapGridSize = new Size(5, 5);
int CurrentSIIndex = -1; //The information item we are editing. -1 means it is a new one.
public SpriteDatabase(ResourceManager theResourceManager, string filename) public SpriteDatabase(ResourceManager theResourceManager, string filename)
{ {
@ -40,6 +41,11 @@ namespace SpriteLibrary
LoadSpriteInfo(); LoadSpriteInfo();
} }
internal ResourceManager GetResourceManager()
{
return myResourceManager;
}
/// <summary> /// <summary>
/// Tell the database to save the sprite definitions. Use this while you are creating your game. /// Tell the database to save the sprite definitions. Use this while you are creating your game.
/// When you are done, you will usually want to take your sprite definition file and add it to the /// When you are done, you will usually want to take your sprite definition file and add it to the
@ -115,7 +121,7 @@ namespace SpriteLibrary
public void OpenEditWindow(int FirstItemIndex=-1) public void OpenEditWindow(int FirstItemIndex=-1)
{ {
SpriteEntryForm SEF = new SpriteEntryForm(myResourceManager, SpriteInfoList, SnapGridSize); SpriteEntryForm SEF = new SpriteEntryForm(this, SpriteInfoList, SnapGridSize);
SEF.ShowDialog(); SEF.ShowDialog();
//Use the updated list returned from the form. //Use the updated list returned from the form.
SpriteInfoList.Clear(); SpriteInfoList.Clear();

View File

@ -247,6 +247,7 @@
this.MinimizeBox = false; this.MinimizeBox = false;
this.Name = "SpriteEntryForm"; this.Name = "SpriteEntryForm";
this.Text = "SpriteEntryForm"; this.Text = "SpriteEntryForm";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SpriteEntryForm_FormClosing);
((System.ComponentModel.ISupportInitialize)(this.pbImageField)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pbImageField)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();

View File

@ -22,12 +22,13 @@ namespace SpriteLibrary
ResourceManager myResources = null; ResourceManager myResources = null;
List<SpriteInfo> SpriteInformation = new List<SpriteInfo>(); List<SpriteInfo> SpriteInformation = new List<SpriteInfo>();
Size SnapGridSize = new Size(5,5); Size SnapGridSize = new Size(5,5);
SpriteDatabase myDatabase = null;
internal SpriteEntryForm(ResourceManager theResourceManager, List<SpriteInfo> ListToWorkOn, Size GridSize) internal SpriteEntryForm(SpriteDatabase theDatabase, List<SpriteInfo> ListToWorkOn, Size GridSize)
{ {
InitializeComponent(); InitializeComponent();
if (theResourceManager == null) throw new Exception("NullException: The ResourceManager passed to the SpriteEntryForm cannot be null. Pass it Properties.Resources.ResourceManager"); myDatabase = theDatabase;
myResources = theResourceManager; myResources = myDatabase.GetResourceManager();
SnapGridSize = GridSize; SnapGridSize = GridSize;
LocalSetup(); LocalSetup();
SpriteInformation.AddRange(ListToWorkOn); SpriteInformation.AddRange(ListToWorkOn);
@ -87,5 +88,10 @@ namespace SpriteLibrary
} }
} }
} }
private void SpriteEntryForm_FormClosing(object sender, FormClosingEventArgs e)
{
myDatabase.Save(); //try saving the file
}
} }
} }

View File

@ -35,11 +35,11 @@ namespace SpriteLibrary
} }
} }
internal class SpriteInfo public class SpriteInfo
{ {
public string SpriteName = ""; internal string SpriteName = "";
public int ViewPercent = 100; //The percent size of the sprite. 100 is full. 50 is half-size internal int ViewPercent = 100; //The percent size of the sprite. 100 is full. 50 is half-size
public List<AnimationInfo> Animations = new List<AnimationInfo>(); internal List<AnimationInfo> Animations = new List<AnimationInfo>();
/// <summary> /// <summary>
/// A generic cloning method that works when everything is public /// A generic cloning method that works when everything is public