예제 #1
0
 void CurrentTile_TileChanged(Tile pTile)
 {
     this.Invalidate();
     this.Refresh();
 }
예제 #2
0
        public void SetTile(Tile pS)
        {
            if (this.mCurrentTile != null) {
                //unplug previous event handler
                this.mCurrentTile.TileChanged -= new Tile.TileChangeDelegate(CurrentTile_TileChanged);
            }

            this.mCurrentTile = pS;
            this.mCurrentTile.TileChanged -= new Tile.TileChangeDelegate(CurrentTile_TileChanged);
            this.mCurrentTile.TileChanged += new Tile.TileChangeDelegate(CurrentTile_TileChanged);
            this.Refresh();
        }
예제 #3
0
 protected void TileChangedHandler(Tile pTile)
 {
     //repaint
     this.OnMapChanged();
 }
예제 #4
0
 private void RegisterTileChangeHandler(Tile pTile)
 {
     //trick to avoid multiple registration on the same instance (always ok to unregister)
     pTile.TileChanged -= new Tile.TileChangeDelegate(TileChangedHandler);
     pTile.TileChanged += new Tile.TileChangeDelegate(TileChangedHandler);
 }
예제 #5
0
        void LibView_SelectedTileChanged(Tile pS)
        {
            ucTileEd.SetTile(pS);

            //should be reccursive to be perfect but will work
            foreach (TabPage vTP in tabMaps.TabPages) {
                foreach (Control vC in vTP.Controls) {
                    if (vC is UcMapEditor) {
                        ((UcMapEditor)vC).CurrentTile = pS;
                    }
                }
            }
        }
예제 #6
0
        public void SetTile(Tile pTile, int pX, int pY)
        {
            //no check

            //unregister event handler of previous sprite
            if (this.mMatrix[pX, pY] != null) {
                MapBucket vOld = this.mMatrix[pX, pY];
                if (vOld.mTile != null) {
                    vOld.mTile.TileChanged -= new Tile.TileChangeDelegate(TileChangedHandler);
                }
            }

            MapBucket vNew = new MapBucket();
            vNew.mTile = pTile;
            this.mMatrix[pX, pY] = vNew;

            RegisterTileChangeHandler(pTile);

            OnMapChanged();
        }
예제 #7
0
        private void btnTilizator_Click(object sender, EventArgs e)
        {
            using (FrmTilizator vFrm = new FrmTilizator()) {
                if (vFrm.ShowDialog(this) == DialogResult.OK) {
                    //Start: create target bitmap with right size
                    Bitmap vTarget = DrawingLogic.CopyAndResize(vFrm.CreateBmp, Tile.WIDTH_PX * vFrm.CreateWidth, Tile.HEIGHT_PX * vFrm.CreateHeight);

                    //map colors
                    Palette vPal = Palette.DEFAULT_PALETTE;
                    DrawingLogic.MapBitmapColorsToPalette(vTarget, vPal);

                    //tilization
                    int vTileNewCount = 0, vTileReusedCount = 0;
                    for (int x = 0; x < vFrm.CreateWidth; x++) {
                        for (int y = 0; y < vFrm.CreateHeight; y++) {
                            Rectangle vTileRect = new Rectangle(x * Tile.WIDTH_PX, y * Tile.HEIGHT_PX, Tile.WIDTH_PX, Tile.HEIGHT_PX);
                            Bitmap vTileBmp = (Bitmap)vTarget.Clone(vTileRect, vTarget.PixelFormat);

                            //make new tile and add/get similar from library
                            Tile vT = new Tile(vTileBmp, vPal);
                            bool vTileAlreadyExisted = false;
                            vT = this.mCurrentMap.ParentProject.mLibraries[0].AddTileWithoutDuplicate(vT, out vTileAlreadyExisted);

                            if (!vTileAlreadyExisted)
                                vTileNewCount++;
                            else
                                vTileReusedCount++;

                            //apply the tile to the map
                            this.mCurrentMap.SetTile(vT, vFrm.CreateLeft + x, vFrm.CreateTop+ y);
                        }
                    }

                    //refresh
                    panMap.Invalidate();

                    ((FrmMain)this.FindForm()).SetStatus("Tilization: generated " + vTileNewCount + " tiles, reused "+vTileReusedCount+" tiles.");
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Reccursive fill algo
        /// </summary>
        /// <param name="pPosition"></param>
        /// <param name="pReplacedTile"></param>
        /// <param name="pNewTile"></param>
        private void RecFillTile(Point pPosition, Tile pReplacedTile, Tile pNewTile)
        {
            if (pPosition.X < 0 || pPosition.X >= this.mCurrentMap.Width ||
                pPosition.Y < 0 || pPosition.Y >= this.mCurrentMap.Height) {
                    return;
            }

            if (this.mCurrentMap[pPosition.X, pPosition.Y] != null
                &&
                !this.mCurrentMap[pPosition.X, pPosition.Y].Equals(pReplacedTile)) {
                return;
            }

            //new we know it's wether null wether same as replaceTile
            this.mCurrentMap.SetTile(pNewTile, pPosition.X, pPosition.Y);

            //reccurse
            RecFillTile(new Point(pPosition.X - 1, pPosition.Y), pReplacedTile, pNewTile);
            RecFillTile(new Point(pPosition.X + 1, pPosition.Y), pReplacedTile, pNewTile);
            RecFillTile(new Point(pPosition.X, pPosition.Y - 1), pReplacedTile, pNewTile);
            RecFillTile(new Point(pPosition.X, pPosition.Y + 1), pReplacedTile, pNewTile);
        }
예제 #9
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            Bitmap vBmp = new Bitmap(Tile.WIDTH_PX, Tile.HEIGHT_PX, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            using (Graphics g = Graphics.FromImage(vBmp)) {
                g.FillRectangle(new SolidBrush(Palette.DEFAULT_PALETTE.mColors[0]), 0, 0, Tile.WIDTH_PX, Tile.HEIGHT_PX);
            }

            Tile vT = new Tile(vBmp, Palette.DEFAULT_PALETTE);
            this.mCurrentLib.AddTile(vT);
        }
예제 #10
0
 public TileViewItem(Tile pS)
 {
     this.mTile = pS;
 }
예제 #11
0
 void TileChanged(Tile pTile)
 {
     lvLibrary.Invalidate();
 }
예제 #12
0
 void CurrentLib_TileDeleted(Tile pTile)
 {
     //TODO
     lvLibrary.Invalidate();
 }
예제 #13
0
        void CurrentLib_TileAdded(Tile pTile)
        {
            TileViewItem vTVI = new TileViewItem(pTile);
            lvLibrary.Items.Add(vTVI);
            pTile.TileChanged -= new Tile.TileChangeDelegate(TileChanged);
            pTile.TileChanged += new Tile.TileChangeDelegate(TileChanged);
            lvLibrary.Invalidate();

            //unselect all and reselect the new one
            foreach (ListViewItem vLVI in this.lvLibrary.Items) {
                vLVI.Selected = false;
            }
            vTVI.Selected = true;
        }