Exemplo n.º 1
0
 public int AddTileset(Tileset tile)
 {
     while (tilesets.ContainsKey(tile.tileset_code))
     {
         tile.tileset_code++;
     }
     tilesets.Add(tile.tileset_code, tile);
     return tile.tileset_code;
 }
Exemplo n.º 2
0
        public void add_tile_set(Tileset tileset)
        {
            try
            {
                if (tileset == null)
                    return;

                ProjectTileSet tmp = new ProjectTileSet();
                tmp.tileset_name = tileset.Name;
                tmp.buffer = tileset.buffer;
                tmp.tileset_code = tileset.tileset_code;
                tmp.tiles = new ProjectTiles[tileset.setor.Count];
                int i = 0;
                foreach (string key in tileset.setor.Keys)
                {
                    ProjectTiles tmp_tiles = new ProjectTiles();

                    if (tileset.walk_region.ContainsKey(key))
                    {
                        List<bool> walk_list = tileset.walk_region[key];

                        tmp_tiles.tileset_walk = new bool[walk_list.Count];

                        for (int j = 0; j < walk_list.Count; j++)
                        {
                            tmp_tiles.tileset_walk[j] = walk_list[j];
                        }
                    }

                    if (tileset.setor.ContainsKey(key))
                    {
                        Setor sector = tileset.setor[key];

                        tmp_tiles.tileset_setor = new int[4];

                        tmp_tiles.tileset_setor[0] = sector.map_width;
                        tmp_tiles.tileset_setor[1] = sector.map_height;
                        tmp_tiles.tileset_setor[2] = sector.tile_width;
                        tmp_tiles.tileset_setor[3] = sector.tile_height;

                    }

                    if (tileset.tile_image.ContainsKey(key))
                    {
                        Dictionary<string, Image> list = tileset.tile_image[key];

                        tmp_tiles.tileset_names = new string[list.Count];

                        tmp_tiles.tileset_images = new List<byte[]>();

                        int j = 0;
                        foreach (string names in list.Keys)
                        {
                            tmp_tiles.tileset_names[j] = names;

                            Image crop_image = new Bitmap(list[names]);

                            using (MemoryStream stream = new MemoryStream())
                            {
                                crop_image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                                byte[] buffer = stream.ToArray();
                                tmp_tiles.tileset_images.Add(buffer);
                            }

                            j++;
                        }
                    }

                    tmp.tiles[i] = tmp_tiles;
                    i++;
                }
                tilesets.Add(tmp);
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }
        }
Exemplo n.º 3
0
        private void InsertTileset(string name, int code)
        {
            code_tileset = code;
            DataTable dt = dsControle.tilesets;
            DataRow dr = dt.NewRow();
            dr["nm_tileset"] = name;
            dr["code"] = code_tileset;
            dt.Rows.InsertAt(dr, 0);
            dgTilesets.Rows[0].Selected = true;
            dgTilesets.Refresh();

            tileset = world.tilesets[code_tileset];

            tileset.Name = name;

            btnDeleteTileset.Enabled = (dgTilesets.Rows.Count > 1);
            WalktoolStripButton.Enabled = (dgTilesets.Rows.Count > 0);

            checkTileSet();
        }
Exemplo n.º 4
0
        private void dgTilesets_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewCell celula = dgTilesets["codeDataGridViewTextBoxColumn", e.RowIndex];

            int code = Convert.ToInt32(celula.Value);
            if (code != code_tileset)
            {
                code_tileset = code;
                if (world.tilesets.ContainsKey(code_tileset))
                    tileset = world.tilesets[code_tileset];
                checkTileSet();
            }

            dgTilesets.Rows[e.RowIndex].Selected = true;
        }
Exemplo n.º 5
0
        private void clear_project()
        {
            world = null;
            tileset = null;
            region = null;
            layer = null;

            default_save = string.Empty;

            this.Text = "Editor Map 2D";

            ErasetoolStripButton.Checked = false;
            PenciltoolStripButton.Checked = false;
            BuckettoolStripButton.Checked = false;
            WalktoolStripButton.Checked = false;
            GridMaptoolStripButton.Checked = false;
            LayertoolStripButton.Checked = false;
            EventostoolStripButton.Checked = false;

            dsControle.maps.Clear();
            dsControle.tilesets.Clear();
            dsControle.layers.Clear();

            dgTilesets.Refresh();
            dgMaps.Refresh();
            dgLayers.Refresh();

            pbTileSet.Image = null;
            pbMap.BackgroundImage = null;
            pbMap.Refresh();
        }
Exemplo n.º 6
0
        private int OpenTileset(ProjectTileSet pTileSet)
        {
            int i = 0;
            try
            {
                Tileset tileset = new Tileset();

                tileset.Name = pTileSet.tileset_name;
                tileset.tileset_code = pTileSet.tileset_code;
                tileset.buffer = pTileSet.buffer;

                for (i = 0; i < pTileSet.tiles.Length; i++)
                {
                    ProjectTiles pTile = pTileSet.tiles[i];

                    Setor setor = new Setor(pTile.tileset_setor[0], pTile.tileset_setor[1], pTile.tileset_setor[2], pTile.tileset_setor[3]);

                    string code = tileset.getCode(setor.tile_width, setor.tile_height);

                    if (!tileset.setor.ContainsKey(code))
                    {
                        tileset.setor.Add(code, setor);

                        List<bool> walk_r = new List<bool>();
                        int j;
                        for (j = 0; j < pTile.tileset_walk.Length; j++)
                            walk_r.Add(pTile.tileset_walk[j]);

                        tileset.walk_region.Add(code, walk_r);

                        tileset.tile_image.Add(code, new Dictionary<string, Image>());

                        Dictionary<string, Image> tile_images = tileset.tile_image[code];
                        List<byte[]> image_l = pTile.tileset_images;
                        string[] names_l = pTile.tileset_names;

                        for (j = 0; j < names_l.Length; j++)
                        {
                            Image tile;

                            using (MemoryStream ms = new MemoryStream(image_l[j]))
                            {
                                tile = Bitmap.FromStream(ms);
                            }

                            tile_images.Add(names_l[j], tile);
                        }
                    }
                }
                i = world.AddTileset(tileset);
                InsertTileset(tileset.Name, i);
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }
            return i;
        }