Пример #1
0
        /// <summary>
        /// Plots a chunk of tiles within a specified rectangle
        /// </summary>
        /// <param name="rect">The MapPoint based selection rectangle</param>
        private void PlotRectangleChunk(Rectangle rect)
        {
            var camera = this.context.SceneProvider.Cameras["camera1"];
            var map = MapEditorManager.CurrentMap;
            var tilerect = MapEditorManager.SelectedTilesRectangle;
            var plotstart = new MapPoint(rect.X, rect.Y);

            ActionBatchAction<PlaceTileAction> batchactions = new ActionBatchAction<PlaceTileAction>();

            // Keep track of where in the tile sheet we are
            int tilex = 0;
            int totalx = 0;
            int tiley = 0;

            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(tilerect.X + tilex, tilerect.Y + tiley);

                if (ComponentHelpers.PointInMap(map, tilepoint))
                {
                    batchactions.Add(new PlaceTileAction(tilepoint.IntX, tilepoint.IntY,MapEditorManager.CurrentLayer,map.GetTileSetValue(sheetpoint)));
                }

                tilex++;
                totalx++;
                if (tilex >= tilerect.Width || totalx >= rect.Width)
                {
                    if (totalx >= rect.Width)
                    {
                        tiley++;

                        totalx = 0;
                        tilex = 0;
                    }

                    tilex = 0;
                }

                if (tiley >= tilerect.Height)
                    tiley = 0;
            }

            MapEditorManager.ActionManager.PerformAction(batchactions);
            MapEditorManager.OnMapChanged();
        }
Пример #2
0
        private void PutDownGrabbable(Grabbable grabbable, Map map)
        {
            Check.NullArgument<Grabbable>(grabbable, "grabbable");
            Check.NullArgument<Map>(map, "map");

            var startpoint = grabbable.GetStartPoint();

            ActionBatchAction<PlaceTileAction> batchaction = new ActionBatchAction<PlaceTileAction>();

            foreach (var tile in grabbable.Tiles)
            {
                var mappoint = new MapPoint(startpoint.X + tile.Offset.X, startpoint.Y + tile.Offset.Y);

                if (!ComponentHelpers.PointInMap(map, mappoint))
                    continue;

                batchaction.Add(new PlaceTileAction(mappoint.IntX, mappoint.IntY, MapLayers.UnderLayer, tile.Layer1));
                batchaction.Add(new PlaceTileAction(mappoint.IntX, mappoint.IntY, MapLayers.BaseLayer, tile.Layer2));
                batchaction.Add(new PlaceTileAction(mappoint.IntX, mappoint.IntY, MapLayers.MiddleLayer, tile.Layer3));
                batchaction.Add(new PlaceTileAction(mappoint.IntX, mappoint.IntY, MapLayers.TopLayer, tile.Layer4));
            }

            if (grabbable.CreatePoint != grabbable.GetStartPoint())
            {
                MapEditorManager.ActionManager.PerformAction(batchaction);
                batchaction.AddRange(grabbable.MoveClearActions.Actions);
            }
            else
                batchaction.Do(context);
        }
Пример #3
0
        private void GrabbableMoveClearAction(Grabbable g, MapPoint point, Map map)
        {
            // We moved, we haven't cleared, and we should clear tiles under our starting point
            if (point != g.CreatePoint && g.ClearOnMove && !g.Cleared)
            {
                ActionBatchAction<PlaceTileAction> batchaction = new ActionBatchAction<PlaceTileAction>();

                foreach (var tile in g.Tiles)
                {
                    var original = new MapPoint(g.CreatePoint.X + tile.Offset.X, g.CreatePoint.Y + tile.Offset.Y);

                    batchaction.Add(new PlaceTileAction(original.IntX, original.IntY, MapLayers.UnderLayer, -1));
                    batchaction.Add(new PlaceTileAction(original.IntX, original.IntY, MapLayers.BaseLayer, -1));
                    batchaction.Add(new PlaceTileAction(original.IntX, original.IntY, MapLayers.MiddleLayer, -1));
                    batchaction.Add(new PlaceTileAction(original.IntX, original.IntY, MapLayers.TopLayer, -1));
                }

                batchaction.Do(context);
                g.MoveClearActions = batchaction;

                g.Cleared = true;
            }
        }
Пример #4
0
        private Grabbable CreateGrabbable(Rectangle maprect, Map map, bool clearout)
        {
            Check.NullArgument<Map>(map, "map");

            Grabbable grab = new Grabbable(maprect, true);

            int width = maprect.Width + 1;
            int height = maprect.Height + 1;

            ActionBatchAction<PlaceTileAction> batchaction = new ActionBatchAction<PlaceTileAction>();

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    var mappoint = new MapPoint(x + maprect.X, y + maprect.Y);

                    if (!ComponentHelpers.PointInMap(map, mappoint))
                        continue;

                    GrabbedTile tile = new GrabbedTile(new MapPoint(x, y))
                    {
                        Layer1 = map.GetLayerValue(mappoint, MapLayers.UnderLayer),
                        Layer2 = map.GetLayerValue(mappoint, MapLayers.BaseLayer),
                        Layer3 = map.GetLayerValue(mappoint, MapLayers.MiddleLayer),
                        Layer4 = map.GetLayerValue(mappoint, MapLayers.TopLayer)
                    };

                    grab.Tiles.Add(tile);
                }
            }

            return grab;
        }
Пример #5
0
        public void OnMouseDown(object sender, MouseEventArgs ev)
        {
            var camera = this.context.SceneProvider.Cameras["camera1"];

            if(!MapEditorManager.IsMapLoaded || camera == null)
                return;

            if (ComponentHelpers.PointInBounds(camera, ev.X, ev.Y))
            {
                startedinwindow = true;
                actionbuffer = new ActionBatchAction<PlaceTileAction>();
            }
        }
Пример #6
0
        public void OnMouseUp(object sender, MouseEventArgs ev)
        {
            if (!startedinwindow) return;

            MapEditorManager.ActionManager.AddNoPerform(actionbuffer);
            actionbuffer = null;

            startedinwindow = false;
        }