Beispiel #1
0
        public void NewPat()
        {
            PAT0Node node = ((BRRESNode)_resource).CreateResource <PAT0Node>("NewPAT");

            node.Version = 3;
            BaseWrapper res = this.FindResource(node, true);

            res = res.FindResource(node, false);
            res.EnsureVisible();
            res.TreeView.SelectedNode = res;
        }
Beispiel #2
0
        public void ImportPat()
        {
            if (Program.OpenFile(FileFilters.PAT0, out string path) > 0)
            {
                PAT0Node node = NodeFactory.FromFile(null, path) as PAT0Node;
                ((BRRESNode)_resource).GetOrCreateFolder <PAT0Node>().AddChild(node);

                BaseWrapper w = FindResource(node, true);
                w.EnsureVisible();
                w.TreeView.SelectedNode = w;
            }
        }
        public static void Pat02Ftxp(MaterialAnim matAnim, string FileName)
        {
            PAT0Node pat0 = new PAT0Node();

            matAnim.FrameCount = pat0.FrameCount;
            matAnim.Name       = pat0.Name;
            matAnim.Path       = pat0.OriginalPath;
            matAnim.Loop       = pat0.Loop;

            foreach (var entry in pat0.Children)
            {
                var Material = (PAT0EntryNode)entry;
            }
        }
Beispiel #4
0
 protected override void UpdatePAT0FocusControls(PAT0Node node)
 {
     leftPanel.UpdatePAT0Selection(node);
 }
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            PAT0Node main = (context.Instance as PAT0TextureEntryNode).Parent.Parent.Parent as PAT0Node;

            return(new StandardValuesCollection(main.Palettes));
        }
Beispiel #6
0
 protected virtual void UpdatePAT0FocusControls(PAT0Node node)
 {
 }
        public void ConvertToStockDefault()
        {
            string          matchName  = _resource.Name.Substring(0, _resource.Name.LastIndexOf(".")) + ".";
            string          matchNameX = _resource.Name.Substring(0, _resource.Name.LastIndexOf(".")) + "X.";
            List <TEX0Node> texList    = new List <TEX0Node>();

            for (int i = 0; i < _resource.Parent.Children.Count; i++)
            {
                if (!(_resource.Parent.Children[i] is TEX0Node))
                {
                    continue;
                }

                TEX0Node tx0 = (TEX0Node)_resource.Parent.Children[i];
                if (tx0.Name.StartsWith(matchName) && tx0.Name.LastIndexOf(".") > 0 &&
                    tx0.Name.LastIndexOf(".") < tx0.Name.Length &&
                    int.TryParse(
                        tx0.Name.Substring(tx0.Name.LastIndexOf(".") + 1,
                                           tx0.Name.Length - (tx0.Name.LastIndexOf(".") + 1)), out int x) && x >= 0)
                {
                    tx0.texSortNum = x;
                    if (x <= 0) // 0 edge case
                    {
                        tx0.texSortNum = 0;
                        if (tx0.HasPalette)
                        {
                            tx0.GetPaletteNode().Name = "InfStc." + tx0.texSortNum.ToString("000");
                        }

                        tx0.Name = "InfStc." + tx0.texSortNum.ToString("000");
                        if (((BRRESNode)_resource.Parent.Parent).GetFolder <PLT0Node>()
                            .FindChildrenByName("InfStc." + x.ToString("0000"))
                            .Count() > 0)
                        {
                            foreach (PLT0Node p in ((BRRESNode)_resource.Parent.Parent).GetFolder <PLT0Node>()
                                     .FindChildrenByName(
                                         "InfStc." + x.ToString(
                                             "0000")))
                            {
                                p.Remove();
                            }
                        }
                    }
                    else if (x == 9001) // WarioMan edge case (should pre-program)
                    {
                        tx0.texSortNum = 475 + x % 9001;
                        if (tx0.HasPalette)
                        {
                            tx0.GetPaletteNode().Name = "InfStc." + tx0.texSortNum.ToString("000");
                        }

                        tx0.Name = "InfStc." + tx0.texSortNum.ToString("000");
                        if (((BRRESNode)_resource.Parent.Parent).GetFolder <PLT0Node>()
                            .FindChildrenByName("InfStc." + x.ToString("0000"))
                            .Count() > 0)
                        {
                            foreach (PLT0Node p in ((BRRESNode)_resource.Parent.Parent).GetFolder <PLT0Node>()
                                     .FindChildrenByName(
                                         "InfStc." + x.ToString(
                                             "0000")))
                            {
                                p.Remove();
                            }
                        }
                    }
                    else if (x % 50 <= 10 && x % 50 != 0 ||
                             x >= 0961 && x <= 0965 || // Ganon Edge Case
                             x >= 1711 && x <= 1715 || // ROB Edge Case
                             x >= 1861 && x <= 1864 || // Wario Edge Case
                             x >= 2011 && x <= 2015 || // Toon Link Edge Case
                             x >= 2311 && x <= 2314)   // Sonic Edge Case
                    {
                        tx0.texSortNum = (int)Math.Floor(((double)x + 1) / 50.0) * 10 + x % 10;

                        if (x % 10 == 0 ||
                            x >= 0961 && x <= 0965 || // Ganon Edge Case
                            x >= 1711 && x <= 1715 || // ROB Edge Case
                            x >= 1861 && x <= 1864 || // Wario Edge Case
                            x >= 2011 && x <= 2015 || // Toon Link Edge Case
                            x >= 2311 && x <= 2314)   // Sonic Edge Case
                        {
                            tx0.texSortNum += 10;
                        }

                        if (tx0.HasPalette)
                        {
                            tx0.GetPaletteNode().Name = "InfStc." + tx0.texSortNum.ToString("000");
                        }

                        tx0.Name = "InfStc." + tx0.texSortNum.ToString("000");
                        if (((BRRESNode)_resource.Parent.Parent).GetFolder <PLT0Node>()
                            .FindChildrenByName("InfStc." + x.ToString("0000"))
                            .Count() > 0)
                        {
                            foreach (PLT0Node p in ((BRRESNode)_resource.Parent.Parent).GetFolder <PLT0Node>()
                                     .FindChildrenByName(
                                         "InfStc." + x.ToString(
                                             "0000")))
                            {
                                p.Remove();
                            }
                        }
                    }
                    else
                    {
                        if (tx0.HasPalette)
                        {
                            tx0.GetPaletteNode().Name = "InfStcX." + tx0.texSortNum.ToString("0000");
                        }

                        tx0.Name = "InfStcX." + tx0.texSortNum.ToString("0000");
                        if (((BRRESNode)_resource.Parent.Parent).GetFolder <PLT0Node>()
                            .FindChildrenByName("InfStc." + x.ToString("0000"))
                            .Count() > 0)
                        {
                            foreach (PLT0Node p in ((BRRESNode)_resource.Parent.Parent).GetFolder <PLT0Node>()
                                     .FindChildrenByName(
                                         "InfStc." + x.ToString(
                                             "0000")))
                            {
                                p.Remove();
                            }
                        }
                    }
                }
            }

            PAT0Node newPat0 = GeneratePAT0(true);

            if (((BRRESNode)_resource.Parent.Parent).GetFolder <CHR0Node>() != null)
            {
                ResourceNode[] temp = ((BRRESNode)_resource.Parent.Parent).GetFolder <CHR0Node>()
                                      .FindChildrenByName(newPat0.Name);
                if (temp.Length > 0)
                {
                    foreach (CHR0Node cn in temp)
                    {
                        cn.FrameCount = newPat0.FrameCount;
                    }
                }
            }

            if (((BRRESNode)_resource.Parent.Parent).GetFolder <CLR0Node>() != null)
            {
                ResourceNode[] temp = ((BRRESNode)_resource.Parent.Parent).GetFolder <CLR0Node>()
                                      .FindChildrenByName(newPat0.Name);
                if (temp.Length > 0)
                {
                    foreach (CLR0Node cn in temp)
                    {
                        cn.FrameCount = newPat0.FrameCount;
                    }
                }
            }

            if (MessageBox.Show(
                    "Would you like to convert the InfFace portraits to the new system as well at this time?",
                    "Convert InfFace?", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                string infFaceFolder   = "";
                bool   autoFoundFolder = false;
                if (Program.RootPath.EndsWith("\\info2\\info.pac", StringComparison.OrdinalIgnoreCase))
                {
                    string autoFolder =
                        Program.RootPath.Substring(0, Program.RootPath.LastIndexOf("\\info2\\info.pac")) +
                        "\\info\\portrite";
                    if (Directory.Exists(autoFolder))
                    {
                        if (MessageBox.Show(
                                "The folder for InfFace was autodetected to be: \n" + autoFolder +
                                "\n\nIs this correct?", "InfFace Converter", MessageBoxButtons.YesNo) ==
                            DialogResult.Yes)
                        {
                            infFaceFolder   = autoFolder;
                            autoFoundFolder = true;
                        }
                    }
                }

                if (!autoFoundFolder)
                {
                    FolderBrowserDialog f = new FolderBrowserDialog
                    {
                        Description = "Select the \"portrite\" folder"
                    };
                    DialogResult dr = f.ShowDialog();
                    infFaceFolder = f.SelectedPath;
                    if (dr != DialogResult.OK || infFaceFolder == null || infFaceFolder == "")
                    {
                        return;
                    }
                }

                try
                {
                    DirectoryInfo d  = Directory.CreateDirectory(infFaceFolder);
                    DirectoryInfo d2 = Directory.CreateDirectory(infFaceFolder + '\\' + "temp");
                    Console.WriteLine(infFaceFolder);
                    int count = 0;
                    foreach (FileInfo infFace in d.GetFiles().Reverse())
                    {
                        Console.WriteLine(infFaceFolder + '\\' + infFace.Name);
                        int properlength = infFace.Name.EndsWith(".brres", StringComparison.OrdinalIgnoreCase)
                            ? infFace.Name.Length - ".brres".Length
                            : infFace.Name.Length;

                        if (infFace.Name.StartsWith("InfFace") && !infFace.Name.StartsWith("InfFaceX") &&
                            infFace.Name.EndsWith(".brres", StringComparison.CurrentCultureIgnoreCase) &&
                            int.TryParse(infFace.Name.Substring(7, properlength - 7), out int x) && x >= 0)
                        {
                            int n = x;
                            if (x <= 0) // 0 edge case
                            {
                                n = 0;
                                infFace.MoveTo(infFaceFolder + '\\' + "temp" + '\\' + "InfFace" + n.ToString("000") +
                                               ".brres");
                            }
                            else if (x >= 9001 && x <= 9014) // WarioMan edge case (should pre-program)
                            {
                                n = 661 + x % 9001;
                                infFace.MoveTo(infFaceFolder + '\\' + "temp" + '\\' + "InfFace" + n.ToString("000") +
                                               ".brres");
                            }
                            else if (x % 50 <= 10 && x % 50 != 0 ||
                                     x >= 0961 && x <= 0965 || // Ganon Edge Case
                                     x >= 1711 && x <= 1715 || // ROB Edge Case
                                     x >= 1861 && x <= 1864 || // Wario Edge Case
                                     x >= 2011 && x <= 2015 || // Toon Link Edge Case
                                     x >= 2311 && x <= 2314)   // Sonic Edge Case
                            {
                                n = (int)Math.Floor(((double)x + 1) / 50.0) * 10 + x % 10;

                                if (x % 10 == 0 ||
                                    x >= 0961 && x <= 0965 || // Ganon Edge Case
                                    x >= 1711 && x <= 1715 || // ROB Edge Case
                                    x >= 1861 && x <= 1864 || // Wario Edge Case
                                    x >= 2011 && x <= 2015 || // Toon Link Edge Case
                                    x >= 2311 && x <= 2314)   // Sonic Edge Case
                                {
                                    n += 10;
                                }

                                infFace.MoveTo(infFaceFolder + '\\' + "temp" + '\\' + "InfFace" + n.ToString("000") +
                                               ".brres");
                                count++;
                            }
                            else
                            {
                                infFace.MoveTo(infFaceFolder + '\\' + "temp" + '\\' + "InfFaceX" + n.ToString("0000") +
                                               ".brres");
                                count++;
                            }
                        }
                    }

                    foreach (FileInfo infFace in d2.GetFiles())
                    {
                        infFace.MoveTo(infFaceFolder + '\\' + infFace.Name +
                                       (infFace.Name.EndsWith(".brres", StringComparison.OrdinalIgnoreCase)
                                           ? ""
                                           : ".brres"));
                    }

                    d2.Delete();
                    if (count > 0)
                    {
                        MessageBox.Show("InfFace conversion successful!");
                    }
                    else
                    {
                        MessageBox.Show("No convertable InfFace portraits found in " + infFaceFolder);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            }
        }
        public PAT0Node GeneratePAT0(bool force)
        {
            if (Parent == null)
            {
                return(null);
            }

            if (_resource.Parent is BRESGroupNode && _resource.Parent.Parent != null &&
                _resource.Parent.Parent is BRRESNode)
            {
                // Check if this is part of a sequence
                if (Regex.Match(_resource.Name, @"(\.\d+)?$").Success&& _resource.Name.LastIndexOf(".") > 0 &&
                    _resource.Name.LastIndexOf(".") <= _resource.Name.Length && int.TryParse(
                        _resource.Name.Substring(_resource.Name.LastIndexOf(".") + 1,
                                                 _resource.Name.Length - (_resource.Name.LastIndexOf(".") + 1)), out int n))
                {
                    //Console.WriteLine(_resource.Name.Substring(0, _resource.Name.LastIndexOf(".")) + " is part of a sequence");
                    //Console.WriteLine(_resource.Name.Substring(_resource.Name.LastIndexOf(".") + 1, _resource.Name.Length - (_resource.Name.LastIndexOf(".") + 1)));
                    // Determine the name to match
                    string          matchName    = _resource.Name.Substring(0, _resource.Name.LastIndexOf(".")) + ".";
                    BRESGroupNode   paletteGroup = ((BRRESNode)_resource.Parent.Parent).GetFolder <PLT0Node>();
                    List <string>   textureList  = new List <string>();
                    List <PLT0Node> paletteList  = new List <PLT0Node>();
                    int             highestNum   = -1;
                    bool            isStock      = false;
                    bool            isStockEx    = false;
                    if (matchName.Equals("InfStc.", StringComparison.OrdinalIgnoreCase))
                    {
                        isStock = true;
                        if (_resource.Name.Length >= 11)
                        {
                            isStockEx = true;
                        }
                    }

                    foreach (TEX0Node tx0 in _resource.Parent.Children)
                    {
                        if (tx0.Name.StartsWith(matchName) && tx0.Name.LastIndexOf(".") > 0 &&
                            tx0.Name.LastIndexOf(".") <= tx0.Name.Length &&
                            int.TryParse(
                                tx0.Name.Substring(tx0.Name.LastIndexOf(".") + 1,
                                                   tx0.Name.Length - (tx0.Name.LastIndexOf(".") + 1)), out int n2) && n2 >= 0 &&
                            !textureList.Contains(tx0.Name))
                        {
                            if (isStock)
                            {
                                if (isStockEx && tx0.Name.Length < 11)
                                {
                                    continue;
                                }
                            }

                            // Add the matching texture to the texture list for the PAT0
                            textureList.Add(tx0.Name);
                            // Determine the highest number used
                            if (n2 > highestNum)
                            {
                                highestNum = n2;
                            }

                            Console.WriteLine(tx0.Name);
                            Console.WriteLine(tx0.HasPalette);
                            if (tx0.HasPalette)
                            {
                                paletteList.Add(tx0.GetPaletteNode());
                            }
                            else
                            {
                                paletteList.Add(null);
                            }
                        }
                    }

                    if (textureList.Count <= 0)
                    {
                        return(null);
                    }

                    PAT0Node newPat0 = new PAT0Node
                    {
                        Name = _resource.Name.Substring(0, _resource.Name.LastIndexOf(".")).Equals("InfStc")
                            ? "InfStockface_TopN__0"
                            : _resource.Name.Substring(0, _resource.Name.LastIndexOf(".")),
                        _numFrames = highestNum + 1
                    };
                    PAT0EntryNode pat0Entry = new PAT0EntryNode();
                    newPat0.AddChild(pat0Entry);
                    pat0Entry.Name = _resource.Name.Substring(0, _resource.Name.LastIndexOf(".")).Equals("InfStc")
                        ? "lambert87"
                        : _resource.Name.Substring(0, _resource.Name.LastIndexOf("."));
                    PAT0TextureNode pat0Tex = new PAT0TextureNode((PAT0Flags)7, 0);
                    pat0Entry.AddChild(pat0Tex);
                    if (((BRRESNode)_resource.Parent.Parent).GetFolder <PAT0Node>() != null &&
                        ((BRRESNode)_resource.Parent.Parent).GetFolder <PAT0Node>().FindChildrenByName(newPat0.Name)
                        .Length > 0)
                    {
                        if (force)
                        {
                            while (((BRRESNode)_resource.Parent.Parent).GetFolder <PAT0Node>()
                                   .FindChildrenByName(newPat0.Name).Length > 0)
                            {
                                ((BRRESNode)_resource.Parent.Parent).GetFolder <PAT0Node>()
                                .FindChildrenByName(newPat0.Name)[0].Remove();
                            }
                        }
                        else
                        {
                            DialogResult d = MessageBox.Show(
                                "Would you like to replace the currently existing \"" + newPat0.Name +
                                "\" PAT0 animation?", "PAT0 Generator", MessageBoxButtons.YesNoCancel);
                            if (d == DialogResult.Cancel || d == DialogResult.Abort)
                            {
                                return(null);
                            }

                            if (d == DialogResult.Yes)
                            {
                                while (((BRRESNode)_resource.Parent.Parent).GetFolder <PAT0Node>()
                                       .FindChildrenByName(newPat0.Name).Length >
                                       0)
                                {
                                    ((BRRESNode)_resource.Parent.Parent).GetFolder <PAT0Node>()
                                    .FindChildrenByName(newPat0.Name)[0].Remove();
                                }
                            }
                        }
                    }

                    if (isStock && !isStockEx && !textureList.Contains("InfStc.000"))
                    {
                        textureList.Add("InfStc.000");
                        paletteList.Add(null);
                    }
                    else if (isStock && isStockEx && !textureList.Contains("InfStc.0000"))
                    {
                        textureList.Add("InfStc.0000");
                        paletteList.Add(null);
                    }

                    //foreach(string s in textureList)
                    for (int i = 0; i < textureList.Count; ++i)
                    {
                        string s = textureList[i];
                        if (float.TryParse(s.Substring(s.LastIndexOf(".") + 1, s.Length - (s.LastIndexOf(".") + 1)),
                                           out float fr))
                        {
                            PAT0TextureEntryNode pat0texEntry = new PAT0TextureEntryNode();
                            pat0Tex.AddChild(pat0texEntry);
                            pat0texEntry.Name   = s;
                            pat0texEntry._frame = fr;
                            if (paletteList[i] != null)
                            {
                                pat0Tex.HasPalette = true;
                                pat0texEntry._plt  = paletteList[i].Name;
                            }
                            else if ((s == "InfStc.000" || s == "InfStc.0000") && pat0Tex.HasPalette)
                            {
                                pat0texEntry._plt = s;
                            }

                            if (fr == 0)
                            {
                                PAT0TextureEntryNode pat0texEntryFinal = new PAT0TextureEntryNode();
                                pat0Tex.AddChild(pat0texEntryFinal);
                                pat0texEntryFinal.Name   = s;
                                pat0texEntryFinal._frame = highestNum + 1;
                                if (paletteList[i] != null)
                                {
                                    pat0Tex.HasPalette        = true;
                                    pat0texEntryFinal.Palette = paletteList[i].Name;
                                }
                                else if ((s == "InfStc.000" || s == "InfStc.0000") && pat0Tex.HasPalette)
                                {
                                    pat0texEntryFinal._plt = s;
                                }
                            }
                        }

                        //newPat0.AddChild
                    }

                    pat0Tex._children = pat0Tex._children.OrderBy(o => ((PAT0TextureEntryNode)o)._frame).ToList();
                    if (isStock && !isStockEx && newPat0.FrameCount < 501)
                    {
                        newPat0.FrameCount = 501;
                    }
                    else if (isStockEx && newPat0.FrameCount < 9201)
                    {
                        newPat0.FrameCount = 9201;
                    }

                    ((BRRESNode)_resource.Parent.Parent).GetOrCreateFolder <PAT0Node>().AddChild(newPat0);
                    if (!force)
                    {
                        MainForm.Instance.TargetResource(newPat0);
                    }

                    return(newPat0);
                }
                else
                {
                    PAT0Node newPat0 = new PAT0Node
                    {
                        Name       = _resource.Name,
                        _numFrames = 1
                    };
                    PAT0EntryNode pat0Entry = new PAT0EntryNode();
                    newPat0.AddChild(pat0Entry);
                    pat0Entry.Name = _resource.Name;
                    PAT0TextureNode pat0Tex = new PAT0TextureNode((PAT0Flags)7, 0);
                    pat0Entry.AddChild(pat0Tex);
                    PAT0TextureEntryNode pat0texEntry = new PAT0TextureEntryNode();
                    pat0Tex.AddChild(pat0texEntry);
                    pat0texEntry.Name   = _resource.Name;
                    pat0texEntry._frame = 0;
                    if (((TEX0Node)_resource).HasPalette)
                    {
                        pat0Tex.HasPalette   = true;
                        pat0texEntry.Palette = ((TEX0Node)_resource).GetPaletteNode().Name;
                    }

                    ((BRRESNode)_resource.Parent.Parent).GetOrCreateFolder <PAT0Node>().AddChild(newPat0);
                    MainForm.Instance.TargetResource(newPat0);
                    return(newPat0);
                }
            }

            return(null);
        }