public void addTile(Tile tile) { Dictionary<int, Tile> tmp; if (!tiles.ContainsKey(tile.point.X)) { tiles.Add(tile.point.X, new Dictionary<int,Tile>()); } tmp = tiles[tile.point.X]; if (!tmp.ContainsKey(tile.point.Y)) { tmp.Add(tile.point.Y, tile); } else { tmp[tile.point.Y] = tile; } }
private int[,] get_image_crop(Tile tile, out int index_image) { int[,] arr = new int[0, 0]; index_image = -1; try { if (world_export.tilesets.ContainsKey(tile.tileset_code)) { if (!tilesets.ContainsKey(tile.tileset_code)) tilesets.Add(tile.tileset_code, new ProjectExportEGLTileSet()); Tileset tileset = world_export.tilesets[tile.tileset_code]; ProjectExportEGLTileSet tmp = tilesets[tile.tileset_code]; if (tileset.tile_image.ContainsKey(tile.tile_code)) { if (!tmp.tile.ContainsKey(tile.tile_code)) tmp.tile.Add(tile.tile_code, new Dictionary<string, ProjectExportEGLTile>()); Dictionary<string, Image> list_image = tileset.tile_image[tile.tile_code]; Dictionary<string, ProjectExportEGLTile> listTile = tmp.tile[tile.tile_code]; if (list_image.ContainsKey(tile.tile_crop)) { if (!listTile.ContainsKey(tile.tile_crop)) { Image image = list_image[tile.tile_crop]; using (FileStream fs = new FileStream(path_export + "\\" + path_image + name_image + image_index + ".png", FileMode.Create)) { image.Save(fs, System.Drawing.Imaging.ImageFormat.Png); } index_image = image_index; image_index++; ProjectExportEGLTile tmpTile = new ProjectExportEGLTile(); tmpTile.image_idx = index_image; List<bool> list_walk = tileset.walk_region[tile.tile_code]; Setor setor = tileset.setor[tile.tile_code]; Rectangle sector = Tileset.convert_tile_crop(tile.tile_crop); int x = sector.X; int y = sector.Y; int iX = x / setor.tile_width; int iY = y / setor.tile_height; int iW = sector.Width / setor.tile_width; int iH = sector.Height / setor.tile_height; arr = new int[iW, iH]; int k = 1; for (i = 0; i < arr.GetLength(0); i++) { for (j = 0; j < arr.GetLength(1); j++) { k = Setor.ConvertNumero(new Point(((i + iX) * setor.tile_width), ((j + iY) * setor.tile_height)), setor.tile_width, setor.tile_height, setor.map_width); if (list_walk.Count > k) { arr[i, j] = list_walk[k] ? 1 : 0; } } } tmpTile.walk_region = arr; listTile.Add(tile.tile_crop, tmpTile); } else { ProjectExportEGLTile tmpTile = listTile[tile.tile_crop]; index_image = tmpTile.image_idx; arr = tmpTile.walk_region; } } } } } catch (Exception ex) { string error = ex.Message; } return arr; }
private bool BucketPaint(Rectangle r, string codeCropImage, string tileCode, Tile tileOld) { if (r.X < 0 || r.Y < 0 || r.Y > (pbMap.Height - r.Height) || r.X > (pbMap.Width - r.Width)) return false; Tile local = layer[r.Location]; if (tileOld == local) { layer.addTile(new Tile(code_tileset, tileCode, codeCropImage, r.Location)); return true; } else { return false; } }
private void OpenRegion(ProjectRegion pRegion) { try { Region region = new Region(pRegion.setor[0], pRegion.setor[1], pRegion.setor[2], pRegion.setor[3]); region.name = pRegion.name; int i; for (i = 0; i < pRegion.layer.Length; i++) { ProjectLayer pLayer = pRegion.layer[i]; Layer layer = new Layer(); layer.name = pLayer.name; layer.visible = pLayer.visible; layer.tiles = new Dictionary<int, Dictionary<int, Tile>>(); int j; if (pLayer.tiles != null) { for (j = 0; j < pLayer.tiles.Length; j++) { ProjectTile pTile = pLayer.tiles[j]; if (pTile == null) continue; Tile tile = new Tile(); tile.point = new Point(pTile.point[0], pTile.point[1]); tile.tile_code = pTile.tile_code; tile.tile_crop = pTile.tile_crop; tile.tileset_code = pTile.tileset_code; if (!layer.tiles.ContainsKey(pTile.point[0])) { layer.tiles.Add(pTile.point[0], new Dictionary<int, Tile>()); } Dictionary<int, Tile> coluna = layer.tiles[pTile.point[0]]; if (!coluna.ContainsKey(pTile.point[1])) { coluna.Add(pTile.point[1], tile); } else { coluna[pTile.point[1]] = tile; } } } if (pLayer.events != null) { for (j = 0; j < pLayer.events.GetLongLength(0); j++) { int code = pLayer.events[j, 0]; int x = pLayer.events[j, 1]; int y = pLayer.events[j, 2]; layer.addEvent(new Point(x, y), code); } } region.addLayer(layer); } i = world.AddRegion(region); insert_region(region.name, i); } catch (Exception ex) { string error = ex.Message; } }
private void PaintInMap(Point e) { if (tilesetQSel != Rectangle.Empty && mapaQSel != Rectangle.Empty && e.X >= 0 && e.X <= width && e.Y >= 0 && e.Y <= height) { string code_crop_image = tileset.CropImage(region.tile_width, region.tile_height, tilesetQSel); string tile_code = tileset.getCode(region.tile_width, region.tile_height); Tile tile_new = new Tile(code_tileset, tile_code, code_crop_image, mapaQSel.Location); Tile tile_old = layer[mapaQSel.Location]; if (tile_old != tile_new) { txtTileWidth.ReadOnly = true; txtTileHeight.ReadOnly = true; layer.addTile(tile_new); if (BuckettoolStripButton.Checked) { List<quad> lista = new List<quad>(); quad item_atual; lista.Add(new quad(0, new Point(mapaQSel.X - mapaQSel.Width, mapaQSel.Y))); item_atual = lista[lista.Count-1]; if (!BucketPaint(new Rectangle(item_atual.p, mapaQSel.Size), code_crop_image, tile_code, tile_old)) { lista.Remove(item_atual); } lista.Add(new quad(0, new Point(mapaQSel.X, mapaQSel.Y + mapaQSel.Height))); item_atual = lista[lista.Count - 1]; if (!BucketPaint(new Rectangle(item_atual.p, mapaQSel.Size), code_crop_image, tile_code, tile_old)) { lista.Remove(item_atual); } lista.Add(new quad(0, new Point(mapaQSel.X + mapaQSel.Width, mapaQSel.Y))); item_atual = lista[lista.Count - 1]; if (!BucketPaint(new Rectangle(item_atual.p, mapaQSel.Size), code_crop_image, tile_code, tile_old)) { lista.Remove(item_atual); } lista.Add(new quad(0, new Point(mapaQSel.X, mapaQSel.Y - mapaQSel.Height))); item_atual = lista[lista.Count - 1]; if (!BucketPaint(new Rectangle(item_atual.p, mapaQSel.Size), code_crop_image, tile_code, tile_old)) { lista.Remove(item_atual); } int top = 0; Rectangle recTmp; Point poiTmp; while (lista.Count > 0) { top = (lista.Count - 1); item_atual = lista[top]; poiTmp = item_atual.p; switch(item_atual.i) { case 0: poiTmp = new Point(poiTmp.X, poiTmp.Y - mapaQSel.Height); break; case 1: poiTmp = new Point(poiTmp.X + mapaQSel.Width, poiTmp.Y); break; case 2: poiTmp = new Point(poiTmp.X, poiTmp.Y + mapaQSel.Height); break; case 3: poiTmp = new Point(poiTmp.X - mapaQSel.Width, poiTmp.Y); break; default: lista.Remove(item_atual); continue; } item_atual.i++; recTmp = new Rectangle(poiTmp, mapaQSel.Size); if (BucketPaint(recTmp, code_crop_image, tile_code, tile_old)) { lista.Add(new quad(0, new Point(recTmp.X, recTmp.Y))); } } } } } }