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); }
/// <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(); }
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; } }