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; } }
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); }
private void DrawGrabbable(SpriteBatch spritebatch, BaseCamera camera, Map map, Grabbable grabbable) { Check.NullArgument<SpriteBatch>(spritebatch, "spritebatch"); Check.NullArgument<BaseCamera>(camera, "camera"); Check.NullArgument<Map>(map, "map"); Check.NullArgument<Grabbable>(grabbable, "grabbable"); var startpoint = grabbable.GetStartPoint(); spritebatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearWrap, DepthStencilState.Default, RasterizerState.CullCounterClockwise, null, camera.TransformMatrix); foreach (var tile in grabbable.Tiles) { Rectangle destrect = new Rectangle((startpoint.IntX + tile.Offset.IntX ) * map.TileSize, (startpoint.IntY + tile.Offset.IntY) * map.TileSize, map.TileSize, map.TileSize); MapPoint mappoint = new MapPoint(startpoint.IntX + tile.Offset.IntX, startpoint.IntY + tile.Offset.IntY); if (!ComponentHelpers.PointInMap(map, mappoint)) continue; PlotLayerTile(spritebatch, map, destrect, tile.Layer1); PlotLayerTile(spritebatch, map, destrect, tile.Layer2); PlotLayerTile(spritebatch, map, destrect, tile.Layer3); PlotLayerTile(spritebatch, map, destrect, tile.Layer4); } spritebatch.End(); }
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; }
public void OnMouseUp(object sender, MouseEventArgs ev) { if (!MapEditorManager.IsMapLoaded || MapEditorManager.IgnoreInput) return; if (this.isselecting) { // They stop selecting, now make the region grabbable var region = ComponentHelpers.GetSelectionRectangle(this.startpoint.ToScreenPoint().ToPoint(), this.endpoint.ToScreenPoint().ToPoint()); var mapregion = new Rectangle(region.X / 32, region.Y / 32, (region.Width / 32) - 1, (region.Height / 32) - 1); var camera = MapEditorManager.GameInstance.Engine.SceneProvider.Cameras["camera1"]; var map = MapEditorManager.CurrentMap; if (camera == null) return; var grabbable = this.CreateGrabbable(mapregion, map, true); this.grabbables.Add(grabbable); this.currentgrabed = grabbable; this.isselecting = false; } else if (this.isgrabbing) { // Place grabbed tile at new location this.isgrabbing = false; } this.startedinwindow = false; }
public void OnMouseDown(object sender, MouseEventArgs ev) { if (!MapEditorManager.IsMapLoaded || MapEditorManager.IgnoreInput || ev.Button != MouseButtons.Left) return; var camera = MapEditorManager.GameInstance.Engine.SceneProvider.Cameras["camera1"]; var map = MapEditorManager.CurrentMap; if (!ComponentHelpers.PointInBounds(camera, ev.X, ev.Y) || camera == null) return; var grabpointmap = camera.ScreenSpaceToWorldSpace (new ScreenPoint(ev.X, ev.Y)).ToMapPoint(); bool ingrabbed = this.IsGrabbableAtPoint(grabpointmap); // We are grabbing and we clicked somewhere out of the grab region if (currentgrabed != null && !ingrabbed) { this.PutDownGrabbable(currentgrabed, map); this.grabbables.Clear(); this.currentgrabed = null; this.isgrabbing = false; } // We aren't grabbing and we grab a grabbable region else if (!this.isgrabbing && ingrabbed) { this.currentgrabed = this.GetGrabbableAtPoint(grabpointmap); var mappoint = camera.ScreenSpaceToWorldSpace(new ScreenPoint(ev.X, ev.Y)).ToMapPoint(); this.graboffset = mappoint - new MapPoint(this.currentgrabed.GetStartPoint()); this.isgrabbing = true; } // We aren't grabbing and we don't click in any grabbable regions if(!this.isgrabbing && !ingrabbed) { if(currentgrabed != null) this.PutDownGrabbable(currentgrabed, map); this.grabbables.Clear(); this.currentgrabed = null; this.isgrabbing = false; // Start selecting this.startpoint = camera.ScreenSpaceToWorldSpace(new ScreenPoint(ev.X, ev.Y)).ToMapPoint(); this.startpoint = this.ConstrainPoint(map, this.startpoint); this.endpoint = new MapPoint(startpoint.X, startpoint.Y); this.isselecting = true; } }
public void OnComponentDeactivated() { var map = MapEditorManager.CurrentMap; if (currentgrabed != null && map != null) this.PutDownGrabbable(currentgrabed, map); this.grabbables.Clear(); this.currentgrabed = null; this.isgrabbing = false; this.isselecting = false; this.startedinwindow = false; }