Beispiel #1
0
 public void SetPaletteFromRawPAL(byte[] rawPalette, bool resetColourTypes)
 {
     for (int i = 0; i < _palette.Length; i++)
     {
         _palette[i] = new PaletteEntry(i, Color.FromArgb(rawPalette[i * 3] * 4, rawPalette[i * 3 + 1] * 4, rawPalette[i * 3 + 2] * 4));
         if (resetColourTypes)
         {
             if (i <= 41)
             {
                 _palette[i].ColourType = PaletteColourType.Gamewide;
             }
             else
             {
                 _palette[i].ColourType = PaletteColourType.Background;
             }
         }
     }
 }
Beispiel #2
0
 public PaletteEntry[] ReadPaletteFromXML(XmlNode parentOfPaletteNode)
 {
     PaletteEntry[] palette = new PaletteEntry[PALETTE_SIZE];
     for (int i = 0; i < palette.Length; i++)
     {
         palette[i]            = new PaletteEntry(i, _palette[i].Colour);
         palette[i].ColourType = _palette[i].ColourType;
     }
     foreach (XmlNode palNode in SerializeUtils.GetChildNodes(parentOfPaletteNode, "Palette"))
     {
         PaletteEntry paletteEntry = palette[Convert.ToInt32(palNode.Attributes["Index"].InnerText)];
         paletteEntry.Colour = Color.FromArgb(
             Convert.ToInt32(palNode.Attributes["Red"].InnerText),
             Convert.ToInt32(palNode.Attributes["Green"].InnerText),
             Convert.ToInt32(palNode.Attributes["Blue"].InnerText));
         paletteEntry.ColourType = (PaletteColourType)Enum.Parse(typeof(PaletteColourType), palNode.Attributes["Type"].InnerText);
     }
     return(palette);
 }
Beispiel #3
0
 private static Dictionary<int, int> ImportSpritesFromXML(XmlNode spritesNode, PaletteEntry[] paletteEntries, SpriteFolder folderToAddTo)
 {
     Dictionary<int, int> spriteNumberMapping = new Dictionary<int, int>();
     ImportSpritesFromXML(spritesNode, paletteEntries, folderToAddTo, spriteNumberMapping);
     return spriteNumberMapping;
 }
Beispiel #4
0
        private static void ImportSpritesFromXML(XmlNode spritesNode, PaletteEntry[] paletteEntries, SpriteFolder folderToAddTo, Dictionary<int, int> spriteNumberMapping)
        {
            Color[] palette = new Color[paletteEntries.Length];
            for (int i = 0; i < paletteEntries.Length; i++)
            {
                palette[i] = paletteEntries[i].Colour;
            }

            List<Sprite> newSprites = new List<Sprite>();

            foreach (XmlNode childNode in spritesNode.ChildNodes)
            {
                if (childNode.Name == GUI_XML_SPRITE_NODE)
                {
                    int spriteNumber = SerializeUtils.GetAttributeInt(childNode, GUI_XML_SPRITE_NUMBER);
                    int colDepth = SerializeUtils.GetAttributeInt(childNode, GUI_XML_SPRITE_COLOR_DEPTH);
                    bool hasAlphaChannel = bool.Parse(SerializeUtils.GetAttributeString(childNode, GUI_XML_SPRITE_ALPHA_CHANNEL));
                    int width = SerializeUtils.GetAttributeInt(childNode, GUI_XML_SPRITE_WIDTH);
                    int height = SerializeUtils.GetAttributeInt(childNode, GUI_XML_SPRITE_HEIGHT);
                    SpriteImportResolution resolution = (SpriteImportResolution)Enum.Parse(typeof(SpriteImportResolution), SerializeUtils.GetAttributeString(childNode, GUI_XML_SPRITE_RESOLUTION));
                    byte[]spriteData = Convert.FromBase64String(childNode.InnerText);

                    Sprite newSprite = ImportSpriteFromRawData(colDepth, width, height, hasAlphaChannel, spriteData, palette);
                    newSprite.Resolution = resolution;

                    newSprites.Add(newSprite);
                    spriteNumberMapping.Add(spriteNumber, newSprite.Number);
                    folderToAddTo.Sprites.Add(newSprite);
                }
            }

            Factory.NativeProxy.SpriteResolutionsChanged(newSprites.ToArray());
        }
Beispiel #5
0
        public static PaletteEntry[] ImportPaletteFromFile(string filename)
        {
            PaletteEntry[] newPalette = new PaletteEntry[256];

            if (filename.ToLower().EndsWith(".pal"))
            {
                byte[] rawPalette = new byte[768];
                FileStream fs = new FileStream(filename, FileMode.Open);
                fs.Read(rawPalette, 0, rawPalette.Length);
                fs.Close();

                for (int i = 0; i < newPalette.Length; i++)
                {
                    newPalette[i] = new PaletteEntry(i, Color.FromArgb(rawPalette[i * 3] * 4, rawPalette[i * 3 + 1] * 4, rawPalette[i * 3 + 2] * 4));
                }
            }
            else if (filename.ToLower().EndsWith(".bmp"))
            {
                Bitmap bmp = new Bitmap(filename);
                if (bmp.PixelFormat != PixelFormat.Format8bppIndexed)
                {
                    throw new AGSEditorException("Selected bitmap file is not a 256-colour bitmap. Only 8-bit images can have a palette imported.");
                }
                for (int i = 0; i < newPalette.Length; i++)
                {
                    newPalette[i] = new PaletteEntry(i, bmp.Palette.Entries[i]);
                }
                bmp.Dispose();
            }
            else
            {
                throw new AGSEditorException("Invalid file format requested for import. Supports PAL and BMP.");
            }

            return newPalette;
        }
Beispiel #6
0
 private static int ReadAndAddNewStyleView(XmlNode parentOfViewNode, Game game, Dictionary<int, int> spriteMapping, PaletteEntry[] palette, SpriteFolder newFolder)
 {
     View newView = new View(parentOfViewNode.SelectSingleNode("View"));
     newView.ID = game.FindAndAllocateAvailableViewID();
     ImportSpritesFromXML(parentOfViewNode, palette, newFolder, spriteMapping);
     UpdateViewWithSpriteMapping(newView, spriteMapping);
     EnsureViewNameIsUnique(newView, game);
     game.RootViewFolder.Views.Add(newView);
     return newView.ID;
 }
Beispiel #7
0
 public void SetPaletteFromRawPAL(byte[] rawPalette, bool resetColourTypes)
 {
     for (int i = 0; i < _palette.Length; i++)
     {
         _palette[i] = new PaletteEntry(i, Color.FromArgb(rawPalette[i * 3] * 4, rawPalette[i * 3 + 1] * 4, rawPalette[i * 3 + 2] * 4));
         if (resetColourTypes)
         {
             if (i <= 41)
             {
                 _palette[i].ColourType = PaletteColourType.Gamewide;
             }
             else
             {
                 _palette[i].ColourType = PaletteColourType.Background;
             }
         }
     }
 }
Beispiel #8
0
 public PaletteEntry[] ReadPaletteFromXML(XmlNode parentOfPaletteNode)
 {
     PaletteEntry[] palette = new PaletteEntry[PALETTE_SIZE];
     for (int i = 0; i < palette.Length; i++)
     {
         palette[i] = new PaletteEntry(i, _palette[i].Colour);
         palette[i].ColourType = _palette[i].ColourType;
     }
     foreach (XmlNode palNode in SerializeUtils.GetChildNodes(parentOfPaletteNode, "Palette"))
     {
         PaletteEntry paletteEntry = palette[Convert.ToInt32(palNode.Attributes["Index"].InnerText)];
         paletteEntry.Colour = Color.FromArgb(
             Convert.ToInt32(palNode.Attributes["Red"].InnerText),
             Convert.ToInt32(palNode.Attributes["Green"].InnerText),
             Convert.ToInt32(palNode.Attributes["Blue"].InnerText));
         paletteEntry.ColourType = (PaletteColourType)Enum.Parse(typeof(PaletteColourType), palNode.Attributes["Type"].InnerText);
     }
     return palette;
 }
Beispiel #9
0
        public static PaletteEntry[] ImportPaletteFromFile(string filename)
        {
            PaletteEntry[] newPalette = new PaletteEntry[256];

            if (filename.ToLower().EndsWith(".pal"))
            {
                byte[] rawPalette = new byte[768];
                FileStream fs = new FileStream(filename, FileMode.Open);
                fs.Read(rawPalette, 0, rawPalette.Length);
                fs.Close();

                for (int i = 0; i < newPalette.Length; i++)
                {
                    newPalette[i] = new PaletteEntry(i, Color.FromArgb(rawPalette[i * 3] * 4, rawPalette[i * 3 + 1] * 4, rawPalette[i * 3 + 2] * 4));
                }
            }
            else if (filename.ToLower().EndsWith(".bmp"))
            {
                Bitmap bmp = new Bitmap(filename);
                if (bmp.PixelFormat != PixelFormat.Format8bppIndexed)
                {
                    throw new AGSEditorException("Le fichier bitmap sélectionné n'est pas un fichier bitmap 256 couleurs. Seules les images 8-bit peuvent avoir une palette importée.");
                }
                for (int i = 0; i < newPalette.Length; i++)
                {
                    newPalette[i] = new PaletteEntry(i, bmp.Palette.Entries[i]);
                }
                bmp.Dispose();
            }
            else
            {
                throw new AGSEditorException("Format de fichier à l'import invalide. Support du PAL et du BMP.");
            }

            return newPalette;
        }