示例#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
        private void saveSettings()
        {
            if (updating)
            {
                return;
            }
            byte[][] newData = UndoManager.Clone(Level.Blocks);
            newData[0][0]  = (byte)startEntranceUpDown.Value;
            newData[0][1]  = (byte)midwayEntranceUpDown.Value;
            newData[0][4]  = (byte)((int)timeLimitUpDown.Value & 255);
            newData[0][5]  = (byte)((int)timeLimitUpDown.Value >> 8);
            newData[0][26] = (byte)((int)soundSetUpDown.Value & 255);

            byte settingsByte = 0x00;

            if (levelWrapCheckBox.Checked)
            {
                settingsByte |= 0x20;
            }
            if (forceMiniCheckBox.Checked)
            {
                settingsByte |= 0x01;
            }
            if (miniMarioPhysicsCheckBox.Checked)
            {
                settingsByte |= 0x02;
            }
            newData[0][2] = settingsByte;

            int oldTileset  = newData[0][0xC];
            int oldBottomBg = newData[0][6];

            newData[0][0xC] = (byte)tilesetComboBox.SelectedIndex; // ncg
            newData[3][4]   = (byte)tilesetComboBox.SelectedIndex; // ncl

            int FGIndex = bgTopLayerComboBox.SelectedIndex;

            if (FGIndex == bgTopLayerComboBox.Items.Count - 1)
            {
                FGIndex = 0xFFFF;
            }
            newData[0][0x12] = (byte)FGIndex;        // ncg
            newData[0][0x13] = (byte)(FGIndex >> 8); // ncg
            newData[4][4]    = (byte)FGIndex;        // ncl
            newData[4][5]    = (byte)(FGIndex >> 8); // ncg
            newData[4][2]    = (byte)FGIndex;        // nsc
            newData[4][3]    = (byte)(FGIndex >> 8); // ncg

            int BGIndex = bgBottomLayerComboBox.SelectedIndex;

            if (BGIndex == bgBottomLayerComboBox.Items.Count - 1)
            {
                BGIndex = 0xFFFF;
            }
            newData[0][6] = (byte)BGIndex;        // ncg
            newData[0][7] = (byte)(BGIndex >> 8); // ncg
            newData[2][4] = (byte)BGIndex;        // ncl
            newData[2][5] = (byte)(BGIndex >> 8); // ncg
            newData[2][2] = (byte)BGIndex;        // nsc
            newData[2][3] = (byte)(BGIndex >> 8); // ncg


            ComboBox[] checkthese = new ComboBox[] {
                set1ComboBox, set2ComboBox, set3ComboBox, set4ComboBox,
                set5ComboBox, set6ComboBox, set7ComboBox, set8ComboBox,
                set9ComboBox, set10ComboBox, set16ComboBox
            };

            int[] checkthese_idx = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 15 };

            for (int CheckIdx = 0; CheckIdx < checkthese.Length; CheckIdx++)
            {
                string Item        = (string)(checkthese[CheckIdx].Items[Math.Max(0, checkthese[CheckIdx].SelectedIndex)]);
                int    cpos        = Item.IndexOf(':');
                int    modifierval = int.Parse(Item.Substring(0, cpos));
                newData[13][checkthese_idx[CheckIdx]] = (byte)modifierval;
            }

            EdControl.UndoManager.Do(new ChangeLevelSettingsAction(newData));
            if (oldTileset != newData[0][0xC] || oldBottomBg != newData[0][6])
            {
                EdControl.editor.LevelConfigForm_ReloadTileset();
            }
            else
            {
                EdControl.Invalidate();
            }
        }
示例#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
                    findSelectedObjects(x, y, x, y, true, true);
                    SelectMode = SelectedObjects.Count == 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();
        }
示例#5
0
 public override void AfterSetEdControl()
 {
     this.oldData = UndoManager.Clone(EdControl.Level.Blocks);
 }
示例#6
0
 public override void Redo()
 {
     EdControl.Level.Blocks = UndoManager.Clone(newData);
     EdControl.Level.CalculateSpriteModifiers();
     EdControl.config.LoadSettings();
 }
        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;

            bool drag = false;

            getActionAtPos(x, y, out drag, out vertResize, out horResize);
            // Resize with the shift key
            if (Control.ModifierKeys == Keys.Shift && drag && vertResize == ResizeType.ResizeNone && horResize == ResizeType.ResizeNone)
            {
                vertResize = ResizeType.ResizeEnd;
                horResize  = ResizeType.ResizeEnd;
            }
            if (!drag)
            {
                // Select an object
                findSelectedObjects(x, y, x, y, true, true);
                SelectMode = SelectedObjects.Count == 0;
            }
            else if (vertResize == ResizeType.ResizeNone && horResize == 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();
        }
示例#8
0
 public void LoadUndoManager(ToolStripSplitButton Undo, ToolStripSplitButton Redo)
 {
     UndoManager = new UndoManager(Undo, Redo, this);
 }