Beispiel #1
0
        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);
                }
            }
        }
Beispiel #2
0
        private void loadTilesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Open load dialog
            DialogResult loaded_result = this.load_tiles_dialog.ShowDialog();

            if (loaded_result == DialogResult.OK)
            {
                // Load image

                if (GLB_Data.TilesTexture != null)
                {
                    GLB_Data.TilesTexture.Dispose();
                }

                GLB_Data.TextureFileName = load_tiles_dialog.FileName;

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

                tile_palette.SetImage(load_tiles_dialog.FileName);
                tile_palette.Invalidate();

                // reset selected tiles
                this.ResetSelectedTiles();

                toolbar_brush_Click(sender, e);
            }
        }