Exemple #1
0
        public Palette256(Document doc, Palettes pals, string strName, int id, string strDesc)
            : base(doc, pals, strName, id, strDesc)
        {
            m_type = Palette.Type.Color256;

            m_data = new PaletteColorData(k_nColors);

            if (m_doc.Owner != null)
                m_winPalette = new Palette256Form(m_doc.Owner, this);
        }
Exemple #2
0
        public Palette(Document doc, Palettes pals, string strName, int id, string strDesc)
        {
            m_doc      = doc;
            m_palettes = pals;
            m_strName  = strName;
            m_id       = id;
            m_strDesc  = strDesc;

            m_type            = Type.Unknown;
            m_nMaxSubpalettes = 0;
        }
Exemple #3
0
        public Palette(Document doc, Palettes pals, string strName, int id, string strDesc)
        {
            m_doc = doc;
            m_palettes = pals;
            m_strName = strName;
            m_id = id;
            m_strDesc = strDesc;

            m_type = Type.Unknown;
            m_nMaxSubpalettes = 0;
        }
Exemple #4
0
        public Palette256(Document doc, Palettes pals, string strName, int id, string strDesc) :
            base(doc, pals, strName, id, strDesc)
        {
            m_type = Palette.Type.Color256;

            m_data = new PaletteColorData(k_nColors);

            if (m_doc.Owner != null)
            {
                m_winPalette = new Palette256Form(m_doc.Owner, this);
            }
        }
Exemple #5
0
        public Palette16(Document doc, Palettes pals, string strName, int id, string strDesc)
            : base(doc, pals, strName, id, strDesc)
        {
            m_type = Palette.Type.Color16;
            m_nMaxSubpalettes = 16;

            m_subpalettes = new Subpalette[m_nMaxSubpalettes];
            for (int i = 0; i < m_nMaxSubpalettes; i++)
                m_subpalettes[i] = new Subpalette(doc, this, i, Subpalette.DefaultColorSet.BlackAndWhite);

            CurrentSubpaletteId = 0;

            if (m_doc.Owner != null)
                m_winPalette = new Palette16Form(m_doc.Owner, this);
        }
Exemple #6
0
        public Palette16(Document doc, Palettes pals, string strName, int id, string strDesc) :
            base(doc, pals, strName, id, strDesc)
        {
            m_type            = Palette.Type.Color16;
            m_nMaxSubpalettes = 16;

            m_subpalettes = new Subpalette[m_nMaxSubpalettes];
            for (int i = 0; i < m_nMaxSubpalettes; i++)
            {
                m_subpalettes[i] = new Subpalette(doc, this, i, Subpalette.DefaultColorSet.BlackAndWhite);
            }

            CurrentSubpaletteId = 0;

            if (m_doc.Owner != null)
            {
                m_winPalette = new Palette16Form(m_doc.Owner, this);
            }
        }
Exemple #7
0
        private bool LoadXML_OLD_palettes(XmlNodeList xnl, Palettes palettes, string strName)
        {
            Palette16 palette     = palettes.AddPalette16(strName, 0, "");
            int       nSubpalette = 0;

            foreach (XmlNode xn in xnl)
            {
                if (xn.Name == "palette")
                {
                    int nSubpaletteId = XMLUtils.GetXMLIntegerAttribute(xn, "id");
                    if (nSubpalette > 16)
                    {
                        // Incorrect number of subpalettes - too many.
                        m_doc.ErrorString("Too many subpalettes specified for palette (expected 16)");
                        return(false);
                    }
                    if (nSubpaletteId != nSubpalette)
                    {
                        // Subpalettes out of order.
                        m_doc.ErrorString("Subpalette ids are out of order");
                        return(false);
                    }

                    int[] anPalette  = new int[16];
                    int   nCurrEntry = 0;

                    Regex rxPalette = new Regex(@"\s*0x([0-9A-Fa-f]{4})\s*,");
                    Match mxPalette = rxPalette.Match(xn.InnerText);
                    if (mxPalette.Success)
                    {
                        while (mxPalette.Success)
                        {
                            GroupCollection matchGroups = mxPalette.Groups;

                            if (nCurrEntry >= 16)
                            {
                                // Wrong number of colors in palette - too many.
                                m_doc.ErrorString("Too many colors specified for subpalette {0} (expected 16)", nSubpaletteId);
                                return(false);
                            }

                            anPalette[nCurrEntry] = Convert.ToInt32(matchGroups[1].Value, 16);
                            nCurrEntry++;
                            if (nCurrEntry == 16)
                            {
                                // After we've read 16 colors, update the subpalette.
                                if (!palette.ImportSubpalette(nSubpaletteId, anPalette))
                                {
                                    // Warning/Error message already displayed.
                                    return(false);
                                }

                                // Since we just loaded from a file, update the snapshot without creating an UndoAction
                                palette.GetSubpalette(nSubpaletteId).RecordSnapshot();
                            }

                            // Get the next match.
                            mxPalette = mxPalette.NextMatch();
                        }

                        if (nCurrEntry != 16)
                        {
                            // "Wrong number of colors in palette with ID='{0}'. Found {1}, expected 16."
                            m_doc.ErrorId("ErrorNumColorsInPalette", nSubpaletteId, nCurrEntry);
                            return(false);
                        }
                    }
                    nSubpalette++;
                }
            }

            if (nSubpalette != 16)
            {
                // Incorrect number of subpalettes - too few.
                m_doc.ErrorString("Too few subpalettes (expected 16)");
                return(false);
            }

            return(true);
        }
        private bool LoadXML_OLD_palettes(XmlNodeList xnl, Palettes palettes, string strName)
        {
            Palette16 palette = palettes.AddPalette16(strName, 0, "");
            int nSubpalette = 0;

            foreach (XmlNode xn in xnl)
            {
                if (xn.Name == "palette")
                {
                    int nSubpaletteId = XMLUtils.GetXMLIntegerAttribute(xn, "id");
                    if (nSubpalette > 16)
                    {
                        // Incorrect number of subpalettes - too many.
                        m_doc.ErrorString("Too many subpalettes specified for palette (expected 16)");
                        return false;
                    }
                    if (nSubpaletteId != nSubpalette)
                    {
                        // Subpalettes out of order.
                        m_doc.ErrorString("Subpalette ids are out of order");
                        return false;
                    }

                    int[] anPalette = new int[16];
                    int nCurrEntry = 0;

                    Regex rxPalette = new Regex(@"\s*0x([0-9A-Fa-f]{4})\s*,");
                    Match mxPalette = rxPalette.Match(xn.InnerText);
                    if (mxPalette.Success)
                    {
                        while (mxPalette.Success)
                        {
                            GroupCollection matchGroups = mxPalette.Groups;

                            if (nCurrEntry >= 16)
                            {
                                // Wrong number of colors in palette - too many.
                                m_doc.ErrorString("Too many colors specified for subpalette {0} (expected 16)", nSubpaletteId);
                                return false;
                            }

                            anPalette[nCurrEntry] = Convert.ToInt32(matchGroups[1].Value, 16);
                            nCurrEntry++;
                            if (nCurrEntry == 16)
                            {
                                // After we've read 16 colors, update the subpalette.
                                if (!palette.ImportSubpalette(nSubpaletteId, anPalette))
                                {
                                    // Warning/Error message already displayed.
                                    return false;
                                }

                                // Since we just loaded from a file, update the snapshot without creating an UndoAction
                                palette.GetSubpalette(nSubpaletteId).RecordSnapshot();
                            }

                            // Get the next match.
                            mxPalette = mxPalette.NextMatch();
                        }

                        if (nCurrEntry != 16)
                        {
                            // "Wrong number of colors in palette with ID='{0}'. Found {1}, expected 16."
                            m_doc.ErrorId("ErrorNumColorsInPalette", nSubpaletteId, nCurrEntry);
                            return false;
                        }
                    }
                    nSubpalette++;
                }
            }

            if (nSubpalette != 16)
            {
                // Incorrect number of subpalettes - too few.
                m_doc.ErrorString("Too few subpalettes (expected 16)");
                return false;
            }

            return true;
        }
        private bool ExportFromTemplate(string strProjName, string strTemplateFilename, string strOutputFilename, bool fNDS)
        {
            try
            {
                string strExeDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

                string strTemplateDir = String.Format("{0}{1}{2}{3}", strExeDir,
                                                      Path.DirectorySeparatorChar,
                                                      "templates",
                                                      Path.DirectorySeparatorChar);

                using (TextReader tr = new StreamReader(strTemplateDir + strTemplateFilename, Encoding.UTF8))
                {
                    using (TextWriter tw = new StreamWriter(strOutputFilename))
                    {
                        Spritesets sprites    = m_doc.Spritesets;
                        Spritesets bgsprites  = m_doc.BackgroundSpritesets;
                        Palettes   palettes   = m_doc.Palettes;
                        Palettes   bgpalettes = m_doc.BackgroundPalettes;
                        Maps       maps       = m_doc.BackgroundMaps;
                        BgImages   bgimages   = m_doc.BackgroundImages;

                        sprites.Export_AssignIDs();
                        bgsprites.Export_AssignIDs();
                        palettes.Export_AssignIDs();
                        bgpalettes.Export_AssignIDs();
                        maps.Export_AssignIDs();
                        bgimages.Export_AssignIDs();

                        string strLine;
                        while ((strLine = tr.ReadLine()) != null)
                        {
                            if (strLine.StartsWith("%%NDS:%%"))
                            {
                                if (fNDS)
                                {
                                    tw.WriteLine(strLine.Substring(8));
                                }
                                continue;
                            }
                            if (strLine.StartsWith("%%GBA:%%"))
                            {
                                if (!fNDS)
                                {
                                    tw.WriteLine(strLine.Substring(8));
                                }
                                continue;
                            }

                            if (strLine == "%%_SPRITE_PALETTE_INFO_%%")
                            {
                                palettes.Export_PaletteInfo(tw);
                                continue;
                            }
                            if (strLine == "%%_SPRITE_PALETTES_%%")
                            {
                                palettes.Export_Palettes(tw);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_PALETTE_INFO_%%")
                            {
                                bgpalettes.Export_PaletteInfo(tw);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_PALETTES_%%")
                            {
                                bgpalettes.Export_Palettes(tw);
                                continue;
                            }

                            if (strLine == "%%_SPRITESET_INFO_%%")
                            {
                                sprites.Export_SpritesetInfo(tw);
                                continue;
                            }
                            if (strLine == "%%_SPRITESET_IDS_%%")
                            {
                                sprites.Export_SpritesetIDs(tw);
                                continue;
                            }

                            if (strLine == "%%_SPRITE_INFO_%%")
                            {
                                sprites.Export_SpriteInfo(tw);
                                continue;
                            }
                            if (strLine == "%%_SPRITE_TILES_%%")
                            {
                                sprites.Export_TileData(tw);
                                continue;
                            }
                            if (strLine == "%%_SPRITE_MASKS_%%")
                            {
                                sprites.Export_SpriteMaskData(tw);
                                continue;
                            }
                            if (strLine == "%%_SPRITE_IDS_%%")
                            {
                                sprites.Export_SpriteIDs(tw);
                                continue;
                            }

                            if (strLine == "%%_BACKGROUND_TILESET_INFO_%%")
                            {
                                bgsprites.Export_BgTilesetInfo(tw);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_TILESET_IDS_%%")
                            {
                                bgsprites.Export_BgTilesetIDs(tw);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_TILES_%%")
                            {
                                bgsprites.Export_TileData(tw);
                                continue;
                            }

                            if (strLine == "%%_BACKGROUND_TILE_IDS_%%")
                            {
                                bgsprites.Export_TileIDs(tw);
                                continue;
                            }

                            if (strLine == "%%_BACKGROUND_MAP_INFO_%%")
                            {
                                maps.Export_MapInfo(tw);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_MAP_IDS_%%")
                            {
                                maps.Export_MapIDs(tw);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_MAP_DATA_%%")
                            {
                                maps.Export_MapData(tw);
                                continue;
                            }

                            if (strLine == "%%_BACKGROUND_IMAGE_INFO_%%")
                            {
                                bgimages.Export_BgImageInfo(tw, fNDS);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_IMAGE_IDS_%%")
                            {
                                bgimages.Export_BgImageIDs(tw);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_IMAGE_HEADERS_%%")
                            {
                                bgimages.Export_BgImageHeaders(tw, fNDS);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_IMAGE_PALETTEDATA_%%")
                            {
                                bgimages.Export_BgImagePaletteData(tw);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_IMAGE_DATA_PALETTED_%%")
                            {
                                bgimages.Export_BgImageData_Paletted(tw);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_IMAGE_DATA_DIRECT_%%")
                            {
                                bgimages.Export_BgImageData_Direct(tw);
                                continue;
                            }

                            strLine = strLine.Replace("%%_NAME_%%", strProjName);
                            strLine = strLine.Replace("%%_VERSION_%%", ResourceMgr.GetString("Version"));
                            strLine = strLine.Replace("%%_PLATFORM_%%", fNDS ? "NDS" : "GBA");

                            strLine = strLine.Replace("%%_NUM_PALETTES_%%", palettes.NumPalettes.ToString());
                            strLine = strLine.Replace("%%_NUM_SPRITESETS_%%", sprites.NumSpritesets.ToString());
                            strLine = strLine.Replace("%%_NUM_SPRITES_%%", sprites.NumSprites.ToString());
                            strLine = strLine.Replace("%%_NUM_TILES_%%", sprites.NumTiles.ToString());

                            strLine = strLine.Replace("%%_NUM_BACKGROUND_PALETTES_%%", bgpalettes.NumPalettes.ToString());
                            strLine = strLine.Replace("%%_NUM_BACKGROUND_TILESETS_%%", bgsprites.NumSpritesets.ToString());
                            strLine = strLine.Replace("%%_NUM_BACKGROUND_TILES_%%", bgsprites.NumTiles.ToString());

                            strLine = strLine.Replace("%%_NUM_BACKGROUND_MAPS_%%", maps.NumMaps.ToString());

                            strLine = strLine.Replace("%%_NUM_BACKGROUND_IMAGES_%%", bgimages.NumImages.ToString());

                            tw.WriteLine(strLine);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // "An exception was thrown while load the project template files: {0}"
                m_doc.ErrorId("ExceptionLoadTemplate", ex.Message);
                // "An exception was thrown while opening the project file for writing: {0}"
                //m_doc.ErrorId("ExceptionOpenProjectWrite", ex.Message);
                return(false);
            }

            return(true);
        }