コード例 #1
0
 public void OnMouseUp(MouseEventArgs e, MapToolContext ctx)
 {
     if (e.Button == MouseButtons.Left)
     {
         isPanning = false;
     }
 }
コード例 #2
0
ファイル: MoveTool.cs プロジェクト: MadDanEccles/NHSE
        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;
            }
        }
コード例 #3
0
        public bool ModifySelection(Point controlPt, MapToolContext ctx, SelectionAction action)
        {
            bool selectionChanged;

            if (TryGetItemFromViewportPt(controlPt, ctx, out var item, out var itemTileBounds))
            {
                Item itemCopy = new Item(item.RawValue);
                Debug.Assert(itemCopy.IsRoot);
                SelectedItem selectedItem = new SelectedItem(itemCopy, itemTileBounds);

                switch (action)
                {
                case SelectionAction.Add:
                    selectionChanged = selectedItems.Add(selectedItem);
                    break;

                case SelectionAction.Remove:
                    selectionChanged = selectedItems.Remove(selectedItem);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(action), action, null);
                }
                if (selectionChanged)
                {
                    OnSelectionChanged();
                }
            }
コード例 #4
0
        protected override void CalculateResult(MapToolContext ctx, Rectangle marqueeBounds, out ItemFieldFragment fragment, out string hint)
        {
            Rectangle tileRect = ctx.ToTiles(marqueeBounds);

            fragment = new ItemFieldFragment();
            segmentLayout.CalculateResult(ctx, tileRect, fragment);
            hint = "";  //droppedItemCount > 0 ? $"{droppedItemCount} Items" : "-";
        }
コード例 #5
0
ファイル: PaintAction.cs プロジェクト: MadDanEccles/NHSE
 protected override void OnClick(MouseEventArgs e, Keys modifierKeys, MapToolContext ctx)
 {
     if (ctx.MapEditingService.AddItem(item, ctx.ToTile(e.Location), this.transaction,
                                       CollisionAction.Abort))
     {
         ctx.Viewport.Invalidate();
     }
 }
コード例 #6
0
 public void OnMouseMove(MouseEventArgs e, MapToolContext ctx)
 {
     if (isPanning)
     {
         Size delta = panStartLocation.Subtract(e.Location);
         ctx.Viewport.ScrollPosition = Point.Add(panStartScrollPosition, delta);
     }
 }
コード例 #7
0
ファイル: MoveTool.cs プロジェクト: MadDanEccles/NHSE
 public void OnMouseMove(MouseEventArgs e, MapToolContext ctx)
 {
     if (isDragging)
     {
         Point tileOffset = GetTileDelta(e, ctx);
         selectionRenderer.TileOffset = tileOffset;
     }
 }
コード例 #8
0
 public void OnMouseUp(MouseEventArgs e, MapToolContext ctx)
 {
     if (this.isDragging && e.Button == MouseButtons.Left)
     {
         this.isDragging             = false;
         this.renderer.MarqueeBounds = Rectangle.Empty;
     }
 }
コード例 #9
0
ファイル: EraseAction.cs プロジェクト: MadDanEccles/NHSE
 protected override void OnClick(MouseEventArgs e, Keys modifierKeys, MapToolContext ctx)
 {
     lastTile = ctx.ToTile(e.Location);
     if (ctx.MapEditingService.DeleteTile(lastTile, transaction, true))
     {
         ctx.Viewport.Invalidate();
     }
 }
コード例 #10
0
 public void OnMouseDown(MouseEventArgs e, MapToolContext ctx)
 {
     if (e.Button == MouseButtons.Left)
     {
         this.panStartScrollPosition = ctx.Viewport.ScrollPosition;
         this.panStartLocation       = e.Location;
         isPanning = true;
     }
 }
コード例 #11
0
ファイル: PaintAction.cs プロジェクト: MadDanEccles/NHSE
        private Point GetItemPoint(MapToolContext ctx, Point clientPt)
        {
            var tilePt = ctx.ToTile(clientPt);

            tilePt = new Point(
                tilePt.X - (tilePt.X - startTile.X) % itemSize.Width,
                tilePt.Y - (tilePt.Y - startTile.Y) % itemSize.Height);
            return(tilePt);
        }
コード例 #12
0
 public void OnMouseDown(MouseEventArgs e, MapToolContext ctx)
 {
     if (e.Button == MouseButtons.Left)
     {
         this.dragStart  = e.Location;
         this.dragEnd    = e.Location;
         this.isDragging = true;
     }
 }
コード例 #13
0
 public void OnMouseUp(MouseEventArgs e, Keys modifierKeys, MapToolContext ctx)
 {
     if (mouseAction != null && e.Button == mouseActionButton)
     {
         mouseAction.OnMouseUp(e, modifierKeys, ctx);
         mouseAction.UnbindViewport(ctx.Viewport);
         mouseAction.Dispose();
         mouseAction = null;
     }
 }
コード例 #14
0
 protected override void OnClick(MouseEventArgs e, Keys modifierKeys, MapToolContext ctx)
 {
     if (e.Button == MouseButtons.Left)
     {
         ctx.Viewport.Zoom(ctx.Viewport.ZoomLevel + 1, e.Location);
     }
     else if (e.Button == MouseButtons.Right)
     {
         ctx.Viewport.Zoom(ctx.Viewport.ZoomLevel - 1, e.Location);
     }
 }
コード例 #15
0
ファイル: ZoomTool.cs プロジェクト: MadDanEccles/NHSE
 public void OnMouseDown(MouseEventArgs e, MapToolContext ctx)
 {
     if (e.Button == MouseButtons.Left)
     {
         ctx.Viewport.Zoom(ctx.Viewport.ZoomLevel + 1, e.Location);
     }
     else if (e.Button == MouseButtons.Right)
     {
         ctx.Viewport.Zoom(ctx.Viewport.ZoomLevel - 1, e.Location);
     }
 }
コード例 #16
0
 public void OnMouseMove(MouseEventArgs e, MapToolContext ctx)
 {
     if (this.isDragging)
     {
         this.dragEnd = e.Location;
         var marqueeBounds = GetMarqueeBounds();
         this.renderer.MarqueeBounds = marqueeBounds;
         this.selectionService.ClearSelection();
         this.selectionService.ModifySelection(marqueeBounds, ctx, SelectionAction.Add);
     }
 }
コード例 #17
0
ファイル: PickAction.cs プロジェクト: MadDanEccles/NHSE
        public void OnMouseDown(MouseEventArgs e, Keys modifierKeys, MapToolContext ctx)
        {
            Point tilePt = ctx.ToTile(e.Location);
            Item  item   = ctx.MapEditingService.GetItem(tilePt, true);

            if (item != null)
            {
                Item itemCopy = new Item();
                itemCopy.CopyFrom(item);
                pickTarget.Pick(itemCopy);
            }
        }
コード例 #18
0
 public void OnMouseMove(MouseEventArgs mouseEventArgs, Keys modifierKeys, MapToolContext ctx)
 {
     if (IsDragging)
     {
         OnDragMove(mouseEventArgs, modifierKeys, ctx);
     }
     else if (this.originArgs != null && mouseEventArgs.Location.GetDistance(this.originArgs.Location) > DragThreshold)
     {
         IsDragging = true;
         OnDragStart(originArgs, modifierKeys, ctx);
     }
 }
コード例 #19
0
 public virtual void OnMouseDown(MouseEventArgs e, Keys modifierKeys, MapToolContext ctx)
 {
     if (this.mouseAction == null)
     {
         this.mouseAction = GetMouseAction(e, modifierKeys, ctx);
         if (this.mouseAction != null)
         {
             mouseAction.BindViewport(ctx.Viewport);
             this.mouseAction.OnMouseDown(e, modifierKeys, ctx);
             this.mouseActionButton = e.Button;
         }
     }
 }
コード例 #20
0
        public void OnMouseUp(MouseEventArgs mouseEventArgs, Keys modifierKeys, MapToolContext ctx)
        {
            if (IsDragging)
            {
                IsDragging = false;
                OnDragEnd(mouseEventArgs, modifierKeys, ctx);
            }
            else
            {
                OnClick(mouseEventArgs, modifierKeys, ctx);
            }

            this.originArgs = null;
        }
コード例 #21
0
        public void CalculateResult(MapToolContext ctx, Rectangle tileRect, ItemFieldFragment fragment)
        {
            if (tileRect.Size.Encompasses(placedItemSize))
            {
                Rectangle placedItemRect = new Rectangle(tileRect.Location, placedItemSize);
                fragment.Add(placedItemRect, placedItem, ctx.MapEditingService.IsOccupied(placedItemRect));

                if (recipeItem != null)
                {
                    for (int y = tileRect.Top; y + recipeItemSize.Height <= tileRect.Bottom; y += recipeItemSize.Height)
                    {
                        Rectangle recipeItemRect =
                            new Rectangle(tileRect.Left, y, recipeItemSize.Width, recipeItemSize.Height);
                        if (recipeItemRect.IntersectsWith(placedItemRect))
                        {
                            continue;
                        }
                        fragment.Add(recipeItemRect, recipeItem, ctx.MapEditingService.IsOccupied(recipeItemRect));
                    }
                }

                int droppedItemTop =
                    placedItemRect.Top + droppedItemSize.Height - (placedItemRect.Height % droppedItemSize.Height);
                int doppedItemsPerColumn =
                    (tileRect.Bottom - droppedItemTop) / droppedItemSize.Height;

                if (droppedItems.Count > 0)
                {
                    for (int x = tileRect.Left + recipeItemSize.Width;
                         x + droppedItemSize.Width <= tileRect.Right;
                         x += droppedItemSize.Width)
                    {
                        for (int y = 0; y < doppedItemsPerColumn; y++)
                        {
                            Rectangle droppedItemRect = new Rectangle(x, droppedItemTop + y * droppedItemSize.Height,
                                                                      droppedItemSize.Width, droppedItemSize.Height);
                            if (droppedItemRect.IntersectsWith(placedItemRect))
                            {
                                continue;
                            }
                            var droppedItemIndex = (int)(y / ((float)doppedItemsPerColumn / droppedItems.Count));
                            var droppedItem      = droppedItems[droppedItemIndex];
                            fragment.Add(droppedItemRect, droppedItem,
                                         ctx.MapEditingService.IsOccupied(droppedItemRect));
                        }
                    }
                }
            }
        }
コード例 #22
0
ファイル: FillRectAction.cs プロジェクト: MadDanEccles/NHSE
        protected override void CalculateResult(MapToolContext ctx, Rectangle marqueeBounds, out ItemFieldFragment fragment, out string hint)
        {
            fragment = new ItemFieldFragment();
            var tileRect = ctx.ToTiles(marqueeBounds);

            for (int x = tileRect.Left; x <= tileRect.Right - itemSize.Width; x += itemSize.Width)
            {
                for (int y = tileRect.Top; y <= tileRect.Bottom - itemSize.Height; y += itemSize.Height)
                {
                    Rectangle itemTileRect = new Rectangle(x, y, itemSize.Width, itemSize.Height);
                    fragment.Add(itemTileRect, item, ctx.MapEditingService.IsOccupied(itemTileRect));
                }
            }

            int itemsX = tileRect.Width / itemSize.Width;
            int itemsY = tileRect.Height / itemSize.Height;

            hint = $"{itemsX} × {itemsY}";
        }
コード例 #23
0
ファイル: MoveTool.cs プロジェクト: MadDanEccles/NHSE
        public void OnMouseDown(MouseEventArgs e, MapToolContext ctx)
        {
            if (e.Button == MouseButtons.Left)
            {
                Point tilePt = ctx.ToTile(e.Location);

                // If the cursor is not on a selected tile then clear the selection and select
                // the tile directly under the cursor.
                if (!selectionService.SelectedItems.Any(i => i.Bounds.Contains(tilePt)))
                {
                    selectionService.ClearSelection();
                    selectionService.ModifySelection(e.Location, ctx, SelectionAction.Add);
                }

                if (selectionService.SelectedItems.Any())
                {
                    this.isDragging = true;
                    this.dragStart  = e.Location;
                }
            }
        }
コード例 #24
0
        public bool ModifySelection(Rectangle marqueeBounds, MapToolContext ctx, SelectionAction action)
        {
            bool selectionChanged = false;
            var  tileBounds       = ctx.ToTiles(marqueeBounds);

            for (int tileX = tileBounds.Left; tileX < tileBounds.Right; tileX++)
            {
                for (int tileY = tileBounds.Top; tileY < tileBounds.Bottom; tileY++)
                {
                    if (TryGetItemFromItemPt(new Point(tileX, tileY), out var item, out var itemTileBounds))
                    {
                        Item itemCopy = new Item(item.RawValue);
                        Debug.Assert(itemCopy.IsRoot);
                        SelectedItem selectedItem = new SelectedItem(itemCopy, itemTileBounds);
                        switch (action)
                        {
                        case SelectionAction.Add:
                            selectionChanged |= selectedItems.Add(selectedItem);
                            break;

                        case SelectionAction.Remove:
                            selectionChanged |= selectedItems.Remove(selectedItem);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException(nameof(action), action, null);
                        }
                    }
                }
            }

            if (selectionChanged)
            {
                OnSelectionChanged();
            }

            return(selectionChanged);
        }
コード例 #25
0
        protected override void CalculateResult(MapToolContext ctx, Rectangle marqueeBounds,
                                                out ItemFieldFragment fragment, out string hint)
        {
            var tileRect = ctx.ToTiles(marqueeBounds).Quantize(2);

            fragment = new ItemFieldFragment();
            hint     = $"{segmentLayouts.Length} Item(s)";
            if (layout.GetSegmentRects(tileRect, segmentLayouts, minSegementSizes, rowCount, out var segmentRects,
                                       out var templateHint))
            {
                for (int segmentIndex = 0;
                     segmentIndex < segmentLayouts.Length;
                     segmentIndex++)
                {
                    segmentLayouts[segmentIndex].CalculateResult(ctx, segmentRects[segmentIndex], fragment);
                }
            }

            if (!string.IsNullOrWhiteSpace(templateHint))
            {
                hint = $"{hint} - {templateHint}";
            }
        }
コード例 #26
0
        public override bool OnKeyDown(Keys e, MapToolContext ctx)
        {
            if (IsDragging)
            {
                if (e == Keys.Up)
                {
                    if (rowCount < 50)
                    {
                        rowCount++;
                        InvalidateFragment(ctx);
                    }
                }
                else if (e == Keys.Down)
                {
                    if (rowCount > 0)
                    {
                        rowCount--;
                        InvalidateFragment(ctx);
                    }
                }
            }

            return(true);
        }
コード例 #27
0
 public void OnMouseWheel(MouseEventArgs e, MapToolContext ctx)
 {
     ctx.Viewport.Zoom(ctx.Viewport.ZoomLevel + e.Delta / 120, e.Location);
 }
コード例 #28
0
 protected override IMouseAction GetMouseAction(MouseEventArgs e, Keys modifierKeys, MapToolContext ctx)
 {
     if (modifierKeys.HasFlag(Keys.Alt))
     {
         return(new PanZoomMouseAction());
     }
     else if (modifierKeys.HasFlag(Keys.Control))
     {
         return(new PickAction(pickTarget));
     }
     else
     {
         return(new PaintAction(historyService, options.GetItem()));
     }
 }
コード例 #29
0
ファイル: ZoomTool.cs プロジェクト: MadDanEccles/NHSE
 public void OnMouseWheel(MouseEventArgs e, MapToolContext ctx)
 {
 }
コード例 #30
0
ファイル: ZoomTool.cs プロジェクト: MadDanEccles/NHSE
 public void OnMouseMove(MouseEventArgs e, MapToolContext ctx)
 {
 }