示例#1
0
        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!OnCloseDocument())
            {
                return;
            }

            mapWindow.Tile = null;

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Title           = "Select Burntime Raw or Png Image...";
            dlg.Filter          = "All Formats|mat_*.raw;*.png;*.bmp|Burntime Raw (mat_*.raw)|mat_*.raw|Image (*.png, *.bmp)|*.png;*.bmp";
            dlg.CheckFileExists = true;
            dlg.CheckPathExists = true;
            if (DialogResult.OK == dlg.ShowDialog())
            {
                if (dlg.FileName.EndsWith(".raw", StringComparison.InvariantCultureIgnoreCase))
                {
                    FileStream file = new FileStream(dlg.FileName, FileMode.Open);

                    // check & size selection dialog
                    document = new MapDocument(this);
                    document.Import(file, 32, allTiles[0]);
                    document.Title = Path.GetFileNameWithoutExtension(dlg.FileName);
                    UpdateTitle();

                    mapWindow.SetDocument(document);

                    file.Dispose();
                }
                else
                {
                    Import dlg2 = new Import(allTiles);
                    if (DialogResult.OK != dlg2.ShowDialog())
                    {
                        return;
                    }

                    Cursor = Cursors.WaitCursor;

                    TileSet  addSet  = (dlg2.Set == 0) ? null : allTiles[dlg2.Set];
                    ListView addView = (dlg2.Set == 0) ? null : tileViews[dlg2.Set];

                    int num = 0;
                    if (addSet != null)
                    {
                        num = addSet.Tiles.Count;

                        addSet.CalcLast();

                        if (dlg2.SubSet > addSet.LastSubSet)
                        {
                            addSet.LastSubSet = (byte)(dlg2.SubSet - 1);
                            addSet.LastId     = Tile.LAST_ID;
                        }
                    }

                    document = new MapDocument(this);
                    document.Import(dlg.FileName, dlg2.TileSize, allTiles, addSet);
                    document.Title = Path.GetFileNameWithoutExtension(dlg.FileName);
                    UpdateTitle();

                    if (addSet != null)
                    {
                        for (int i = num; i < addSet.Tiles.Count; i++)
                        {
                            addSet.Tiles[i].Image.Save("tiles\\" + addSet.Name + "\\" + addSet.Tiles[i].SubSet.ToString("D3") + "_" + addSet.Tiles[i].ID.ToString("D2") + ".png");

                            addView.LargeImageList.Images.Add(addSet.Tiles[i].Image);
                            addView.LargeImageList.ColorDepth = ColorDepth.Depth24Bit;

                            ListViewItem item = new ListViewItem();
                            item.ImageIndex  = addView.LargeImageList.Images.Count - 1;
                            item.ToolTipText = "[" + addSet.Tiles[i].SubSet.ToString("D3") + "x" + addSet.Tiles[i].ID.ToString("D2") + "]";

                            addView.Items.Add(item);
                        }

                        addSet.Sort();
                    }

                    mapWindow.SetDocument(document);

                    Cursor = Cursors.Default;
                }
            }
        }