Ejemplo n.º 1
0
        public void SetTileXY(ref int x, ref int y, ref TilePicker tile, ref SelectionArea selection)
        {
            if (selection.IsValid(new PointInt32(x, y)))
            {
                Tile curTile = this.Tiles[x, y];

                if (tile.Tile.IsActive)
                {
                    if (!tile.TileMask.IsActive || (curTile.Type == tile.TileMask.Value && curTile.IsActive))
                    {
                        if (tile.IsEraser)
                        {
                            curTile.IsActive = false;
                        }
                        else
                        {
                            //TODO: i don't like redundant conditionals, but its a fix
                            if (!tile.TileMask.IsActive)
                            {
                                curTile.IsActive = true;
                            }

                            curTile.Type = tile.Tile.Value;

                            // if the tile is solid and there isn't a mask, remove the liquid
                            if (!tile.TileMask.IsActive && WorldSettings.Tiles[curTile.Type].IsSolid && curTile.Liquid > 0)
                            {
                                curTile.Liquid = 0;
                            }
                        }
                    }
                }


                if (tile.Wall.IsActive)
                {
                    if (!tile.WallMask.IsActive || (curTile.Wall == tile.WallMask.Value))
                    {
                        if (tile.IsEraser)
                        {
                            curTile.Wall = 0;
                        }
                        else
                        {
                            curTile.Wall = tile.Wall.Value;
                        }
                    }
                }

                if (tile.Liquid.IsActive && (!curTile.IsActive || !WorldSettings.Tiles[curTile.Type].IsSolid))
                {
                    if (tile.IsEraser)
                    {
                        curTile.Liquid = 0;
                        curTile.IsLava = false;
                    }
                    else
                    {
                        curTile.Liquid = 255;
                        curTile.IsLava = tile.Liquid.IsLava;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void Flood(PointInt32 pt)
        {
            int bitmapWidth  = _world.Header.WorldBounds.W;
            int bitmapHeight = _world.Header.WorldBounds.H;

            int x = pt.X;
            int y = pt.Y;

            tilesChecked = new bool[bitmapWidth * bitmapHeight];

            var originTile = (Tile)_world.Tiles[x, y].Clone();

            LinearFloodFill(ref x, ref y, ref _tilePicker, ref originTile);

            while (ranges.Count > 0)
            {
                //**Get Next Range Off the Queue
                FloodFillRange range = ranges.Dequeue();

                //**Check Above and Below Each Pixel in the Floodfill Range
                int downPxIdx = (bitmapWidth * (range.Y + 1)) + range.StartX; //CoordsToPixelIndex(lFillLoc,y+1);
                int upPxIdx   = (bitmapWidth * (range.Y - 1)) + range.StartX; //CoordsToPixelIndex(lFillLoc, y - 1);
                int upY       = range.Y - 1;                                  //so we can pass the y coord by ref
                int downY     = range.Y + 1;
                for (int i = range.StartX; i <= range.EndX; i++)
                {
                    //*Start Fill Upwards
                    //if we're not above the top of the bitmap and the pixel above this one is within the color tolerance
                    if (range.Y > 0 && (!tilesChecked[upPxIdx]) && CheckTileMatch(ref originTile, ref _world.Tiles[i, upY], ref _tilePicker) && _selection.IsValid(new PointInt32(i, upY)))
                    {
                        LinearFloodFill(ref i, ref upY, ref _tilePicker, ref originTile);
                    }

                    //*Start Fill Downwards
                    //if we're not below the bottom of the bitmap and the pixel below this one is within the color tolerance
                    if (range.Y < (bitmapHeight - 1) && (!tilesChecked[downPxIdx]) && CheckTileMatch(ref originTile, ref _world.Tiles[i, downY], ref _tilePicker) && _selection.IsValid(new PointInt32(i, downY)))
                    {
                        LinearFloodFill(ref i, ref downY, ref _tilePicker, ref originTile);
                    }
                    downPxIdx++;
                    upPxIdx++;
                }

                if (upY < minY)
                {
                    minY = upY;
                }
                if (downY > maxY)
                {
                    maxY = downY;
                }
            }
        }
Ejemplo n.º 3
0
        public override bool MoveTool(TileMouseEventArgs e)
        {
            WriteableBitmap bmp;

            if (_startPoint != null)
            {
                _endPoint = e.Tile;
            }
            CheckDirectionandDraw(e);
            ToolAnchorMode mode = ToolAnchorMode.Center;

            // Line draw preview
            if (_isRightDown && _startPoint != null && _endPoint != null)
            {
                var sp    = (PointInt32)_startPoint;
                var ep    = (PointInt32)_endPoint;
                var delta = ep - sp;
                var rect  = new RectI(new PointInt32(), new SizeInt32(Math.Abs(delta.X) + 1, Math.Abs(delta.Y) + 1));

                // figure out exactly which PreviewMode
                mode = 0;
                if (delta.X < 0)
                {
                    mode += (int)ToolAnchorModeParts.Left;
                }
                else if (delta.X == 0)
                {
                    mode += (int)ToolAnchorModeParts.Center;
                }
                else if (delta.X > 0)
                {
                    mode += (int)ToolAnchorModeParts.Right;
                }

                if (delta.Y < 0)
                {
                    mode += (int)ToolAnchorModeParts.Top;
                }
                else if (delta.Y == 0)
                {
                    mode += (int)ToolAnchorModeParts.Middle;
                }
                else if (delta.Y > 0)
                {
                    mode += (int)ToolAnchorModeParts.Bottom;
                }

                // which direction to draw the line
                var linePnts = new PointInt32[2];
                switch (mode)
                {
                case ToolAnchorMode.TopLeft:     linePnts = new[] { rect.BottomRight, rect.TopLeft }; break;

                case ToolAnchorMode.TopRight:    linePnts = new[] { rect.BottomLeft, rect.TopRight }; break;

                case ToolAnchorMode.BottomLeft:  linePnts = new[] { rect.TopRight, rect.BottomLeft }; break;

                case ToolAnchorMode.BottomRight: linePnts = new[] { rect.TopLeft, rect.BottomRight }; break;

                default:      // has middle or center, order doesn't matter
                    linePnts = new[] { rect.TopLeft, rect.BottomRight };
                    break;
                }

                bmp = new WriteableBitmap(
                    rect.W,
                    rect.H,
                    96,
                    96,
                    System.Windows.Media.PixelFormats.Bgra32,
                    null);

                bmp.Clear();
                foreach (PointInt32 p in WorldRenderer.DrawLine(linePnts[0], linePnts[1]))
                {
                    if (_selection.IsValid(p))
                    {
                        bmp.SetPixel(p.X, p.Y, previewColor);
                    }
                }
            }
            // Single dot
            else
            {
                bmp = new WriteableBitmap(
                    1,
                    1,
                    96,
                    96,
                    System.Windows.Media.PixelFormats.Bgra32,
                    null);

                bmp.Clear();
                bmp.SetPixel(0, 0, previewColor);
            }

            _properties.Image       = bmp;
            _properties.PreviewMode = mode;

            return(false);
        }