From e9f1a9a3edde1a8cd4665948845aadc20edbbbee Mon Sep 17 00:00:00 2001 From: Tim Young Date: Sat, 16 Sep 2017 08:23:47 -0500 Subject: [PATCH] initial saving working (possibly) --- SpriteLibrary/SpriteDatabase.cs | 10 ++++++++-- SpriteLibrary/SpriteEntryForm.Designer.cs | 1 + SpriteLibrary/SpriteEntryForm.cs | 12 +++++++++--- SpriteLibrary/SpriteInfo.cs | 8 ++++---- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/SpriteLibrary/SpriteDatabase.cs b/SpriteLibrary/SpriteDatabase.cs index 2872998..86f7df9 100644 --- a/SpriteLibrary/SpriteDatabase.cs +++ b/SpriteLibrary/SpriteDatabase.cs @@ -22,11 +22,12 @@ namespace SpriteLibrary /// public class SpriteDatabase { - List SpriteInfoList = new List(); + public List SpriteInfoList = new List(); List TheImages = new List(); ResourceManager myResourceManager = null; string Filename = ""; 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) { @@ -40,6 +41,11 @@ namespace SpriteLibrary LoadSpriteInfo(); } + internal ResourceManager GetResourceManager() + { + return myResourceManager; + } + /// /// 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 @@ -115,7 +121,7 @@ namespace SpriteLibrary public void OpenEditWindow(int FirstItemIndex=-1) { - SpriteEntryForm SEF = new SpriteEntryForm(myResourceManager, SpriteInfoList, SnapGridSize); + SpriteEntryForm SEF = new SpriteEntryForm(this, SpriteInfoList, SnapGridSize); SEF.ShowDialog(); //Use the updated list returned from the form. SpriteInfoList.Clear(); diff --git a/SpriteLibrary/SpriteEntryForm.Designer.cs b/SpriteLibrary/SpriteEntryForm.Designer.cs index 0759e7d..28400bb 100644 --- a/SpriteLibrary/SpriteEntryForm.Designer.cs +++ b/SpriteLibrary/SpriteEntryForm.Designer.cs @@ -247,6 +247,7 @@ this.MinimizeBox = false; this.Name = "SpriteEntryForm"; this.Text = "SpriteEntryForm"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SpriteEntryForm_FormClosing); ((System.ComponentModel.ISupportInitialize)(this.pbImageField)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); diff --git a/SpriteLibrary/SpriteEntryForm.cs b/SpriteLibrary/SpriteEntryForm.cs index 26bafcc..8ece2de 100644 --- a/SpriteLibrary/SpriteEntryForm.cs +++ b/SpriteLibrary/SpriteEntryForm.cs @@ -22,12 +22,13 @@ namespace SpriteLibrary ResourceManager myResources = null; List SpriteInformation = new List(); Size SnapGridSize = new Size(5,5); + SpriteDatabase myDatabase = null; - internal SpriteEntryForm(ResourceManager theResourceManager, List ListToWorkOn, Size GridSize) + internal SpriteEntryForm(SpriteDatabase theDatabase, List ListToWorkOn, Size GridSize) { InitializeComponent(); - if (theResourceManager == null) throw new Exception("NullException: The ResourceManager passed to the SpriteEntryForm cannot be null. Pass it Properties.Resources.ResourceManager"); - myResources = theResourceManager; + myDatabase = theDatabase; + myResources = myDatabase.GetResourceManager(); SnapGridSize = GridSize; LocalSetup(); SpriteInformation.AddRange(ListToWorkOn); @@ -87,5 +88,10 @@ namespace SpriteLibrary } } } + + private void SpriteEntryForm_FormClosing(object sender, FormClosingEventArgs e) + { + myDatabase.Save(); //try saving the file + } } } diff --git a/SpriteLibrary/SpriteInfo.cs b/SpriteLibrary/SpriteInfo.cs index eea3962..6e313c1 100644 --- a/SpriteLibrary/SpriteInfo.cs +++ b/SpriteLibrary/SpriteInfo.cs @@ -35,11 +35,11 @@ namespace SpriteLibrary } } - internal class SpriteInfo + public class SpriteInfo { - public string SpriteName = ""; - public int ViewPercent = 100; //The percent size of the sprite. 100 is full. 50 is half-size - public List Animations = new List(); + internal string SpriteName = ""; + internal int ViewPercent = 100; //The percent size of the sprite. 100 is full. 50 is half-size + internal List Animations = new List(); /// /// A generic cloning method that works when everything is public