Ejemplo n.º 1
0
        void Core_UpdateDisplay()
        {
            const int palettes = 8;
            int       width    = (int)Width_NumberBox.Value;
            int       height   = (int)Height_NumberBox.Value;

            byte[] palette = Core.ReadData(
                Palette_PointerBox.Value,
                Palette_CheckBox.Checked ? 0 : palettes * Palette.LENGTH);
            byte[] tileset = Core.ReadData(
                Tileset_PointerBox.Value,
                Tileset_CheckBox.Checked ? 0 : width * height * Tile.LENGTH);

            for (int i = 0; i < palette.Length; i += 2)
            {
                palette[i + 1] &= 0x7F;
            }   // force opaque colors on display

            if (palette == null || palette.Length == 0)
            {
                Spell_PaletteBox.Reset();
                Spell_ImageBox.Reset();
                return;
            }
            if (tileset == null || tileset.Length == 0)
            {
                Spell_PaletteBox.Load(new Palette(palette, Palette.MAX * 16));
                Spell_ImageBox.Reset();
                return;
            }

            IDisplayable image = null;

            try
            {
                if (TSA_Label.Checked && TSA_PointerBox.Value != new Pointer())
                {
                    image = new TSA_Image(palette, tileset, Core.ReadTSA(
                                              TSA_PointerBox.Value,
                                              width, height,
                                              TSA_CheckBox.Checked, false));
                }
                else
                {
                    image = new Tileset(tileset).ToImage(
                        width, height, palette.GetBytes(0, Palette.LENGTH));
                }
                Spell_PaletteBox.Load(new Palette(palette, Palette.MAX * 16));
                Spell_ImageBox.Load(image);
            }
            catch (Exception ex)
            {
                Program.ShowError("There has been an error while trying to load the image.", ex);
            }
        }
Ejemplo n.º 2
0
        public WorldMap_FE7_Large(string path, Palette palette = null)
        {
            TSA_Image image;

            if (palette == null)
            {
                image = new TSA_Image(WIDTH, HEIGHT, new GBA.Bitmap(path), PALETTES, false);
            }
            else
            {
                image = new TSA_Image(WIDTH, HEIGHT, new GBA.Bitmap(path), palette, PALETTES, false);
            }

            Palettes = image.Palettes;

            Graphics     = new Tileset[SECTIONS];
            TSA_Sections = new TSA_Array[SECTIONS];
            int width  = 32;
            int height = 32;

            for (int i = 0; i < SECTIONS; i++)
            {
                if (i == 8)
                {
                    height = 22;
                }

                Graphics[i] = new Tileset(width * height);
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        Graphics[i].Add(image.Graphics[
                                            (i % 4 * width + x) +
                                            (i / 4 * width + y) * WIDTH]);
                    }
                }

                TSA_Sections[i] = TSA_Array.GetBasicTSA(width, height);
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        TSA_Sections[i].SetPalette(x, y, image.Tiling[
                                                       (i % 4 * width) + x,
                                                       (i / 4 * width) + y].Palette);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public WorldMap_FE8_Small(string path, Palette palette = null) : base(WIDTH, HEIGHT)
        {
            TSA_Image image;

            if (palette == null)
            {
                image = new TSA_Image(WIDTH, HEIGHT, new GBA.Bitmap(path), PALETTES, true);
            }
            else
            {
                image = new TSA_Image(WIDTH, HEIGHT, new GBA.Bitmap(path), palette, PALETTES, true);
            }
            Graphics = image.Graphics;
            Palettes = image.Palettes;
            Tiling   = image.Tiling;
        }
Ejemplo n.º 4
0
        public MapTileset(Palette palette, Bitmap tileset, Bitmap tileset1, Bitmap tileset2)
        {
            TSA_Image maptileset;

            if (palette == null)
            {
                maptileset = new TSA_Image(64, 64, tileset, 4, true);
                Palettes   = new Palette[8];
                for (int i = 0; i < 4; i++)
                {
                    Palettes[i] = maptileset.Palettes[i];
                }
                for (int i = 0; i < 4; i++)
                {
                    Palettes[4 + i] = new Palette();
                    Color color;
                    for (int j = 0; j < Palette.MAX; j++)
                    {
                        color = maptileset.Palettes[i][j];
                        Palettes[4 + i].Add(new GBA.Color(0,
                                                          (byte)(color.GetValueR() + 32),
                                                          (byte)(color.GetValueG() + 32),
                                                          (byte)(color.GetValueB() + 32)));
                    }
                }
            }
            else
            {
                maptileset = new TSA_Image(64, 64, tileset, palette, 8, true);
                Palettes   = Palette.Split(palette, 8);
            }

            if (tileset1 == null)
            {
                Tileset1 = maptileset.Graphics;
            }
            else
            {
            }
            if (tileset2 == null)
            {
            }
            else
            {
            }
        }
Ejemplo n.º 5
0
        public WorldMap_FE8_Large(string path, Palette palette = null)
        {
            TSA_Image image;

            if (palette == null)
            {
                image = new TSA_Image(WIDTH, HEIGHT, new GBA.Bitmap(path), PALETTES, false);
            }
            else
            {
                image = new TSA_Image(WIDTH, HEIGHT, new GBA.Bitmap(path), palette, PALETTES, false);
            }
            Graphics   = image.Graphics;
            Palettes   = image.Palettes;
            PaletteMap = new int[WIDTH, HEIGHT];
            for (int y = 0; y < HEIGHT; y++)
            {
                for (int x = 0; x < WIDTH; x++)
                {
                    PaletteMap[x, y] = image.Tiling[x, y].Palette;
                }
            }
        }
Ejemplo n.º 6
0
        void Core_LoadTitleScreen_FE8(
            Palette bg_palette, Tileset bg_tileset, TSA_Array bg_tsa,
            Palette mg_palette, Tileset mg_tileset, TSA_Array mg_tsa,
            Palette fg_palette, Tileset fg_tileset)
        {
            GBA.Bitmap result;
            Palette    palette = Palette.Empty(256);

            for (int i = 0; i < bg_palette.Count; i++)
            {
                bg_palette[i] = bg_palette[i].SetAlpha(false);
                palette.Set(GBA.Palette.MAX * 15 + i, bg_palette[i]);
            }
            for (int i = 0; i < mg_palette.Count; i++)
            {
                palette.Set(GBA.Palette.MAX * 14 + i, mg_palette[i]);
            }
            for (int i = 0; i < fg_palette.Count; i++)
            {
                palette.Set(i, fg_palette[i]);
            }
            result        = new GBA.Bitmap(GBA.Screen.WIDTH, GBA.Screen.HEIGHT);
            result.Colors = palette;

            if (BG_CheckBox.Checked)
            {
                TSA_Image bg = new TSA_Image(bg_palette, bg_tileset, bg_tsa);
                for (int y = 0; y < bg.Height; y++)
                {
                    for (int x = 0; x < bg.Width; x++)
                    {
                        if (bg[x, y] != 0)
                        {
                            result[x, y] = GBA.Palette.MAX * 15 + bg[x, y];
                        }
                    }
                }
            }
            if (MG_CheckBox.Checked)
            {
                TSA_Image mg = new TSA_Image(mg_palette, mg_tileset, mg_tsa);
                for (int y = 0; y < mg.Height; y++)
                {
                    for (int x = 0; x < mg.Width; x++)
                    {
                        if (mg[x, y] != 0)
                        {
                            result[x, y] = GBA.Palette.MAX * 14 + mg[x, y];
                        }
                    }
                }
            }
            if (FG_CheckBox.Checked)
            {
                Palette[] palettes = Palette.Split(fg_palette, 8);
                GBA.Image fg;
                if (Core.CurrentROM.Version == GameVersion.JAP)
                {
                    // large 'FIRE EMBLEM' title logo
                    fg = fg_tileset.ToImage(32, 32, palettes[2].ToBytes(false));
                    Core_DrawLayer(result, fg, new Rectangle(0, 48, 240, 48), 0, 44);   // shadow
                    Core_DrawLayer(result, fg, new Rectangle(0, 0, 240, 48), 0, 39);    // logo
                    Core_DrawLayer(result, fg, new Rectangle(240, 0, 16, 16), 216, 39); // TM
                    // small 'FIRE EMBLEM' overhead
                    fg.Colors = palettes[1];
                    Core_DrawLayer(result, fg, new Rectangle(128, 104, 120, 16), 60, 26);
                    // 'THE SACRED STONES' subtitle/scroll thingy
                    fg.Colors = palettes[3];
                    Core_DrawLayer(result, fg, new Rectangle(0, 104, 128, 32), 56, 87);
                    // 'Press START'
                    fg.Colors = palettes[0];
                    Core_DrawLayer(result, fg, new Rectangle(128, 120, 80, 16), 80, 124);
                    // Nintendo & IS copyrights
                    fg.Colors = palettes[1];
                    Core_DrawLayer(result, fg, new Rectangle(0, 96, 240, 8), 16, 148);
                }
                else
                {
                    // large 'FIRE EMBLEM' title logo
                    fg = fg_tileset.ToImage(32, 32, palettes[2].ToBytes(false));
                    Core_DrawLayer(result, fg, new Rectangle(0, 32, 240, 32), 4, 53);   // shadow
                    Core_DrawLayer(result, fg, new Rectangle(0, 0, 240, 32), 4, 48);    // logo
                    Core_DrawLayer(result, fg, new Rectangle(240, 0, 16, 16), 220, 41); // TM
                    // 'THE SACRED STONES' subtitle/scroll thingy
                    fg.Colors = palettes[3];
                    Core_DrawLayer(result, fg, new Rectangle(0, 72, 208, 32), 16, 85);
                    // 'Press START'
                    fg.Colors = palettes[0];
                    Core_DrawLayer(result, fg, new Rectangle(208, 72, 48, 16), 72, 124);
                    Core_DrawLayer(result, fg, new Rectangle(208, 88, 48, 16), 120, 124);
                    // Nintendo & IS copyrights
                    fg.Colors = palettes[1];
                    Core_DrawLayer(result, fg, new Rectangle(0, 64, 240, 8), 4, 148);
                }
            }
            Current        = result;
            CurrentPalette = palette;
        }
Ejemplo n.º 7
0
        void Core_LoadTitleScreen_FE7(
            Palette bg_palette, Tileset bg_tileset,
            Palette mg_palette, Tileset mg_tileset, TSA_Array mg_tsa,
            Palette fg_palette, Tileset fg_tileset)
        {
            GBA.Bitmap result;
            Palette    palette = Palette.Empty(256);

            for (int i = 0; i < bg_palette.Count; i++)
            {
                palette.Set(GBA.Palette.MAX * 15 + i, bg_palette[i]);
            }
            for (int i = 0; i < mg_palette.Count; i++)
            {
                palette.Set(GBA.Palette.MAX * 14 + i, mg_palette[i]);
            }
            for (int i = 0; i < fg_palette.Count; i++)
            {
                palette.Set(i, fg_palette[i]);
            }
            result        = new GBA.Bitmap(GBA.Screen.WIDTH, GBA.Screen.HEIGHT);
            result.Colors = palette;

            if (BG_CheckBox.Checked)
            {
                GBA.Image bg = bg_tileset.ToImage(GBA.Screen.W_TILES, GBA.Screen.H_TILES + 1, bg_palette.ToBytes(false));
                for (int y = 0; y < GBA.Screen.HEIGHT; y++)
                {
                    for (int x = 0; x < GBA.Screen.WIDTH; x++)
                    {
                        if (x < 8 && y < 8)
                        {
                            result[x, y] = GBA.Palette.MAX * 15 + bg[x, GBA.Screen.HEIGHT + y];
                        }
                        else
                        {
                            result[x, y] = GBA.Palette.MAX * 15 + bg[x, y];
                        }
                    }
                }
            }
            if (MG_CheckBox.Checked)
            {
                TSA_Image mg = new TSA_Image(mg_palette, mg_tileset, mg_tsa);
                for (int y = 0; y < mg.Height; y++)
                {
                    for (int x = 0; x < mg.Width; x++)
                    {
                        if (mg[x, y] != 0)
                        {
                            result[x, 8 + y] = GBA.Palette.MAX * 14 + mg[x, y];
                        }
                    }
                }
            }
            if (FG_CheckBox.Checked)
            {
                bool      jap      = (Core.CurrentROM.Version == GameVersion.JAP);
                bool      eur      = (Core.CurrentROM.Version == GameVersion.EUR);
                Palette[] palettes = Palette.Split(fg_palette, 8);
                GBA.Image fg;
                // durandal sword
                fg = fg_tileset.ToImage(32, 32, palettes[0].ToBytes(false));
                Core_DrawLayer(result, fg, new Rectangle(0, 0, 192, 112), 32, 16);
                // large 'FIRE EMBLEM' title
                fg.Colors = palettes[4];
                Core_DrawLayer(result, fg, new Rectangle(0, GBA.Screen.HEIGHT, GBA.Screen.WIDTH, 48), 2, jap ? 52 : 54);
                Core_DrawLayer(result, fg, new Rectangle(0, GBA.Screen.HEIGHT - 48, GBA.Screen.WIDTH, 48), 0, jap ? 48 : 52);
                // Nintendo & IS copyrights
                fg.Colors = palettes[2];
                Core_DrawLayer(result, fg, new Rectangle(0, GBA.Screen.WIDTH - 16, GBA.Screen.HEIGHT - 16, 8), eur ?   8 : 16, GBA.Screen.HEIGHT - 16);
                Core_DrawLayer(result, fg, new Rectangle(0, GBA.Screen.WIDTH - 8, GBA.Screen.HEIGHT - 64, 8), eur ? 136 : GBA.Screen.HEIGHT, GBA.Screen.HEIGHT - 16);
                // 'Press Start'
                fg.Colors = palettes[1];
                Core_DrawLayer(result, fg, new Rectangle(128, 208, 96, 16), jap ? 80 : 72, 120);
                if (jap)
                {   // japanese subtitle
                    fg.Colors = palettes[3];
                    Core_DrawLayer(result, fg, new Rectangle(144, 224, 112, 32), 64, 96);
                    // japanese 'FIRE EMBLEM' overhead
                    fg.Colors = palettes[2];
                    Core_DrawLayer(result, fg, new Rectangle(0, 208, 128, 16), 56, 40);
                }
            }
            Current        = result;
            CurrentPalette = palette;
        }
Ejemplo n.º 8
0
        void Core_LoadTitleScreen_FE6(
            Palette mg_palette, Tileset mg_tileset,
            Tileset fg_tileset, TSA_Array mg_tsa,
            Palette bg_palette, Tileset bg_tileset)
        {
            GBA.Bitmap result;
            Palette    palette = Palette.Empty(256);

            for (int i = 0; i < mg_palette.Count; i++)
            {
                palette.Set(i, mg_palette[i]);
            }
            for (int i = 0; i < bg_palette.Count; i++)
            {
                bg_palette[i] = bg_palette[i].SetAlpha(false);
                palette.Set(GBA.Palette.MAX * 15 + i, bg_palette[i]);
            }
            result        = new GBA.Bitmap(GBA.Screen.WIDTH, GBA.Screen.HEIGHT);
            result.Colors = palette;

            if (BG_CheckBox.Checked)
            {
                GBA.Image bg = bg_tileset.ToImage(GBA.Screen.W_TILES + 2, GBA.Screen.H_TILES, bg_palette.ToBytes(false));
                for (int y = 0; y < GBA.Screen.HEIGHT; y++)
                {
                    for (int x = 0; x < GBA.Screen.WIDTH; x++)
                    {
                        result[x, y] = GBA.Palette.MAX * 15 + bg[x, y];
                    }
                }
            }
            if (MG_CheckBox.Checked)
            {
                TSA_Image mg = new TSA_Image(mg_palette, mg_tileset, mg_tsa);
                for (int y = 0; y < GBA.Screen.HEIGHT; y++)
                {
                    for (int x = 0; x < GBA.Screen.WIDTH; x++)
                    {
                        if (mg.GetColor(x, y).Value != 0)
                        {
                            result[x, y] = mg[x, y];
                        }
                    }
                }
            }
            if (FG_CheckBox.Checked)
            {
                Palette[] palettes = Palette.Split(mg_palette, 8);
                GBA.Image fg;
                // large japanese 'FIRE EMBLEM' title
                fg = mg_tileset.ToImage(32, 25, palettes[4].ToBytes(false));
                Core_DrawLayer(result, fg, new Rectangle(0, 152, GBA.Screen.WIDTH, 48), 0, 48);
                Core_DrawLayer(result, fg, new Rectangle(0, 104, GBA.Screen.WIDTH, 48), 0, 40);
                // small english 'FIRE EMBLEM'
                fg = fg_tileset.ToImage(32, 32, palettes[2].ToBytes(false));
                Core_DrawLayer(result, fg, new Rectangle(0, 0, 128, 16), 99, 27);
                // Nintendo & IS copyrights
                Core_DrawLayer(result, fg, new Rectangle(0, 48, 208, 8), 16, 152);
                // japanese subtitle scroll thingy
                fg.Colors = palettes[3];
                Core_DrawLayer(result, fg, new Rectangle(128, 16, 120, 32), 64, 85);
                // 'Press Start'
                fg.Colors = palettes[1];
                Core_DrawLayer(result, fg, new Rectangle(128, 0, 80, 16), 80, 120);
            }
            Current        = result;
            CurrentPalette = palette;
        }
Ejemplo n.º 9
0
        public override void Core_Update()
        {
            try
            {
                byte[] palette = Core.ReadData(
                    Palette_PointerBox.Value + (int)Palette_Index_NumBox.Value * Palette.LENGTH,
                    Palette_CheckBox.Checked ? 0 : 16 * Palette.LENGTH);
                byte[] tileset = Core.ReadData(
                    Tileset_PointerBox.Value,
                    Tileset_CheckBox.Checked ? 0 : (Tileset_8bpp_RadioButton.Checked ?
                                                    ((int)Width_NumBox.Value * (int)Height_NumBox.Value * Tile.SIZE * Tile.SIZE) :
                                                    ((int)Width_NumBox.Value * (int)Height_NumBox.Value * Tile.LENGTH)));

                if (Palette_Opaque_CheckBox.Checked)
                {
                    for (int i = 0; i < palette.Length; i += 2)
                    {
                        palette[i + 1] &= 0x7F;
                    }
                }

                if (palette == null || palette.Length == 0)
                {
                    Palette_PaletteBox.Reset();
                    Image_ImageBox.Reset();
                    return;
                }
                if (tileset == null || tileset.Length == 0)
                {
                    Palette_PaletteBox.Load(new Palette(palette, Palette.MAX * 16));
                    Image_ImageBox.Reset();
                    return;
                }

                IDisplayable image = null;
                if (TSA_Label.Checked && TSA_PointerBox.Value != new Pointer())
                {
                    image = new TSA_Image(palette, tileset,
                                          Core.ReadTSA(TSA_PointerBox.Value,
                                                       (int)Width_NumBox.Value,
                                                       (int)Height_NumBox.Value,
                                                       TSA_CheckBox.Checked,
                                                       TSA_FlipRows_CheckBox.Checked));

                    Tool_OpenTSAEditor.Enabled = true;
                }
                else if (Tileset_8bpp_RadioButton.Checked)
                {
                    image = new Bitmap(
                        (int)Width_NumBox.Value * Tile.SIZE,
                        (int)Height_NumBox.Value * Tile.SIZE,
                        View_GrayscalePalette.Checked ?
                        GrayScale.ToBytes(false) :
                        palette,
                        tileset);

                    Tool_OpenTSAEditor.Enabled = false;
                }
                else
                {
                    image = new Tileset(tileset).ToImage(
                        (int)Width_NumBox.Value,
                        (int)Height_NumBox.Value,
                        View_GrayscalePalette.Checked ?
                        GrayScale.ToBytes(false) :
                        palette.GetBytes(0, Palette.LENGTH));

                    Tool_OpenTSAEditor.Enabled = false;
                }

                Palette_PaletteBox.Load(new Palette(palette, Palette.MAX * 16));
                Image_ImageBox.Size = new System.Drawing.Size(image.Width, image.Height);
                Image_ImageBox.Load(image);
            }
            catch (Exception ex)
            {
                Program.ShowError("There has been an error while trying to load the image.", ex);

                Image_ImageBox.Reset();
            }
        }
Ejemplo n.º 10
0
        void Core_InsertImage(string filepath)
        {
            IDisplayable image;

            try
            {
                Palette palette = Core.FindPaletteFile(filepath);

                if (TSA_Label.Checked && TSA_PointerBox.Value != new Pointer())
                {
                    int width = TSA_FlipRows_CheckBox.Checked ?
                                ((TSA_Image)Image_ImageBox.Display).Tiling.Width :
                                (int)Width_NumBox.Value;
                    int height = TSA_FlipRows_CheckBox.Checked ?
                                 ((TSA_Image)Image_ImageBox.Display).Tiling.Height :
                                 (int)Height_NumBox.Value;

                    if (palette == null)
                    {
                        image = new TSA_Image(
                            width, height,
                            new GBA.Bitmap(filepath),
                            Palette.MAX,
                            true);
                    }
                    else
                    {
                        image = new TSA_Image(
                            width, height,
                            new GBA.Bitmap(filepath),
                            palette,
                            Palette.MAX,
                            true);
                    }
                }
                else if (Tileset_8bpp_RadioButton.Checked)
                {
                    image = new GBA.Bitmap(filepath, palette);
                }
                else
                {
                    image = new GBA.Image(filepath, palette);
                }
            }
            catch (Exception ex)
            {
                Program.ShowError("Could not load image file.", ex);
                Core_Update();
                return;
            }

            if (image is GBA.TSA_Image)
            {
                Core_Insert(
                    Palette.Merge(((TSA_Image)image).Palettes),
                    ((TSA_Image)image).Graphics.ToBytes(false),
                    ((TSA_Image)image).Tiling);
                return;
            }
            if (image is GBA.Bitmap)
            {
                Core_Insert(
                    ((Bitmap)image).Colors,
                    ((Bitmap)image).ToBytes());
                return;
            }
            if (image is GBA.Image)
            {
                Core_Insert(
                    ((Image)image).Colors,
                    new Tileset((Image)image).ToBytes(false));
                return;
            }
            Program.ShowError("Image couldn't be inserted because of an internal error.");
        }
Ejemplo n.º 11
0
        public TextPreview(Font font, bool bubble, string[] text, int line)
        {
            Text = new Bitmap(Width, Height);
            for (int i = 0; i < Glyph.Colors.Length; i++)
            {
                Text.Colors.Add(Glyph.Colors[i]);
            }
            Dictionary <char, byte> fontmap = (Core.CurrentROM.Version == GameVersion.JAP) ?
                                              Font.GetFontMap(bubble) : Font.GetFontMap();

            List <Glyph>[] glyphs  = new List <Glyph> [text.Length];
            int[]          lengths = new int[text.Length];
            int            length;
            int            offset_x;
            int            offset_y;

            for (int i = 0; i < text.Length; i++)
            {
                glyphs[i] = new List <Glyph>();
                for (int j = 0; j < text[i].Length; j++)
                {
                    glyphs[i].Add(font.GetGlyph(text[i][j], fontmap));

                    if (glyphs[i][glyphs[i].Count - 1] != null)
                    {
                        lengths[i] += glyphs[i][glyphs[i].Count - 1].TextWidth;
                    }
                }
            }
            int lines = Math.Min(bubble ? 2 : 4, text.Length);

            for (int i = line; i < line + lines; i++)
            {
                offset_x = bubble ? 8 : Width / 2 - lengths[i] / 2;
                offset_y = (bubble ? 8 : 0) + (i - line) * 16;

                length = 0;
                for (int j = 0; j < glyphs[i].Count; j++)
                {
                    if (glyphs[i][j] != null)
                    {
                        for (int y = 0; y < 16; y++)
                        {
                            for (int x = 0; x < 16; x++)
                            {
                                if (offset_x + length + x < Width && offset_y + y < Height && glyphs[i][j].GetColor(x, y) != Glyph.Colors[0])
                                {
                                    Text.SetColor(
                                        offset_x + length + x,
                                        offset_y + y,
                                        glyphs[i][j].GetColor(x, y));
                                }
                            }
                        }
                        length += glyphs[i][j].TextWidth;
                    }
                }
            }

            length = 0;
            for (int i = 0; i < text.Length; i++)
            {
                if (lengths[i] > length)
                {
                    length = lengths[i];
                }
            }   // Store the pixel length of the biggest line

            if (bubble)
            {
                Bubble = MakeTextBubble(length,
                                        Core.GetPointer("Text Bubble Tileset"),
                                        Core.GetPointer("Text Bubble Palette"));
            }
        }