示例#1
0
        private void PlotTiles(BaseCamera camera, int mousex, int mousey)
        {
            var map = MapEditorManager.CurrentMap;
            var rect = MapEditorManager.SelectedTilesRectangle;

            if (!ComponentHelpers.PointInBounds(camera, mousex, mousey))
                return;

            MapPoint plotstart = camera.ScreenSpaceToWorldSpace(new ScreenPoint(mousex, mousey)).ToMapPoint();

            for (int i = 0; i < rect.Width * rect.Height; i++)
            {
                int y = (i / rect.Width);
                int x = (i - (y * rect.Width));

                MapPoint tilepoint = new MapPoint(plotstart.X + x, plotstart.Y + y);
                MapPoint sheetpoint = new MapPoint(rect.X + x, rect.Y + y);

                if (ComponentHelpers.PointInMap(map, tilepoint))
                {
                    var action = new PlaceTileAction(tilepoint.IntX, tilepoint.IntY, MapEditorManager.CurrentLayer, map.GetTileSetValue(sheetpoint));
                    action.Do(context);
                    actionbuffer.Add(action);
                }
            }

            MapEditorManager.OnMapChanged();
        }
示例#2
0
        /// <summary>
        /// Performs a flood fill beginning on the target square
        /// </summary>
        /// <param name="map">The map to perform the operation on</param>
        /// <param name="layer">The layer to perform on</param>
        /// <param name="x">The x location to begin filling</param>
        /// <param name="y">The y location to begin filling</param>
        /// <param name="oldtileid">The ID of the tile to begin replacing.</param>
        /// <param name="newtileid">The ID of the replacement tile.</param>
        private void FloodFill(Map map, MapLayers layer, int x, int y, int oldtileid, int newtileid)
        {
            int value = map.GetLayerValue(new MapPoint(x, y), layer);

            if (value != oldtileid || value == newtileid)
                return;

            var action = new PlaceTileAction(x, y, layer, newtileid);
            action.Do(context);
            tmpactions.Add(action);

            if (x + 1 < MapEditorManager.CurrentMap.MapSize.X)
                this.FloodFill(map, layer, x + 1, y, oldtileid, newtileid);

            if (x - 1 >= 0)
                this.FloodFill(map, layer, x - 1, y, oldtileid, newtileid);

            if (y + 1 < MapEditorManager.CurrentMap.MapSize.Y)
                this.FloodFill(map, layer, x, y + 1, oldtileid, newtileid);

            if (y - 1 >= 0)
                this.FloodFill(map, layer, x, y - 1, oldtileid, newtileid);
        }