Beispiel #1
0
        public void SaveMap(string fileName)
        {
            if (tileLibs.Count > 0 && tileMap.layerList.Count > 0)
            {
                string[] fullpath = fileName.Split('\\');
                Console.WriteLine(fullpath[fullpath.Length - 2]);

                //if(Directory.Exists(fileName + "\\Graphics") == false)
                //{
                //    DirectoryInfo di = Directory.CreateDirectory(fileName + "\\Graphics");

                //}

                using (StreamWriter stream = new StreamWriter(File.Open(fileName, FileMode.Create)))
                {
                    for (int tileLibIndex = 0; tileLibIndex < tileLibs.Count; tileLibIndex++)
                    {
                        string[] path = tileLibs[tileLibIndex].imageFileName.Split('\\');

                        stream.WriteLine("[TILELIB]");
                        stream.WriteLine(tileLibs[tileLibIndex].imageFileName);
                        stream.Write(tileLibs[tileLibIndex].cellWidth + ",");
                        stream.Write(tileLibs[tileLibIndex].cellHeight);
                        stream.WriteLine();
                    }

                    for (int layerIndex = 0; layerIndex < tileMap.layerList.Count; layerIndex++)
                    {
                        TileMapLayer layer = tileMap.layerList[layerIndex];
                        MapCell[]    mc    = layer.cellCache;

                        stream.WriteLine("[LAYER]");
                        stream.Write(layer.cellWidth + ",");
                        stream.Write(layer.cellHeight + ",");
                        stream.Write(layer.columnCount + ",");
                        stream.Write(layer.rowCount);
                        stream.WriteLine();

                        for (int index = 0; index < mc.Length; index++)
                        {
                            int tileLibIndex = mc[index].tileLibIndex;
                            int tileIndex    = mc[index].tileIndex;

                            stream.Write(tileLibIndex + ",");
                            stream.Write(tileIndex);

                            if (index < mc.Length - 1)
                            {
                                stream.Write(",");
                            }
                        }

                        stream.WriteLine();
                    }

                    stream.WriteLine("[END]");
                    stream.Close();
                }
            }
        }
Beispiel #2
0
        private void SelectMapLayer(int index)
        {
            try
            {
                currentMapLayer = tileMap.layerList[index];
            }
            catch
            {
            }

            textBoxCustomMapCellWidth.Text  = currentMapLayer.cellWidth.ToString();
            textBoxCustomMapCellHeight.Text = currentMapLayer.cellHeight.ToString();
            textBoxCustomMapColumns.Text    = currentMapLayer.columnCount.ToString();
            textBoxCustomMapRows.Text       = currentMapLayer.rowCount.ToString();

            panelCustomLayerList.Invalidate();
        }
Beispiel #3
0
        public void AddMapLayer()
        {
            int cellWidth;
            int cellHeight;
            int columns;
            int rows;

            try
            {
                cellWidth  = int.Parse(textBoxCustomMapCellWidth.Text);
                cellHeight = int.Parse(textBoxCustomMapCellHeight.Text);
                columns    = int.Parse(textBoxCustomMapColumns.Text);
                rows       = int.Parse(textBoxCustomMapRows.Text);
            }
            catch
            {
                MessageBox.Show("Parameters must be integers above zero");
                textBoxCustomMapCellWidth.RevertText();
                textBoxCustomMapCellHeight.RevertText();
                textBoxCustomMapColumns.RevertText();
                textBoxCustomMapRows.RevertText();

                return;
            }
            finally
            {
                textBoxCustomMapCellWidth.StoreText();
                textBoxCustomMapCellHeight.StoreText();
                textBoxCustomMapColumns.StoreText();
                textBoxCustomMapRows.StoreText();
            }

            if (cellWidth <= 0 || cellHeight <= 0)
            {
                MessageBox.Show("Parameters must be integers above zero");
                return;
            }

            CheckBox checkBox = new CheckBox();

            checkBox.Parent          = panelCustomLayerList;
            checkBox.Size            = new Size(checkBox.Height, this.FontHeight);
            checkBox.Checked         = true;
            checkBox.CheckedChanged += delegate(object sender, EventArgs e) { panelCustomMapWindow.Invalidate(); };
            mapLayerCheckBoxes.Add(checkBox);

            TileMapLayer mapLayer = new TileMapLayer();

            mapLayer.cellWidth   = cellWidth;
            mapLayer.cellHeight  = cellHeight;
            mapLayer.columnCount = columns;
            mapLayer.rowCount    = rows;
            mapLayer.cellCache   = new MapCell[columns * rows];

            for (int i = 0; i < columns * rows; i++)
            {
                mapLayer.cellCache[i] = new MapCell();
            }

            tileMap.AddLayer(mapLayer);
            currentMapLayer = mapLayer;

            vScrollBarMapLayerList.Maximum     = tileMap.layerList.Count - 1;
            vScrollBarMapLayerList.LargeChange = panelCustomLayerList.Height / this.FontHeight;
            vScrollBarMapLayerList.Value       = 0;

            hScrollBarTileMap.Maximum     = currentMapLayer.columnCount - 1;
            hScrollBarTileMap.LargeChange = panelCustomMapWindow.Width / currentMapLayer.cellWidth;
            hScrollBarTileMap.Value       = 0;

            vScrollBarTileMap.Maximum     = currentMapLayer.rowCount - 1;
            vScrollBarTileMap.LargeChange = panelCustomMapWindow.Width / currentMapLayer.cellHeight;
            vScrollBarTileMap.Value       = 0;
        }
Beispiel #4
0
 public void AddLayer(TileMapLayer tileMapLayer)
 {
     this.layerList.Add(tileMapLayer);
 }