예제 #1
0
파일: Menu.cs 프로젝트: plhearn/tileEditor
        private void loadMapToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Open load dialog
            DialogResult loaded_result = this.load_map_dialog.ShowDialog();

            if (loaded_result == DialogResult.OK)
            {
                // Load tile map data
                MapLoader map_loader = new MapLoader();

                GLB_Data.MapName = load_map_dialog.FileName.Replace(".xml", "").Substring(load_map_dialog.FileName.Replace(".xml", "").LastIndexOf("\\") + 1);

                if(load_map_dialog.FileName.EndsWith(".xml"))
                {
                    XmlDocument xml = new XmlDocument();
                    xml.Load(load_map_dialog.FileName);

                    string outie = xml.OuterXml;

                    int startIndex;
                    int length;

                    //Texture Name
                    startIndex = outie.IndexOf("<TextureName>") + "<TextureName>".Length;
                    length = outie.IndexOf("</TextureName>") - startIndex;

                    GLB_Data.TextureFileName = outie.Substring(startIndex, length).Trim();

                    TextureLoader textureLoader = new TextureLoader(GraphicsDevice);
                    GLB_Data.TilesTexture = textureLoader.FromFile(GLB_Data.TextureFileName);
                }

                if (map_loader.LoadMapDataXML(load_map_dialog.FileName))
                {

                    // success
                    if (GLB_Data.TextureFileName == null || GLB_Data.TextureFileName == "")
                    {
                        //MessageBox.Show("TileMap loaded successfully!", "Save Map", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    tile_palette.SetImage(GLB_Data.TextureFileName, GLB_Data.TilePalette);
                    tile_palette.Invalidate();

                    // reset settings
                    this.ResetSelectedTiles();
                    this.ResetLayers();
                    this.ResetCamera();

                    terrain_editor_form.PopulateCombo();

                    // loading done
                    //MessageBox.Show("TileMap loaded successfully!", "Save Map", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
예제 #2
0
        private void toolbar_loadMapPortals_Click(object sender, EventArgs e)
        {
            load_map_dialog = new OpenFileDialog();
            load_map_dialog.InitialDirectory = Environment.CurrentDirectory + @"\Maps";
            //load_map_dialog.Filter = "XNA Map Editor TileMaps (*.xmap) | *.xmap";
            load_map_dialog.Filter = "XNA Map Editor TileMaps (*.xml) | *.xml";
            load_map_dialog.Title = "Load TileMap";

            // Open load dialog
            DialogResult loaded_result = this.load_map_dialog.ShowDialog();

            if (loaded_result == DialogResult.OK)
            {
                // Load tile map data
                MapLoader map_loader = new MapLoader();

                otherFileName = load_map_dialog.FileName;

                XmlDocument xml = new XmlDocument();
                xml.Load(otherFileName);

                //chop off directory info
                otherFileName = otherFileName.Substring(otherFileName.LastIndexOf("\\") + 1, otherFileName.LastIndexOf(".") - otherFileName.LastIndexOf("\\") - 1);

                string outie = xml.OuterXml;

                int startIndex;
                int length;

                //Texture Name
                startIndex = outie.IndexOf("<TextureName>") + "<TextureName>".Length;
                length = outie.IndexOf("</TextureName>") - startIndex;

                GLB_Data_Other.TextureFileName = outie.Substring(startIndex, length).Trim();

                using (FileStream stream = File.OpenRead(GLB_Data_Other.TextureFileName))
                {
                    GLB_Data_Other.TilesTexture = Texture2D.FromStream(xnaRenderer1.GraphicsDevice, stream);
                }

                if (map_loader.LoadMapDataXMLOther(load_map_dialog.FileName))
                {
                    // success
                    if (GLB_Data_Other.TextureFileName == null || GLB_Data_Other.TextureFileName == "")
                    {
                        //MessageBox.Show("TileMap loaded successfully!", "Save Map", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    //tile_palette.SetImage(GLB_Data_Other.TextureFileName, GLB_Data_Other.TilePalette);
                    tile_palette.Invalidate();

                    // reset settings
                    this.ResetSelectedTiles();
                    this.ResetLayers();
                    this.ResetCamera();

                    //terrain_editor_form.PopulateCombo();

                    // loading done
                    //MessageBox.Show("TileMap loaded successfully!", "Save Map", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }