예제 #1
0
        public EditTileDlg(int tileID, CFREETILE freeTile, string f0, string f1, string f2, string f3, string f4, string f5)
        {
            InitializeComponent();
            cbTileFlag.Items.Add(f0);
            cbTileFlag.Items.Add(f1);
            cbTileFlag.Items.Add(f2);
            cbTileFlag.Items.Add(f3);
            cbTileFlag.Items.Add(f4);
            cbTileFlag.Items.Add(f5);
            cbTileFlag.SelectedIndex = freeTile.NTileFlag;

            m_tileID = tileID;
            cbTileFlag.Text = freeTile.NTileFlag.ToString();
            nudPosX.Value = freeTile.MapPt.X;
            nudPosY.Value = freeTile.MapPt.Y;
            nudScaleX.Value = 1;
            nudScaleY.Value = 1;
            nudSourceX.Value = freeTile.SourceRect.Left;
            nudSourceY.Value = freeTile.SourceRect.Top;
            nudSourceWidth.Value = freeTile.SourceRect.Width;
            nudSourceHeight.Value = freeTile.SourceRect.Height;
            nudPOIX.Value = freeTile.AnchorX;
            nudPOIY.Value = freeTile.AnchorY;
            nudRot.Value = (decimal)freeTile.Rotation;
        }
예제 #2
0
        /// <summary>
        /// Handles binary, text, and xml loading depending on which was chosen
        /// 
        ///     <LoadParams>
        /// 
        ///     Save Variables:
        ///     Version number.
        ///     Map Name.
        ///     Is it isometric?
        ///     Total number of tiles.
        ///     Columns.
        ///     Rows.
        ///     Cell Width.
        ///     Cell Height.
        ///     "Layer Name".
        ///     
        ///         <IndividualTiles>
        ///         Map ID.
        ///         Image ID.
        ///         ID (tileset tile ID).
        ///         Flag.
        ///         (Free Placed adds x and y, source rect is used for tileset x and y).
        ///         Tile Width.
        ///         Tile Height.
        ///         Trigger.
        ///         </IndividualTiles>
        ///     
        ///     </SaveParams>
        /// </summary>
        /// <param name="fileName">The file to load from</param>
        /// <returns>void</returns>
        private void OpenFile()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            switch (loadType)
            {
                case (int)LOAD_TYPE.XML:
                    {
                        ofd.FileName = ".xml";
                        ofd.Filter = "XML Files|*.xml";
                        if (DialogResult.OK == ofd.ShowDialog(this))
                        {
                            if (Path.GetExtension(ofd.FileName) == ".xml" ||
                                Path.GetExtension(ofd.FileName) == ".XML")
                            {
                                this.Text = "TED - " + Path.GetFileNameWithoutExtension(ofd.FileName);
                                m_mMap = null;
                                for (int i = 0; i < MAX_NUM_TILESETS && m_tsTileset[i] != null; ++i)
                                {
                                    m_tsTileset[i] = null;
                                    m_tsComponents[i] = null;
                                    m_strTilesetFilenames[i] = null;
                                    m_mTM.ReleaseTexture(m_nCurrImageID[i]);
                                    m_nCurrImageID[i] = -1;
                                    m_clrKey[i] = Color.White;
                                }
                                XmlReaderSettings settings = new XmlReaderSettings();
                                settings.ConformanceLevel = ConformanceLevel.Document;
                                settings.IgnoreComments = true;
                                settings.IgnoreWhitespace = true;

                                using (XmlReader reader = XmlReader.Create(ofd.FileName, settings))
                                {
                                    reader.MoveToContent();
                                    if (reader.Name == m_strVersionNumber)
                                    {
                                        int nNumTiles;
                                        int nNumCols;
                                        int nNumRows;
                                        int nCellWidth;
                                        int nCellHeight;
                                        int nNumTilesets = 0;
                                        int type;
                                        reader.ReadStartElement();
                                        if (reader.Name == "Map")
                                        {
                                            m_strSaveFileName = reader.GetAttribute("Name");
                                            type         = Convert.ToInt32(reader.GetAttribute("Type"));
                                            m_bIsIsometric = Convert.ToBoolean(reader.GetAttribute("Isometric"));
                                            nNumTiles    = Convert.ToInt32(reader.GetAttribute("TotalTiles"));
                                            nNumCols     = Convert.ToInt32(reader.GetAttribute("Columns"));
                                            nNumRows     = Convert.ToInt32(reader.GetAttribute("Rows"));
                                            nCellWidth   = Convert.ToInt32(reader.GetAttribute("CellWidth"));
                                            nCellHeight  = Convert.ToInt32(reader.GetAttribute("CellHeight"));
                                            nNumTilesets = Convert.ToInt32(reader.GetAttribute("NumTilesets"));

                                            // set up the map
                                            if (m_bIsIsometric)
                                            {
                                                m_mMap = new CMap(nCellWidth, nCellHeight, nNumCols, nNumRows, m_nZoomIncrement, true, type, this.Height, Width);
                                                nudMapCellSize.Enabled = false;

                                                nudMapNumCols.Enabled = false;
                                                nudMapNumRows.Enabled = false;
                                                nudMapCellSize.Enabled = false;
                                                nudMapZoom.Enabled = false;
                                                m_bIsIsometric = true;

                                                switch (type)
                                                {
                                                    case (int)IsoType.ISO_DIAMOND:
                                                        m_mMap.NPanelWidth = m_mMap.NNumCols * m_mMap.NCellWidth + m_mMap.NCellWidth;
                                                        m_mMap.NPanelHeight = m_mMap.NNumRows * m_mMap.NCellHeight + m_mMap.NCellHeight;
                                                        splitContainer1.Panel2.AutoScrollMinSize = new Size(0, 0);
                                                        splitContainer1.Panel2.AutoScrollMinSize = new Size(m_mMap.NPanelWidth, m_mMap.NPanelHeight);
                                                        break;
                                                    case (int)IsoType.ISO_SLIDE:
                                                        m_mMap.NPanelWidth = m_mMap.NNumCols * m_mMap.NCellWidth + m_mMap.NCellWidth;
                                                        m_mMap.NPanelHeight = (m_mMap.NNumRows >> 1) * m_mMap.NCellHeight + m_mMap.NCellHeight;
                                                        splitContainer1.Panel2.AutoScrollMinSize = new Size(0, 0);
                                                        splitContainer1.Panel2.AutoScrollMinSize = new Size(m_mMap.NPanelWidth + 100, m_mMap.NPanelHeight + 100);
                                                        break;
                                                    case (int)IsoType.ISO_STAG:
                                                        int tempWidth, tempHeight;
                                                        tempWidth = m_mMap.NPanelWidth = m_mMap.NNumCols * m_mMap.NCellWidth + m_mMap.NCellWidth + 100;
                                                        tempHeight = m_mMap.NPanelHeight = (m_mMap.NNumRows >> 1) * m_mMap.NCellHeight + m_mMap.NCellHeight + m_mMap.GMapGrid.NIsoTopY;
                                                        splitContainer1.Panel2.AutoScrollMinSize = new Size(0, 0);
                                                        splitContainer1.Panel2.AutoScrollMinSize = new Size(tempWidth, m_mMap.NPanelHeight);

                                                        if (tempWidth > splitContainer1.Panel2.ClientSize.Width)
                                                            m_mMap.NPanelWidth = tempWidth;
                                                        if (tempHeight > splitContainer1.Panel2.ClientSize.Height)
                                                            m_mMap.NPanelHeight = tempHeight;

                                                        break;
                                                }
                                            }
                                            else
                                            {
                                                m_mMap = new CMap(nCellWidth, nNumCols, nNumRows, m_nZoomIncrement, false);
                                                nudMapCellSize.Value = nCellWidth;
                                                nudMapCellSize.Enabled = true;
                                                splitContainer1.Panel2.AutoScrollMinSize = new Size(nNumCols * nCellWidth, nNumRows * nCellHeight);
                                                m_mMap.NPanelWidth = splitContainer1.Panel2.Width;
                                                m_mMap.NPanelHeight = splitContainer1.Panel2.Height;
                                                nudMapNumCols.Value = nNumCols;
                                                nudMapNumRows.Value = nNumRows;
                                            }
                                            m_mMap.NZoom = (int)nudMapZoom.Value;
                                            m_mMap.ClrTilesetKey = Color.White;
                                        }

                                        m_nCurrTilesetIndex = 0;

                                        // set up all the tilesets
                                        {
                                            string filename = "";
                                            int imageID;
                                            int red, green, blue;
                                            Color clrKey = Color.White;
                                            int width;
                                            int height;
                                            int cellwidth = 0;
                                            int cellheight = 0;
                                            for (int i = 0; i < tabControl1.TabCount - 1; ++i )
                                            {
                                                tabControl1.TabPages.RemoveAt(i + 1);
                                            }
                                            for (int i = 0; i < nNumTilesets; ++i)
                                            {
                                                reader.ReadStartElement();
                                                if (reader.Name == "Tileset")
                                                {
                                                    filename = reader.GetAttribute("FileName");
                                                    m_strTilesetFilenames[i] = filename;
                                                    red = Convert.ToInt32(reader.GetAttribute("ColorKeyRed"));
                                                    green = Convert.ToInt32(reader.GetAttribute("ColorKeyGreen"));
                                                    blue = Convert.ToInt32(reader.GetAttribute("ColorKeyBlue"));
                                                    width = Convert.ToInt32(reader.GetAttribute("Width"));
                                                    height = Convert.ToInt32(reader.GetAttribute("Height"));
                                                    cellwidth = Convert.ToInt32(reader.GetAttribute("CellWidth"));
                                                    cellheight = Convert.ToInt32(reader.GetAttribute("CellHeight"));
                                                    clrKey = Color.FromArgb(red, green, blue);
                                                    imageID = m_mTM.LoadTexture((filename), Color.FromArgb(clrKey.R, clrKey.G, clrKey.B).ToArgb());
                                                    m_nCurrImageID[i] = imageID;
                                                    bNewTS = true;
                                                    AddTileset(imageID, clrKey, width, height, cellwidth, cellheight, filename);
                                                    bNewTS = false;
                                                    m_clrKey[i] = clrKey;
                                                }
                                            }
                                            Rectangle SourceRect = new Rectangle(0, 0, cellwidth, cellheight);
                                            m_tCurrTile = new CTILE(0, SourceRect, m_nCurrTileFlag, m_nCurrImageID[m_nCurrTilesetIndex], 0, "None", filename);
                                        }
                                        // set up the map tiles
                                        int mapID = 0;
                                        int tileImageID = 0;
                                        int sourceID = 0;
                                        int flag = 0;
                                        int tileX = 0;
                                        int tileY = 0;
                                        int tileWidth = 0;
                                        int tileHeight = 0;
                                        int cost = 0;
                                        float rotation = 0.0f;
                                        string trigger = "";
                                        string fileName = "";
                                        Rectangle srcRect;
                                        m_mMap.NCurrLayer = (int)LAYER.LAYER_ONE;
                                        reader.ReadToFollowing("Layer1");

                                        reader.Read();
                                        m_mMap.ContainsTile[(int)LAYER.LAYER_ONE] = true;
                                        while (reader.Name == "TILE")
                                        {
                                            reader.Read();
                                            mapID = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            fileName = reader.ReadString();
                                            //tileImageID = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            sourceID = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            flag = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            tileX = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            tileY = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            tileWidth = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            tileHeight = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            trigger = reader.ReadString();
                                            reader.Read();
                                            cost = Convert.ToInt32(reader.ReadString());

                                            // find the imageId of the tile's texture
                                            for (int i = 1; i < nNumTilesets + 1; ++i)
                                            {
                                                if (fileName == m_mTM.GetTextureFilename(i))
                                                { tileImageID = i; break; }
                                            }

                                            srcRect = new Rectangle(tileX, tileY, tileWidth, tileHeight);
                                            CTILE tempTile = new CTILE(sourceID, srcRect, flag, tileImageID, cost, trigger, fileName);
                                            tempTile.Trigger = trigger;

                                            m_mMap.AddTile(tempTile, mapID);
                                            reader.Read();
                                            reader.Read();
                                        }
                                        m_mMap.NCurrLayer = (int)LAYER.LAYER_TWO;
                                        reader.ReadToFollowing("Layer2");
                                        reader.Read();
                                        while (reader.Name == "TILE")
                                        {
                                            reader.Read();
                                            mapID = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            fileName = reader.ReadString();
                                            //tileImageID = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            sourceID = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            flag = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            tileX = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            tileY = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            tileWidth = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            tileHeight = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            trigger = reader.ReadString();
                                            reader.Read();
                                            cost = Convert.ToInt32(reader.ReadString());

                                            // find the imageId of the tile's texture, start at [1] (dot is [0]
                                            for (int i = 1; i < nNumTilesets+1; ++i)
                                            {
                                                if (fileName == m_mTM.GetTextureFilename(i))
                                                { tileImageID = i; break; }
                                            }
                                            srcRect = new Rectangle(tileX, tileY, tileWidth, tileHeight);
                                            CTILE tempTile = new CTILE(sourceID, srcRect, flag, tileImageID, cost, trigger, fileName);
                                            tempTile.Trigger = trigger;

                                            m_mMap.AddTile(tempTile, mapID);
                                            reader.Read();
                                            reader.Read();
                                        }
                                        m_mMap.NCurrLayer = (int)LAYER.LAYER_ONE;
                                        if (reader.Name != "FreePlace")
                                        {
                                            reader.ReadToFollowing("FreePlace");
                                        }
                                        reader.Read();
                                        int posX, posY, count = 0;
                                        if (reader.Name == "FREETILE")
                                            m_mMap.ContainsTile[(int)LAYER.LAYER_FREE] = true;
                                        while (reader.Name == "FREETILE")
                                        {
                                            reader.Read();
                                            fileName = reader.ReadString();
                                            //tileImageID = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            tileX = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            tileY = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            flag = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            posX = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            posY = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            tileWidth = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            tileHeight = Convert.ToInt32(reader.ReadString());
                                            reader.Read();
                                            trigger = reader.ReadString();
                                            reader.Read();
                                            rotation = (float)Convert.ToDouble(reader.ReadString());
                                            reader.Read();

                                            // find the imageId of the tile's texture
                                            for (int i = 0; i < nNumTilesets; ++i)
                                            {
                                                if (fileName == m_strTilesetFilenames[i])
                                                { tileImageID = i; break; }
                                            }
                                            srcRect = new Rectangle(tileX, tileY, tileWidth, tileHeight);
                                            CFREETILE tempFree = new CFREETILE(posX, posY, srcRect, flag, tileImageID, rotation, fileName);
                                            tempFree.Trigger = trigger;
                                            // TODO:: save and load rotation
                                            m_mMap.LoadFreePlacedTiles(tempFree, count++);
                                            reader.Read();
                                            //reader.Read();
                                        }
                                    }
                                }
                                m_bDontDraw = false;
                                m_bInPanelTwo = true;
                                m_bInPanelOne = false;
                                return;
                            }
                            else // try again
                            {
                                MessageBox.Show("You have entered an invalid file extension.",
                                                "Failed to load", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                OpenFile();
                            }
                        }
                    }
                    break;
                case (int)LOAD_TYPE.BINARY:
                    {
                        ofd.FileName = ".dat";
                        ofd.Filter = "DATA Files|*.dat";
                        if (DialogResult.OK == ofd.ShowDialog(this))
                        {
                            if (Path.GetExtension(ofd.FileName) == ".dat" ||
                                Path.GetExtension(ofd.FileName) == ".DAT")
                            {
                                m_mMap = null;
                                for (int i = 0; i < MAX_NUM_TILESETS; ++i)
                                {
                                    this.Text = "TED - " + Path.GetFileNameWithoutExtension(ofd.FileName);
                                    m_tsTileset[i] = null;
                                    m_tsComponents[i] = null;
                                    m_strTilesetFilenames[i] = null;
                                    m_nCurrImageID[i] = -1;
                                    m_clrKey[i] = Color.White;
                                }
                                return;
                            }
                            else // try again
                            {
                                MessageBox.Show("You have entered an invalid file extension.",
                                                "Failed to load", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                OpenFile();
                            }
                        }
                    }
                    break;
            }
        }
예제 #3
0
 private void SortFreePlaced(CFREETILE tileToSort, int index)
 {
     if (tileToSort.MapPt.Y < m_tFreePlaced[index].MapPt.Y)
     {
         m_tFreePlaced[index + 1] = m_tFreePlaced[index];
         m_tFreePlaced[index] = tileToSort;
         if (--index < 0)
             return;
         SortFreePlaced(tileToSort, index);
     }
 }
예제 #4
0
 public void LoadFreePlacedTiles(CFREETILE freeTile, int index)
 {
     m_tFreePlaced[index] = freeTile;
     ++m_nTotNumFreeTiles;
 }
예제 #5
0
 public void AddMarqueeFreePlaceTile(CTILE tile, int posX, int posY, Rectangle srcRect)
 {
     for (int i = 0; i < MAX_NUM_FREETILES; ++i)
     {
         if (m_tFreePlaced[i] == null)
         {
             CFREETILE tNewFree = new CFREETILE(posX, posY, srcRect, tile.NTileFlag, tile.ImageID, tile.FileName);
             m_tFreePlaced[i] = tNewFree;
             m_bContainsTile[m_nCurrLayer] = true;
             return;
         }
     }
 }
예제 #6
0
 public void AddFreePlacedTile(CTILE tile, int posX, int posY, float rotation)
 {
     // sort the tiles by their y coordinate, so that when rendered,
     // they will render top to bottom (lowest y first)
     ++m_nTotNumFreeTiles;
     m_bContainsTile[m_nCurrLayer] = true;
     CFREETILE tNewFree = new CFREETILE(posX, posY, tile.SourceRect, tile.NTileFlag, tile.ImageID, rotation, tile.FileName);
     if (m_nTotNumFreeTiles - 1 == 0)
     {
         m_tFreePlaced[0] = tNewFree;
         return;
     }
     else if (tNewFree.MapPt.Y > m_tFreePlaced[m_nTotNumFreeTiles - 2].MapPt.Y)
     {
         m_tFreePlaced[m_nTotNumFreeTiles - 1] = tNewFree;
         return;
     }
     SortFreePlaced(tNewFree, m_nTotNumFreeTiles - 2);
 }