示例#1
0
        public unsafe void draw_tile(Tile t, int xx, int yy, ushort tileUnder = 0xFFFF)
        {
            if (preview)
            {
                if (xx < 57 && yy < 57 && xx >= 0 && yy >= 0)
                {
                    var      alltilesData = (byte *)GFX.currentgfx16Ptr.ToPointer();
                    byte *   ptr          = (byte *)GFX.previewObjectsPtr[previewId].ToPointer();
                    TileInfo ti           = t.GetTileInfo();
                    for (var yl = 0; yl < 8; yl++)
                    {
                        for (var xl = 0; xl < 4; xl++)
                        {
                            int  mx = xl;
                            int  my = yl;
                            byte r  = 0;

                            if (ti.h)
                            {
                                mx = 3 - xl;
                                r  = 1;
                            }
                            if (ti.v)
                            {
                                my = 7 - yl;
                            }
                            //Formula information to get tile index position in the array
                            //((ID / nbrofXtiles) * (imgwidth/2) + (ID - ((ID/16)*16) ))
                            int tx    = ((ti.id / 16) * 512) + ((ti.id - ((ti.id / 16) * 16)) * 4);
                            var pixel = alltilesData[tx + (yl * 64) + xl];
                            //nx,ny = object position, xx,yy = tile position, xl,yl = pixel position

                            int index = ((xx / 8) * 8) + ((yy / 8) * 512) + ((mx * 2) + (my * 64));
                            ptr[index + r ^ 1] = (byte)((pixel & 0x0F) + ti.palette * 16);
                            ptr[index + r]     = (byte)(((pixel >> 4) & 0x0F) + ti.palette * 16);
                        }
                    }
                }
            }
            else
            {
                if (((xx / 8) + nx + offsetX) + ((ny + offsetY + (yy / 8)) * 64) < 4096 && ((xx / 8) + nx + offsetX) + ((ny + offsetY + (yy / 8)) * 64) >= 0)
                {
                    ushort td = GFX.getshortilesinfo(t.GetTileInfo());
                    if (layer == 0 || layer == 2 || allBgs)
                    {
                        if (tileUnder == GFX.tilesBg1Buffer[((xx / 8) + nx) + ((ny + (yy / 8)) * 64)])
                        {
                            return;
                        }
                        GFX.tilesBg1Buffer[((xx / 8) + nx) + ((ny + (yy / 8)) * 64)] = td;
                    }
                    if (layer == 1 || allBgs)
                    {
                        if (tileUnder == GFX.tilesBg2Buffer[((xx / 8) + nx + offsetX) + ((ny + offsetY + (yy / 8)) * 64)])
                        {
                            return;
                        }
                        GFX.tilesBg2Buffer[((xx / 8) + nx) + offsetX + ((ny + offsetY + (yy / 8)) * 64)] = td;
                    }
                    if (width < xx + 8)
                    {
                        width = xx + 8;
                    }
                    if (height < yy + 8)
                    {
                        height = yy + 8;
                    }
                }
            }
        }
示例#2
0
        public static Bitmap selectedtobmp(byte[] sheets, int p = 4, bool sprite = false)
        {
            byte[] blocks             = new byte[24];
            byte[] data               = new byte[blocks.Length * 0x1000];
            int    gfxanimatedPointer = (ROM.DATA[Constants.gfx_animated_pointer + 2] << 16) + (ROM.DATA[Constants.gfx_animated_pointer + 1] << 8) + (ROM.DATA[Constants.gfx_animated_pointer]);

            gfxanimatedPointer = Addresses.snestopc(gfxanimatedPointer);
            for (int i = 0; i < blocks.Length; i++)
            {
                if (i < sheets.Length)
                {
                    byte[] d  = GFX.bpp3snestoindexed(GFX.gfxdata, sheets[i]);
                    byte[] dd = new byte[0];
                    if (i == 6)
                    {
                        dd = GFX.bpp3snestoindexed(GFX.gfxdata, ROM.DATA[gfxanimatedPointer + 0]); //static animated gfx1
                    }
                    if (i == 7)
                    {
                        dd = GFX.bpp3snestoindexed(GFX.gfxdata, 92); //static animated gfx1
                    }
                    for (int j = 0; j < d.Length; j++)
                    {
                        data[(i * 0x1000) + j] = d[j];
                        if (i == 6)
                        {
                            if (j >= 0xC00)
                            {
                                data[(i * 0x1000) + j] = dd[j - 0xC00];
                            }
                        }
                        if (i == 7)
                        {
                            if (j < 0x400)
                            {
                                data[(i * 0x1000) + j] = dd[j];
                            }
                        }
                    }
                }
            }



            Bitmap b = new Bitmap(128, 256);

            begin_draw(b, 128, 256);
            unsafe
            {
                for (int x = 0; x < 128; x++)
                {
                    for (int y = 0; y < 32 * sheets.Length; y++)
                    {
                        int dest = (x + (y * 128)) * 4;
                        if (sprite == true)
                        {
                            GFX.currentData[dest]     = (GFX.spritesPalettes[data[(dest / 4)], p].B);
                            GFX.currentData[dest + 1] = (GFX.spritesPalettes[data[(dest / 4)], p].G);
                            GFX.currentData[dest + 2] = (GFX.spritesPalettes[data[(dest / 4)], p].R);
                            GFX.currentData[dest + 3] = 255;
                        }
                        else
                        {
                            GFX.currentData[dest]     = (GFX.loadedPalettes[data[(dest / 4)], p].B);
                            GFX.currentData[dest + 1] = (GFX.loadedPalettes[data[(dest / 4)], p].G);
                            GFX.currentData[dest + 2] = (GFX.loadedPalettes[data[(dest / 4)], p].R);
                            GFX.currentData[dest + 3] = 255;
                        }
                    }
                }
            }
            end_draw(b);
            return(b);
        }
示例#3
0
        public void updateOverworldPalettes()
        {
            //public static int hardcodedGrassLW = 0x75645;
            // public static int hardcodedGrassDW = 0x7564F;//map>40
            //public static int hardcodedGrassSpecial = 0x75640;//map 183,182,180

            int paletteG0 = 0;
            int paletteG1 = ROM.DATA[Constants.overworldMapPaletteGroup + palette];
            int paletteG2 = ROM.DATA[Constants.overworldMapPaletteGroup + palette + 1];
            int paletteG3 = ROM.DATA[Constants.overworldMapPaletteGroup + palette + 2];



            if (index >= 0x40)
            {
                paletteG0 = 1;
                for (int j = 0; j < 6; j++)
                {
                    GFX.loadedPalettes[0, j] = GFX.getColor((short)((ROM.DATA[Constants.hardcodedGrassDW + 1] << 8) + ROM.DATA[Constants.hardcodedGrassDW]));
                    GFX.loadedPalettes[8, j] = GFX.getColor((short)((ROM.DATA[Constants.hardcodedGrassDW + 1] << 8) + ROM.DATA[Constants.hardcodedGrassDW]));
                }
            }
            else
            {
                for (int j = 0; j < 6; j++)
                {
                    GFX.loadedPalettes[0, j] = GFX.getColor((short)((ROM.DATA[Constants.hardcodedGrassLW + 1] << 8) + ROM.DATA[Constants.hardcodedGrassLW]));
                    GFX.loadedPalettes[8, j] = GFX.getColor((short)((ROM.DATA[Constants.hardcodedGrassLW + 1] << 8) + ROM.DATA[Constants.hardcodedGrassLW]));
                }
            }
            if (index >= 0x80)
            {
                paletteG0 = 0;
                for (int j = 0; j < 6; j++)
                {
                    GFX.loadedPalettes[0, j] = GFX.getColor((short)((ROM.DATA[Constants.hardcodedGrassSpecial + 1] << 8) + ROM.DATA[Constants.hardcodedGrassSpecial]));
                    GFX.loadedPalettes[8, j] = GFX.getColor((short)((ROM.DATA[Constants.hardcodedGrassSpecial + 1] << 8) + ROM.DATA[Constants.hardcodedGrassSpecial]));
                }
            }

            if (index >= 0x43 && index <= 0x47)
            {
                paletteG0 = 3;
            }
            if (index >= 0x4B && index <= 0x4E)
            {
                paletteG0 = 3;
            }
            if (index == 136)
            {
                paletteG0 = 4;
            }

            if (index >= 03 && index <= 07)
            {
                paletteG0 = 2;
            }
            if (index >= 0x0B && index <= 0x0E)
            {
                paletteG0 = 2;
            }

            int i = (int)(70 * paletteG0);

            for (int y = 0; y < 5; y++)
            {
                for (int x = 1; x < 8; x++)
                {
                    GFX.loadedPalettes[x, y] = GFX.getColor((short)((ROM.DATA[(Constants.overworldPalGroup1 + i) + 1] << 8) + ROM.DATA[(Constants.overworldPalGroup1 + i)]));
                    i += 2;
                }
            }
            i = (int)(42 * paletteG1);
            for (int y = 0; y < 3; y++)
            {
                for (int x = 9; x < 16; x++)
                {
                    GFX.loadedPalettes[x, y] = GFX.getColor((short)((ROM.DATA[(Constants.overworldPalGroup2 + i) + 1] << 8) + ROM.DATA[(Constants.overworldPalGroup2 + i)]));
                    i += 2;
                }
            }
            i = (int)(42 * paletteG2);
            for (int y = 3; y < 6; y++)
            {
                for (int x = 9; x < 16; x++)
                {
                    GFX.loadedPalettes[x, y] = GFX.getColor((short)((ROM.DATA[(Constants.overworldPalGroup2 + i) + 1] << 8) + ROM.DATA[(Constants.overworldPalGroup2 + i)]));
                    i += 2;
                }
            }
            i = (int)(14 * paletteG3);
            for (int y = 5; y < 6; y++)
            {
                for (int x = 1; x < 8; x++)
                {
                    GFX.loadedPalettes[x, y] = GFX.getColor((short)((ROM.DATA[(Constants.overworldPalGroup3 + i) + 1] << 8) + ROM.DATA[(Constants.overworldPalGroup3 + i)]));
                    i += 2;
                }
            }
        }
示例#4
0
        public void GetSelectedMapGfx()
        {
            updateOverworldPalettes();
            byte[] staticgfx        = new byte[] { 58, 59, 60, 61, 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 0 }; //89 DM Animated
            byte   animatedGfxPart2 = 91;

            //Should be 8 total not 9
            //TODO Find why there's 9 probably because of animated tiles

            if (blockset >= 48)
            {
                staticgfx = new byte[] { 66, 67, 68, 69, 0, 0, 63, 89, 0, 0, 0, 0, 0, 0, 0, 0 };
            }
            else if (blockset < 48)
            {
                staticgfx = new byte[] { 58, 59, 60, 61, 0, 0, 62, 89, 0, 0, 0, 0, 0, 0, 0, 0 };
            }

            staticgfx[4] = ROM.DATA[(int)(Constants.overworldgfxGroups + (blockset * 4) + 1)];
            staticgfx[5] = ROM.DATA[(int)(Constants.overworldgfxGroups + (blockset * 4) + 2)];

            if (index >= 128)
            {
                staticgfx[4] = 71;
                staticgfx[5] = 72;
            }
            if (index >= 136)
            {
                staticgfx = new byte[] { 0, 70, 66, 65, 66, 65, 66, 65, 66, 0, 0, 0, 0, 0, 0, 0, 0 };
            }
            //TODO : Need to find the position of these values for now they are hardcoded
            if (index >= 3 && index < 8)
            {
                staticgfx[7] = 89;
            }
            else if (index >= 11 && index < 15)
            {
                staticgfx[7] = 89;
            }
            else if (index >= 64 + 3 && index < 64 + 8)
            {
                staticgfx[7] = 89;
            }
            else if (index >= 64 + 11 && index < 64 + 15)
            {
                staticgfx[7] = 89;
            }
            else
            {
                staticgfx[7] = 91;
            }

            staticgfx[8] = 115 + 0; staticgfx[9] = 115 + 10; staticgfx[10] = 115 + 6; staticgfx[11] = 115 + 7; //Static Sprites Blocksets (fairy,pot,ect...)
            for (int i = 0; i < 4; i++)
            {
                staticgfx[12 + i] = (byte)(ROM.DATA[Constants.sprite_blockset_pointer + ((spriteset) * 4) + i] + 115);
            }
            GFX.singledata = new byte[staticgfx.Length * 0x1000];
            for (int i = 0; i < staticgfx.Length; i++)
            {
                byte[] d  = GFX.bpp3snestoindexed(GFX.gfxdata, staticgfx[i]);
                byte[] dd = new byte[0];
                if (i == 7)
                {
                    dd = GFX.bpp3snestoindexed(GFX.gfxdata, animatedGfxPart2);
                }

                for (int j = 0; j < d.Length; j++)
                {
                    int pp = 0;
                    if (i == 0)
                    {
                        pp = 8;
                    }
                    else if (i == 1)
                    {
                        pp = 0;
                    }
                    else if (i == 2)
                    {
                        pp = 0;
                    }
                    else if (i == 3)
                    {
                        pp = 8;
                    }
                    else if (i == 4)
                    {
                        pp = 8;
                    }
                    else if (i == 5)
                    {
                        pp = 8;
                    }
                    else if (i == 6)
                    {
                        pp = 0;
                    }
                    else if (i == 7)
                    {
                        pp = 0;
                    }

                    GFX.singledata[(i * 0x1000) + j] = (byte)(d[j] + pp);
                    if (i == 7)
                    {
                        if (j > d.Length / 2)
                        {
                            GFX.singledata[(i * 0x1000) + j] = (byte)(dd[j] + pp);
                        }
                    }
                }
            }
        }
示例#5
0
        private void pictureBox1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (spritemodeButton.Checked)
            {
                if (room.selectedObject.Count > 0)
                {
                    if (room.selectedObject[0] is Sprite)
                    {
                        PickSprite spritepicker = new PickSprite();
                        for (int i = 0; i < 0xF3; i++)
                        {
                            sprites_bitmap[i] = new Bitmap(32, 32, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                            GFX.begin_draw(sprites_bitmap[i], 32, 32);
                            new Sprite(room, (byte)i, 0, 0, Sprites_Names.name[i], 0, 0, 0).Draw(true);
                            GFX.end_draw(sprites_bitmap[i]);

                            spritepicker.listView1.Items.Add(Sprites_Names.name[i]);
                            spritepicker.listView1.Items[i].ImageIndex = i;
                        }
                        //spritepicker.listView1.LargeImageList = new ImageList();
                        // spritepicker.listView1.LargeImageList
                        spriteImageList.Images.Clear();
                        spriteImageList.Images.AddRange(sprites_bitmap);
                        spritepicker.listView1.LargeImageList = spriteImageList;
                        //recreate all sprites images


                        if (spritepicker.ShowDialog() == DialogResult.OK)
                        {
                            List <Object> parameters      = new List <Object>();
                            List <Sprite> changed_sprites = new List <Sprite>();
                            List <int>    old_id          = new List <int>();
                            foreach (Object o in room.selectedObject)
                            {
                                changed_sprites.Add((o as Sprite));
                                old_id.Add((o as Sprite).id);
                                (o as Sprite).id = (byte)spritepicker.listView1.SelectedIndices[0];
                                (o as Sprite).updateBBox();
                            }
                            parameters.Add(changed_sprites.ToArray());
                            parameters.Add(old_id.ToArray());
                            actionsListbox.Items.Add(new DoAction(ActionType.Change, parameters.ToArray()));
                            room.update();
                            drawRoom();
                        }
                    }
                }
                else
                {
                    PickSprite spritepicker = new PickSprite();
                    for (int i = 0; i < 0xF3; i++)
                    {
                        sprites_bitmap[i] = new Bitmap(32, 32, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                        GFX.begin_draw(sprites_bitmap[i], 32, 32);
                        new Sprite(room, (byte)i, 0, 0, Sprites_Names.name[i], 0, 0, 0).Draw(true);
                        GFX.end_draw(sprites_bitmap[i]);

                        spritepicker.listView1.Items.Add(Sprites_Names.name[i]);
                        spritepicker.listView1.Items[i].ImageIndex = i;
                    }
                    //spritepicker.listView1.LargeImageList = new ImageList();
                    // spritepicker.listView1.LargeImageList
                    spriteImageList.Images.Clear();
                    spriteImageList.Images.AddRange(sprites_bitmap);
                    spritepicker.listView1.LargeImageList = spriteImageList;

                    if (spritepicker.ShowDialog() == DialogResult.OK)
                    {
                        List <Object> parameters = new List <Object>();
                        List <Sprite> new_sprite = new List <Sprite>();
                        List <int>    old_id     = new List <int>();
                        Sprite        o          = new Sprite(room, (byte)spritepicker.listView1.SelectedIndices[0], (byte)mx, (byte)my, Sprites_Names.name[spritepicker.listView1.SelectedIndices[0]], 0, 0, 0);
                        new_sprite.Add((o as Sprite));
                        parameters.Add(new_sprite.ToArray());
                        room.sprites.Add(o);
                        actionsListbox.Items.Add(new DoAction(ActionType.Add, parameters.ToArray()));

                        room.update();
                        drawRoom();
                    }
                }
            }
            else if (chestmodeButton.Checked)
            {
                foreach (Chest c in room.chest_list)
                {
                    Console.WriteLine((c.x * 16) + "," + (c.y * 16));
                    Console.WriteLine("Mouse:" + e.X + "," + e.Y);
                    if (e.X >= (c.x * 8) && e.X <= (c.x * 8) + 16 &&
                        e.Y >= (c.y * 8) && e.Y <= (c.y * 8) + 16)
                    {
                        PickChestItem chestpicker = new PickChestItem();
                        for (int i = 0; i < 176; i++)
                        {
                            chest_items_bitmap[i] = new Bitmap(16, 16, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                            GFX.begin_draw(chest_items_bitmap[i], 16, 16);
                            new Chest(0, 0, (byte)i, true).ItemsDraw((byte)i, 0, 0);;

                            GFX.end_draw(chest_items_bitmap[i]);

                            chestpicker.listView1.Items.Add(ChestItems_Name.name[i]);
                            chestpicker.listView1.Items[i].ImageIndex = i;
                        }
                        chestpicker.chestItemsImagesList.Images.AddRange(chest_items_bitmap);
                        chestpicker.listView1.LargeImageList = chestpicker.chestItemsImagesList;
                        if (chestpicker.ShowDialog() == DialogResult.OK)
                        {
                            //change chest item
                            c.item = (byte)chestpicker.listView1.SelectedIndices[0];
                            room.update();
                            drawRoom();
                            anychange = true;
                        }


                        break;
                    }
                }
            }
        }
示例#6
0
        public void drawRoom()
        {
            Bitmap roomBitmap = new Bitmap(512, 512);

            using (Graphics g = Graphics.FromImage(roomBitmap))
            {
                drawRectangles.Clear();
                g.DrawImage(room.room_bitmap, 0, 0);
                if (room.selectedObject.Count > 0)
                {
                    GFX.begin_draw(roomBitmap);
                    foreach (Object o in room.selectedObject)
                    {
                        if (o is Sprite)
                        {
                            if (moved == true)
                            {
                                (o as Sprite).nx = (byte)((o as Sprite).x + move_x);
                                (o as Sprite).ny = (byte)((o as Sprite).y + move_y);
                            }

                            (o as Sprite).Draw();
                            drawRectangles.Add((o as Sprite).boundingbox);
                        }
                    }
                    GFX.end_draw(roomBitmap);

                    if (mouse_down)
                    {
                        foreach (Rectangle r in drawRectangles)
                        {
                            g.DrawRectangle(new Pen(Brushes.LightGreen), r);
                        }
                    }
                    else
                    {
                        foreach (Rectangle r in drawRectangles)
                        {
                            g.DrawRectangle(new Pen(Brushes.Green), r);
                        }
                    }
                }
                else
                {
                    if (mouse_down)
                    {
                        int rx = dragx;
                        int ry = dragy;
                        if (move_x < 0)
                        {
                            Math.Abs(rx = dragx + move_x);
                        }
                        if (move_y < 0)
                        {
                            Math.Abs(ry = dragy + move_y);
                        }

                        g.DrawRectangle(new Pen(Brushes.White), new Rectangle(rx * 16, ry * 16, Math.Abs(move_x) * 16, Math.Abs(move_y) * 16));
                    }
                }
            }

            pictureBox1.Image = roomBitmap;
        }