Beispiel #1
0
        bool check_tiles_block(int _block_id, tiles_data _data)
        {
            if (m_data_sets.screen_data_type == data_sets_manager.EScreenDataType.sdt_Tiles4x4)
            {
                int tile_n;
                int i;

                int _block_id_offset = _block_id << 2;
                int block_n_offset;

                // check duplicate(s)
                for (int block_n = 0; block_n < _block_id; block_n++)
                {
                    block_n_offset = block_n << 2;

                    for (i = 0; i < utils.CONST_BLOCK_SIZE; i++)
                    {
                        if (_data.blocks[block_n_offset + i] != _data.blocks[_block_id_offset + i])
                        {
                            break;
                        }
                    }

                    if (i == utils.CONST_BLOCK_SIZE)
                    {
                        // duplicate found
                        for (tile_n = 0; tile_n < platform_data.get_max_tiles_cnt(); tile_n++)
                        {
                            for (i = 0; i < utils.CONST_TILE_SIZE; i++)
                            {
                                if (_block_id == _data.get_tile_block(tile_n, i))
                                {
                                    // replace _block_id with block_n
                                    _data.set_tile_block(tile_n, i, ( ushort )block_n);
                                }
                            }
                        }
                    }
                }

                for (tile_n = 0; tile_n < platform_data.get_max_tiles_cnt(); tile_n++)
                {
                    for (i = 0; i < utils.CONST_TILE_SIZE; i++)
                    {
                        if (_block_id == _data.get_tile_block(tile_n, i))
                        {
                            return(true);
                        }
                    }
                }
            }
            else
            {
                return(check_screens_block(_block_id, _data));
            }

            return(false);
        }
Beispiel #2
0
        private void TileEditor_MouseClick(object sender, MouseEventArgs e)
        {
            if (m_locked == false)
            {
                m_selected_quad_ind = (e.X >> 6) + 2 * (e.Y >> 6);

                if (UpdateSelectedBlock != null)
                {
                    UpdateSelectedBlock(this, new EventArg2Params(m_tiles_data.get_tile_block(m_selected_tile_id, m_selected_quad_ind), m_tiles_data));
                }

                update();

                update_status_bar();
            }
        }
Beispiel #3
0
        public void set_selected_tile(int _tile_id, tiles_data _data)
        {
            if (_data != null)
            {
                m_selected_tile_id = _tile_id;

                m_tiles_data = _data;

                m_selected_quad_ind = 0;

                update_status_bar();

                if (m_locked == false && (UpdateSelectedBlock != null))
                {
                    UpdateSelectedBlock(this, new EventArg2Params(m_tiles_data.get_tile_block(m_selected_tile_id, m_selected_quad_ind), m_tiles_data));
                }
            }
            else
            {
                m_selected_tile_id = -1;

                m_tiles_data = null;
            }

            update();
        }
Beispiel #4
0
        void shift_tiles_data(int _block_id, tiles_data _data)
        {
            int tile_block_id;

            for (int tile_n = 0; tile_n < platform_data.get_max_tiles_cnt(); tile_n++)
            {
                for (int i = 0; i < utils.CONST_TILE_SIZE; i++)
                {
                    tile_block_id = _data.get_tile_block(tile_n, i);

                    if (tile_block_id >= _block_id)
                    {
                        _data.set_tile_block(tile_n, i, ( ushort )(tile_block_id - 1));
                    }
                }
            }
        }
        public int tile_reserve_blocks(data_sets_manager _data_manager)
        {
            int block_pos = 0;
            int sel_tile  = get_selected_tile();

            if (sel_tile >= 0)
            {
                tiles_data data = _data_manager.get_tiles_data(_data_manager.tiles_data_pos);

                if (data.tiles[sel_tile] != 0)
                {
                    if (MainForm.message_box("All the tile's block links will be replaced!", "Reserve Blocks", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
                    {
                        return(-1);
                    }
                }

                bool reserve_blocks_CHRs = false;

                if (MainForm.message_box("Reserve CHRs?", "Reserve Blocks", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    reserve_blocks_CHRs = true;
                }

                // reset tile's links
                if (reserve_blocks_CHRs)
                {
                    int block_data_offs;

                    for (int i = 0; i < utils.CONST_BLOCK_SIZE; i++)
                    {
                        block_data_offs = data.get_tile_block(sel_tile, i) << 2;

                        data.blocks[block_data_offs]     = 0;
                        data.blocks[block_data_offs + 1] = 0;
                        data.blocks[block_data_offs + 2] = 0;
                        data.blocks[block_data_offs + 3] = 0;
                    }
                }

                data.tiles[sel_tile] = 0;

                int ff_tile_ind = data.get_first_free_tile_id(false);
                int tile_n;
                int block_pos_n;

                for (int block_n = 1; block_n < platform_data.get_max_blocks_cnt(); block_n++)
                {
                    if (data.block_sum(block_n) == 0)
                    {
                        // check if 'zero' block is busy
                        for (tile_n = 1; tile_n < ff_tile_ind; tile_n++)
                        {
                            for (block_pos_n = 0; block_pos_n < utils.CONST_TILE_SIZE; block_pos_n++)
                            {
                                if (data.get_tile_block(tile_n, block_pos_n) == block_n)
                                {
                                    // 'zero' block is busy
                                    break;
                                }
                            }

                            if (block_pos_n != utils.CONST_TILE_SIZE)
                            {
                                // 'zero' block is busy
                                break;
                            }
                        }

                        // 'zero' block isn't in use OR tiles list is empty
                        if (tile_n == ff_tile_ind || ff_tile_ind == 0)
                        {
                            data.set_tile_block(sel_tile, block_pos++, ( ushort )block_n);

                            if (reserve_blocks_CHRs)
                            {
                                block_reserve_CHRs(block_n, _data_manager);
                            }

                            if (block_pos == utils.CONST_TILE_SIZE)
                            {
                                m_tile_editor.set_selected_tile(sel_tile, data);

                                MainForm.set_status_msg(String.Format("Tile Editor: Tile #{0:X2} data reserved", sel_tile));

                                return(data.get_tile_block(sel_tile, m_tile_editor.get_selected_block_pos()));
                            }
                        }
                    }
                }

                MainForm.message_box("Tile Editor: Block list is full!", "Reserve Blocks", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            return(-1);
        }
        private Bitmap create_screen_image(int _screen_n, tiles_data _data, data_sets_manager.EScreenDataType _scr_type, utils.ETileViewType _view_type)
        {
#if DEF_SCREEN_DRAW_FAST
            Image block_img;
#endif
            int tile_n;
            int block_n;

            ushort tile_id;

            int tile_offs_x;
            int tile_offs_y;

            palette_group.Instance.set_palette(_data);

            Bitmap bmp = new Bitmap(platform_data.get_screen_width_pixels(), platform_data.get_screen_height_pixels(), PixelFormat.Format32bppPArgb);

            Graphics gfx = Graphics.FromImage(bmp);

            gfx.InterpolationMode = InterpolationMode.NearestNeighbor;
            gfx.PixelOffsetMode   = PixelOffsetMode.None;

            gfx.Clear(utils.CONST_COLOR_SCREEN_CLEAR);

            if (_scr_type == data_sets_manager.EScreenDataType.sdt_Tiles4x4)
            {
                for (tile_n = 0; tile_n < platform_data.get_screen_tiles_cnt(); tile_n++)
                {
                    tile_id = _data.get_screen_tile(_screen_n, tile_n);

                    tile_offs_x = (tile_n % platform_data.get_screen_tiles_width()) << 5;
                    tile_offs_y = (tile_n / platform_data.get_screen_tiles_width()) << 5;

                    for (block_n = 0; block_n < utils.CONST_BLOCK_SIZE; block_n++)
                    {
#if DEF_SCREEN_DRAW_FAST
                        block_img = m_imagelist_blocks.Images[_data.get_tile_block(tile_id, block_n)];

                        gfx.DrawImage(block_img, ((block_n % 2) << 4) + tile_offs_x, ((block_n >> 1) << 4) + tile_offs_y, block_img.Width >> 1, block_img.Height >> 1);
#else
#if DEF_ZX
                        utils.update_block_gfx(_data.get_tile_block(tile_id, block_n), _data, gfx, 8, 8, ((block_n % 2) << 4) + tile_offs_x, ((block_n >> 1) << 4) + tile_offs_y, utils.get_draw_block_flags_by_view_type(_view_type));
#else
                        utils.update_block_gfx(_data.get_tile_block(tile_id, block_n), _data, gfx, 8, 8, ((block_n % 2) << 4) + tile_offs_x, ((block_n >> 1) << 4) + tile_offs_y);
#endif
#endif
                    }
                }
            }
            else
            {
                for (tile_n = 0; tile_n < platform_data.get_screen_blocks_cnt(); tile_n++)
                {
#if DEF_SCREEN_DRAW_FAST
                    block_img = m_imagelist_blocks.Images[_data.get_screen_tile(_screen_n, tile_n)];

                    gfx.DrawImage(block_img, ((tile_n % platform_data.get_screen_blocks_width()) << 4), ((tile_n / platform_data.get_screen_blocks_width()) << 4), block_img.Width >> 1, block_img.Height >> 1);
#else
#if DEF_ZX
                    utils.update_block_gfx(_data.get_screen_tile(_screen_n, tile_n), _data, gfx, 8, 8, ((tile_n % platform_data.get_screen_blocks_width()) << 4), ((tile_n / platform_data.get_screen_blocks_width()) << 4), utils.get_draw_block_flags_by_view_type(_view_type));
#else
                    utils.update_block_gfx(_data.get_screen_tile(_screen_n, tile_n), _data, gfx, 8, 8, ((tile_n % platform_data.get_screen_blocks_width()) << 4), ((tile_n / platform_data.get_screen_blocks_width()) << 4));
#endif
#endif
                }
            }

            return(bmp);
        }
        public void update_tile(int _tile_ind, utils.ETileViewType _view_type, tiles_data _tiles_data, Graphics _gfx, Image _img, data_sets_manager.EScreenDataType _scr_type)
        {
#if DEF_TILE_DRAW_FAST
            Image block_img;
#else
            ushort[] blocks_arr = null;
            byte[]   CHR_data   = null;

            // draw a block from CHR bank sprites
            if (_tiles_data != null)
            {
                blocks_arr = _tiles_data.blocks;
                CHR_data   = _tiles_data.CHR_bank;
            }
#endif //DEF_TILE_DRAW_FAST

            Image img;

            if (_img != null)
            {
                img = _img;
            }
            else
            {
                img = m_imagelist_tiles.Images[_tile_ind];
            }

            Graphics gfx;

            if (_gfx != null)
            {
                gfx = _gfx;
            }
            else
            {
                gfx = Graphics.FromImage(img);
            }

            gfx.InterpolationMode = InterpolationMode.NearestNeighbor;
            gfx.PixelOffsetMode   = PixelOffsetMode.None;

#if DEF_TILE_DRAW_FAST
            for (int j = 0; j < utils.CONST_TILE_SIZE; j++)
            {
                block_img = m_imagelist_blocks.Images[_tiles_data.get_tile_block(_tile_ind, j)];

                gfx.DrawImage(block_img, ((j % 2) << 5), ((j >> 1) << 5), block_img.Width, block_img.Height);
            }
#else
            // draw a block from CHR bank sprites
            for (int j = 0; j < utils.CONST_TILE_SIZE; j++)
            {
                utils.update_block_gfx(_tiles_data.get_tile_block(_tile_ind, j), blocks_arr, CHR_data, gfx, utils.CONST_BLOCKS_IMG_SIZE >> 1, utils.CONST_BLOCKS_IMG_SIZE >> 1, ((j % 2) << 5), ((j >> 1) << 5));
            }
#endif //DEF_TILE_DRAW_FAST

            if (_scr_type == data_sets_manager.EScreenDataType.sdt_Tiles4x4)
            {
                if (_view_type == utils.ETileViewType.tvt_Number)                  // tile id
                {
                    draw_tile_info(String.Format("{0:X2}", _tile_ind), gfx);
                }
                else
                if (_view_type == utils.ETileViewType.tvt_TilesUsage)                  // usage
                {
                    draw_tile_info(String.Format("{0}", _tiles_data.get_tile_usage(( ushort )_tile_ind, _scr_type)), gfx);
                }
            }

            if (_img == null)
            {
                m_imagelist_tiles.Images[_tile_ind] = img;
            }

            if (_gfx == null)
            {
                gfx.Dispose();
            }
        }