/*  These methods are for loading the individual tile images from the file into the arrays  */
        public TileLoader(int size)
        {
            tileSize = size;

            collision = new Bitmap(MapEditor.Properties.Resources.collision);
            eraser = new Bitmap(MapEditor.Properties.Resources.eraser_tile);

            mapLayers = new Bitmap[4];
            tileLayers = new Bitmap[4];

            // Load tilesets for each layer type
            tileSet = new TileSet[4];
            for(int i = 0; i < 4; i++)
                tileSet[i] = new TileSet();
            tileSet[0].allTiles = new Bitmap(MapEditor.Properties.Resources.background_cropped);
            tileSet[1].allTiles = new Bitmap(MapEditor.Properties.Resources.foreground_cropped);
            tileSet[2].allTiles = new Bitmap(MapEditor.Properties.Resources.objects_cropped);
            tileSet[3].allTiles = new Bitmap(MapEditor.Properties.Resources.collision);
            for (int i = 0; i < 4; i++)
            {
                tileSet[i].numTiles = (tileSet[i].allTiles.Width / tileSize) * (tileSet[i].allTiles.Height / tileSize);
                tileSet[i].tiles = new Bitmap[tileSet[i].numTiles];
            }

            for(int i = 0; i < 4; i++)
                for (int j = 0; j < (tileSet[i].allTiles.Height / tileSize); j++)
                    for (int k = 0; k < (tileSet[i].allTiles.Width / tileSize); k++)
                        tileSet[i].tiles[j * (tileSet[i].allTiles.Width / tileSize) + k] = tileSet[i].allTiles.Clone(
                                                                            new Rectangle(k * tileSize, j * tileSize, tileSize, tileSize),
                                                                            tileSet[i].allTiles.PixelFormat);

            // Convert tileset Bitmaps into images for use in the map editor
            convertTileSetsToBitmap();
        }
Beispiel #2
0
        public static TileSet FromImage( string path )
        {
            try {
                Bitmap ts = (Bitmap)Bitmap.FromFile( path );
                TileSet res = new TileSet( new Tile[ ts.Height / 8 * ts.Width / 8 ] );
                if( ts.PixelFormat != System.Drawing.Imaging.PixelFormat.Format8bppIndexed )
                    throw new NotImplementedException( );

                Dictionary<Color, byte> indices = new Dictionary<Color, byte>( );
                for( byte i = 0; i < 16; i++ )
                    indices[ ts.Palette.Entries[ i ] ] = i;

                for( int j = 0; j < ts.Height / 8; j++ )
                    for( int i = 0; i < ts.Width / 8; i++ ) {
                        res.m_blocks[ j * ts.Width / 8 + i ] = new Tile( new byte[ 32 ] );
                        for( int l = 0; l < 8; l++ )
                            for( int k = 0; k < 8; k += 2 ) {
                                byte p1 = indices[ ts.GetPixel( 8 * i + k, 8 * j + l ) ],
                                p2 =indices[ ts.GetPixel( 8 * i + k + 1, 8 * j + l ) ];
                                res.m_blocks[ j * ts.Width / 8 + i ].m_tile[ k / 2 + 4 * l ]
                                    = (byte)( ( p2 << 4 ) | p1 );
                            }
                    }
                return res;
            } catch( Exception ) {
                return new TileSet( new Tile[ 512 ] );
            }
        }
Beispiel #3
0
 public static TileSet Read( string path, int count = 512 )
 {
     try {
         using( BinaryReader br = new BinaryReader( new FileStream( path, FileMode.Open ) ) ) {
             TileSet res = new TileSet( new Tile[ count ] );
             for( int i = 0; i < count; ++i )
                 res.m_blocks[ i ].m_tile = br.ReadBytes( 32 );
             return res;
         }
     } catch( Exception ) {
         return new TileSet( new Tile[ count ] );
     }
 }
Beispiel #4
0
        public void Draw(Grid grid, TileSet tileSet)
        {
            // Screen block entries
            for (int x = 0; x < Width; x++)
            for (int y = 0; y < Height; y++)
            {
                DrawTile(x, y, tileSet);
            }

            if (grid != null)
            {
                grid.Draw(Panel);
            }
        }
Beispiel #5
0
 // CONTRUCTOR
 // -------------------------------------------------------------
 public CreateTilesForm()
 {
     InitializeComponent();
     _pen = new Pen(new SolidBrush(Color.Blue), 0.5f);
     _graphics = this.panel_tile.CreateGraphics();
     this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // dont know
     ListViewItems = new List<ListViewItem>();
     // khởi tạo backbuffer với độ rộng lớn hơn 1 (recommend)
     _context = BufferedGraphicsManager.Current;
     _context.MaximumBuffer = this.panel_tile.Size + new Size(1, 1);
     _buffergraphics = _context.Allocate(_graphics, new Rectangle(Point.Empty, panel_tile.Size));
     // bind tileset
     _tileset = new Tiles.TileSet();
     this.textBoxWidth.DataBindings.Add("Text", _tileset, "Widthtile");
     this.textBoxHeight.DataBindings.Add("Text", _tileset, "Hieghttile");
 }
Beispiel #6
0
        public void DrawTile(int x, int y, TileSet tileSet)
        {
            Graphics g = Panel.CreateGraphics();

            int tileIndex = screenBlockEntries[x, y];
            // Create rectangle for displaying image
            Rectangle destRect = new Rectangle(x * 8, y * 8, 8, 8);

            if (tileIndex == -1)
            {
                g.FillRectangle(Brushes.White, destRect);
                return;
            }

            // Create rectangle for source image
            Rectangle srcRect = tileSet.GetTileRectangle(tileIndex);
            // Draw image to screen
            g.DrawImage(tileSet.Image, destRect, srcRect, GraphicsUnit.Pixel);

            g.Dispose();
        }
        public bool CloseEditor()
        {
            if (!Saved)
            {
                MessageBoxResult result = MessageBox.Show("Do you want to save changes to " + TitleName + " before closing?",
                    TitleName, MessageBoxButton.YesNoCancel, MessageBoxImage.None, MessageBoxResult.Cancel);
                if (result == MessageBoxResult.Cancel) return false;
                else if (result == MessageBoxResult.Yes)
                {
                    bool saveResult = SaveEditor();
                    if (!saveResult) return false;
                }
            }

            TileEditorGroup.Children.Clear();
            baseImage.Source = null;
            baseTileSet = null;

            return true;
        }
Beispiel #8
0
        private void loadTileSet(string filename)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(filename);
            TileSet tileSet = new TileSet();
            tileSet.loadTileSetFromXmlDoc(xmlDoc);

            currentTileList.Clear();
            foreach (Tile tile in tileSet.tiles)
            {
                currentTileList.Add(tile);
            }
            refreshTileSetLayout();
            gfx.loadTileSetFromXmlDoc(xmlDoc);
        }
        private void SelectTileSet()
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.RestoreDirectory = true;

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                tileSet = new TileSet(dialog.FileName, TilePanel);
                NoTileSetLabel.Visible = false;
                DrawTileSet();
                DrawMap();
            }
        }
Beispiel #10
0
 private void openTileSet2ToolStripMenuItem_Click( object sender, EventArgs e )
 {
     openFileDialog1.Title = "Open a TileSet.";
     openFileDialog1.Filter = tileFilter;
     if( openFileDialog1.ShowDialog( ) == DialogResult.OK )
         if( !openFileDialog1.FileName.ToUpper( ).EndsWith( ".PNG" ) )
             TileSet2 = TileSet.Read( openFileDialog1.FileName );
         else
             TileSet2 = TileSet.FromImage( openFileDialog1.FileName );
     else
         return;
 }
Beispiel #11
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;
                }
            }
        }
Beispiel #12
0
 public TileSetWindow(TileSet tileSet = null)
 {
     TileSet = tileSet ?? new TileSet();
     InitializeComponent();
 }
Beispiel #13
0
        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {

                XmlDocument doc = new XmlDocument();
                doc.Load(openFileDialog1.FileName);
                XmlNode xmlMap = doc.SelectSingleNode("/Map");
                XmlNodeList xmlLayer = doc.SelectNodes("/Layer");
                for
                XmlNode xmlImage = doc.SelectSingleNode("/Map/Image");
                string path = xmlImage.Attributes["path"].Value.ToString();

                XmlNodeList xmlTilesetImage = doc.SelectSingleNode("/map/tileset/image");
                string name = xmlTilesetImage.Attributes["source"].Value.ToString();
                string[] arrSource = openFileDialog1.FileName.Split(new String[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
                arrSource[arrSource.Length - 1] = name;
                string source = "";
                for (int i = 0; i < arrSource.Length; i++)
                {
                    source += arrSource[i] + (i == (arrSource.Length - 1) ? "" : "\\");
                }
                tileset = new TileSet(name, source, int.Parse(xmlTileset.Attributes["tilewidth"].Value.ToString()), int.Parse(xmlTileset.Attributes["tileheight"].Value.ToString()));
                int width = int.Parse(xmlMap.Attributes["width"].Value.ToString());
                int height = int.Parse(xmlMap.Attributes["height"].Value.ToString());
                background = new Background(tileset, width, height);
                XmlNodeList arrBackground = doc.SelectNodes("/map/layer/data/tile");
                for (int i = 0; i < background.MapHeight; i++)
                    for (int j = 0; j < background.MapWidth; j++)
                    {
                        XmlNode tileId = arrBackground.Item(i * background.MapWidth + j).Attributes["gid"];
                        background[i, j] = int.Parse(tileId.Value.ToString());
                    }
                UpdatePanelTileSet();
                //try
                //{
                XmlNodeList objects = doc.SelectNodes("/map/objectgroup/object");
                if (objects.Count > 0)
                {
                    listObject.Clear();
                    lstObject.Items.Clear();
                    proObject.SelectedObject = null;
                    foreach (XmlNode obj in objects)
                    {
                        Objects newObject = new Objects(int.Parse(obj.Attributes["id"].Value), obj.Attributes["name"].Value, int.Parse(obj.Attributes["type"].Value), float.Parse(obj.Attributes["x"].Value), float.Parse(obj.Attributes["y"].Value), float.Parse(obj.Attributes["width"].Value), float.Parse(obj.Attributes["height"].Value));
                        if (obj.HasChildNodes)
                        {
                            XmlNodeList properties = obj.ChildNodes[0].ChildNodes;
                            if (properties.Count > 0)
                            {
                                foreach (XmlNode attribute in properties)
                                {
                                    newObject.Property.Add(attribute.Attributes["name"].Value, attribute.Attributes["value"].Value);
                                }
                            }
                        }
                        listObject.Add(newObject);
                        UpdateListObject(newObject);
                    }
                    Objects.count = int.Parse(objects.Item(objects.Count - 1).Attributes["id"].Value) + 1;
                }
                //}
                //catch (NullReferenceException)
                //{
                //    MessageBox.Show("Map nay chua co object");
                //}
                Draw();

            }
        }
Beispiel #14
0
        public static void LoadTiles(List <TileSet> TileSets)
        {
            TileSet classicSet = new TileSet();

            classicSet.Name = "classic";

            TileSets.Add(classicSet);

            String path = "tiles";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            String[] sets = Directory.GetDirectories(path);

            foreach (String set in sets)
            {
                if (Path.GetFileName(set) == "classic")
                {
                    continue;
                }

                TileSet tiles = new TileSet();
                tiles.Name = Path.GetFileName(set);

                bool stop = false;
                for (int j = 1; !stop && j < 200; j++)
                {
                    for (int i = 0; i < 64; i++)
                    {
                        String file = j.ToString("D3") + "_" + i.ToString("D2") + ".png";
                        if (!File.Exists(set + "\\" + file))
                        {
                            //stop = true;
                            //break;
                            continue;
                        }

                        Tile tile = new Tile();
                        tile.Image  = new Bitmap(set + "\\" + file);
                        tile.Size   = tile.Image.Size;
                        tile.Set    = tiles.Name;
                        tile.ID     = (byte)i;
                        tile.SubSet = (byte)j;

                        String maskFile = j.ToString("D3") + "_" + i.ToString("D2") + ".txt";
                        if (File.Exists(set + "\\" + maskFile))
                        {
                            TextReader reader = new StreamReader(set + "\\" + maskFile);

                            for (int k = 0; k < 4; k++)
                            {
                                String line = reader.ReadLine();
                                if (line.Length < 4)
                                {
                                    continue;
                                }

                                char[] chrs = line.ToCharArray();
                                tile.Mask[k * 4 + 0] = (chrs[0] == '1');
                                tile.Mask[k * 4 + 1] = (chrs[1] == '1');
                                tile.Mask[k * 4 + 2] = (chrs[2] == '1');
                                tile.Mask[k * 4 + 3] = (chrs[3] == '1');
                            }

                            reader.Close();
                        }

                        tiles.Tiles.Add(tile);
                    }
                }

                TileSets.Add(tiles);
            }
        }
Beispiel #15
0
        public static void LoadClassicTiles(TileSet ClassicSet, String Path)
        {
            String path = "tiles";

            Burntime.Platform.IO.FileSystem.AddPackage("burntime", Path + "\\burn_gfx");

            Dictionary <int, int> dicColorTables = new Dictionary <int, int>();

            dicColorTables.Add(6, 23);
            dicColorTables.Add(7, 23);
            dicColorTables.Add(16, 23);
            dicColorTables.Add(10, 14);
            dicColorTables.Add(11, 14);
            dicColorTables.Add(15, 14);
            dicColorTables.Add(12, 13);
            dicColorTables.Add(13, 13);
            dicColorTables.Add(18, 2);
            dicColorTables.Add(25, 26);
            dicColorTables.Add(26, 26);
            dicColorTables.Add(32, 89);
            dicColorTables.Add(44, 84);
            dicColorTables.Add(46, 83);
            dicColorTables.Add(47, 83);
            dicColorTables.Add(29, 35);
            dicColorTables.Add(45, 82);
            dicColorTables.Add(48, 81);
            dicColorTables.Add(49, 80);
            dicColorTables.Add(50, 80);
            dicColorTables.Add(17, 33);

            for (int j = 1; j < 52; j++)
            {
                if (null == Burntime.Platform.IO.FileSystem.GetFile("zei_" + j.ToString("D3") + ".raw"))
                {
                    continue;
                }

                int mapId = 0;
                if (dicColorTables.ContainsKey(j))
                {
                    mapId = dicColorTables[j];
                }

                Burntime.Data.BurnGfx.TileSet tileset = new Burntime.Data.BurnGfx.TileSet("zei_" + j.ToString("D3") + ".raw", mapId);
                tileset.Load();

                for (int i = 0; i < 63; i++)
                {
                    Burntime.Data.BurnGfx.Tile tile = tileset.Tiles[i];
                    if (tile != null)
                    {
                        Bitmap     bmp  = new Bitmap(32, 32, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                        BitmapData data = bmp.LockBits(new Rectangle(0, 0, 32, 32), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
                        tile.Render(data.Scan0);
                        bmp.UnlockBits(data);

                        Tile t = new Tile();
                        t.Set   = ClassicSet.Name;
                        t.Image = bmp;

                        t.SubSet = (byte)j;
                        t.ID     = (byte)i;
                        t.Size   = new Size(32, 32);

                        int mask = tile.Mask;
                        for (int k = 15; k >= 0; k--, mask >>= 1)
                        {
                            t.Mask[k] = (mask & 1) == 1;
                        }

                        String maskFile = j.ToString("D3") + "_" + i.ToString("D2") + ".txt";
                        if (File.Exists(path + "\\classic\\" + maskFile))
                        {
                            TextReader reader = new StreamReader(path + "\\classic\\" + maskFile);

                            for (int k = 0; k < 4; k++)
                            {
                                String line = reader.ReadLine();
                                if (line.Length < 4)
                                {
                                    continue;
                                }

                                char[] chrs = line.ToCharArray();
                                t.Mask[k * 4 + 0] = (chrs[0] == '1');
                                t.Mask[k * 4 + 1] = (chrs[1] == '1');
                                t.Mask[k * 4 + 2] = (chrs[2] == '1');
                                t.Mask[k * 4 + 3] = (chrs[3] == '1');
                            }

                            reader.Close();
                        }

                        //if (t.GetHashCode() != 0)
                        {
                            //bmp.Save("output/" + j.ToString("D3") + "_" + i.ToString("D2") + ".png");
                            ClassicSet.Tiles.Add(t);
                        }
                    }
                }
            }
        }
        public void NewEditor(string texturePath)
        {
            CloseEditor();

            baseTileSet = new TileSet();
            baseTileSet.BaseTexturePath = texturePath;
            baseImage.Source = new BitmapImage(new Uri(BaseTexturePath));
        }
 public void OpenFromTileSet(TileSet tset)
 {
     baseTileSet = tset;
     baseImage.Source = new BitmapImage(new Uri(BaseTexturePath));
     foreach (Tile t in baseTileSet)
     {
         TileEditor ed = new TileEditor(); ed.Editable = Editable;
         ed.Tile = t; ed.Changed += HandleTileChanged;
         TileEditorGroup.Children.Add(ed);
     }
 }
Beispiel #18
0
        public Bitmap ToBitmap( TileSet[ ] tileSets, Palette[ ] palettes )
        {
            if( tileSets[ 0 ] == null )
                tileSets[ 0 ] = tileSets[ 1 ];
            if( tileSets[ 1 ] == null )
                tileSets[ 1 ] = tileSets[ 0 ];
            if( tileSets[ 1 ] == null )
                return null;

            if( palettes[ 0 ] == null )
                palettes[ 0 ] = palettes[ 1 ];
            if( palettes[ 1 ] == null )
                palettes[ 1 ] = palettes[ 0 ];
            if( palettes[ 1 ] == null )
                return null;

            Bitmap res = new Bitmap( 16, 16 );
            for( int x = 0; x < 2; ++x )
                for( int y = 0; y < 2; ++y ) {
                    ushort tileIdx = (ushort)( m_bottom[ y, x ] & 1023 );
                    bool vflip = ( ( m_bottom[ y, x ] >> 11 ) & 1 ) == 1;
                    bool hflip = ( ( m_bottom[ y, x ] >> 10 ) & 1 ) == 1;
                    byte palIdx = (byte)( ( m_bottom[ y, x ] >> 12 ) & 15 );
                    Tile btmTile = tileSets[ tileIdx / 512 ].m_blocks[ tileIdx % 512 ];
                    for( int i = 0; i < 8; i += 2 )
                        for( int j = 0; j < 8; ++j ) {
                            int xi1 = hflip ? 7 - i : i;
                            int xi2 = hflip ? xi1 - 1 : xi1 + 1;
                            int yi = vflip ? 7 - j : j;

                            byte curCol = btmTile.m_tile[ ( 8 * j + i ) / 2 ];

                            if( palIdx >= 12 )
                                continue;

                            res.SetPixel( x * 8 + xi1, y * 8 + yi, palettes[ palIdx / 6 ][ palIdx % 6, curCol & 15 ] );
                            res.SetPixel( x * 8 + xi2, y * 8 + yi, palettes[ palIdx / 6 ][ palIdx % 6, curCol >> 4 ] );
                        }
                }
            for( int x = 0; x < 2; ++x )
                for( int y = 0; y < 2; ++y ) {
                    ushort tileIdx = (ushort)( m_top[ y, x ] & 1023 );
                    bool vflip = ( ( m_top[ y, x ] >> 11 ) & 1 ) == 1;
                    bool hflip = ( ( m_top[ y, x ] >> 10 ) & 1 ) == 1;
                    byte palIdx = (byte)( ( m_top[ y, x ] >> 12 ) & 15 );
                    Tile btmTile = tileSets[ tileIdx / 512 ].m_blocks[ tileIdx % 512 ];
                    for( int i = 0; i < 8; i += 2 )
                        for( int j = 0; j < 8; ++j ) {
                            int xi1 = hflip ? 7 - i : i;
                            int xi2 = hflip ? xi1 - 1 : xi1 + 1;
                            int yi = vflip ? 7 - j : j;

                            byte curCol = btmTile.m_tile[ ( 8 * j + i ) / 2 ];

                            if( palIdx >= 12 )
                                continue;

                            if( ( curCol & 15 ) != 0 )
                                res.SetPixel( x * 8 + xi1, y * 8 + yi, palettes[ palIdx / 6 ][ palIdx % 6, curCol & 15 ] );
                            if( ( curCol >> 4 ) != 0 )
                                res.SetPixel( x * 8 + xi2, y * 8 + yi, palettes[ palIdx / 6 ][ palIdx % 6, curCol >> 4 ] );
                        }
                }
            return res;
        }