예제 #1
0
 public void generateName()
 {
     using (NameDialog n = new NameDialog()) {
         n.EntryText = "Battlefield";
         n.LabelText = "Enter the stage name. (Use \\n for a line break.)\nType just ] to launch genname.bat/genname.exe instead.";
         if (n.ShowDialog() == DialogResult.OK)
         {
             if (n.EntryText == "]")
             {
                 generateNameExternal();
             }
             else
             {
                 if (fontSettings == null)
                 {
                     changeFrontStnameFont();
                 }
                 if (fontSettings == null)
                 {
                     return;
                 }
                 Bitmap bmp      = NameCreator.createImage(fontSettings, n.EntryText);
                 string tempfile = TempFiles.Create(".png");
                 bmp.Save(tempfile);
                 Replace(frontstname, tempfile);
             }
         }
     }
 }
예제 #2
0
        public void generateNameExternal()
        {
            string           exeDir   = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string           tempfile = TempFiles.Create(".png");
            ProcessStartInfo start    = new ProcessStartInfo()
            {
                WorkingDirectory = exeDir,
                FileName         = File.Exists(exeDir + "\\genname.bat") ? "genname.bat" : "genname.exe",
                Arguments        = tempfile
            };

            if (!File.Exists(exeDir + "\\" + start.FileName))
            {
                MessageBox.Show(this, "Could not find genname.bat or genname.exe.\nCreate a program or batch file that takes an output PNG file path as its only argument. It should write to this path before closing.");
                return;
            }
            using (Process p = Process.Start(start)) {
                p.WaitForExit();
                if (!File.Exists(tempfile))
                {
                    MessageBox.Show(this, "The program did not write to the temporary file path. Make sure it's using %1 (first argument) as the output filename.");
                    return;
                }
            }
            Replace(frontstname, tempfile);
        }
예제 #3
0
 private void lblPMAlt_DragDrop(object sender, DragEventArgs e)
 {
     if (e.Effect == DragDropEffects.Copy)
     {
         string s = (e.Data.GetData(DataFormats.FileDrop) as string[])[0];
         new Task(() => {
             Bitmap existing     = GetTexInfoFor(prevbase).tex0.GetImage(0);
             Image newBitmap     = Bitmap.FromFile(s);
             Bitmap lowerPortion = new Bitmap(106, 24);
             using (Graphics g = Graphics.FromImage(lowerPortion)) {
                 int height = (int)(((double)newBitmap.Height / newBitmap.Width) * 106);
                 int offset = (24 - height) / 2;
                 g.DrawImage(newBitmap, 0, offset, 106, height);
             }
             Bitmap canvas = new Bitmap(176, 176);
             using (Graphics g = Graphics.FromImage(canvas)) {
                 g.DrawImage(existing, 0, 0, 176, 176);
                 g.FillRectangle(Brushes.Black, 0, 126, 176, 50);
                 g.DrawImage(lowerPortion, 52, 131, 106, 24);
             }
             string temp = TempFiles.Create(".png");
             canvas.Save(temp);
             Replace(prevbase, temp);
         }).Start();
     }
 }
예제 #4
0
        public void ResizeAllPrevbases(Size newSize)
        {
            if (sc_selmap == null)
            {
                return;
            }
            var prevbases = from c in sc_selmap.FindChild("MiscData[80]/Textures(NW4R)", false).Children
                            where c is TEX0Node && c.Name.Contains("MenSelmapPrevbase")
                            select(TEX0Node) c;
            int i = 0;

            foreach (TEX0Node node in prevbases)
            {
                Bitmap origImage = node.GetImage(0);
                if (origImage.Width <= newSize.Width && origImage.Height <= newSize.Height)
                {
                    continue;
                }

                string file = TempFiles.Create(".png");
                if (useTextureConverter)
                {
                    origImage.Save(file);

                    TextureConverterDialog d = new TextureConverterDialog();
                    d.ImageSource = file;
                    d.InitialSize = newSize;
                    if (d.ShowDialog(null, node) == DialogResult.OK)
                    {
                        node.IsDirty = true;
                        Console.WriteLine("Resized " + node);
                        i++;
                    }
                    else if (MessageBox.Show(this, "Stop resizing textures here?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        break;
                    }
                }
                else
                {
                    Bitmap b = BitmapUtilities.Resize(origImage, newSize);
                    b.Save(file);

                    node.Replace(file);
                    Console.WriteLine("Resized " + node);
                    i++;
                }

                File.Delete(file);
            }
            MessageBox.Show("Resized " + i + " images.");
            UpdateImage();
        }
예제 #5
0
        public bool AddMenSelmapMark(string path, bool ask)
        {
            string tmp = null;

            if (path.EndsWith(".tex0", StringComparison.InvariantCultureIgnoreCase))
            {
                tmp = TempFiles.Create(".png");
                NodeFactory.FromFile(null, path).Export(tmp);
            }
            Bitmap bitmap = new Bitmap(tmp ?? path);

            if (BitmapUtilities.HasSolidCorners(bitmap))
            {
                bitmap = BitmapUtilities.AlphaSwap(bitmap);
            }
            string name = Path.GetFileNameWithoutExtension(path);

            if (ask)
            {
                using (var nameDialog = new AskNameDialog(bitmap)) {
                    nameDialog.Text = name;
                    if (nameDialog.ShowDialog() != DialogResult.OK)
                    {
                        return(false);
                    }
                    else
                    {
                        name = nameDialog.NameText;
                    }
                }
            }
            BRRESNode bres = sc_selmap.FindChild("MiscData[80]", false) as BRRESNode;
            TEX0Node  tex0 = bres.CreateResource <TEX0Node>(name);

            ReplaceSelmapMark(bitmap, tex0, true);
            return(true);
        }
예제 #6
0
        public static void Copy(ResourceNode scSelmap, ResourceNode muMenumain, CustomSSSCodeset sss)
        {
            ResourceNode                miscData0 = muMenumain.FindChild("Misc Data [0]", false);
            List <ResourceNode>         chrToKeep = miscData0.FindChild("AnmChr(NW4R)", false).Children;
            Dictionary <string, string> tempFiles = new Dictionary <string, string>(chrToKeep.Count);

            foreach (ResourceNode n in chrToKeep)
            {
                string file = TempFiles.Create(".chr0");
                tempFiles.Add(n.Name, file);
                n.Export(file);
            }

            ResourceNode miscData80 = scSelmap.FindChild("Misc Data [80]", false);

            miscData0.ReplaceRaw(miscData80.WorkingSource.Address, miscData80.WorkingSource.Length);
            miscData0.SignalPropertyChange();

            List <ResourceNode> chrToReplace = miscData0.FindChild("AnmChr(NW4R)", false).Children;

            foreach (ResourceNode n in chrToReplace)
            {
                string file = tempFiles[n.Name];
                n.Replace(file);
            }

            string       xx_png = TempFiles.Create(".png");
            ResourceNode xx     = miscData0.FindChild("Textures(NW4R)/MenSelmapIcon.XX", false);
            bool         found  = false;

            if (xx != null)
            {
                xx.Export(xx_png);
                found = true;
            }
            else
            {
                Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BrawlCrate.StageManager.XX.png");
                if (stream != null)
                {
                    Image.FromStream(stream).Save(xx_png);
                    found = true;
                }
            }

            if (found)
            {
                foreach (ResourceNode tex in miscData0.FindChild("Textures(NW4R)", false).Children)
                {
                    byte icon_id;
                    if (tex.Name.StartsWith("MenSelmapIcon.") && byte.TryParse(tex.Name.Substring(14, 2), out icon_id))
                    {
                        byte stage_id = sss.StageForIcon(icon_id);
                        if (icon_id != 100 && (stage_id == 0x25 || stage_id > 0x33))
                        {
                            tex.Replace(xx_png);
                        }
                    }
                }
            }

            File.Delete(xx_png);
        }
예제 #7
0
        public void copyIconsToSelcharacter2()
        {
            string fileToSaveTo = null;

            ResourceNode s2 = null;

            if (common5 != null)
            {
                s2 = common5.FindChild("sc_selcharacter2_en", false);
            }
            else if (sc_selmap != null)
            {
                if (File.Exists("../../menu2/sc_selcharacter2.pac"))
                {
                    fileToSaveTo = "../../menu2/sc_selcharacter2.pac";
                    s2           = TempFiles.MakeTempNode(fileToSaveTo);
                }
                else if (File.Exists("../../menu2/sc_selcharacter2_en.pac"))
                {
                    fileToSaveTo = "../../menu2/sc_selcharacter2_en.pac";
                    s2           = TempFiles.MakeTempNode(fileToSaveTo);
                }
            }

            if (s2 == null)
            {
                return;
            }

            ResourceNode md0  = s2.FindChild("MenuRule_en/ModelData[0]", false);
            MSBinNode    md1  = s2.FindChild("MenuRule_en/MiscData[1]", false) as MSBinNode;
            ResourceNode md80 = sc_selmap.FindChild("MiscData[80]", false);

            if (md0 == null || md80 == null)
            {
                return;
            }

            Image[] icons        = new Image[41];
            Image[] frontstnames = new Image[41];
            for (int i = 1; i < 60; i++)
            {
                if (i == 32)
                {
                    i = 50;
                }
                int    sssPos     = StageIDMap.sssPositionForSelcharacter2Icon(i);
                string nameSelmap = BestSSS[sssPos].Item2.ToString("D2");
                icons[sssPos]        = ((md80.FindChild("Textures(NW4R)/MenSelmapIcon." + nameSelmap, false) as TEX0Node).GetImage(0));
                frontstnames[sssPos] = ((md80.FindChild("Textures(NW4R)/MenSelmapFrontStname." + nameSelmap, false) as TEX0Node).GetImage(0));
            }

            var d = new RandomSelectEditNamesDialog(md1._strings, icons, frontstnames);

            d.Message = "When finished, press OK to continue.";
            if (d.ShowDialog() == DialogResult.OK)
            {
                for (int i = 0; i < md1._strings.Count; i++)
                {
                    md1._strings[i] = d[i].ToString();
                }
            }
            else
            {
                return;
            }

            using (ProgressWindow w = new ProgressWindow()
            {
                CanCancel = false
            }) {
                w.Begin(0, 60, 0);
                for (int i = 1; i < 60; i++)
                {
                    if (i == 32)
                    {
                        i = 50;
                    }

                    int      sssPos            = StageIDMap.sssPositionForSelcharacter2Icon(i);
                    string   tempFile1         = TempFiles.Create(".tex0");
                    string   tempFile2         = TempFiles.Create(".plt0");
                    string   nameSelcharacter2 = i.ToString("D2");
                    string   nameSelmap        = BestSSS[sssPos].Item2.ToString("D2");
                    TEX0Node iconFrom          = md80.FindChild("Textures(NW4R)/MenSelmapIcon." + nameSelmap, false) as TEX0Node;
                    TEX0Node iconTo            = md0.FindChild("Textures(NW4R)/MenSelmapIcon." + nameSelcharacter2, false) as TEX0Node;
                    var      palFrom           = md80.FindChild("Palettes(NW4R)/MenSelmapIcon." + nameSelmap, false);
                    var      palTo             = md0.FindChild("Palettes(NW4R)/MenSelmapIcon." + nameSelcharacter2, false);
                    if (iconFrom != null && iconTo != null && palFrom != null && palTo != null)
                    {
                        iconFrom.Export(tempFile1);
                        iconTo.Replace(tempFile1);
                        palFrom.Export(tempFile2);
                        palTo.Replace(tempFile2);
                    }

                    TEX0Node prevbase    = md80.FindChild("Textures(NW4R)/MenSelmapPrevbase." + nameSelmap, false) as TEX0Node;
                    TEX0Node stageswitch = md0.FindChild("Textures(NW4R)/MenStageSwitch." + nameSelcharacter2, false) as TEX0Node;
                    if (prevbase != null && stageswitch != null)
                    {
                        Bitmap thumbnail = new Bitmap(112, 56);
                        using (Graphics g = Graphics.FromImage(thumbnail)) {
                            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                            g.DrawImage(prevbase.GetImage(0), 0, -28, 112, 112);
                        }
                        stageswitch.Replace(thumbnail);
                    }

                    w.Update(i);
                }
            }

            if (fileToSaveTo != null)
            {
                s2.Export(fileToSaveTo);
            }
        }
예제 #8
0
        public void Replace(object sender, string filename)
        {
            var ig = StringComparison.CurrentCultureIgnoreCase;

            if (filename.EndsWith(".tex0", ig))
            {
                TEX0Node tex0 = GetTexInfoFor(sender).tex0;
                if (tex0 == null)
                {
                    return;
                }
                tex0.Replace(filename);
                tex0.IsDirty = true;
                UpdateImage();
            }
            else if (filename.EndsWith(".brres", ig))
            {
                using (ResourceNode node = NodeFactory.FromFile(null, filename)) {
                    TEX0Node tex0;
                    if (node is TEX0Node)
                    {
                        tex0 = (TEX0Node)node;
                    }
                    else
                    {
                        tex0 = (TEX0Node)node.FindChild("Textures(NW4R)", false).Children[0];
                    }
                    string tempFile = TempFiles.Create(".png");
                    tex0.Export(tempFile);
                    Replace(sender, tempFile);                     // call self with new file
                }
            }
            else
            {
                TEX0Node tex0 = GetTexInfoFor(sender).tex0;
                if (tex0 == null)
                {
                    AddNewTEX0(sender, filename);
                    return;
                }
                else if (useTextureConverter)
                {
                    using (TextureConverterDialog dlg = new TextureConverterDialog()) {
                        dlg.ImageSource = filename;
                        dlg.InitialSize =
                            sender == prevbase ? prevbaseResizeTo
                                                        : sender == frontstname ? frontstnameResizeTo
                                                        : sender == selmap_mark ? selmapMarkResizeTo
                                                        : null;
                        dlg.FormBorderStyle = FormBorderStyle.FixedSingle;
                        dlg.ShowInTaskbar   = true;
                        if (dlg.ShowDialog(null, tex0) == DialogResult.OK)
                        {
                            tex0.IsDirty = true;
                            UpdateImage();
                        }
                    }
                }
                else
                {
                    Bitmap bmp = new Bitmap(filename);
                    if (sender == prevbase && prevbaseResizeTo != null)
                    {
                        bmp = BitmapUtilities.Resize(bmp, prevbaseResizeTo.Value);
                    }
                    else if (sender == frontstname && frontstnameResizeTo != null)
                    {
                        bmp = BitmapUtilities.Resize(bmp, frontstnameResizeTo.Value);
                    }
                    else if (sender == selmap_mark && selmapMarkResizeTo != null)
                    {
                        bmp = BitmapUtilities.Resize(bmp, selmapMarkResizeTo.Value);
                    }
                    if (sender == selmap_mark)
                    {
                        ReplaceSelmapMark(bmp, tex0, false);
                    }
                    else
                    {
                        int colorCount = BitmapUtilities.CountColors(bmp, 256).Align(16);
                        tex0.Replace(bmp, colorCount);
                    }
                    tex0.IsDirty = true;
                    UpdateImage();
                }
            }
        }