コード例 #1
0
        private void addTpl(ListBox lbx, string inputFile)
        {
            try
            {
                int switchVal = lbx == lbxBannerTpls ? cmbFormatBanner.SelectedIndex : cmbFormatIcon.SelectedIndex;
                if (switchVal > 9)
                    throw new Exception("This format is not supported, you must choose a different one!");

                if (string.IsNullOrEmpty(inputFile))
                {
                    OpenFileDialog ofd = new OpenFileDialog();
                    ofd.Filter = "TPL|*.tpl|PNG|*.png|JPG|*.jpg|GIF|*.gif|BMP|*.bmp|All|*.tpl;*.png;*.jpg;*.gif;*.bmp";
                    ofd.FilterIndex = 6;

                    if (ofd.ShowDialog() == DialogResult.OK)
                        inputFile = ofd.FileName;
                }

                if (!string.IsNullOrEmpty(inputFile))
                {
                    string tplName = Path.GetFileNameWithoutExtension(inputFile) + ".tpl";

                    if (lbx == lbxBannerTpls)
                    {
                        if (string.IsNullOrEmpty(replacedBanner))
                        {
                            for (int i = 0; i < bannerBin.NumOfNodes; i++)
                                if (bannerBin.StringTable[i].ToLower() == tplName.ToLower())
                                { errorBox("This TPL already exists, use the Replace button"); return; }
                        }
                        else
                        {
                            for (int i = 0; i < newBannerBin.NumOfNodes; i++)
                                if (newBannerBin.StringTable[i].ToLower() == tplName.ToLower())
                                { errorBox("This TPL already exists, use the Replace button"); return; }
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(replacedIcon))
                        {
                            for (int i = 0; i < iconBin.NumOfNodes; i++)
                                if (iconBin.StringTable[i].ToLower() == tplName.ToLower())
                                { errorBox("This TPL already exists, use the Replace button"); return; }
                        }
                        else
                        {
                            for (int i = 0; i < newIconBin.NumOfNodes; i++)
                                if (newIconBin.StringTable[i].ToLower() == tplName.ToLower())
                                { errorBox("This TPL already exists, use the Replace button"); return; }
                        }
                    }

                    string[] requiredTpls = new string[0];

                    if (lbx == lbxBannerTpls)
                    {
                        if (string.IsNullOrEmpty(replacedBanner))
                        {
                            for (int i = 0; i < bannerBin.NumOfNodes; i++)
                            {
                                if (bannerBin.StringTable[i].ToLower().EndsWith(".brlyt"))
                                { requiredTpls = Shared.MergeStringArrays(requiredTpls, Brlyt.GetBrlytTpls(bannerBin.Data[i])); }
                                else if (bannerBin.StringTable[i].ToLower().EndsWith(".brlan"))
                                { requiredTpls = Shared.MergeStringArrays(requiredTpls, Brlan.GetBrlanTpls(bannerBin.Data[i])); }
                            }
                        }
                        else
                        {
                            for (int i = 0; i < newBannerBin.NumOfNodes; i++)
                            {
                                if (newBannerBin.StringTable[i].ToLower().EndsWith(".brlyt"))
                                { requiredTpls = Shared.MergeStringArrays(requiredTpls, Brlyt.GetBrlytTpls(newBannerBin.Data[i])); }
                                else if (newBannerBin.StringTable[i].ToLower().EndsWith(".brlan"))
                                { requiredTpls = Shared.MergeStringArrays(requiredTpls, Brlan.GetBrlanTpls(newBannerBin.Data[i])); }
                            }
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(replacedIcon))
                        {
                            for (int i = 0; i < iconBin.NumOfNodes; i++)
                            {
                                if (iconBin.StringTable[i].ToLower().EndsWith(".brlyt"))
                                { requiredTpls = Shared.MergeStringArrays(requiredTpls, Brlyt.GetBrlytTpls(iconBin.Data[i])); }
                                else if (iconBin.StringTable[i].ToLower().EndsWith(".brlan"))
                                { requiredTpls = Shared.MergeStringArrays(requiredTpls, Brlan.GetBrlanTpls(iconBin.Data[i])); }
                            }
                        }
                        else
                        {
                            for (int i = 0; i < newIconBin.NumOfNodes; i++)
                            {
                                if (newIconBin.StringTable[i].ToLower().EndsWith(".brlyt"))
                                { requiredTpls = Shared.MergeStringArrays(requiredTpls, Brlyt.GetBrlytTpls(newIconBin.Data[i])); }
                                else if (newIconBin.StringTable[i].ToLower().EndsWith(".brlan"))
                                { requiredTpls = Shared.MergeStringArrays(requiredTpls, Brlan.GetBrlanTpls(newIconBin.Data[i])); }
                            }
                        }
                    }

                    if (!Array.Exists(requiredTpls, thisTpl => thisTpl.ToLower() == tplName.ToLower()))
                    {
                        if (MessageBox.Show(
                            string.Format("{0} is not required by your {1}.brlyt and thus only wastes memory!\n" +
                            "Do you still want to add it?", tplName, lbx == lbxBannerTpls ? "banner" : "icon"),
                            "TPL not required", MessageBoxButtons.YesNo, MessageBoxIcon.Information) ==
                            DialogResult.No)
                            return;
                    }

                    int tplFormat = 6;

                    TPL_PaletteFormat pFormat = TPL_PaletteFormat.RGB5A3;

                    switch (switchVal)
                    {
                        case 6:
                            tplFormat = (int)TPL_TextureFormat.I4;
                            break;
                        case 5:
                            tplFormat = (int)TPL_TextureFormat.I8;
                            break;
                        case 4:
                            tplFormat = (int)TPL_TextureFormat.IA4;
                            break;
                        case 3:
                            tplFormat = (int)TPL_TextureFormat.IA8;
                            break;
                        case 0:
                            tplFormat = (int)TPL_TextureFormat.RGBA8;
                            break;
                        case 1:
                            tplFormat = (int)TPL_TextureFormat.RGB565;
                            break;
                        case 2:
                            tplFormat = (int)TPL_TextureFormat.RGB5A3;
                            break;
                        case 7:
                            tplFormat = (int)TPL_TextureFormat.CI4;

                            CustomizeMii_PaletteFormatBox pfb = new CustomizeMii_PaletteFormatBox();
                            pfb.ShowDialog();

                            pFormat = pfb.PaletteFormat;
                            break;
                        case 8:
                            tplFormat = (int)TPL_TextureFormat.CI8;

                            CustomizeMii_PaletteFormatBox pfb2 = new CustomizeMii_PaletteFormatBox();
                            pfb2.ShowDialog();

                            pFormat = pfb2.PaletteFormat;
                            break;
                        case 9:
                            tplFormat = (int)TPL_TextureFormat.CI14X2;

                            CustomizeMii_PaletteFormatBox pfb3 = new CustomizeMii_PaletteFormatBox();
                            pfb3.ShowDialog();

                            pFormat = pfb3.PaletteFormat;
                            break;
                        default:
                            if (!inputFile.ToLower().EndsWith(".tpl"))
                                throw new Exception("This format is not supported, you must choose a different one!");
                            break;
                    }

                    byte[] newTpl;
                    if (inputFile.ToLower().EndsWith(".tpl"))
                        newTpl = File.ReadAllBytes(inputFile);
                    else
                        newTpl = TPL.FromImage(inputFile, (TPL_TextureFormat)tplFormat, pFormat).ToByteArray();

                    if (lbx == lbxBannerTpls)
                    {
                        if (string.IsNullOrEmpty(replacedBanner))
                        { bannerBin.AddFile("/arc/timg/" + tplName, newTpl); }
                        else
                        { newBannerBin.AddFile("/arc/timg/" + tplName, newTpl); }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(replacedIcon))
                        { iconBin.AddFile("/arc/timg/" + tplName, newTpl); }
                        else
                        { newIconBin.AddFile("/arc/timg/" + tplName, newTpl); }
                    }

                    addTpls();
                }
            }
            catch (Exception ex) { throw ex; }
        }
コード例 #2
0
        private void btnReplaceBanner_Click(object sender, EventArgs e)
        {
            if (lbxBannerTpls.SelectedIndex != -1)
            {
                int format = cmbFormatBanner.SelectedIndex;

                if (format < 9)
                {
                    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 = lbxBannerTpls.SelectedItem.ToString().Remove(lbxBannerTpls.SelectedItem.ToString().IndexOf('(', 0) - 3);
                            TPL tmpTpl;
                            Image img;

                            if (string.IsNullOrEmpty(replacedBanner))
                                tmpTpl = TPL.Load(bannerBin.Data[bannerBin.GetNodeIndex(tplName)]);
                            else tmpTpl = TPL.Load(newBannerBin.Data[newBannerBin.GetNodeIndex(tplName)]);

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

                            if (img.Width != tmpTpl.GetTextureSize(0).Width ||
                                img.Height != tmpTpl.GetTextureSize(0).Height)
                                img = resizeImage(img, tmpTpl.GetTextureSize(0).Width, tmpTpl.GetTextureSize(0).Height);

                            TPL_PaletteFormat pFormat = TPL_PaletteFormat.RGB5A3;

                            switch (format)
                            {
                                case 6:
                                    format = (int)TPL_TextureFormat.I4;
                                    break;
                                case 5:
                                    format = (int)TPL_TextureFormat.I8;
                                    break;
                                case 4:
                                    format = (int)TPL_TextureFormat.IA4;
                                    break;
                                case 3:
                                    format = (int)TPL_TextureFormat.IA8;
                                    break;
                                case 1:
                                    format = (int)TPL_TextureFormat.RGB565;
                                    break;
                                case 2:
                                    format = (int)TPL_TextureFormat.RGB5A3;
                                    break;
                                case 7:
                                    format = (int)TPL_TextureFormat.CI4;

                                    CustomizeMii_PaletteFormatBox pfb = new CustomizeMii_PaletteFormatBox();
                                    pfb.ShowDialog();

                                    pFormat = pfb.PaletteFormat;
                                    break;
                                case 8:
                                    format = (int)TPL_TextureFormat.CI8;

                                    CustomizeMii_PaletteFormatBox pfb2 = new CustomizeMii_PaletteFormatBox();
                                    pfb2.ShowDialog();

                                    pFormat = pfb2.PaletteFormat;
                                    break;
                                case 9:
                                    format = (int)TPL_TextureFormat.CI14X2;

                                    CustomizeMii_PaletteFormatBox pfb3 = new CustomizeMii_PaletteFormatBox();
                                    pfb3.ShowDialog();

                                    pFormat = pfb3.PaletteFormat;
                                    break;
                                default:
                                    format = (int)TPL_TextureFormat.RGBA8;
                                    break;
                            }

                            tmpTpl.RemoveTexture(0);
                            tmpTpl.AddTexture(img, (TPL_TextureFormat)format, pFormat);

                            if (string.IsNullOrEmpty(replacedBanner))
                                bannerBin.ReplaceFile(bannerBin.GetNodeIndex(tplName), tmpTpl.ToByteArray());
                            else newBannerBin.ReplaceFile(newBannerBin.GetNodeIndex(tplName), tmpTpl.ToByteArray());

                            addTpls();
                        }
                        catch (Exception ex) { errorBox(ex.Message); }
                    }
                }
                else { errorBox("This format is not supported, you must choose a different one!"); }
            }
        }