Beispiel #1
0
        public static SpriteData readFromStream(XmlReader xmlr)
        {
            SpriteData sd = new SpriteData();

            sd.spriteID = int.Parse(xmlr.GetAttribute("id"));
            xmlr.ReadToFollowing("name");
            sd.name = xmlr.ReadElementContentAsString();
            spriteNames.Add(sd.name);
            xmlr.ReadToFollowing("category");
            sd.categoryID = int.Parse(xmlr.GetAttribute("id"));
            spritesInCategory[sd.categoryID].Add(sd.spriteID);
            xmlr.ReadToFollowing("notes");
            sd.notes = xmlr.ReadElementContentAsString();
            while (xmlr.ReadToNextSibling("field"))
            {
                SpriteDataField f = new SpriteDataField();
                f.display = xmlr.GetAttribute("type");
                f.name    = xmlr.GetAttribute("name");
                f.notes   = xmlr.GetAttribute("notes");
                string nybbles = xmlr.GetAttribute("id");
                if (nybbles.Contains("-"))
                {
                    string[] nybbles2 = nybbles.Split('-');
                    f.startNibble = int.Parse(nybbles2[0]);
                    f.endNibble   = int.Parse(nybbles2[1]);
                }
                else
                {
                    f.startNibble = f.endNibble = int.Parse(nybbles);
                }
                string values = xmlr.GetAttribute("values");
                switch (f.display)
                {
                case "list":
                    string[] items = values.Split(',');
                    f.values  = new int[items.Length];
                    f.strings = new string[items.Length];

                    for (int j = 0; j < items.Length; j++)
                    {
                        string[] lulz = items[j].Split(new char[] { '=' });
                        f.values[j]  = Int32.Parse(lulz[0]);
                        f.strings[j] = lulz[1];
                    }
                    break;

                case "signedvalue":
                    if (values.Trim() == "")
                    {
                        f.data = 0;
                    }
                    else
                    {
                        f.data = Int32.Parse(values);
                    }
                    break;

                case "value":
                    if (values.Trim() == "")
                    {
                        f.data = 0;
                    }
                    else
                    {
                        f.data = Int32.Parse(values);
                    }
                    break;

                case "checkbox":
                    if (values.Trim() == "")
                    {
                        f.data = 1;
                    }
                    else
                    {
                        f.data = Int32.Parse(values);
                    }
                    break;
                }
                sd.fields.Add(f);
            }

            return(sd);
        }
Beispiel #2
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;
            }
 private void updateSpriteDataButton_Click(object sender, EventArgs e)
 {
     SpriteData.update();
 }
Beispiel #4
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 #5
0
        public static SpriteData readFromStream(XmlReader xmlr)
        {
            SpriteData sd = new SpriteData();

            sd.spriteID = int.Parse(xmlr.GetAttribute("id"));
            xmlr.ReadToFollowing("name");
            sd.name = xmlr.ReadElementContentAsString();
            spriteNames.Add(sd.name);
            xmlr.ReadToFollowing("category");
            sd.categoryID = int.Parse(xmlr.GetAttribute("id"));
            spritesInCategory[sd.categoryID].Add(sd.spriteID);
            xmlr.ReadToFollowing("notes");
            sd.notes = xmlr.ReadElementContentAsString();
            while (xmlr.ReadToNextSibling("field"))
            {
                SpriteDataField f = new SpriteDataField();
                f.display = xmlr.GetAttribute("type");
                f.name = xmlr.GetAttribute("name");
                f.notes = xmlr.GetAttribute("notes");
                string nybbles = xmlr.GetAttribute("id");
                if (nybbles.Contains("-"))
                {
                    string[] nybbles2 = nybbles.Split('-');
                    f.startNibble = int.Parse(nybbles2[0]);
                    f.endNibble = int.Parse(nybbles2[1]);
                }
                else
                    f.startNibble = f.endNibble = int.Parse(nybbles);
                string values = xmlr.GetAttribute("values");
                switch (f.display)
                {
                    case "list":
                        string[] items = values.Split(',');
                        f.values = new int[items.Length];
                        f.strings = new string[items.Length];

                        for (int j = 0; j < items.Length; j++)
                        {
                            string[] lulz = items[j].Split(new char[] { '=' });
                            f.values[j] = Int32.Parse(lulz[0]);
                            f.strings[j] = lulz[1];
                        }
                        break;
                    case "signedvalue":
                        if (values.Trim() == "")
                            f.data = 0;
                        else
                            f.data = Int32.Parse(values);
                        break;
                    case "value":
                        if (values.Trim() == "")
                            f.data = 0;
                        else
                            f.data = Int32.Parse(values);
                        break;
                    case "checkbox":
                        if (values.Trim() == "")
                            f.data = 1;
                        else
                            f.data = Int32.Parse(values);
                        break;
                }
                sd.fields.Add(f);
            }

            return sd;
        }
Beispiel #6
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string langDir      = System.IO.Path.Combine(Application.StartupPath, "Languages");
            string langFileName = System.IO.Path.Combine(langDir, Properties.Settings.Default.LanguageFile + ".ini");

            if (System.IO.File.Exists(langFileName))
            {
                System.IO.StreamReader rdr = new StreamReader(langFileName);
                LanguageManager.Load(rdr.ReadToEnd().Split('\n'));
                rdr.Close();
            }
            else
            {
                MessageBox.Show("File " + langFileName + " could not be found, so the language has defaulted to English.");
                LanguageManager.Load(Properties.Resources.English.Split('\n'));
            }

            string[] args = Environment.GetCommandLineArgs();

            if (args.Length == 2)
            {
                Console.Out.WriteLine("Loading ROM: " + args[1]);

                NitroROMFilesystem fs = new NitroROMFilesystem(args[1]);
                ROM.load(fs);

                SpriteData.Load();
                if (Properties.Settings.Default.mdi)
                {
                    new MdiParentForm().Show();
                }
                else
                {
                    new LevelChooser().Show();
                }
            }
            else
            {
                new StartForm().Show();
            }

            Application.Run();

            /*
             *
             * if(args.Length > 2 && args[2] == "asmpatch")
             * {
             *                  PatchMaker pm = new PatchMaker(ROM.romfile.Directory);
             *                  pm.restore();
             *                  pm.generatePatch();
             * }
             * else if(args.Length > 2 && args[2] == "getcodeaddr")
             * {
             *                  PatchMaker pm = new PatchMaker(ROM.romfile.Directory);
             *                  pm.restore();
             *  Console.Out.WriteLine(String.Format("{0:X8}", pm.getCodeAddr()));
             * }*/
        }
Beispiel #7
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string langDir      = System.IO.Path.Combine(Application.StartupPath, "Languages");
            string langFileName = System.IO.Path.Combine(langDir, Properties.Settings.Default.LanguageFile + ".ini");

            if (System.IO.File.Exists(langFileName))
            {
                System.IO.StreamReader rdr = new StreamReader(langFileName);
                LanguageManager.Load(rdr.ReadToEnd().Split('\n'));
                rdr.Close();
            }
            else
            {
                MessageBox.Show("File " + langFileName + " could not be found, so the language has defaulted to English.");
                LanguageManager.Load(Properties.Resources.English.Split('\n'));
            }

            //This makes the editor behave BAD when no internet.
            //This actually catches the error now, but I'm leaving it disabled because the Sprite DB outputs a corrupt file

            //if (Properties.Settings.Default.AutoUpdateSD)
            //    SpriteData.update();


            string path = "";

            string[] args    = Environment.GetCommandLineArgs();
            string[] backups = null;

            if (Properties.Settings.Default.BackupFiles != "" &&
                MessageBox.Show("NSMBe did not shut down correctly and has recovered some of your levels.\nWould you like to open those now? If not, they can be opened later from the /Backup folder", "Open backups?", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                backups = Properties.Settings.Default.BackupFiles.Split(';');
                path    = backups[0];
            }
            else if (args.Length > 1)
            {
                path = args[1];
            }
            else
            {
                OpenFileDialog openROMDialog = new OpenFileDialog();
                openROMDialog.Filter = LanguageManager.Get("LevelChooser", "ROMFilter");
                if (openROMDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    path = openROMDialog.FileName;
                }
            }


            if (path != "")
            {
//                try
                {
                    ROM.load(path);
                }

                /*              catch (Exception ex)
                 *            {
                 *                MessageBox.Show("Could not open ROM file for writing. Is it open with other program?\n\n"+ex.Message);
                 *                return;
                 *            }
                 */
                if (args.Length > 2 && args[2] == "asmpatch")
                {
                    PatchMaker pm = new PatchMaker(ROM.romfile.Directory);
                    pm.restore();
                    pm.generatePatch();
                }
                else if (args.Length > 2 && args[2] == "getcodeaddr")
                {
                    PatchMaker pm = new PatchMaker(ROM.romfile.Directory);
                    pm.restore();
                    Console.Out.WriteLine(String.Format("{0:X8}", pm.getCodeAddr()));
                }
                else
                {
                    if (backups != null)
                    {
                        for (int l = 1; l < backups.Length; l++)
                        {
                            ROM.fileBackups.Add(backups[l]);
                        }
                    }

                    SpriteData.Load();
                    if (Properties.Settings.Default.mdi)
                    {
                        Application.Run(new MdiParentForm());
                    }
                    else
                    {
                        Application.Run(new LevelChooser());
                    }
                }
            }
        }