示例#1
0
        private void addPath_Click(object sender, EventArgs e)
        {
            Rectangle va = EdControl.ViewableBlocks;
            NSMBPath  np = new NSMBPath();

            if (isProgress)
            {
                np.id = EdControl.Level.getFreePathNumber(lst, 1);
            }
            else
            {
                np.id = EdControl.Level.getFreePathNumber(lst, 0);
            }
            np.isProgressPath = isProgress;

            NSMBPathPoint npp = new NSMBPathPoint(np);

            npp.X = (va.X + va.Width / 2) * 16;
            npp.Y = (va.Y + va.Height / 2) * 16;
            EdControl.UndoManager.Do(new AddLvlItemAction(UndoManager.ObjToList(npp)));
            EdControl.mode.SelectObject(npp);
        }
示例#2
0
 public void LoadUndoManager(ToolStripSplitButton Undo, ToolStripSplitButton Redo)
 {
     UndoManager = new UndoManager(Undo, Redo, this);
 }
示例#3
0
        public override void MouseDrag(int x, int y)
        {
            //Resize the new object that was created by right-clicking.
            if (CreateObj && newObj != null)
            {
                Rectangle r = newObj.getRectangle();
                x = Math.Max(0, x / 16);
                y = Math.Max(0, y / 16);
                if (x == lx && y == ly)
                {
                    return;
                }
                lx            = x;
                ly            = y;
                newObj.X      = Math.Min(lx, dx);
                newObj.Y      = Math.Min(ly, dy);
                newObj.Width  = Math.Abs(lx - dx) + 1;
                newObj.Height = Math.Abs(ly - dy) + 1;
                newObj.UpdateObjCache();
                r = Rectangle.Union(r, newObj.getRectangle());
                Level.repaintTilemap(r.X, r.Y, r.Width, r.Height);
                EdControl.repaint();
                return;
            }

            if (lx == x && ly == y) // don't clone objects if there is no visible movement
            {
                return;
            }

            if (SelectMode)
            {
                findSelectedObjects(x, y, dx, dy, false, true);
                lx = x;
                ly = y;
            }
            else
            {
                UpdateSelectionBounds();
                if (CloneMode)
                {
                    List <LevelItem> newObjects = CloneList(SelectedObjects);
                    EdControl.UndoManager.Do(new AddLvlItemAction(newObjects));

                    CloneMode     = false;
                    mouseAct.vert = ResizeType.ResizeNone;
                    mouseAct.hor  = ResizeType.ResizeNone;

                    SelectedObjects = newObjects;
                }

                if (mouseAct.hor == ResizeType.ResizeNone && mouseAct.vert == ResizeType.ResizeNone)
                {
                    int xDelta = x - lx;
                    int yDelta = y - ly;
                    if (xDelta < -minBoundX)
                    {
                        xDelta = -minBoundX;
                    }
                    if (yDelta < -minBoundY)
                    {
                        yDelta = -minBoundY;
                    }
                    xDelta &= ~(selectionSnap - 1);
                    yDelta &= ~(selectionSnap - 1);
                    if (xDelta == 0 && yDelta == 0)
                    {
                        return;
                    }
                    minBoundX += xDelta;
                    minBoundY += yDelta;
                    EdControl.UndoManager.Do(new MoveResizeLvlItemAction(SelectedObjects, xDelta, yDelta));
                    lx += xDelta;
                    ly += yDelta;

                    //Force align =D
                    //Only done when ONE object because you'll probably NOT want multiple objects
                    //moving relative to each other.
                    if (SelectedObjects.Count == 1)
                    {
                        foreach (LevelItem o in SelectedObjects)
                        {
                            if (o.rx % selectionSnap != 0 || o.ry % selectionSnap != 0 || o.rwidth % selectionSnap != 0 || o.rheight % selectionSnap != 0)
                            {
                                EdControl.UndoManager.Do(new MoveResizeLvlItemAction(UndoManager.ObjToList(o), -o.rx % selectionSnap, -o.ry % selectionSnap, -o.rwidth % selectionSnap, -o.rheight % selectionSnap));
                            }
                        }
                    }
                }
                else
                {
                    int xDelta = x - lx;
                    int yDelta = y - ly;

                    int xMoveDelta   = 0;
                    int xResizeDelta = 0;
                    int yMoveDelta   = 0;
                    int yResizeDelta = 0;

                    xDelta &= ~(selectionSnap - 1);
                    yDelta &= ~(selectionSnap - 1);
                    if (xDelta == 0 && yDelta == 0)
                    {
                        return;
                    }

                    if (mouseAct.hor == ResizeType.ResizeBegin)
                    {
                        if (-xDelta <= -minSizeX + selectionSnap)
                        {
                            xDelta = -(-minSizeX + selectionSnap);
                        }
                        if (xDelta < -minBoundX)
                        {
                            xDelta = -minBoundX;
                        }
                        xMoveDelta   = xDelta;
                        xResizeDelta = -xDelta;
                    }
                    if (mouseAct.vert == ResizeType.ResizeBegin)
                    {
                        if (-yDelta <= -minSizeY + selectionSnap)
                        {
                            yDelta = -(-minSizeY + selectionSnap);
                        }
                        if (yDelta < -minBoundY)
                        {
                            yDelta = -minBoundY;
                        }
                        yMoveDelta   = yDelta;
                        yResizeDelta = -yDelta;
                    }
                    if (mouseAct.hor == ResizeType.ResizeEnd)
                    {
                        if (xDelta <= -minSizeX + selectionSnap)
                        {
                            xDelta = -minSizeX + selectionSnap;
                        }
                        xResizeDelta = xDelta;
                    }
                    if (mouseAct.vert == ResizeType.ResizeEnd)
                    {
                        if (yDelta <= -minSizeY + selectionSnap)
                        {
                            yDelta = -minSizeY + selectionSnap;
                        }
                        yResizeDelta = yDelta;
                    }
                    if (xMoveDelta == 0 && yMoveDelta == 0 && xResizeDelta == 0 && yResizeDelta == 0)
                    {
                        return;
                    }

                    minBoundX += xMoveDelta;
                    minBoundY += yMoveDelta;
                    minSizeX  += xResizeDelta;
                    minSizeY  += yResizeDelta;
                    EdControl.UndoManager.Do(new MoveResizeLvlItemAction(SelectedObjects, xMoveDelta, yMoveDelta, xResizeDelta, yResizeDelta));
                    lx += xDelta;
                    ly += yDelta;
                }
            }
        }
示例#4
0
        public override void MouseDown(int x, int y, MouseButtons buttons)
        {
            //Right clicking creates a new object
            if (buttons == MouseButtons.Right)
            {
                dx        = x / 16;
                dy        = y / 16;
                lx        = x;
                ly        = y;
                CreateObj = true;
                if (tabs.SelectedTab == 2) //The sprite tab
                {
                    NSMBSprite newSprite = new NSMBSprite(Level);
                    newSprite.Type = tabs.sprites.getSelectedType();
                    if (newSprite.Type == -1)
                    {
                        return;
                    }
                    newSprite.Data = new byte[6];
                    newSprite.x    = x;
                    newSprite.y    = y;
                    EdControl.UndoManager.Do(new AddLvlItemAction(UndoManager.ObjToList(newSprite)));
                    SelectObject(newSprite);
                    return;
                }
                newObj = new NSMBObject(tabs.objects.getObjectType(), tabs.objects.getTilesetNum(), dx, dy, 1, 1, Level.GFX);
                EdControl.UndoManager.Do(new AddLvlItemAction(UndoManager.ObjToList(newObj)));
                SelectObject(newObj);
                return;
            }
            lx = x;
            ly = y;
            dx = x;
            dy = y;

            mouseAct = getActionAtPos(x, y);
            // Resize with the shift key
            if (mouseAct.nodeType != CreateNode.None)
            {
                NSMBPathPoint pp     = new NSMBPathPoint(mouseAct.node);
                int           zIndex = pp.parent.points.IndexOf(mouseAct.node);
                if (mouseAct.nodeType == CreateNode.After)
                {
                    pp.x += 16;
                    zIndex++;
                }
                else
                {
                    pp.x -= 16;
                }
                EdControl.UndoManager.Do(new AddPathNodeAction(UndoManager.ObjToList(pp), zIndex));
                SelectObject(pp);
            }
            else
            {
                if (Control.ModifierKeys == Keys.Shift && mouseAct.drag && mouseAct.vert == ResizeType.ResizeNone && mouseAct.hor == ResizeType.ResizeNone)
                {
                    mouseAct.vert = ResizeType.ResizeEnd;
                    mouseAct.hor  = ResizeType.ResizeEnd;
                }
                if (!mouseAct.drag)
                {
                    // Select an object
                    if (Control.ModifierKeys != Keys.Shift)
                    {
                        SelectedObjects.Clear();
                    }
                    findSelectedObjects(x, y, x, y, true, true);
                    SelectMode = CurSelectedObjs.Count == 0;
                    if (!SelectMode)
                    {
                        SelectedObjects.Add(CurSelectedObjs[0]);
                    }
                }
                else if (mouseAct.vert == ResizeType.ResizeNone && mouseAct.hor == ResizeType.ResizeNone)
                {
                    List <LevelItem> selectedObjectsBack = new List <LevelItem>();
                    selectedObjectsBack.AddRange(SelectedObjects);

                    // Select an object
                    findSelectedObjects(x, y, x, y, true, true);

                    if (SelectedObjects.Count == 0)
                    {
                        SelectMode = true;
                    }
                    else
                    {
                        if (selectedObjectsBack.Contains(SelectedObjects[0]))
                        {
                            SelectedObjects = selectedObjectsBack;
                        }
                    }
                    UpdateSelectionBounds();
                    EdControl.repaint();
                }

                if (!SelectMode)
                {
                    CloneMode = Control.ModifierKeys == Keys.Control;
                    lx       -= selectionSnap / 2;
                    ly       -= selectionSnap / 2;
                }
            }
            EdControl.repaint();

            tabs.SelectObjects(SelectedObjects);
            UpdatePanel();
        }