public static GbProject LoadFromFile(String pFilename) { GbProject vResult = new GbProject(); using (FileStream vFS = new FileStream(pFilename, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (StreamReader vSR = new StreamReader(vFS)) { XmlDocument vDoc = new XmlDocument(); vDoc.LoadXml(vSR.ReadToEnd()); //First, load the library and its tiles foreach (XmlNode vNode in vDoc.DocumentElement.SelectNodes("/gbProject/libraries/library")) { Library vLib = new Library(vNode.Attributes["name"].Value); foreach (XmlNode vNodeTile in vNode.SelectNodes("./tile")) { Tile vS = Tile.LoadFromXml(vNodeTile); vLib.AddTile(vS); } vResult.mLibraries.Add(vLib); } //Second, load the maps foreach (XmlNode vNode in vDoc.DocumentElement.SelectNodes("/gbProject/maps/map")) { Map vMap = new Map( Convert.ToInt32(vNode.Attributes["width"].Value), Convert.ToInt32(vNode.Attributes["height"].Value) ); vMap.Name = vNode.Attributes["name"].Value; foreach (XmlNode vNodeCell in vNode.SelectNodes("./cell")) { Guid vG = new Guid(vNodeCell.Attributes["tileID"].Value); Tile vT = null; foreach (Library vL in vResult.mLibraries) { vT = vL.GetTileByID(vG); if (vT != null) break; } if (vT != null) { vMap.SetTile( vT, Convert.ToInt32(vNodeCell.Attributes["x"].Value), Convert.ToInt32(vNodeCell.Attributes["y"].Value) ); } } vResult.AddMap(vMap); } } } return vResult; }
private void CreateNewMapAndTab() { using (FrmNewMap vFrm = new FrmNewMap()) { if (DialogResult.OK == vFrm.ShowDialog(this)) { Map vNew = new Map(vFrm.CreateWidth, vFrm.CreateHeight); vNew.Name = vFrm.CreateName; this.mCurrentProject.AddMap(vNew); TabPage vTP = new TabPage(vNew.Name); UcMapEditor vME = new UcMapEditor(); vME.CurrentMap = vNew; vME.CurrentTile = ucLibView.SelectedTile; vTP.Controls.Add(vME); vME.Dock = DockStyle.Fill; tabMaps.TabPages.Add(vTP); tabMaps.SelectedTab = vTP; vME.NewMap += new EventHandler(MapEditor_NewMap); } } }
public void AddMap(Map pNewMap) { this.mMaps.Add(pNewMap); pNewMap.ParentProject = this; }