Beispiel #1
0
        public NSMBSprite(NSMBSprite s)
        {
            this.X = s.X;
            this.Y = s.Y;
            this.Type = s.Type;
            this.Level = s.Level;

            this.Data = new byte[6];
            Array.Copy(s.Data, Data, 6);
        }
Beispiel #2
0
 private void CreateSprite_Click(object sender, EventArgs e)
 {
     Rectangle ViewableArea = EdControl.ViewableBlocks;
     NSMBSprite ns = new NSMBSprite(EdControl.Level);
     ns.X = ViewableArea.X + ViewableArea.Width / 2;
     ns.Y = ViewableArea.Y + ViewableArea.Height / 2;
     ns.Type = 0;
     ns.Data = new byte[6];
     EdControl.UndoManager.Do(new AddLvlItemAction(UndoManager.ObjToList(ns)));
     EdControl.mode.SelectObject(ns);
 }
Beispiel #3
0
        private void spriteFindNext_Click(object sender, EventArgs e)
        {
            if (EdControl.Level.Sprites.Count == 0)
            {
                //MessageBox.Show(LanguageManager.Get("ToolsForm", "NoSprites"), LanguageManager.Get("General", "Warning"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            int ind = -1;
            if (foundSprite != null && EdControl.Level.Sprites.Contains(foundSprite))
                ind = EdControl.Level.Sprites.IndexOf(foundSprite);


            int startInd = ind;
            ind++;
            ind %= EdControl.Level.Sprites.Count;
            bool found = false;

            while (ind != startInd && !found)
            {
                if (EdControl.Level.Sprites[ind].Type == SpriteNumber.Value)
                {
                    foundSprite = EdControl.Level.Sprites[ind];
                    found = true;
                }
                ind++;
                ind %= EdControl.Level.Sprites.Count;
            }

            if (found)
            {
                EdControl.SelectObject(foundSprite);
                EdControl.EnsureBlockVisible(foundSprite.X, foundSprite.Y);
            }
            //else
                //MessageBox.Show(LanguageManager.Get("ToolsForm", "NotFound"), LanguageManager.Get("General", "Warning"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
Beispiel #4
0
        private void LoadLevel(File levelFile, File bgFile, byte[] eLevelFile, byte[] eBGFile, NSMBGraphics GFX)
        {
            this.LevelFile = levelFile;
            this.BGFile = bgFile;
            this.GFX = GFX;

            int FilePos;

            for(int x = 0; x < 512; x++)
                for (int y = 0; y < 256; y++)
                {
                    levelTilemap[x,y] = (x + y) % 512;
                }

            // Level loading time yay.
            // Since I don't know the format for every block, I will just load them raw.
            Blocks = new byte[][] { null, null, null, null, null, null, null, null, null, null, null, null, null, null };

            FilePos = 0;
            for (int BlockIdx = 0; BlockIdx < 14; BlockIdx++) {
                int BlockOffset = eLevelFile[FilePos] | (eLevelFile[FilePos + 1] << 8) | (eLevelFile[FilePos + 2] << 16) | eLevelFile[FilePos + 3] << 24;
                FilePos += 4;
                int BlockSize = eLevelFile[FilePos] | (eLevelFile[FilePos + 1] << 8) | (eLevelFile[FilePos + 2] << 16) | eLevelFile[FilePos + 3] << 24;
                FilePos += 4;

                Blocks[BlockIdx] = new byte[BlockSize];
                Array.Copy(eLevelFile, BlockOffset, Blocks[BlockIdx], 0, BlockSize);
            }

            // Now objects.

            int ObjectCount = eBGFile.Length / 10;
            Objects = new List<NSMBObject>(ObjectCount);
            FilePos = 0;
            for (int ObjectIdx = 0; ObjectIdx < ObjectCount; ObjectIdx++) {
                int ObjID = eBGFile[FilePos] | (eBGFile[FilePos + 1] << 8);
                int ObjX = eBGFile[FilePos + 2] | (eBGFile[FilePos + 3] << 8);
                int ObjY = eBGFile[FilePos + 4] | (eBGFile[FilePos + 5] << 8);
                int ObjWidth = eBGFile[FilePos + 6] | (eBGFile[FilePos + 7] << 8);
                int ObjHeight = eBGFile[FilePos + 8] | (eBGFile[FilePos + 9] << 8);
                Objects.Add(new NSMBObject(ObjID & 4095, (ObjID & 61440) >> 12, ObjX, ObjY, ObjWidth, ObjHeight, GFX));
                FilePos += 10;
            }

            /*
             * Sprite struct:
             * Offs Len Dat
             * 0x0   2   Sprite id
             * 0x2   2   X
             * 0x4   2   Y
             * 0x6   6   Dat
             * 0xD   end
             */

            // Sprites
            byte[] SpriteBlock = Blocks[6];
            int SpriteCount = (SpriteBlock.Length - 2) / 12;
            Sprites = new List<NSMBSprite>(SpriteCount);
            FilePos = 0;
            for (int SpriteIdx = 0; SpriteIdx < SpriteCount; SpriteIdx++) {
                NSMBSprite Sprite = new NSMBSprite(this);
                Sprite.Type = SpriteBlock[FilePos] | (SpriteBlock[FilePos + 1] << 8);
                Sprite.X = SpriteBlock[FilePos + 2] | (SpriteBlock[FilePos + 3] << 8);
                Sprite.Y = SpriteBlock[FilePos + 4] | (SpriteBlock[FilePos + 5] << 8);
                Sprite.Data = new byte[6];
                FilePos += 6;
                Sprite.Data[0] = SpriteBlock[FilePos + 1];
                Sprite.Data[1] = SpriteBlock[FilePos + 0];
                Sprite.Data[2] = SpriteBlock[FilePos + 5];
                Sprite.Data[3] = SpriteBlock[FilePos + 4];
                Sprite.Data[4] = SpriteBlock[FilePos + 3];
                Sprite.Data[5] = SpriteBlock[FilePos + 2];
            //                Array.Copy(SpriteBlock, FilePos + 6, Sprite.Data, 0, 6);
                Sprites.Add(Sprite);
                FilePos += 6;
            }

            // Entrances.
            byte[] EntranceBlock = Blocks[5];
            int EntranceCount = EntranceBlock.Length / 20;
            Entrances = new List<NSMBEntrance>(EntranceCount);
            FilePos = 0;
            for (int EntIdx = 0; EntIdx < EntranceCount; EntIdx++) {
                NSMBEntrance Entrance = new NSMBEntrance();
                Entrance.X = EntranceBlock[FilePos] | (EntranceBlock[FilePos + 1] << 8);
                Entrance.Y = EntranceBlock[FilePos + 2] | (EntranceBlock[FilePos + 3] << 8);
                Entrance.CameraX = EntranceBlock[FilePos + 4] | (EntranceBlock[FilePos + 5] << 8);
                Entrance.CameraY = EntranceBlock[FilePos + 6] | (EntranceBlock[FilePos + 7] << 8);
                Entrance.Number = EntranceBlock[FilePos + 8];
                Entrance.DestArea = EntranceBlock[FilePos + 9];
                Entrance.ConnectedPipeID = EntranceBlock[FilePos + 10];
                Entrance.DestEntrance = EntranceBlock[FilePos + 12];
                Entrance.Type = EntranceBlock[FilePos + 14];
                Entrance.Settings = EntranceBlock[FilePos + 15];
                Entrance.Unknown1 = EntranceBlock[FilePos + 16];
                Entrance.EntryView = EntranceBlock[FilePos + 18];
                Entrance.Unknown2 = EntranceBlock[FilePos + 19];
                //Array.Copy(EntranceBlock, FilePos, Entrance.Data, 0, 20);
                Entrances.Add(Entrance);
                FilePos += 20;
            }

            // Views
            ByteArrayInputStream ViewBlock = new ByteArrayInputStream(Blocks[7]);
            ByteArrayInputStream CamBlock = new ByteArrayInputStream(Blocks[1]);
            Views = new List<NSMBView>();
            while (ViewBlock.lengthAvailable(16))
                Views.Add(NSMBView.read(ViewBlock, CamBlock));

            // Zones
            ByteArrayInputStream ZoneBlock = new ByteArrayInputStream(Blocks[8]);
            Zones = new List<NSMBView>();
            while (ZoneBlock.lengthAvailable(12))
                Zones.Add(NSMBView.readZone(ZoneBlock));

            // Paths

            ByteArrayInputStream PathBlock = new ByteArrayInputStream(Blocks[10]);
            ByteArrayInputStream PathNodeBlock = new ByteArrayInputStream(Blocks[12]);

            Paths = new List<NSMBPath>();
            while (!PathBlock.end())
            {
                Paths.Add(NSMBPath.read(PathBlock, PathNodeBlock, false));
            }

            PathBlock = new ByteArrayInputStream(Blocks[9]);
            PathNodeBlock = new ByteArrayInputStream(Blocks[11]);

            ProgressPaths = new List<NSMBPath>();
            while (!PathBlock.end())
            {
                ProgressPaths.Add(NSMBPath.read(PathBlock, PathNodeBlock, true));
            }

            CalculateSpriteModifiers();
            repaintAllTilemap();
        }
        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);
            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();
        }
Beispiel #6
0
            public SpriteDataEditor(List<LevelItem> sprites, SpriteData sd, LevelEditorControl EdControl)
            {
                this.SizeChanged += new EventHandler(this_SizeChanged);
                updating = true;
                this.ColumnCount = 3;
                //Talbe layout panel doesn't automatically create row or column styles
                this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
                this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
                this.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 20F));
                this.RowCount = sd.fields.Count;
                for (int l = 0; l < this.RowCount; l++)
                    this.RowStyles.Add(new RowStyle(SizeType.Absolute));
                this.AutoSize = true;
                this.AutoSizeMode = AutoSizeMode.GrowAndShrink;

                this.sprites = sprites;
                foreach (LevelItem obj in sprites)
                    if (obj is NSMBSprite) {
                        s = obj as NSMBSprite;
                        break;
                    }
                this.sd = sd;
                this.Dock = DockStyle.Fill;
                this.EdControl = EdControl;

                int row = 0;
                foreach (SpriteDataField v in sd.fields)
                {
                    Control c = CreateControlFor(v);
                    c.Anchor = AnchorStyles.Left | AnchorStyles.Right;
                    if (c is CheckBox || c is Label)
                    {
                        c.Font = new System.Drawing.Font(c.Font.FontFamily, c.Font.Size * 0.9F);
                        this.Controls.Add(c, 0, row);
                        this.RowStyles[row].Height = 25;
                        if (v.notes == "")
                            this.SetColumnSpan(c, 3);
                        else
                        {
                            NotesCtrl note = new NotesCtrl();
                            this.Controls.Add(note, 2, row);
                            note.Text = v.notes;
                        }
                    }
                    else {
                        this.Controls.Add(c, 1, row);
                        Label l = new Label();
                        l.Text = v.name;
                        l.Font = new System.Drawing.Font(l.Font.FontFamily, l.Font.Size * 0.9F);
                        l.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
                        l.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
                        this.Controls.Add(l, 0, row);
                        this.RowStyles[row].Height = 25;
                        if (v.notes == "")
                            this.SetColumnSpan(c, 2);
                        else
                        {
                            NotesCtrl note = new NotesCtrl();
                            this.Controls.Add(note, 2, row);
                            note.Text = v.notes;
                        }
                        
                    }
                    row++;
                    controls.Add(v, c);
                }
                updating = false;
            }
Beispiel #7
0
 public static NSMBSprite FromString(string[] strs, ref int idx, NSMBLevel lvl)
 {
     NSMBSprite s = new NSMBSprite(lvl);
     s.X = int.Parse(strs[1 + idx]);
     s.Y = int.Parse(strs[2 + idx]);
     s.Type = int.Parse(strs[3 + idx]);
     s.Data = new byte[6];
     for (int l = 0; l < 6; l++) {
         s.Data[l] = byte.Parse(strs[4 + idx].Substring(l * 2, 2), System.Globalization.NumberStyles.HexNumber);
     }
     idx += 5;
     return s;
 }
        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();
        }
Beispiel #9
0
 public SpriteDataRow(NSMBSprite sprite, int eventID)
 {
     this.sprite = sprite;
     this._eventID = eventID;
 }