Exemplo n.º 1
0
        private void btnFromTplInputBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "TPL|*.tpl";

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try { inputTpl = TPL.Load(ofd.FileName); }
                catch { MessageBox.Show("The selected file is not a valid TPL!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }

                tbFromTplInput.Text = ofd.FileName;

                if (inputTpl.NumOfTextures > 1)
                {
                    cmbFromTplTexture.Items.Clear();

                    for (int i = 0; i < inputTpl.NumOfTextures; i++)
                        cmbFromTplTexture.Items.Add(i + 1);

                    cmbFromTplTexture.SelectedIndex = 0;

                    cmbFromTplTexture.Visible = true;
                    lbFromTplTexture.Visible = true;
                }
                else
                {
                    cmbFromTplTexture.Visible = false;
                    lbFromTplTexture.Visible = false;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads a TPL file.
        /// </summary>
        /// <param name="tplFile"></param>
        /// <returns></returns>
        public static TPL Load(byte[] tplFile)
        {
            TPL tmpTpl = new TPL();
            MemoryStream ms = new MemoryStream(tplFile);

            try { tmpTpl.parseTpl(ms); }
            catch { ms.Dispose(); throw; }

            ms.Dispose();
            return tmpTpl;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Loads a TPL file.
 /// </summary>
 /// <param name="tpl"></param>
 /// <returns></returns>
 public static TPL Load(Stream tpl)
 {
     TPL t = new TPL();
     t.parseTpl(tpl);
     return t;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Loads a TPL file.
        /// </summary>
        /// <param name="pathToTpl"></param>
        /// <returns></returns>
        public static TPL Load(string pathToTpl)
        {
            TPL tmpTpl = new TPL();

            MemoryStream ms = new MemoryStream(File.ReadAllBytes(pathToTpl));

            try { tmpTpl.parseTpl(ms); }
            catch { ms.Dispose(); throw; }

            ms.Dispose();
            return tmpTpl;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a TPL from multiple images.
        /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)!
        /// If you use a color indexed format, please provide at least one palette format.
        /// If you use multiple color indexed TPLs, the palette formats must have the same index as the image and tpl format!
        /// </summary>
        /// <param name="images"></param>
        /// <param name="tplFormats"></param>
        /// <returns></returns>
        public static TPL FromImages(Image[] images, TPL_TextureFormat[] tplFormats, TPL_PaletteFormat[] paletteFormats)
        {
            if (tplFormats.Length < images.Length)
                throw new Exception("You must specify a format for each image!");

            TPL tmpTpl = new TPL();
            tmpTpl.createFromImages(images, tplFormats, paletteFormats);
            return tmpTpl;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a TPL from multiple images.
        /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)!
        /// If you use a color indexed format, please provide at least one palette format.
        /// If you use multiple color indexed TPLs, the palette formats must have the same index as the image and tpl format!
        /// </summary>
        /// <param name="imagePaths"></param>
        /// <param name="tplFormats"></param>
        /// <returns></returns>
        public static TPL FromImages(string[] imagePaths, TPL_TextureFormat[] tplFormats, TPL_PaletteFormat[] paletteFormats)
        {
            if (tplFormats.Length < imagePaths.Length)
                throw new Exception("You must specify a format for each image!");

            List<Image> images = new List<Image>();
            foreach (string imagePath in imagePaths)
                images.Add(Image.FromFile(imagePath));

            TPL tmpTpl = new TPL();
            tmpTpl.createFromImages(images.ToArray(), tplFormats, paletteFormats);
            return tmpTpl;
        }
Exemplo n.º 7
0
        private void cmFormat_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "PNG|*.png|JPG|*.jpg|GIF|*.gif|BMP|*.bmp|TPL|*.tpl|All|*.png;*.jpg;*.gif;*.bmp;*.tpl";
            ofd.FilterIndex = 6;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    string tplName;
                    TPL tmpTpl = new TPL();
                    Image newImg;

                    if (cbIcon.SelectedIndex == -1)
                    {
                        tplName = cbBanner.SelectedItem.ToString().ToLower();
                        tmpTpl.LoadFile(bannerBin.Data[bannerBin.GetNodeIndex(tplName)]);
                    }
                    else
                    {
                        tplName = cbIcon.SelectedItem.ToString().ToLower();
                        tmpTpl.LoadFile(iconBin.Data[iconBin.GetNodeIndex(tplName)]);
                    }

                    if (!ofd.FileName.ToLower().EndsWith(".tpl")) newImg = Image.FromFile(ofd.FileName);
                    else
                    {
                        TPL newTpl = TPL.Load(ofd.FileName);
                        newImg = newTpl.ExtractTexture();
                    }

                    Size tplSize = tmpTpl.GetTextureSize(0);

                    if (newImg.Width != tplSize.Width ||
                        newImg.Height != tplSize.Height)
                        newImg = resizeImage(newImg, tplSize.Width, tplSize.Height);

                    ToolStripMenuItem cmSender = sender as ToolStripMenuItem;
                    TPL_TextureFormat tplFormat;
                    TPL_PaletteFormat pFormat = TPL_PaletteFormat.RGB5A3;

                    switch (cmSender.Tag.ToString().ToLower())
                    {
                        case "i4":
                            tplFormat = TPL_TextureFormat.I4;
                            break;
                        case "i8":
                            tplFormat = TPL_TextureFormat.I8;
                            break;
                        case "ia4":
                            tplFormat = TPL_TextureFormat.IA4;
                            break;
                        case "ia8":
                            tplFormat = TPL_TextureFormat.IA8;
                            break;
                        case "rgb565":
                            tplFormat = TPL_TextureFormat.RGB565;
                            break;
                        case "rgb5a3":
                            tplFormat = TPL_TextureFormat.RGB5A3;
                            break;
                        case "ci8rgb5a3":
                            tplFormat = TPL_TextureFormat.CI8;
                            pFormat = TPL_PaletteFormat.RGB5A3;
                            break;
                        case "ci8rgb565":
                            tplFormat = TPL_TextureFormat.CI8;
                            pFormat = TPL_PaletteFormat.RGB565;
                            break;
                        case "ci8ia8":
                            tplFormat = TPL_TextureFormat.CI8;
                            pFormat = TPL_PaletteFormat.IA8;
                            break;
                        case "ci4rgb5a3":
                            tplFormat = TPL_TextureFormat.CI4;
                            pFormat = TPL_PaletteFormat.RGB5A3;
                            break;
                        case "ci4rgb565":
                            tplFormat = TPL_TextureFormat.CI4;
                            pFormat = TPL_PaletteFormat.RGB565;
                            break;
                        case "ci4ia8":
                            tplFormat = TPL_TextureFormat.CI4;
                            pFormat = TPL_PaletteFormat.IA8;
                            break;
                        default:
                            tplFormat = TPL_TextureFormat.RGBA8;
                            break;
                    }

                    tmpTpl.RemoveTexture(0);
                    tmpTpl.AddTexture(newImg, tplFormat, pFormat);

                    if (cbBanner.SelectedIndex != -1)
                    {
                        bannerBin.ReplaceFile(bannerBin.GetNodeIndex(tplName), tmpTpl.ToByteArray());
                        images[0][cbBanner.SelectedIndex].tplImage = tmpTpl.ExtractTexture();
                        images[0][cbBanner.SelectedIndex].tplFormat = tmpTpl.GetTextureFormat(0).ToString();

                        if (images[0][cbBanner.SelectedIndex].tplFormat.StartsWith("CI"))
                            images[0][cbBanner.SelectedIndex].tplFormat += " + " + tmpTpl.GetPaletteFormat(0);

                        pbPic.Image = images[0][cbBanner.SelectedIndex].tplImage;
                        lbFormat.Text = images[0][cbBanner.SelectedIndex].tplFormat;
                        lbSize.Text = string.Format("{0} x {1}", images[0][cbBanner.SelectedIndex].tplImage.Width, images[0][cbBanner.SelectedIndex].tplImage.Height);
                    }
                    else
                    {
                        iconBin.ReplaceFile(iconBin.GetNodeIndex(tplName), tmpTpl.ToByteArray());
                        images[1][cbIcon.SelectedIndex].tplImage = tmpTpl.ExtractTexture();
                        images[1][cbIcon.SelectedIndex].tplFormat = tmpTpl.GetTextureFormat(0).ToString();

                        if (images[1][cbIcon.SelectedIndex].tplFormat.StartsWith("CI"))
                            images[1][cbIcon.SelectedIndex].tplFormat += " + " + tmpTpl.GetPaletteFormat(0);

                        pbPic.Image = images[1][cbIcon.SelectedIndex].tplImage;
                        lbFormat.Text = images[1][cbIcon.SelectedIndex].tplFormat;
                        lbSize.Text = string.Format("{0} x {1}", images[1][cbIcon.SelectedIndex].tplImage.Width, images[1][cbIcon.SelectedIndex].tplImage.Height);
                    }

                    if (cbBanner.SelectedIndex != -1) cbBanner.Select();
                    else if (cbIcon.SelectedIndex != -1) cbIcon.Select();

                    if (tplFormat == TPL_TextureFormat.CI4 || tplFormat == TPL_TextureFormat.CI8)
                    {
                        lbTip.Visible = true;
                        tipTimer.Start();
                    }
                }
                catch (Exception ex)
                { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            }
        }
Exemplo n.º 8
0
        private void cmChangeFormat_Click(object sender, EventArgs e)
        {
            try
            {
                string tplName;
                TPL tmpTpl = new TPL();
                Image newImg;

                if (cbIcon.SelectedIndex == -1)
                {
                    tplName = cbBanner.SelectedItem.ToString().ToLower();
                    tmpTpl.LoadFile(bannerBin.Data[bannerBin.GetNodeIndex(tplName)]);
                }
                else
                {
                    tplName = cbIcon.SelectedItem.ToString().ToLower();
                    tmpTpl.LoadFile(iconBin.Data[iconBin.GetNodeIndex(tplName)]);
                }

                newImg = tmpTpl.ExtractTexture();
                TPL_TextureFormat tplFormat;
                TPL_PaletteFormat pFormat = TPL_PaletteFormat.RGB5A3;

                ToolStripMenuItem cmSender = sender as ToolStripMenuItem;
                switch (cmSender.Tag.ToString().ToLower())
                {
                    case "i4":
                        tplFormat = TPL_TextureFormat.I4;
                        break;
                    case "i8":
                        tplFormat = TPL_TextureFormat.I8;
                        break;
                    case "ia4":
                        tplFormat = TPL_TextureFormat.IA4;
                        break;
                    case "ia8":
                        tplFormat = TPL_TextureFormat.IA8;
                        break;
                    case "rgb565":
                        tplFormat = TPL_TextureFormat.RGB565;
                        break;
                    case "rgb5a3":
                        tplFormat = TPL_TextureFormat.RGB5A3;
                        break;
                    case "ci8rgb5a3":
                        tplFormat = TPL_TextureFormat.CI8;
                        pFormat = TPL_PaletteFormat.RGB5A3;
                        break;
                    case "ci8rgb565":
                        tplFormat = TPL_TextureFormat.CI8;
                        pFormat = TPL_PaletteFormat.RGB565;
                        break;
                    case "ci8ia8":
                        tplFormat = TPL_TextureFormat.CI8;
                        pFormat = TPL_PaletteFormat.IA8;
                        break;
                    case "ci4rgb5a3":
                        tplFormat = TPL_TextureFormat.CI4;
                        pFormat = TPL_PaletteFormat.RGB5A3;
                        break;
                    case "ci4rgb565":
                        tplFormat = TPL_TextureFormat.CI4;
                        pFormat = TPL_PaletteFormat.RGB565;
                        break;
                    case "ci4ia8":
                        tplFormat = TPL_TextureFormat.CI4;
                        pFormat = TPL_PaletteFormat.IA8;
                        break;
                    default:
                        tplFormat = TPL_TextureFormat.RGBA8;
                        break;
                }

                if (tmpTpl.GetTextureFormat(0) == tplFormat) return;

                tmpTpl.RemoveTexture(0);
                tmpTpl.AddTexture(newImg, tplFormat, pFormat);

                if (cbBanner.SelectedIndex != -1)
                {
                    bannerBin.ReplaceFile(bannerBin.GetNodeIndex(tplName), tmpTpl.ToByteArray());
                    images[0][cbBanner.SelectedIndex].tplImage = tmpTpl.ExtractTexture();
                    images[0][cbBanner.SelectedIndex].tplFormat = tmpTpl.GetTextureFormat(0).ToString();

                    if (images[0][cbBanner.SelectedIndex].tplFormat.StartsWith("CI"))
                        images[0][cbBanner.SelectedIndex].tplFormat += " + " + tmpTpl.GetPaletteFormat(0);

                    pbPic.Image = images[0][cbBanner.SelectedIndex].tplImage;
                    lbFormat.Text = images[0][cbBanner.SelectedIndex].tplFormat;
                    lbSize.Text = string.Format("{0} x {1}", images[0][cbBanner.SelectedIndex].tplImage.Width, images[0][cbBanner.SelectedIndex].tplImage.Height);
                }
                else
                {
                    iconBin.ReplaceFile(iconBin.GetNodeIndex(tplName), tmpTpl.ToByteArray());
                    images[1][cbIcon.SelectedIndex].tplImage = tmpTpl.ExtractTexture();
                    images[1][cbIcon.SelectedIndex].tplFormat = tmpTpl.GetTextureFormat(0).ToString();

                    if (images[1][cbIcon.SelectedIndex].tplFormat.StartsWith("CI"))
                        images[1][cbIcon.SelectedIndex].tplFormat += " + " + tmpTpl.GetPaletteFormat(0);

                    pbPic.Image = images[1][cbIcon.SelectedIndex].tplImage;
                    lbFormat.Text = images[1][cbIcon.SelectedIndex].tplFormat;
                    lbSize.Text = string.Format("{0} x {1}", images[1][cbIcon.SelectedIndex].tplImage.Width, images[1][cbIcon.SelectedIndex].tplImage.Height);
                }

                if (cbBanner.SelectedIndex != -1) cbBanner.Select();
                else if (cbIcon.SelectedIndex != -1) cbIcon.Select();

                if (tplFormat == TPL_TextureFormat.CI4 || tplFormat == TPL_TextureFormat.CI8)
                {
                    lbTip.Visible = true;
                    tipTimer.Start();
                }
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }