private void RowsnumericUpDown1_ValueChanged(object sender, EventArgs e)
 {
     Mapsize_RC.Width = (int)RowsnumericUpDown1.Value;
     Map = new TileClass[Mapsize_RC.Width, Mapsize_RC.Height];
     for (int x = 0; x < Mapsize_RC.Width; ++x)
     {
         for (int y = 0; y < Mapsize_RC.Height; ++y)
         {
             if (Map != null)
             {
                 Map[x, y] = new TileClass();
                 Rectangle temprect = new Rectangle(x * TilePixelSize.Width, y * TilePixelSize.Height, TilePixelSize.Width, TilePixelSize.Height);
                 Map[x, y].Rect = temprect;
             }
         }
     }
 }
        public Form1()
        {
            if (File.Exists("Config.xml"))
            {
                XElement xRoot = XElement.Load("Config.xml");
                XAttribute filepath = xRoot.Attribute("Path");
                StartPath = filepath.Value;
            }
            FolderBrowserDialog fbdlg = new FolderBrowserDialog();
            fbdlg.Description = "Please Navigate to where you would like Save";
            if (DialogResult.OK == fbdlg.ShowDialog())
            {
                StartPath = fbdlg.SelectedPath;
            }

            Looping = true;
            InitializeComponent();
            this.HeightcomboBox2.DataSource = System.Enum.GetValues(typeof(TileSize));
            this.WidthcomboBox1.DataSource = System.Enum.GetValues(typeof(TileSize));

            WidthcomboBox1.SelectedItem = TileSize.__64;
            HeightcomboBox2.SelectedItem = TileSize.__64;

            d3D.InitManagedDirect3D(TilesetGraphicsPanel);
            d3D.InitManagedDirect3D(MapGraphicsPanel);

            tm.InitManagedTextureManager(d3D.Device, d3D.Sprite);
            TilePixelSize = new Size((int)WidthcomboBox1.Items[WidthcomboBox1.SelectedIndex], (int)HeightcomboBox2.Items[HeightcomboBox2.SelectedIndex]);
            MapPixelSize = TilePixelSize;
            Size minsize = new Size(TilePixelSize.Width * TileSetSize_RC.Width, TilePixelSize.Width * TileSetSize_RC.Height);
            TilesetGraphicsPanel.AutoScrollMinSize= minsize;

            RowsnumericUpDown1.Value = 10;
            ColumnsnumericUpDown2.Value = 10;
            Map = new TileClass[10, 10];

            for (int x = 0;x < Mapsize_RC.Width; ++x)
            {
                for (int y = 0; y < Mapsize_RC.Height; ++y)
                {
                    Map[x, y] = new TileClass();
                    Rectangle temprect= new Rectangle(x * TilePixelSize.Width, y * TilePixelSize.Height, TilePixelSize.Width, TilePixelSize.Height);
                    Map[x, y].Rect = temprect;
                }
            }
            NormtextureId = -1;
        }
        private void loadToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OpenFileDialog SaveFolderPath = new OpenFileDialog();
            //SaveFolderPath.InitialDirectory = StartPath;
            //SaveFolderPath.ShowDialog();

            if (DialogResult.OK==SaveFolderPath.ShowDialog())
            {
                XElement xRoot = XElement.Load(SaveFolderPath.FileName);
                if (xRoot==null)
                {
                    String title = "Failure to Load";
                    String content = "Load Failed: xRoot is null";
                    MessageBox.Show(content, title, MessageBoxButtons.OK);
                    return;
                }

                XAttribute maprows= xRoot.Attribute("Rows");
                XAttribute mapcolumns= xRoot.Attribute("Columns");

                Mapsize_RC.Width = Convert.ToInt32(mapcolumns.Value);
                Mapsize_RC.Height = Convert.ToInt32(maprows.Value);

                //THIS IS GOING TO BE A PROBLEM
                XAttribute texturefile= xRoot.Attribute("FileName");

                String RelativePath= StartPath + texturefile.Value;
                NormtextureId = tm.LoadTexture(RelativePath, 0);

                XElement pTiles = (XElement) xRoot.FirstNode;
                XElement xTile = (XElement) pTiles.FirstNode;

                Map = new TileClass[Mapsize_RC.Width, Mapsize_RC.Height];
                for (int x = 0; x < Mapsize_RC.Width; ++x)
                {
                    for (int y = 0; y < Mapsize_RC.Height; ++y)
                    {
                        Map[x, y] = new TileClass();
                        Rectangle temprect = new Rectangle(x * TilePixelSize.Width, y * TilePixelSize.Height, TilePixelSize.Width, TilePixelSize.Height);
                        Map[x, y].Rect = temprect;
                    }
                }

                XAttribute tempdata1,tempdata2;

                for (int x = 0; x < Mapsize_RC.Width; ++x)
                {
                    for (int y = 0; y < Mapsize_RC.Height; ++y)
                    {
                        tempdata1 = xTile.Attribute("PosX");
                        tempdata2 = xTile.Attribute("PosY");
                        Map[x,y].Position = new Point(Convert.ToInt32(tempdata1.Value),Convert.ToInt32(tempdata2.Value));

                        tempdata1 = xTile.Attribute("PixWidth");
                        tempdata2 = xTile.Attribute("PixHeight");
                        TilePixelSize = new Size(Convert.ToInt32(tempdata1.Value), Convert.ToInt32(tempdata2.Value));

                        tempdata1 = xTile.Attribute("Status");
                        Map[x,y].Status = Convert.ToByte(tempdata1.Value);

                        tempdata1 = xTile.Attribute("PlayerID");
                        Map[x,y].PlayerID=(Convert.ToInt32(tempdata1.Value));

                        tempdata1 = xTile.Attribute("TType");
                        Map[x,y].TType = (TILE_TYPE)Convert.ToInt32(tempdata1.Value);

                        xTile = (XElement)xTile.NextNode;
                    }
                }
            }
        }