コード例 #1
0
 private void toolStripMenuItemDelete_Click(object sender, EventArgs e)
 {   // delete selected tile
     if (MessageBox.Show("Delete this tile?", "Delete Tile", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
     {
         TilesManagement.DeleteSelectedTile(this, _map, ref _tile_library, pnlTileLibrary, Convert.ToInt32(_map_info.SelectedTile.Name));
     }
 }
コード例 #2
0
 public void SaveMap(string fileName)
 {   // save map
     Cursor.Current = Cursors.WaitCursor;
     _map.SaveMap(fileName);
     TilesManagement.SaveTiles(ref _tile_library, fileName);
     tbMapName.Text = Path.GetFileNameWithoutExtension(_map.MapFileName);
     Cursor.Current = Cursors.Default;
 }
コード例 #3
0
        public void OpenMap(string fileName)
        {   // open saved map
            _map.OpenMap(fileName, _map);
            ClearSelectedTile();

            TilesManagement.LoadTiles(this, _map, ref _tile_library, pnlTileLibrary, fileName);
            tbMapName.Text = Path.GetFileNameWithoutExtension(_map.MapFileName);

            _history.ResetHistory();
            undoToolStripMenuItem.Enabled = false;
            redoToolStripMenuItem.Enabled = false;
        }
コード例 #4
0
        public void SetupMap(string mapName, int mapWidth, int mapHeight, int tileWidth, int tileHeight)
        {
            _map.SetupMap(mapName, mapWidth, mapHeight, tileWidth, tileHeight);

            TilesManagement.RenderTiles(_map, ref _tile_library, pnlTileLibrary);
            RenderMap();
            ClearSelectedTile();
            tbMapName.Text = Path.GetFileNameWithoutExtension(_map.MapFileName);

            _history.ResetHistory();
            undoToolStripMenuItem.Enabled = false;
            redoToolStripMenuItem.Enabled = false;
        }
コード例 #5
0
        private void clearTilesToolStripMenuItem_Click(object sender, EventArgs e)
        {   // clear tile library
            Cursor.Current = Cursors.WaitCursor;

            if (MessageBox.Show("Clear the Tile Library?", "Clear Tile Library", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                ClearTiles();

                TilesManagement.RenderTiles(_map, ref _tile_library, pnlTileLibrary);
                RenderMap();
            }

            Cursor.Current = Cursors.Default;
        }
コード例 #6
0
        public D2DMapEditor()
        {
            InitializeComponent();
            Init();
            _map = new Map();

            string[] args = Environment.GetCommandLineArgs();
            if (args.Length > 1)
            {   // open file
                String d2dFileName = Convert.ToString(args[1]);

                if (Path.GetExtension(d2dFileName) != ".d2d")
                {
                    MessageBox.Show(d2dFileName + " is not a d2d file", "Cannot Load File", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    try
                    {
                        Cursor.Current = Cursors.WaitCursor;

                        OpenMap(d2dFileName);
                        TilesManagement.RenderTiles(_map, ref _tile_library, pnlTileLibrary);
                        // switch to design view
                        tctrlDesign.SelectedTab = tpgDesign;

                        Cursor.Current = Cursors.Default;

                        saveMapToolStripMenuItem.Enabled = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Failed to open: " + d2dFileName + "\n" + ex.Message);
                    }
                }
            }
            else
            {
                // reset and render map
                ResetMap();
            }

            tbMapName.Text = Path.GetFileNameWithoutExtension(_map.MapFileName);
            ClearSelectedTile();
            ReloadLayers(0);
            RenderMap();
        }
コード例 #7
0
        private void loadMapToolStripMenuItem_Click(object sender, EventArgs e)
        {   // open saved map
            openMapDialog.InitialDirectory = Application.ExecutablePath;
            DialogResult openMap = this.openMapDialog.ShowDialog();

            if (openMap == DialogResult.OK)
            {   // open Map
                string d2dFileName = this.openMapDialog.FileName;

                if (Path.GetExtension(d2dFileName) != ".d2d")
                {
                    MessageBox.Show(d2dFileName + " is not a d2d file", "Cannot Load File", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    try
                    {
                        Cursor.Current = Cursors.WaitCursor;

                        OpenMap(this.openMapDialog.FileName);
                        TilesManagement.RenderTiles(_map, ref _tile_library, pnlTileLibrary);
                        // switch to design view
                        tctrlDesign.SelectedTab = tpgDesign;

                        Cursor.Current = Cursors.Default;

                        ReloadLayers(0);
                        RenderMap();
                        saveMapToolStripMenuItem.Enabled = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Failed to open: " + this.openMapDialog.FileName + "\n" + ex.Message);
                    }
                }
            }
        }
コード例 #8
0
 public void ClearTiles()
 {   // clear all tiles in the tile library
     TilesManagement.ClearTiles(this, _map, ref _tile_library, pnlTileLibrary);
 }
コード例 #9
0
 public void AddTiles(string folderName)
 {   // add tiles to tile library
     TilesManagement.AddTiles(this, _map, ref _tile_library, pnlTileLibrary, folderName);
 }
コード例 #10
0
        public Boolean ExportMap(ref Tile[] tileLibrary, string path, ListBox lbLayers, ExportLayer exportLayer, ProgrammingLanguage language, ImageFormat format)
        {
            path = path + "\\D2D_" + Path.GetFileNameWithoutExtension(MapFileName);
            Directory.CreateDirectory(path);
            StreamWriter sw;
            string       layerPath;

            switch (exportLayer)
            {
            case ExportLayer.SelectedOnly:
                int index = FindLayerIndexWithName(lbLayers.SelectedItem.ToString());
                if (index == -1)
                {
                    MessageBox.Show("No layer selected.", "Export Failed");
                    return(false);
                }
                layerPath = path + "\\" + Layers[index].Name + ".txt";
                sw        = new StreamWriter(layerPath);
                sw.Write(CodesGenerator.GenerateCodes(index, this, format, tileLibrary, language));
                sw.Flush();
                sw.Close();
                break;

            case ExportLayer.VisibleOnly:
                foreach (Layer layer in Layers)
                {
                    if (layer.Visible)
                    {
                        layerPath = path + "\\" + layer.Name + ".txt";
                        sw        = new StreamWriter(layerPath);
                        sw.Write(CodesGenerator.GenerateCodes(FindLayerIndexWithId(layer.LayerId), this, format, tileLibrary, language));
                        sw.Flush();
                        sw.Close();
                    }
                }
                break;

            case ExportLayer.All:
                foreach (Layer layer in Layers)
                {
                    layerPath = path + "\\" + layer.Name + ".txt";
                    sw        = new StreamWriter(layerPath);
                    sw.Write(CodesGenerator.GenerateCodes(FindLayerIndexWithId(layer.LayerId), this, format, tileLibrary, language));
                    sw.Flush();
                    sw.Close();
                }
                break;

            default:
                break;
            }

            // save tiles
            path = path + "\\" + Path.GetFileNameWithoutExtension(MapFileName);
            Directory.CreateDirectory(path);
            for (int i = 0; i < tileLibrary.Length; i++)
            {
                TilesManagement.SaveTileImage(ref tileLibrary, i, path, format);
            }

            return(true);
        }