public static bool Show(ExportParams p) { using (ExportSettingsForm f = new ExportSettingsForm()) { f.textBoxDir.Text = p.Directory; f.checkBoxTiles.Checked = p.ExportTiles; f.checkBoxMap.Checked = p.ExportMap; f.checkBoxGrid.Checked = p.ShowGrid; f.radioButtonPng.Checked = p.Format == ImageFormat.Png; f.radioButtonJpeg.Checked = p.Format == ImageFormat.Jpeg; bool result = f.ShowDialog() == DialogResult.OK; if (result) { p.Directory = f.textBoxDir.Text; p.ExportTiles = f.checkBoxTiles.Checked; p.ExportMap = f.checkBoxMap.Checked; p.ShowGrid = f.checkBoxGrid.Checked; p.Format = f.radioButtonPng.Checked ? ImageFormat.Png : ImageFormat.Jpeg; } return(result); } }
public static bool Show(ExportParams p) { using (ExportSettingsForm f = new ExportSettingsForm()) { f.textBoxDir.Text = p.Directory; f.checkBoxTiles.Checked = p.ExportTiles; f.checkBoxMap.Checked = p.ExportMap; f.checkBoxGrid.Checked = p.ShowGrid; f.radioButtonPng.Checked = p.Format == ImageFormat.Png; f.radioButtonJpeg.Checked = p.Format == ImageFormat.Jpeg; bool result = f.ShowDialog() == DialogResult.OK; if (result) { p.Directory = f.textBoxDir.Text; p.ExportTiles = f.checkBoxTiles.Checked; p.ExportMap = f.checkBoxMap.Checked; p.ShowGrid = f.checkBoxGrid.Checked; p.Format = f.radioButtonPng.Checked ? ImageFormat.Png : ImageFormat.Jpeg; } return result; } }
private Common() { parameters = new Hashtable(); exportParams = new ExportParams(); InitParams(); }
public void Save(ExportParams exportParams) { //if (Directory.Exists(exportParams.Directory)) // throw new Exception(string.Format("Directory exists:\n{0}", exportParams.Directory)); //Directory.CreateDirectory(exportParams.Directory); if (exportParams.ExportTiles) { string mapdir = Path.Combine(exportParams.Directory, Name); if (Directory.Exists(mapdir)) throw new Exception(string.Format("Directory exists:\n{0}", mapdir)); Directory.CreateDirectory(mapdir); if (chosen == null) { foreach (Tile tile in tiles) tile.Image.Save(Path.Combine(mapdir, string.Format("tile_{0}_{1}.png", tile.X / tile.Width, tile.Y / tile.Height)), ImageFormat.Png); } else { foreach (Tile tile in tiles) tile.Image.Save(Path.Combine(mapdir, string.Format("tile_{0}_{1}.png", (tile.X - chosen.X) / tile.Width, (tile.Y - chosen.Y) / tile.Height)), ImageFormat.Png); } } if (exportParams.ExportMap) { var mapfile = Path.Combine(exportParams.Directory, String.Concat(Name, (Equals(exportParams.Format, ImageFormat.Png) ? ".png" : ".jpg"))); if (File.Exists(mapfile)) throw new Exception(string.Format("File exists:\n{0}", mapfile)); try { using (Image i = new Bitmap((int)r.Width, (int)r.Height)) { using (Graphics g = Graphics.FromImage(i)) { foreach (Tile tile in tiles) g.DrawImage(tile.Image, tile.X, tile.Y); if (exportParams.ShowGrid) { if (chosen == null) { foreach (Tile tile in tiles) { g.DrawRectangle(Pens.White, tile.X, tile.Y, tile.Width, tile.Height); g.DrawString(string.Format("({0},{1})", tile.X / tile.Width, tile.Y / tile.Height), new Font(FontFamily.GenericSansSerif, 8), Brushes.White, tile.X + 2, tile.Y + 2); } } else { foreach (Tile tile in tiles) { g.DrawRectangle(Pens.White, tile.X, tile.Y, tile.Width, tile.Height); g.DrawString(string.Format("({0},{1})", (tile.X - chosen.X) / tile.Width, (tile.Y - chosen.Y) / tile.Height), new Font(FontFamily.GenericSansSerif, 8), Brushes.White, tile.X + 2, tile.Y + 2); } } } } i.Save(mapfile, exportParams.Format); } } catch (Exception e) { throw new Exception(string.Format("Whole map can not be saved:\n{0}", e.Message)); } } }
public void Save(ExportParams exportParams) { //if (Directory.Exists(exportParams.Directory)) // throw new Exception(string.Format("Directory exists:\n{0}", exportParams.Directory)); //Directory.CreateDirectory(exportParams.Directory); if (exportParams.ExportTiles) { string mapdir = Path.Combine(exportParams.Directory, Name); if (Directory.Exists(mapdir)) { throw new Exception(string.Format("Directory exists:\n{0}", mapdir)); } Directory.CreateDirectory(mapdir); if (chosen == null) { foreach (Tile tile in tiles) { tile.Image.Save(Path.Combine(mapdir, string.Format("tile_{0}_{1}.png", tile.X / tile.Width, tile.Y / tile.Height)), ImageFormat.Png); } } else { foreach (Tile tile in tiles) { tile.Image.Save(Path.Combine(mapdir, string.Format("tile_{0}_{1}.png", (tile.X - chosen.X) / tile.Width, (tile.Y - chosen.Y) / tile.Height)), ImageFormat.Png); } } } if (exportParams.ExportMap) { var mapfile = Path.Combine(exportParams.Directory, String.Concat(Name, (Equals(exportParams.Format, ImageFormat.Png) ? ".png" : ".jpg"))); if (File.Exists(mapfile)) { throw new Exception(string.Format("File exists:\n{0}", mapfile)); } try { using (Image i = new Bitmap((int)r.Width, (int)r.Height)) { using (Graphics g = Graphics.FromImage(i)) { foreach (Tile tile in tiles) { g.DrawImage(tile.Image, tile.X, tile.Y); } if (exportParams.ShowGrid) { if (chosen == null) { foreach (Tile tile in tiles) { g.DrawRectangle(Pens.White, tile.X, tile.Y, tile.Width, tile.Height); g.DrawString(string.Format("({0},{1})", tile.X / tile.Width, tile.Y / tile.Height), new Font(FontFamily.GenericSansSerif, 8), Brushes.White, tile.X + 2, tile.Y + 2); } } else { foreach (Tile tile in tiles) { g.DrawRectangle(Pens.White, tile.X, tile.Y, tile.Width, tile.Height); g.DrawString(string.Format("({0},{1})", (tile.X - chosen.X) / tile.Width, (tile.Y - chosen.Y) / tile.Height), new Font(FontFamily.GenericSansSerif, 8), Brushes.White, tile.X + 2, tile.Y + 2); } } } } i.Save(mapfile, exportParams.Format); } } catch (Exception e) { throw new Exception(string.Format("Whole map can not be saved:\n{0}", e.Message)); } } }