コード例 #1
0
        void OpenPng_Click(object sender, EventArgs e)
        {
            if (OpenPngs.Enabled == false)
            {
                return;
            }
            OpenPngs.Enabled = false;
            LoadingForm Open   = new LoadingForm();
            var         result = Open.ShowDialog();

            if (result == DialogResult.Cancel)
            {
                OpenPngs.Enabled = true;
                return;
            }
            string[] filenames    = Open.files;
            bool     Autofill     = Open.result;
            int      shinymatch   = Open.shinymatch;
            bool     paletteMatch = Open.paletteMatch;

            Open.Dispose();
            SpriteSet temp = new SpriteSet();
            Bitmap    image;

            for (int i = 0; i < 4; i++)
            {
                if (filenames[i] == "")
                {
                    continue;
                }
                image           = new Bitmap(filenames[i]);
                temp.Sprites[i] = CheckSize(image, filenames[i], names[i], i);
            }
            bool[] tempUsed = null;
            if (paletteMatch)
            {
                temp.Normal = CurrentSprites.Normal;
                tempUsed    = used;
            }
            for (int i = 0; i < 4; i++)
            {
                if (temp.Sprites[i] == null)
                {
                    continue;
                }
                if (temp.Normal == null)
                {
                    temp.Normal = temp.Sprites[i].Palette;
                    tempUsed    = Handler.IsUsed(temp.Sprites[i]);
                }
                else
                {
                    bool match = Handler.PaletteEquals(temp.Normal, temp.Sprites[i]);
                    if (!match)
                    {
                        temp.Sprites[i] = Handler.PaletteMatch(temp.Normal, temp.Sprites[i], tempUsed);
                        temp.Normal     = temp.Sprites[i].Palette;
                    }
                    tempUsed = Handler.IsUsed(temp.Sprites[i], tempUsed);
                }
            }
            used = tempUsed;
            if (filenames[4] != "")
            {
                image = new Bitmap(filenames[4]);
                image = CheckSize(image, filenames[4], names[4], 4);
                if ((shinymatch < 4) && (temp.Sprites[shinymatch] != null))
                {
                    temp.Shiny = Handler.AlternatePalette(temp.Sprites[shinymatch], image);
                }
                else
                {
                    temp.Shiny = image.Palette;
                }
            }

            if (Autofill)
            {
                if (temp.Sprites[0] == null)
                {
                    temp.Sprites[0] = temp.Sprites[1];
                }
                if (temp.Sprites[1] == null)
                {
                    temp.Sprites[1] = temp.Sprites[0];
                }
                if (temp.Sprites[2] == null)
                {
                    temp.Sprites[2] = temp.Sprites[3];
                }
                if (temp.Sprites[3] == null)
                {
                    temp.Sprites[3] = temp.Sprites[2];
                }
                if (filenames[4] == "")
                {
                    temp.Shiny = temp.Normal;
                }
            }

            for (int i = 0; i < 4; i++)
            {
                if (temp.Sprites[i] != null)
                {
                    CurrentSprites.Sprites[i] = temp.Sprites[i];
                }
            }
            if (temp.Normal != null)
            {
                CurrentSprites.Normal = temp.Normal;
            }
            if (temp.Shiny != null)
            {
                CurrentSprites.Shiny = temp.Shiny;
            }

            LoadImages();
            OpenPngs.Enabled = true;
        }
コード例 #2
0
        void Picturebox_Click(object sender, EventArgs e)
        {
            if (OpenPngs.Enabled == false)
            {
                return;
            }
            OpenPngs.Enabled = false;
            PictureBox     source         = sender as PictureBox;
            int            index          = Convert.ToInt32(source.Name);
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Title           = "Choose an image";
            openFileDialog.CheckPathExists = true;
            openFileDialog.Filter          = "Supported fomats: *.bmp, *.gif, *.png | *.bmp; *.gif; *.png";
            openFileDialog.ShowHelp        = true;
            Bitmap image;

            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                OpenPngs.Enabled = true;
                return;
            }
            image = new Bitmap(openFileDialog.FileName);
            IndexedBitmapHandler Handler = new IndexedBitmapHandler();

            if (index > 3)
            {
                image = CheckSize(image, openFileDialog.FileName, "Shiny");
                if (image == null)
                {
                    OpenPngs.Enabled = true;
                    return;
                }
                ColorPalette temp = Handler.AlternatePalette(CurrentSprites.Sprites[index % 4], image);
                if (temp != null)
                {
                    CurrentSprites.Shiny = temp;
                }
                else
                {
                    CurrentSprites.Shiny = image.Palette;
                }
            }
            else
            {
                image = CheckSize(image, openFileDialog.FileName, names[index], index);
                if (image == null)
                {
                    OpenPngs.Enabled = true;
                    return;
                }
                bool match = Handler.PaletteEquals(CurrentSprites.Normal, image);
                if (!match)
                {
                    DialogResult yesno = MessageBox.Show("Image's palette does not match the current palette.  Use PaletteMatch?", "Palette mismatch", MessageBoxButtons.YesNo);
                    if (yesno == DialogResult.Yes)
                    {
                        image = Handler.PaletteMatch(CurrentSprites.Normal, image, used);
                        used  = Handler.IsUsed(image, used);
                    }
                    else
                    {
                        used = Handler.IsUsed(image);
                    }
                    CurrentSprites.Normal = image.Palette;
                }
                CurrentSprites.Sprites[index] = image;
            }
            OpenPngs.Enabled = true;
            LoadImages();
        }