Exemple #1
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;
            }
        }
Exemple #2
0
        void impTsDlg_CreatePushed(object sender, EventArgs e)
        {
            m_bInPanelOne = true; m_bDontDraw = false;

            ImportTilesetDlg impDlg = sender as ImportTilesetDlg;
            if (impDlg != null)
            {
                // replacing a tileset
                if (!m_bAddTileset)
                {
                    // set up first selected default tile
                    Rectangle srcRect = new Rectangle(0, 0, impDlg.Ts.NCellWidth, impDlg.Ts.NCellHeight);
                    m_tCurrTile = new CTILE(0, srcRect, m_nCurrTileFlag, m_nCurrImageID[m_nCurrTilesetIndex], 0, "None", Path.GetFullPath(impDlg.StrFileName));

                    m_mMap.ClrTilesetKey = impDlg.ClrKey;
                    m_clrKey[m_nCurrTilesetIndex] = impDlg.ClrKey;
                    m_mMap.NZoom = (int)nudMapZoom.Value;

                    m_strTilesetFilenames[m_nCurrTilesetIndex] = Path.GetFullPath(impDlg.StrFileName);

                    m_nCurrImageID[m_nCurrTilesetIndex] = impDlg.Ts.NTilesetImageID;
                    AddTileset(impDlg.Ts.NTilesetImageID, impDlg.ClrKey, impDlg.Ts.NTilesetWidth, impDlg.Ts.NTilesetHeight,
                                            impDlg.Ts.NCellWidth, impDlg.Ts.NCellHeight, m_strTilesetFilenames[m_nCurrTilesetIndex]);
                    m_tsTileset[m_nCurrTilesetIndex].NCurrLayer = m_nCurrLayer;

                    m_impTsDlg.Close();

                    nudMapNumRows.Enabled = false;
                    nudMapNumCols.Enabled = false;
                    nudMapCellSize.Enabled = false;
                }
                // adding a new tileset
                else
                {
                    // set up default starting selected tile
                    Rectangle SourceRect = new Rectangle(0, 0, impDlg.Ts.NCellWidth, impDlg.Ts.NCellHeight);
                    m_tCurrTile = new CTILE(0, SourceRect, m_nCurrTileFlag, impDlg.Ts.NTilesetImageID, 0, "None", Path.GetFullPath(impDlg.StrFileName));
                    bNewTS = true;
                    AddTileset(impDlg.Ts.NTilesetImageID, impDlg.ClrKey, impDlg.Ts.NTilesetWidth, impDlg.Ts.NTilesetHeight,
                                            impDlg.Ts.NCellWidth, impDlg.Ts.NCellHeight, impDlg.StrFileName);
                    m_tsTileset[m_nCurrTilesetIndex].NCurrLayer = m_nCurrLayer;
                    bNewTS = false;
            //                     string tempString = Path.GetFileName(impDlg.StrFileName);
            //
            //                     if (tempString[0] != 'V' || tempString[1] != 'G' || tempString[2] != '_')
            //                     {
            //                         tempString = tempString.Insert(0, "VG_");
            //                     }
                    m_strTilesetFilenames[m_nCurrTilesetIndex] = Path.GetFullPath(impDlg.StrFileName);

                    m_nCurrImageID[m_nCurrTilesetIndex] = impDlg.Ts.NTilesetImageID;
                    m_clrKey[m_nCurrTilesetIndex] = impDlg.ClrKey;

                    m_impTsDlg.Close();
                }
            }
        }
Exemple #3
0
 public CTILE(CTILE tile)
 {
     CTILE newTILE = new CTILE();
     this.AnchorX = tile.AnchorX;
     this.AnchorY = tile.AnchorY;
     this.ImageID = tile.ImageID;
     this.NSourceID = tile.NSourceID;
     this.NTileFlag = tile.NTileFlag;
     this.SourceRect = tile.SourceRect;
     this.Trigger = tile.Trigger;
     this.m_nCost = tile.Cost;
     this.FileName = tile.FileName;
 }
Exemple #4
0
 void stDlg_AcceptPushed(object sender, EventArgs e)
 {
     SetTriggerDlg stDlg = sender as SetTriggerDlg;
     if (stDlg.Changes)
     {
         m_bChangesMade = true;
         switch (m_nCurrLayer)
         {
             case (int)LAYER.LAYER_ONE:
                 m_mMap.TMapTiles[m_nCurrTileEditID].Trigger = stDlg.Trigger;
                 m_tCurrTile = new CTILE();
                 m_tCurrTile = m_tsTileset[m_nCurrTilesetIndex].TTilesetTiles[m_tsTileset[m_nCurrTilesetIndex].NCurrSelectedTile];
                 break;
             case (int)LAYER.LAYER_TWO:
                 m_mMap.TMapTilesLayer2[m_nCurrTileEditID].Trigger = stDlg.Trigger;
                 m_tCurrTile = new CTILE();
                 m_tCurrTile = m_tsTileset[m_nCurrTilesetIndex].TTilesetTiles[m_tsTileset[m_nCurrTilesetIndex].NCurrSelectedTile];
                 break;
             case (int)LAYER.LAYER_FREE:
                 m_mMap.FreePlaced[m_nCurrTileEditID].Trigger = stDlg.Trigger;
                 break;
         }
     }
     stDlg.Close();
 }
Exemple #5
0
 private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
 {
     if (tabControl1.SelectedIndex != 0 && !m_bJustClick)
     {
         m_nCurrTilesetIndex = tabControl1.SelectedIndex - 1;
         while (m_tsTileset[m_nCurrTilesetIndex] == null)
         {
             m_nCurrTilesetIndex++;
         }
         int selectedTile = m_tsTileset[m_nCurrTilesetIndex].NCurrSelectedTile;
         int newTileFlag = m_tsTileset[m_nCurrTilesetIndex].TTilesetTiles[selectedTile].NTileFlag;
         int left = (selectedTile % m_tsTileset[m_nCurrTilesetIndex].NNumCols) * m_tsTileset[m_nCurrTilesetIndex].NCellWidth;
         int top = (selectedTile / m_tsTileset[m_nCurrTilesetIndex].NNumCols) * m_tsTileset[m_nCurrTilesetIndex].NCellHeight;
         Rectangle sRect = new Rectangle(left, top, m_tsTileset[m_nCurrTilesetIndex].NCellWidth, m_tsTileset[m_nCurrTilesetIndex].NCellHeight);
         m_tCurrTile = new CTILE(selectedTile, sRect, newTileFlag, m_nCurrImageID[m_nCurrTilesetIndex], 0, "None", m_tsTileset[m_nCurrTilesetIndex].StrFilePath);
         m_bDrawMarquee = m_tsTileset[m_nCurrTilesetIndex].DrawMarquee;
         m_bMarqueeSelect = m_bDrawMarquee;
         if (m_bDrawMarquee)
         {
             m_tMarqueeTiles = m_tsTileset[m_nCurrTilesetIndex].MarqueeTiles;
         }
         splitContainer1.Panel1.VerticalScroll.Value = -m_tsComponents[m_nCurrTilesetIndex].m_nScrollY;
         splitContainer1.Panel1.HorizontalScroll.Value = -m_tsComponents[m_nCurrTilesetIndex].m_nScrollX;
         splitContainer1.Panel1.VerticalScroll.Value = -m_tsComponents[m_nCurrTilesetIndex].m_nScrollY;
         splitContainer1.Panel1.HorizontalScroll.Value = -m_tsComponents[m_nCurrTilesetIndex].m_nScrollX;
         nudAdjustRectX.Maximum = m_tsComponents[m_nCurrTilesetIndex].nudImageWidth.Value;
         nudAdjustRectY.Maximum = m_tsComponents[m_nCurrTilesetIndex].nudImageHeight.Value;
     }
     m_bInPanelOne = true;
     m_bDontDraw = false;
     m_bJustClick = false;
 }
Exemple #6
0
        private void splitContainer1_Panel1_MouseClick(object sender, MouseEventArgs e)
        {
            m_bPanel2HasFocus = false;
            if ( m_nCurrTilesetIndex != -1 && m_tsTileset[m_nCurrTilesetIndex] != null && m_bSingleSelect)
            {
                if (e.X <= m_tsTileset[m_nCurrTilesetIndex].NWidth+m_nTilesetXoffset && e.Y > m_nTilesetYoffset && e.Y < m_tsTileset[m_nCurrTilesetIndex].NHeight + m_nTilesetYoffset)
                {
                    m_bDrawSelRectScroll = false;
                    m_bDontDraw = false;
                    Point click = new Point(e.X, e.Y);
                    click.X += (-m_nTilesetXoffset + (-splitContainer1.Panel1.AutoScrollPosition.X));
                    click.Y += (-m_nTilesetYoffset + (-splitContainer1.Panel1.AutoScrollPosition.Y));
                    Point anchor = click;

                    click.X = (click.X / m_tsTileset[m_nCurrTilesetIndex].NCellWidth);
                    click.Y = (click.Y / m_tsTileset[m_nCurrTilesetIndex].NCellHeight);
                    m_tsTileset[m_nCurrTilesetIndex].NCurrSelectedTile = click.Y * m_tsTileset[m_nCurrTilesetIndex].NNumCols + click.X;

                    // add a tile from the tile set to the currently selected
                    int nSourceID = m_tsTileset[m_nCurrTilesetIndex].NCurrSelectedTile;
                    int newTileFlag = m_tsTileset[m_nCurrTilesetIndex].TTilesetTiles[nSourceID].NTileFlag;
                    int left = (nSourceID % m_tsTileset[m_nCurrTilesetIndex].NNumCols) * m_tsTileset[m_nCurrTilesetIndex].NCellWidth;
                    int top = (nSourceID / m_tsTileset[m_nCurrTilesetIndex].NNumCols) * m_tsTileset[m_nCurrTilesetIndex].NCellHeight;
                    Rectangle sRect = new Rectangle(left, top, m_tsTileset[m_nCurrTilesetIndex].NCellWidth, m_tsTileset[m_nCurrTilesetIndex].NCellHeight);
                    m_tCurrTile = new CTILE(nSourceID, sRect, newTileFlag, m_nCurrImageID[m_nCurrTilesetIndex], 0, "None", m_tsTileset[m_nCurrTilesetIndex].StrFilePath);
                    tbAnchorX.Text = m_tsTileset[m_nCurrTilesetIndex].TTilesetTiles[nSourceID].AnchorX.ToString();
                    tbAnchorY.Text = m_tsTileset[m_nCurrTilesetIndex].TTilesetTiles[nSourceID].AnchorY.ToString();
                    m_tsComponents[m_nCurrTilesetIndex].cbTileFlag.SelectedIndex = newTileFlag;
                    m_tsTileset[m_nCurrTilesetIndex].DrawMarquee = false;

                    lblTileID.Text = m_strSelectedID + nSourceID.ToString();
                    if (m_bFreePlace)
                    {
                        m_ptMouseFreePlacePos = e.Location;
                        nudAdjustRectHeight.Value = 1;
                        nudAdjustRectWidth.Value = 1;
                        nudAdjustRectX.Value = 1;
                        nudAdjustRectY.Value = 1;
                    }
                    if (MouseButtons.Right == e.Button)
                    {
                        m_tCurrTile.AnchorX = anchor.X - left;
                        m_tCurrTile.AnchorY = anchor.Y - top;
                        m_tsTileset[m_nCurrTilesetIndex].TTilesetTiles[nSourceID].AnchorX = anchor.X - left;
                        m_tsTileset[m_nCurrTilesetIndex].TTilesetTiles[nSourceID].AnchorY = anchor.Y - top;
                        tbAnchorX.Text = m_tCurrTile.AnchorX.ToString();
                        tbAnchorY.Text = m_tCurrTile.AnchorY.ToString();
                    }
                    m_tsTileset[m_nCurrTilesetIndex].SetSelectionRect();

                    Point pt = m_tsTileset[m_nCurrTilesetIndex].GetTLPointOfSelectedTile();
                    pt.X += 10; pt.Y += 10;
                    nudTileCost.Location = pt;
                    nudTileCost.Value = m_tsTileset[m_nCurrTilesetIndex].TTilesetTiles[nSourceID].Cost;
                }
            }
        }
Exemple #7
0
        private void splitContainer1_Panel1_MouseUp(object sender, MouseEventArgs e)
        {
            if (m_bDrawMarquee)
            {
                m_bDontDraw = false;
                m_bSingleSelect = true;
                m_bIsDraggingMarquee = false;
                int swap;
                if (m_ptBottomRight.X < m_ptTopLeft.X)
                {
                    swap = m_ptTopLeft.X;
                    m_ptTopLeft.X = m_ptBottomRight.X;
                    m_ptBottomRight.X = swap;
                }
                if (m_ptBottomRight.Y < m_ptTopLeft.Y)
                {
                    swap = m_ptTopLeft.Y;
                    m_ptTopLeft.Y = m_ptBottomRight.Y;
                    m_ptBottomRight.Y = swap;
                }
                int width = 0;
                int height = 0;
                int left = 0;
                int top = 0;
                if (m_bIsIsometric)
                {
                    // add a tile from the tile set to the currently selected
                    left = m_ptTopLeft.X;
                    top = m_ptTopLeft.Y;
                    width = m_ptBottomRight.X - left;
                    height = m_ptBottomRight.Y - top;
                    Rectangle sRect = new Rectangle(left, top, width, height);
                    m_tCurrTile = new CTILE(0, sRect, 0, m_nCurrImageID[m_nCurrTilesetIndex], 0, "None", m_tsTileset[m_nCurrTilesetIndex].StrFilePath);
                    //tbAnchorX.Text = m_tsTileset[m_nCurrTilesetIndex].TTilesetTiles[nSourceID].AnchorX.ToString();
                    //tbAnchorY.Text = m_tsTileset[m_nCurrTilesetIndex].TTilesetTiles[nSourceID].AnchorY.ToString();
                    m_tsComponents[m_nCurrTilesetIndex].cbTileFlag.SelectedIndex = 0;
                }
                else
                {
                    int startCol = m_ptTopLeft.X / m_tsTileset[m_nCurrTilesetIndex].GTilesetGrid.NCellWidth;
                    int sourceX = startCol * m_tsTileset[m_nCurrTilesetIndex].GTilesetGrid.NCellWidth;
                    int endCol = m_ptBottomRight.X / m_tsTileset[m_nCurrTilesetIndex].GTilesetGrid.NCellWidth;

                    int startRow = m_ptTopLeft.Y / m_tsTileset[m_nCurrTilesetIndex].GTilesetGrid.NCellHeight;
                    int sourceY = startRow * m_tsTileset[m_nCurrTilesetIndex].GTilesetGrid.NCellHeight;
                    int endRow = m_ptBottomRight.Y / m_tsTileset[m_nCurrTilesetIndex].GTilesetGrid.NCellHeight;

                    int totalNumTiles = ((endCol + 1) - startCol) * ((endRow + 1) - startRow);
                    m_nMarqueeNumCols = (endCol + 1) - startCol;
                    int currCol = startCol;
                    int currRow = startRow;

                    int ID = currRow * m_tsTileset[m_nCurrTilesetIndex].NNumCols + currCol;
                    int startID = ID;
                    int count = 0;

                    m_tMarqueeTiles = new CTILE[totalNumTiles];
                    m_tsTileset[m_nCurrTilesetIndex].MarqueeTiles = new CTILE[totalNumTiles];
                    for (int i = 0; i < totalNumTiles; ++i)
                    {
                        Rectangle sRect = new Rectangle(sourceX, sourceY, m_tsTileset[m_nCurrTilesetIndex].GTilesetGrid.NCellWidth, m_tsTileset[m_nCurrTilesetIndex].GTilesetGrid.NCellHeight);
                        m_tMarqueeTiles[i] = new CTILE(ID, sRect, m_tsTileset[m_nCurrTilesetIndex].TTilesetTiles[ID].NTileFlag, m_nCurrImageID[m_nCurrTilesetIndex], 0, "None", m_tsTileset[m_nCurrTilesetIndex].StrFilePath);
                        m_tsTileset[m_nCurrTilesetIndex].MarqueeTiles[i] = m_tMarqueeTiles[i];
                        currCol++;
                        ID++;
                        if (currCol > endCol)
                        {
                            count++;
                            currCol = startCol;
                            currRow++;
                            ID = startID + (m_tsTileset[m_nCurrTilesetIndex].NNumCols * count);
                            sourceY = currRow * m_tsTileset[m_nCurrTilesetIndex].GTilesetGrid.NCellHeight;
                        }
                        sourceX = currCol * m_tsTileset[m_nCurrTilesetIndex].GTilesetGrid.NCellWidth;
                    }
                    m_tsTileset[m_nCurrTilesetIndex].SetMarqueeSelectionRect(m_tMarqueeTiles[0].NSourceID, m_nMarqueeNumCols, (endRow + 1) - startRow);
                    m_tsComponents[m_nCurrTilesetIndex].cbTileFlag.SelectedIndex = m_tMarqueeTiles[0].NTileFlag;
                }
                m_bJustClick = true;
                if (width > 0 && width < 1025)
                {
                    nudAdjustRectWidth.Value = width;
                }
                if (height > 0 && height < 1025)
                {
                    nudAdjustRectHeight.Value = height;
                }
                if (left > 0 && left < (int)nudAdjustRectX.Maximum)
                {
                    nudAdjustRectX.Value = left;
                }
                if (top > 0 && top < (int)nudAdjustRectY.Maximum)
                {
                    nudAdjustRectY.Value = top;
                }
                m_bJustClick = false;
            }
        }
Exemple #8
0
        private void removeCurrentTilesetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tabControl1.TabCount > 1)
            {
                if (DialogResult.Yes == MessageBox.Show(this, "Are you sure you want to remove the " + m_strTilesetFilenames[m_nCurrTilesetIndex] + " tile set?",
                        "Close tile set...", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning))
                {
                    m_tsTileset[m_nCurrTilesetIndex] = null;
                    int imageIDtoRemove = m_nCurrImageID[m_nCurrTilesetIndex];
                    m_nCurrImageID[m_nCurrTilesetIndex] = -1;
                    m_strTilesetFilenames[m_nCurrTilesetIndex] = null;

                    for (int i = 0; i < m_mMap.NTotalNumTiles; ++i )
                    {
                        if (m_mMap.TMapTiles[i] != null && m_mMap.TMapTiles[i].ImageID == imageIDtoRemove)
                        {
                            m_mMap.TMapTiles[i] = new CTILE();
                        }
                        if (m_mMap.TMapTilesLayer2[i] != null && m_mMap.TMapTilesLayer2[i].ImageID == imageIDtoRemove)
                        {
                            m_mMap.TMapTilesLayer2[i] = new CTILE();
                        }
                    }
                    for (int i = 0; i < m_mMap.FreePlaced.GetLength(0); ++i )
                    {
                        if (m_mMap.FreePlaced[i] == null)
                            break;
                        if (m_mMap.FreePlaced[i].ImageID == imageIDtoRemove)
                        {
                            m_mMap.FreePlaced[i] = null;
                            --m_mMap.TotNumFreeTiles;
                        }
                    }

                    tabControl1.TabPages.RemoveAt(m_nCurrTilesetIndex + 1);
                    if (tabControl1.TabCount > 0 && m_tsTileset[0] == null)
                    {
                        m_nCurrTilesetIndex = 0;
                        m_tsTileset[0] = m_tsTileset[1];
                        m_tsTileset[1] = null;
                        m_nCurrImageID[0] = m_nCurrImageID[1];
                        m_nCurrImageID[1] = -1;
                        m_tsComponents[0] = m_tsComponents[1];
                        m_tsComponents[1] = null;
                        m_nCurrImageID[0] = m_nCurrImageID[1];
                        m_nCurrImageID[1] = -1;
                        m_strTilesetFilenames[0] = m_strTilesetFilenames[1];
                        m_strTilesetFilenames[1] = null;
                    }
                    tabControl1.SelectedIndex = tabControl1.TabCount - 1;
                    m_mTM.ReleaseTexture(imageIDtoRemove);
                }
            }
            if (tabControl1.TabCount == 1)
            {
                m_nCurrTilesetIndex = -1;
                m_tCurrTile = new CTILE();
                btnAddTileset.Visible = true;
            }
        }
Exemple #9
0
 private void ResetCurrTile()
 {
     // set up default starting selected tile
     if (m_tsTileset[m_nCurrTilesetIndex] != null)
         m_tCurrTile = new CTILE(m_tsTileset[m_nCurrTilesetIndex].TTilesetTiles[m_tsTileset[m_nCurrTilesetIndex].NCurrSelectedTile]);
     else
     {
         m_tCurrTile = new CTILE();
         m_tCurrTile.NSourceID = 0;
         m_tCurrTile.SourceRect = new Rectangle(0, 0, 64, 45);
         m_tCurrTile.NTileFlag = 0;
         m_tCurrTile.ImageID = m_nCurrImageID[m_nCurrTilesetIndex];
     }
     //lblTileID.Text = "Tile ID = " + m_nCurrImageID[m_nCurrTilesetIndex].ToString();
 }
Exemple #10
0
 public void SetupTilesetNotSquare(int tileFlag, int imageID)
 {
     int srcX = 0, srcY = 0;
     m_tTilesetTiles = new CTILE[m_nTotalNumTiles];
     for (int y = 0; y < m_nNumRows; ++y )
     {
         for (int x = 0; x < m_nNumCols; ++x )
         {
             int id = y * m_nNumCols + x;
             srcX = id % m_nNumCols * m_nCellWidth;
             srcY = m_nCellHeight * y;
             Rectangle srcRect = new Rectangle(srcX, srcY, m_nCellWidth, m_nCellHeight);
             m_tTilesetTiles[id] = new CTILE(id, srcRect, tileFlag, imageID, 0, "None", m_strFilePath);
         }
     }
 }
Exemple #11
0
 private void nudAdjustRectY_ValueChanged(object sender, EventArgs e)
 {
     if (!m_bJustClick)
     {
         int left = m_ptTopLeft.X;
         int top = m_ptTopLeft.Y = (int)nudAdjustRectY.Value;
         int width = m_ptBottomRight.X - left;
         int height = m_ptBottomRight.Y - top;
         if (height < 0)
             return;
         nudAdjustRectHeight.Value = height;
         Rectangle sRect = new Rectangle(left, top, width, height);
         m_tCurrTile = new CTILE(0, sRect, 0, m_nCurrImageID[m_nCurrTilesetIndex], 0, "None", m_tsTileset[m_nCurrTilesetIndex].StrFilePath);
         m_bDontDraw = false;
     }
 }
Exemple #12
0
        public void SetupTileset(int tileFlag, int imageID)
        {
            m_tTilesetTiles = new CTILE[m_nTotalNumTiles];
            for (int id = 0; id < m_nTotalNumTiles; ++id)
            {
                int x = id % m_nNumCols * m_nCellWidth;
                int y = id / m_nNumCols * m_nCellWidth;

                Rectangle srcRect = new Rectangle( x, y, m_nCellWidth, m_nCellHeight);
                m_tTilesetTiles[id] = new CTILE(id, srcRect, tileFlag, imageID, 0, "None", m_strFilePath);
            }
        }
Exemple #13
0
 public void NewMapTileArray()
 {
     int i = 0;
     // if we already have a first (and second) layer
     if (m_tMapTilesLayer1 != null)
     {
         //////////////////////////////////////////////////////////////////////////
         // First layer
         CTILE[] tempIDs = m_tMapTilesLayer1;
         m_tMapTilesLayer1 = new CTILE[m_nTotalNumTiles];
         int lengthNew = m_tMapTilesLayer1.GetLength(0);
         int lengthOld = tempIDs.GetLength(0);
         if (lengthNew > lengthOld)
         {
             for (i = lengthOld; i < lengthNew; ++i)
                 m_tMapTilesLayer1[i] = null;// new CTILE();
             for (i = 0; i < lengthOld; ++i)
                 m_tMapTilesLayer1[i] = tempIDs[i];
         }
         else
         {
             int length = m_tMapTilesLayer1.GetLength(0);
             for (i = 0; i < lengthNew; ++i)
                 m_tMapTilesLayer1[i] = null;// new CTILE();
             for (i = 0; i < m_nTotalNumTiles; ++i)
                 m_tMapTilesLayer1[i] = tempIDs[i];
         }
         //////////////////////////////////////////////////////////////////////////
         // Second layer
         CTILE[] tempIDsLayer2 = m_tMapTilesLayer2;
         m_tMapTilesLayer2 = new CTILE[m_nTotalNumTiles];
         lengthNew = m_tMapTilesLayer2.GetLength(0);
         lengthOld = tempIDsLayer2.GetLength(0);
         if (lengthNew > lengthOld)
         {
             for (i = lengthOld; i < lengthNew; ++i)
                 m_tMapTilesLayer2[i] = new CTILE();
             for (i = 0; i < lengthOld; ++i)
                 m_tMapTilesLayer2[i] = tempIDsLayer2[i];
         }
         else
         {
             for (i = 0; i < lengthNew; ++i)
                 m_tMapTilesLayer2[i] = new CTILE();
             for (i = 0; i < m_nTotalNumTiles; ++i)
                 m_tMapTilesLayer2[i] = tempIDsLayer2[i];
         }
     }
     else
     {
         // First layer
         m_tMapTilesLayer1 = new CTILE[m_nTotalNumTiles];
         for ( i = 0; i < m_nTotalNumTiles; ++i)
             m_tMapTilesLayer1[i] = null;// new CTILE();
         // Second layer
         m_tMapTilesLayer2 = new CTILE[m_nTotalNumTiles];
         for (i = 0; i < m_nTotalNumTiles; ++i)
             m_tMapTilesLayer2[i] = null;
     }
 }
Exemple #14
0
 public void AddTile(CTILE tile, int tileID)
 {
     CTILE addTile = new CTILE();
     addTile = tile;
     if (tileID < m_nTotalNumTiles)
     {
         if (m_nCurrLayer == (int)LAYER.LAYER_ONE)
         {
             m_tMapTilesLayer1[tileID] = addTile;
             m_bContainsTile[(int)LAYER.LAYER_ONE] = true;
         }
         else
         {
             m_tMapTilesLayer2[tileID] = addTile;
             m_bContainsTile[(int)LAYER.LAYER_TWO] = true;
         }
     }
 }
Exemple #15
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;
         }
     }
 }
Exemple #16
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);
 }