示例#1
0
        public void OnMouseUp(MouseEventArgs e, MapToolContext ctx)
        {
            if (isDragging && e.Button == MouseButtons.Left)
            {
                Point tileDelta = GetTileDelta(e, ctx);
                if (IsValidDropPos(tileDelta))
                {
                    // The drop location is valid; delete all tiles to be moved then recreate them in their
                    // new location.
                    foreach (var selectedItem in selectionService.SelectedItems)
                    {
                        mapService.DeleteTile(selectedItem.Bounds.Location);
                    }

                    foreach (var selectedItem in selectionService.SelectedItems)
                    {
                        Point newLocation = selectedItem.Bounds.Location;
                        newLocation.Offset(tileDelta);
                        mapService.AddItem(selectedItem.Item, newLocation);
                    }

                    selectionService.ApplyTileDelta(tileDelta);
                }
                else
                {
                    MessageBox.Show(ctx.Viewport, "This space is already occupied", "Unable to Move Items", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                isDragging = false;
                selectionRenderer.TileOffset = Point.Empty;
            }
        }
示例#2
0
        protected override void OnDragEnd(MouseEventArgs mouseEventArgs, Keys modifierKeys, MapToolContext ctx)
        {
            bool  createCopy = modifierKeys.HasFlag(Keys.Control);
            Point tileDelta  = GetTileDelta(mouseEventArgs.Location, ctx);

            if (IsValidDropPos(tileDelta, ctx.MapEditingService, createCopy))
            {
                using (var trans = historyService.BeginTransaction($"Move {selectionService.SelectedItems.Count()} items"))
                {
                    if (!createCopy)
                    {
                        // The drop location is valid; delete all tiles to be moved then recreate them in their
                        // new location.
                        foreach (var selectedItem in selectionService.SelectedItems)
                        {
                            ctx.MapEditingService.DeleteTile(selectedItem.Bounds.Location, trans);
                        }
                    }

                    foreach (var selectedItem in selectionService.SelectedItems)
                    {
                        Point newLocation = selectedItem.Bounds.Location;
                        newLocation.Offset(tileDelta);
                        ctx.MapEditingService.AddItem(selectedItem.Item, newLocation, trans);
                    }
                }

                selectionService.ApplyTileDelta(tileDelta);
            }
            else
            {
                MessageBox.Show(ctx.Viewport, "This space is already occupied", "Unable to Move Items", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            selectionRenderer.TileOffset = Point.Empty;
        }