Example #1
0
 public void AddRedoHistory(Tile[,,] MapState)
 {
     redo_deque.PushFront(MapState.Clone());
 }
Example #2
0
        public Boolean LoadMapDataXMLOther(string fileName)
        {
            XmlDocument xml = new XmlDocument();
            xml.Load(fileName);

            string outie = xml.OuterXml;

            int startIndex;
            int length;
            string[] split;

            //Texture Name
            startIndex = outie.IndexOf("<TextureName>") + "<TextureName>".Length;
            length = outie.IndexOf("</TextureName>") - startIndex;

            GLB_Data_Other.TextureFileName = outie.Substring(startIndex, length).Trim();

            //map dimensions
            startIndex = outie.IndexOf("<MapDimensions>") + "<MapDimensions>".Length;
            length = outie.IndexOf("</MapDimensions>") - startIndex;

            split = outie.Substring(startIndex, length).Split(' ');

            int.TryParse(split[0], out GLB_Data_Other.MapSize.Width);
            int.TryParse(split[1], out GLB_Data_Other.MapSize.Height);

            //tile size
            startIndex = outie.IndexOf("<FileTileSize>") + "<FileTileSize>".Length;
            length = outie.IndexOf("</FileTileSize>") - startIndex;

            if (length <= 0)
            {
                startIndex = outie.IndexOf("<TileSize>") + "<TileSize>".Length;
                length = outie.IndexOf("</TileSize>") - startIndex;
            }

            split = outie.Substring(startIndex, length).Split(' ');

            int.TryParse(split[0], out GLB_Data_Other.MapSize.TileSize);

            xmap = new FileFormat();

            xmap.texture_file_name = GLB_Data_Other.TextureFileName;

            xmap.texture_dimensions.X = GLB_Data_Other.TilesTexture.Width;
            xmap.texture_dimensions.Y = GLB_Data_Other.TilesTexture.Height;

            xmap.map_dimensions.Width = GLB_Data_Other.MapSize.Width;
            xmap.map_dimensions.Height = GLB_Data_Other.MapSize.Height;
            xmap.map_dimensions.Depth = 4;
            xmap.map_dimensions.TileSize = GLB_Data_Other.MapSize.TileSize;

            if (CheckTileTexture(ref xmap.texture_file_name, true))
            {
                /*
                //map name
                startIndex = outie.IndexOf("<Name>") + "<Name>".Length;
                length = outie.IndexOf("</Name>") - startIndex;

                GLB_Data_Other.MapName = outie.Substring(startIndex, length).Trim();
                */

                // palette

                GLB_Data_Other.MapSize.Depth = 4;

                Tile t;

                int x = GLB_Data_Other.TilesTexture.Width / GLB_Data_Other.MapSize.TileSize;
                int y = GLB_Data_Other.TilesTexture.Height / GLB_Data_Other.MapSize.TileSize;

                int index = 1;
                GLB_Data_Other.TilePalette = new Tile[x, y];

                for (int j = 0; j < y; j++)
                {
                    for (int i = 0; i < x; i++)
                    {
                        t = new Tile();

                        t.grid_location.X = i;
                        t.grid_location.Y = j;

                        t.id = index;
                        index++;

                        t.terrain_type = 0;
                        t.texture_location.X = 0;
                        t.texture_location.Y = 0;
                        t.walkable = true;

                        GLB_Data_Other.TilePalette[i, j] = t;
                    }
                }

                char[] splitChars = new char[4];
                splitChars[0] = ' ';
                splitChars[1] = '\n';
                splitChars[2] = '\r';
                splitChars[3] = '\t';

                GLB_Data_Other.TileMap = new Tile[4, GLB_Data_Other.MapSize.Width, GLB_Data_Other.MapSize.Height];

                //BaseLayer
                startIndex = outie.IndexOf("<BaseLayer>") + "<BaseLayer>".Length;
                length = outie.IndexOf("</BaseLayer>") - startIndex;

                split = outie.Substring(startIndex, length).Split(splitChars);

                x = 0;
                y = 0;

                foreach (string s in split)
                {
                    if (s != "")
                    {
                        t = new Tile();

                        t.grid_location.X = x;
                        t.grid_location.Y = y;

                        t.id = int.Parse(s);

                        t.terrain_type = 0;
                        t.texture_location.X = (t.id - 1) % (GLB_Data_Other.TilesTexture.Width / GLB_Data_Other.MapSize.TileSize);
                        t.texture_location.Y = (t.id - 1) / (GLB_Data_Other.TilesTexture.Width / GLB_Data_Other.MapSize.TileSize);
                        t.walkable = false;

                        GLB_Data_Other.TileMap[0, x, y] = t;

                        x++;

                        if (x > GLB_Data_Other.MapSize.Width - 1)
                        {
                            x = 0;
                            y++;
                        }
                    }

                }

                //Tile d = GLB_Data_Other.TileMap[0, 58, 79];
                //Tile f = GLB_Data_Other.TileMap[0, 59, 79];

                //FringeLayer
                startIndex = outie.IndexOf("<FringeLayer>") + "<FringeLayer>".Length;
                length = outie.IndexOf("</FringeLayer>") - startIndex;

                split = outie.Substring(startIndex, length).Split(splitChars);

                x = 0;
                y = 0;

                foreach (string s in split)
                {
                    if (s != "")
                    {
                        t = new Tile();

                        t.grid_location.X = x;
                        t.grid_location.Y = y;

                        t.id = int.Parse(s);

                        t.terrain_type = 0;
                        t.texture_location.X = (t.id - 1) % (GLB_Data_Other.TilesTexture.Width / GLB_Data_Other.MapSize.TileSize);
                        t.texture_location.Y = (t.id - 1) / (GLB_Data_Other.TilesTexture.Width / GLB_Data_Other.MapSize.TileSize);
                        t.walkable = false;

                        GLB_Data_Other.TileMap[1, x, y] = t;

                        x++;

                        if (x > GLB_Data_Other.MapSize.Width - 1)
                        {
                            x = 0;
                            y++;
                        }
                    }

                }

                //ObjectLayer
                startIndex = outie.IndexOf("<ObjectLayer>") + "<ObjectLayer>".Length;
                length = outie.IndexOf("</ObjectLayer>") - startIndex;

                split = outie.Substring(startIndex, length).Split(splitChars);

                x = 0;
                y = 0;

                foreach (string s in split)
                {
                    if (s != "")
                    {
                        t = new Tile();

                        t.grid_location.X = x;
                        t.grid_location.Y = y;

                        t.id = int.Parse(s);

                        t.terrain_type = 0;
                        t.texture_location.X = (t.id - 1) % (GLB_Data_Other.TilesTexture.Width / GLB_Data_Other.MapSize.TileSize);
                        t.texture_location.Y = (t.id - 1) / (GLB_Data_Other.TilesTexture.Width / GLB_Data_Other.MapSize.TileSize);
                        t.walkable = false;

                        GLB_Data_Other.TileMap[2, x, y] = t;

                        x++;

                        if (x > GLB_Data_Other.MapSize.Width - 1)
                        {
                            x = 0;
                            y++;
                        }
                    }

                }

                //CollisionLayer
                startIndex = outie.IndexOf("<CollisionLayer>") + "<CollisionLayer>".Length;
                length = outie.IndexOf("</CollisionLayer>") - startIndex;

                split = outie.Substring(startIndex, length).Split(splitChars);

                x = 0;
                y = 0;

                foreach (string s in split)
                {
                    if (s != "")
                    {
                        t = new Tile();

                        t.grid_location.X = x;
                        t.grid_location.Y = y;

                        t.id = -1;

                        t.terrain_type = 0;
                        t.texture_location.X = 0;
                        t.texture_location.Y = 0;

                        bool walk = false;

                        if (int.Parse(s) == 0)
                            walk = true;

                        if (int.Parse(s) == 2)
                            t.terrain_type = 2;

                        t.walkable = walk;

                        GLB_Data_Other.TileMap[3, x, y] = t;

                        x++;

                        if (x > GLB_Data_Other.MapSize.Width - 1)
                        {
                            x = 0;
                            y++;
                        }
                    }

                }

                GLB_Data_Other.portals = xmap.portals;
                if (GLB_Data_Other.portals == null)
                    GLB_Data_Other.portals = new List<Portal>();

                GLB_Data_Other.portalIndex = xmap.portalIndex;

                GLB_Data_Other.destinations = xmap.destinations;
                if (GLB_Data_Other.destinations == null)
                    GLB_Data_Other.destinations = new List<PortalDestination>();

                GLB_Data_Other.chests = xmap.chests;
                if (GLB_Data_Other.chests == null)
                    GLB_Data_Other.chests = new List<Chest>();

                GLB_Data_Other.npcs = xmap.npcs;
                if (GLB_Data_Other.npcs == null)
                    GLB_Data_Other.npcs = new List<NPC>();

                GLB_Data_Other.fixedCombatNPCs = xmap.fixedCombatNPCs;
                if (GLB_Data_Other.fixedCombatNPCs == null)
                    GLB_Data_Other.fixedCombatNPCs = new List<FixedCombatNPC>();

                GLB_Data_Other.blocks = xmap.blocks;
                if (GLB_Data_Other.blocks == null)
                    GLB_Data_Other.blocks = new List<Block>();

                GLB_Data_Other.switches = xmap.switches;
                if (GLB_Data_Other.switches == null)
                    GLB_Data_Other.switches = new List<Switch>();

                xmap.tile_map = GLB_Data_Other.TileMap;
                xmap.tile_palette = GLB_Data_Other.TilePalette;

                return true;
            }

            return false;
        }
Example #3
0
        private void ResizeMap(int Depth, int Width, int Height)
        {
            // temp copy
            Tile[,,] aux_tile_map       = (Tile[,,]) GLB_Data.TileMap.Clone();
            Tile[,] aux_walk_layer      = new Tile[GLB_Data.MapSize.Width, GLB_Data.MapSize.Height];
            Int32[,] aux_terrain_layer  = new Int32[GLB_Data.MapSize.Width, GLB_Data.MapSize.Height];

            // Make a copy of the walk layer layout  & terrain layer
            for (int id_y = 0; id_y < GLB_Data.MapSize.Height; id_y++)
            {
                for (int id_x = 0; id_x < GLB_Data.MapSize.Width; id_x++)
                {
                    aux_walk_layer[id_x, id_y].walkable = GLB_Data.TileMap[GLB_Data.MapSize.Depth, id_x, id_y].walkable;
                    //aux_terrain_layer[id_x, id_y] = GLB_Data.TerrainLayout[id_x, id_y];
                }
            }

            // Assign new tilemap dimensions
            GLB_Data.MapSize.Depth  = Depth;
            GLB_Data.MapSize.Width  = Width;
            GLB_Data.MapSize.Height = Height;

            GLB_Data.TileMap = new Tile[Depth + Constants.WALK_LAYER, Width, Height];
            GLB_Data.TerrainLayout = new Int32[GLB_Data.MapSize.Width, GLB_Data.MapSize.Height];
            main_form.InitTileMap();
            main_form.ShowCurrentLayer();

            for (int id_z = 0; id_z < GLB_Data.MapSize.Depth; id_z++)
            {
                for (int id_y = 0; id_y < GLB_Data.MapSize.Height; id_y++)
                {
                    for (int id_x = 0; id_x < GLB_Data.MapSize.Width; id_x++)
                    {
                        if ( id_z < aux_tile_map.GetLength(0) &&
                             id_x < aux_tile_map.GetLength(1) &&
                             id_y < aux_tile_map.GetLength(2) )
                        {
                            // Copy existing data
                            GLB_Data.TileMap[id_z, id_x, id_y].id               = aux_tile_map[id_z, id_x, id_y].id;
                            GLB_Data.TileMap[id_z, id_x, id_y].grid_location    = aux_tile_map[id_z, id_x, id_y].grid_location;
                            if (GLB_Data.TileMap[id_z, id_x, id_y].id == Constants.NULL_TILE)
                            {
                                GLB_Data.TileMap[id_z, id_x, id_y].texture_location = new XNA.Point();
                            }
                            else
                            {
                                GLB_Data.TileMap[id_z, id_x, id_y].texture_location = aux_tile_map[id_z, id_x, id_y].texture_location;
                            }
                        }
                    }
                }
            }

            // copy previous walk layout && terrain layout
            for (int id_y = 0; id_y < aux_walk_layer.GetLength(1); id_y++)
            {
                for (int id_x = 0; id_x < aux_walk_layer.GetLength(0); id_x++)
                {
                    if (id_x < GLB_Data.MapSize.Width && id_y < GLB_Data.MapSize.Height)
                    {
                        GLB_Data.TileMap[GLB_Data.TileMap.GetLength(0) - 1, id_x, id_y].walkable = aux_walk_layer[id_x, id_y].walkable;
                        GLB_Data.TerrainLayout[id_x, id_y] = aux_terrain_layer[id_x, id_y];
                    }
                }
            }
        }
Example #4
0
        internal void SetSelectedTile(Tile[,] SelectedTiles, System.Drawing.Rectangle SelectedArea)
        {
            GLB_Data.SelectedTiles = new Tile[SelectedTiles.GetLength(0), SelectedTiles.GetLength(1)];

            // Copy all the selected tiles
            for (int id_y = 0; id_y < SelectedTiles.GetLength(1); id_y++)
            {
                for (int id_x = 0; id_x < SelectedTiles.GetLength(0); id_x++)
                {
                    GLB_Data.SelectedTiles[id_x, id_y].grid_location    = SelectedTiles[id_x, id_y].grid_location;
                    GLB_Data.SelectedTiles[id_x, id_y].id               = SelectedTiles[id_x, id_y].id;
                    GLB_Data.SelectedTiles[id_x, id_y].walkable         = SelectedTiles[id_x, id_y].walkable;
                }
            }
        }
Example #5
0
        internal void SetSelectedTile(Tile SelectedTile, System.Drawing.Rectangle SelectedArea)
        {
            GLB_Data.SelectedTiles = new Tile[1, 1];

            GLB_Data.SelectedTiles[0, 0].grid_location  = SelectedTile.grid_location;
            GLB_Data.SelectedTiles[0, 0].id             = SelectedTile.id;
            GLB_Data.SelectedTiles[0, 0].walkable       = SelectedTile.walkable;

            this.SetSelectedTile(GLB_Data.SelectedTiles, SelectedArea);
        }
Example #6
0
        ///////////////////////////////////////////////////////////////////////////
        // MOUSE UP
        //
        ///////////////////////////////////////////////////////////////////////////
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (marquee_selection)
            {

                if (selected_area.Width == GLB_Data.MapSize.TileSize && selected_area.Height == GLB_Data.MapSize.TileSize)
                {
                    marquee_selection = false;
                    return;
                }
                //Make the the selected tiles one single selection object
                Tile[,] selected_tiles = new Tile[selected_area.Width / GLB_Data.MapSize.TileSize, selected_area.Height / GLB_Data.MapSize.TileSize];

                // Load the selected tiles data
                for (int id_y = 0; id_y < selected_area.Height / GLB_Data.MapSize.TileSize; id_y++)
                {
                    for (int id_x = 0; id_x < selected_area.Width / GLB_Data.MapSize.TileSize; id_x++)
                    {
                        selected_tiles[id_x, id_y] = GLB_Data.TilePalette[(selected_area.X + (id_x * GLB_Data.MapSize.TileSize)) / GLB_Data.MapSize.TileSize, (selected_area.Y + (id_y * GLB_Data.MapSize.TileSize)) / GLB_Data.MapSize.TileSize];
                    }
                }

                parent_form.SetSelectedTile(selected_tiles, selected_area);
            }
        }
Example #7
0
        /////////////////////////////////////////////////////////////////////////////////////////
        // SetImage(FileName, WalkData)
        // Overloaded method, creates the new tile palette but recovers loaded walk palette data
        /////////////////////////////////////////////////////////////////////////////////////////
        internal void SetImage(string FileName, Tile[,] WalkData)
        {
            this.SetImage(FileName);

            for (int id_y = 0; id_y < WalkData.GetLength(1); id_y++)
            {
                for (int id_x = 0; id_x < WalkData.GetLength(0); id_x++)
                {
                    GLB_Data.TilePalette[id_x, id_y].walkable = WalkData[id_x, id_y].walkable;
                }
            }
        }
Example #8
0
        ///////////////////////////////////////////////////////////////////////////
        // SetWalkable
        // Sets the selected tile walkable flag to the desired value
        ///////////////////////////////////////////////////////////////////////////
        public void SetWalkable(Boolean Value)
        {
            //Make the the selected tiles one single selection object
            Tile[,] selected_tiles = new Tile[selected_area.Width / GLB_Data.MapSize.TileSize, selected_area.Height / GLB_Data.MapSize.TileSize];

            // Load the selected tiles data
            for (int id_y = 0; id_y < selected_area.Height / GLB_Data.MapSize.TileSize; id_y++)
            {
                for (int id_x = 0; id_x < selected_area.Width / GLB_Data.MapSize.TileSize; id_x++)
                {
                    GLB_Data.TilePalette[(selected_area.X + (id_x * GLB_Data.MapSize.TileSize)) / GLB_Data.MapSize.TileSize, (selected_area.Y + (id_y * GLB_Data.MapSize.TileSize)) / GLB_Data.MapSize.TileSize].walkable = Value;
                    selected_tiles[id_x, id_y] = GLB_Data.TilePalette[(selected_area.X + (id_x * GLB_Data.MapSize.TileSize)) / GLB_Data.MapSize.TileSize, (selected_area.Y + (id_y * GLB_Data.MapSize.TileSize)) / GLB_Data.MapSize.TileSize];
                }
            }

               parent_form.SetSelectedTile(selected_tiles, selected_area);

            this.Invalidate();
        }