Example #1
0
        public Tileset Load(FilePath path)
        {
            var tileset = new Tileset();

            tileset.FilePath = path;

            var doc = XDocument.Load(path.Absolute);
            var reader = doc.Element("Tileset");
            if (reader == null)
                throw new Exception("The specified tileset definition file does not contain a Tileset tag.");

            var sheetPath = FilePath.FromRelative(reader.Attribute("tilesheet").Value, path.BasePath);
            tileset.ChangeSheetPath(sheetPath.Absolute);

            int size;
            if (!int.TryParse(reader.Attribute("tilesize").Value, out size))
                throw new Exception("The tileset definition does not contain a valid tilesize attribute.");
            tileset.TileSize = size;

            var propParent = reader.Element("TileProperties");
            if (propParent != null)
            {
                foreach (XElement propNode in propParent.Elements("Properties"))
                {
                    var prop = new TileProperties(propNode);
                    tileset.AddProperties(prop);
                }
            }

            foreach (XElement tileNode in reader.Elements("Tile"))
            {
                int id = int.Parse(tileNode.Attribute("id").Value);
                string name = tileNode.Attribute("name").Value;

                var spriteNode = tileNode.Element("Sprite");
                if (spriteNode == null)
                    throw new GameXmlException(tileNode, "All Tile tags must contain a Sprite tag.");

                var sprite = LoadSprite(spriteNode);
                var tileSprite = new TileSprite(tileset, sprite);

                Tile tile = new Tile(id, tileSprite);

                string propName = "Default";
                XAttribute propAttr = tileNode.Attribute("properties");
                if (propAttr != null)
                    propName = propAttr.Value;

                tile.Properties = tileset.GetProperties(propName);

                tile.Sprite.Play();
                tileset.Add(tile);
            }

            return tileset;
        }
Example #2
0
        public Tileset Load(FilePath path)
        {
            var tileset = new Tileset();

            tileset.FilePath = path;

            var doc    = XDocument.Load(path.Absolute);
            var reader = doc.Element("Tileset");

            if (reader == null)
            {
                throw new Exception("The specified tileset definition file does not contain a Tileset tag.");
            }

            var sheetPath = FilePath.FromRelative(reader.Attribute("tilesheet").Value, path.BasePath);

            tileset.ChangeSheetPath(sheetPath.Absolute);

            int size;

            if (!int.TryParse(reader.Attribute("tilesize").Value, out size))
            {
                throw new Exception("The tileset definition does not contain a valid tilesize attribute.");
            }
            tileset.TileSize = size;

            var propParent = reader.Element("TileProperties");

            if (propParent != null)
            {
                foreach (XElement propNode in propParent.Elements("Properties"))
                {
                    var prop = new TileProperties(propNode);
                    tileset.AddProperties(prop);
                }
            }

            foreach (XElement tileNode in reader.Elements("Tile"))
            {
                int    id   = int.Parse(tileNode.Attribute("id").Value);
                string name = tileNode.Attribute("name").Value;

                var spriteNode = tileNode.Element("Sprite");
                if (spriteNode == null)
                {
                    throw new GameXmlException(tileNode, "All Tile tags must contain a Sprite tag.");
                }

                var sprite     = LoadSprite(spriteNode);
                var tileSprite = new TileSprite(tileset, sprite);

                Tile tile = new Tile(id, tileSprite);

                string     propName = "Default";
                XAttribute propAttr = tileNode.Attribute("properties");
                if (propAttr != null)
                {
                    propName = propAttr.Value;
                }

                tile.Properties = tileset.GetProperties(propName);

                tile.Sprite.Play();
                tileset.Add(tile);
            }

            return(tileset);
        }
        void Core_Insert(BattleScreen insert)
        {
            Core.SuspendUpdate();
            Tileset tileset = new Tileset(insert.Graphics.Count);

            for (int i = 0; i < insert.Graphics.Count; i++)
            {
                if (i >= BattleScreen.TILE_LIMIT && i < BattleScreen.TILE_LIMIT_END)
                {
                    tileset.Add(Tile.Empty);
                }
                else
                {
                    tileset.Add(insert.Graphics[i]);
                }
            }
            byte[] data_tileset  = tileset.ToBytes(true);
            byte[] data_palette  = Palette.Merge(insert.Palettes).ToBytes(false);
            byte[] data_tsa      = BattleScreen.GetInsertableTSA(insert.Tiling).ToBytes(false, false);
            byte[] data_L_name   = insert.L_Name.ToBytes(true);
            byte[] data_L_weapon = insert.L_Weapon.ToBytes(true);
            byte[] data_R_name   = insert.R_Name.ToBytes(true);
            byte[] data_R_weapon = insert.R_Weapon.ToBytes(true);
            try
            {
                bool cancel = Prompt.ShowRepointDialog(this, "Repoint Battle Screen",
                                                       "The battle screen to insert might need some of its parts to be repointed.",
                                                       BattleScreenEntry, new Tuple <string, Pointer, int>[] {
                    Tuple.Create("Tileset", Core.GetPointer("Battle Screen Tileset"), data_tileset.Length),
                    Tuple.Create("Palette", Core.GetPointer("Battle Screen Palettes"), data_palette.Length),
                    // Tuple.Create("TSA", Core.GetPointer("Battle Screen TSA"), data_tsa.Length),
                    // repointing this TSA f***s everything up, shouldn't be too accessible
                    Tuple.Create("L Name", Core.GetPointer("Battle Screen L Name"), data_L_name.Length),
                    Tuple.Create("L Weapon", Core.GetPointer("Battle Screen L Weapon"), data_L_weapon.Length),
                    Tuple.Create("R Name", Core.GetPointer("Battle Screen R Name"), data_R_name.Length),
                    Tuple.Create("R Weapon", Core.GetPointer("Battle Screen R Weapon"), data_R_weapon.Length)
                });
                if (cancel)
                {
                    return;
                }

                Core.WriteData(this,
                               Core.GetPointer("Battle Screen Tileset"),
                               data_tileset,
                               CurrentEntry + "Tileset changed");

                Core.WriteData(this,
                               Core.GetPointer("Battle Screen Palettes"),
                               data_palette,
                               CurrentEntry + "Palettes changed");

                Core.WriteData(this,
                               Core.GetPointer("Battle Screen TSA"),
                               data_tsa,
                               CurrentEntry + "TSA changed");

                Core.WriteData(this,
                               Core.GetPointer("Battle Screen L Name"),
                               data_L_name, CurrentEntry + "L Name changed");
                Core.WriteData(this,
                               Core.GetPointer("Battle Screen L Weapon"),
                               data_L_weapon, CurrentEntry + "L Weapon changed");
                Core.WriteData(this,
                               Core.GetPointer("Battle Screen R Name"),
                               data_R_name, CurrentEntry + "R Name changed");
                Core.WriteData(this,
                               Core.GetPointer("Battle Screen R Weapon"),
                               data_R_weapon, CurrentEntry + "R Weapon changed");
            }
            catch (Exception ex)
            {
                Program.ShowError("Could not insert the Battle Screen Frame.", ex);
                Core_Update();
            }
            Core.ResumeUpdate();
            Core.PerformUpdate();
        }
Example #4
0
        public BattleScreen(Bitmap image, Palette[] palettes) : base(WIDTH, HEIGHT)
        {
            if (image.Width != Width || image.Height != Height)
            {
                throw new Exception("Image given has invalid dimensions, should be " + Width + "x" + Height + " pixels.");
            }

            Palettes = palettes;
            Graphics = new Tileset(WIDTH * HEIGHT);
            Tiling   = new TSA_Array(WIDTH, HEIGHT);

            const int X_L_NAME   = 1;
            const int X_L_WEAPON = 8;
            int       X_R_NAME   = Core.CurrentROM is FE8 ? 24 : 25;
            const int X_R_WEAPON = 18;
            const int Y_NAME     = 1;
            const int Y_WEAPON   = 8;

            Tile tile;
            byte paletteIndex;

            System.Drawing.Rectangle region;
            for (int y = 0; y < HEIGHT; y++)
            {
                for (int x = 0; x < WIDTH; x++)
                {
                    if (x >= HALFWIDTH)
                    {
                        if ((x >= X_R_NAME && x < X_R_NAME + NAME_WIDTH && y >= Y_NAME && y < Y_NAME + 2) ||
                            (x >= X_R_WEAPON && x < X_R_WEAPON + 6 && y >= Y_WEAPON && y < Y_WEAPON + 2))
                        {
                            continue;
                        }
                        paletteIndex = 0;
                    }
                    else
                    {
                        if ((x >= X_L_NAME && x < X_L_NAME + NAME_WIDTH && y >= Y_NAME && y < Y_NAME + 2) ||
                            (x >= X_L_WEAPON && x < X_L_WEAPON + WEAPON_WIDTH && y >= Y_WEAPON && y < Y_WEAPON + 2))
                        {
                            continue;
                        }
                        paletteIndex = 1;
                    }
                    region = new System.Drawing.Rectangle(x * Tile.SIZE, y * Tile.SIZE, Tile.SIZE, Tile.SIZE);
                    tile   = new Tile(new Image(image, region, palettes[paletteIndex]));

                    if (Graphics.Count == EMPTY_TILE)
                    {
                        Graphics.Add(Tile.Empty);
                    }
                    if (Graphics.Count == TILE_LIMIT)
                    {
                        for (int i = 0; TILE_LIMIT + i < TILE_LIMIT_END; i++)
                        {
                            Graphics.Add(Tile.Empty);
                        }
                    }
                    if (Graphics.Count >= 128)
                    {
                        throw new Exception("Battle Screen Frame cannot have more than 128 tiles.");
                    }
                    if (tile.IsEmpty())
                    {
                        Tiling[x, y] = new TSA(EMPTY_TILE, paletteIndex, false, false);
                    }
                    else
                    {
                        var match = Graphics.FindMatch(tile);

                        if (match == null)
                        {
                            Tiling[x, y] = new TSA(Graphics.Count, paletteIndex, false, false);
                            Graphics.Add(tile);
                        }
                        else
                        {
                            Tiling[x, y] = new TSA(match.Item1, paletteIndex, match.Item2, match.Item3);
                        }
                    }
                }
            }
            while (Graphics.Count < TILE_LIMIT_END)
            {
                Graphics.Add(Tile.Empty);
            }

            LoadSecondaryTileset(image, palettes, L_NAME_OFFSET, 1, X_L_NAME, Y_NAME, NAME_WIDTH, 2);
            LoadSecondaryTileset(image, palettes, L_WEAPON_OFFSET, 1, X_L_WEAPON, Y_WEAPON, WEAPON_WIDTH, 2);
            LoadSecondaryTileset(image, palettes, R_NAME_OFFSET, 0, X_R_NAME, Y_NAME, NAME_WIDTH, 2);
            LoadSecondaryTileset(image, palettes, R_WEAPON_OFFSET, 0, X_R_WEAPON, Y_WEAPON, WEAPON_WIDTH, 2);
        }