static LUtfNode DefaultMaterialNode(LUtfNode parent, ColladaMaterial mat, int i)
        {
            var matnode = new LUtfNode()
            {
                Name = mat.Name, Parent = parent
            };

            matnode.Children = new List <LUtfNode>();
            matnode.Children.Add(new LUtfNode()
            {
                Name = "Type", Parent = matnode, Data = Encoding.ASCII.GetBytes("DcDt")
            });
            var arr = new float[] { mat.Dc.R, mat.Dc.G, mat.Dc.B };

            matnode.Children.Add(new LUtfNode()
            {
                Name = "Dc", Parent = matnode, Data = UnsafeHelpers.CastArray(arr)
            });
            matnode.Children.Add(new LUtfNode()
            {
                Name = "Dt_name", Parent = matnode, Data = Encoding.ASCII.GetBytes(mat.Name + ".dds")
            });
            matnode.Children.Add(new LUtfNode()
            {
                Name = "Dt_flags", Parent = matnode, Data = BitConverter.GetBytes(64)
            });
            return(matnode);
        }
示例#2
0
        static LUtfNode DefaultMaterialNode(LUtfNode parent, string name, int i)
        {
            var matnode = new LUtfNode()
            {
                Name = name, Parent = parent
            };

            matnode.Children = new List <LUtfNode>();
            matnode.Children.Add(new LUtfNode()
            {
                Name = "Type", Parent = matnode, Data = Encoding.ASCII.GetBytes("DcDt")
            });
            matnode.Children.Add(new LUtfNode()
            {
                Name = "Dc", Parent = matnode, Data = UnsafeHelpers.CastArray(matColors[i % matColors.Length])
            });
            matnode.Children.Add(new LUtfNode()
            {
                Name = "Dt_name", Parent = matnode, Data = Encoding.ASCII.GetBytes(name + ".dds")
            });
            matnode.Children.Add(new LUtfNode()
            {
                Name = "Dt_flags", Parent = matnode, Data = BitConverter.GetBytes(64)
            });
            return(matnode);
        }
示例#3
0
 public override bool Draw()
 {
     if (ImGuiExt.BeginDock(Title + "##" + Unique, ref open, 0))
     {
         /*if (HasChild(Utf.Root, "ALEffectLib") &&
          *      HasChild(Utf.Root, "AlchemyNodeLibrary"))
          * {
          *      if (ImGui.Button("Open ALE"))
          *      {
          *
          *      }
          * } */
         //Layout
         if (selectedNode != null)
         {
             ImGui.Columns(2, "NodeColumns", true);
         }
         //Headers
         ImGui.Separator();
         ImGui.Text("Nodes");
         if (selectedNode != null)
         {
             ImGui.NextColumn();
             ImGui.Text("Node Information");
             ImGui.NextColumn();
         }
         ImGui.Separator();
         //Tree
         ImGui.BeginChild("##scroll", false, 0);
         var flags  = selectedNode == Utf.Root ? TreeNodeFlags.Selected | tflags : tflags;
         var isOpen = ImGui.TreeNodeEx("/", flags);
         if (ImGuiNative.igIsItemClicked(0))
         {
             selectedNode = Utf.Root;
         }
         ImGui.PushID("/");
         DoNodeMenu("/", Utf.Root, null);
         ImGui.PopID();
         if (isOpen)
         {
             int i = 0;
             foreach (var node in Utf.Root.Children)
             {
                 DoNode(node, Utf.Root, i++);
             }
             ImGui.TreePop();
         }
         ImGui.EndChild();
         //End Tree
         if (selectedNode != null)
         {
             //Node preview
             ImGui.NextColumn();
             NodeInformation();
         }
     }
     ImGuiExt.EndDock();
     Popups();
     return(open);
 }
 private JointMapView(LUtfNode node)
 {
     unique     = uniqueCount--;
     name       = node.Name;
     scriptName = node.Parent.Name;
     map        = new JointMap(EditableUtf.NodeToEngine(node));
 }
示例#5
0
        bool Finish(out EditableUtf result)
        {
            result = null;
            var utf = new EditableUtf();
            //Vanity
            var expv = new LUtfNode()
            {
                Name = "Exporter Version", Parent = utf.Root
            };

            expv.Data = System.Text.Encoding.UTF8.GetBytes(EXPORTER_VERSION);
            utf.Root.Children.Add(expv);
            //Actual stuff
            if (output.Count == 1)
            {
                if (output[0].Children.Count == 0)
                {
                    Export3DB(utf.Root, output[0]);
                }
                else
                {
                    return(false); //TODO: CMP
                }
                result = utf;
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#6
0
        LUtfNode CmpndNode(LUtfNode cmpnd, string name, string filename, string objname, int index)
        {
            var node = new LUtfNode()
            {
                Parent = cmpnd, Name = name, Children = new List <LUtfNode>()
            };

            node.Children.Add(new LUtfNode()
            {
                Name   = "File Name",
                Parent = node,
                Data   = Encoding.ASCII.GetBytes(filename)
            });
            node.Children.Add(new LUtfNode()
            {
                Name   = "Object Name",
                Parent = node,
                Data   = Encoding.ASCII.GetBytes(objname)
            });
            node.Children.Add(new LUtfNode()
            {
                Name   = "Index",
                Parent = node,
                Data   = BitConverter.GetBytes(index)
            });
            return(node);
        }
示例#7
0
        public static void FloatEditor(string title, ref float[] floats, LUtfNode selectedNode)
        {
            if (ImGui.BeginPopupModal(title))
            {
                bool remove = false;
                bool add    = false;
                ImGui.Text(string.Format("Count: {0} ({1} bytes)", floats.Length, floats.Length * 4));
                ImGui.SameLine();
                add = ImGui.Button("+");
                ImGui.SameLine();
                remove = ImGui.Button("-");
                ImGui.Separator();
                //Magic number 94px seems to fix the scrollbar thingy
                var h = ImGui.GetWindowHeight();
                ImGui.BeginChild("##scroll", new Vector2(0, h - 94), false, 0);
                ImGui.Columns(4, "##columns", true);
                for (int i = 0; i < floats.Length; i++)
                {
                    ImGui.InputFloat("##" + i, ref floats[i], 0, 0);
                    ImGui.NextColumn();
                    if (i % 4 == 0 && i != 0)
                    {
                        ImGui.Separator();
                    }
                }
                ImGui.EndChild();
                if (ImGui.Button("Ok"))
                {
                    var bytes = new byte[floats.Length * 4];
                    fixed(byte *ptr = bytes)
                    {
                        var f = (float *)ptr;

                        for (int i = 0; i < floats.Length; i++)
                        {
                            f[i] = floats[i];
                        }
                    }

                    selectedNode.Data = bytes;
                    floats            = null;
                    ImGui.CloseCurrentPopup();
                }
                ImGui.SameLine();
                if (ImGui.Button("Cancel"))
                {
                    floats = null; ImGui.CloseCurrentPopup();
                }
                ImGui.EndPopup();
                if (add)
                {
                    Array.Resize(ref floats, floats.Length + 1);
                }
                if (remove && floats.Length > 1)
                {
                    Array.Resize(ref floats, floats.Length - 1);
                }
            }
        }
示例#8
0
 void ExportModels(string mdlName, LUtfNode root, string suffix,LUtfNode vms, OutModel model)
 {
     var modelNode = new LUtfNode() { Parent = root, Name = model.Name + suffix };
     modelNode.Children = new List<LUtfNode>();
     root.Children.Add(modelNode);
     Export3DB(mdlName, modelNode, model, vms);
     foreach (var child in model.Children)
         ExportModels(mdlName, root, suffix, vms, child);
 }
示例#9
0
 static void Export3DB(string mdlName, LUtfNode node3db, OutModel mdl, LUtfNode vmeshlibrary = null)
 {
     var vms = vmeshlibrary ?? new LUtfNode() { Name = "VMeshLibrary", Parent = node3db, Children = new List<LUtfNode>() };
     for (int i = 0; i < mdl.LODs.Count; i++)
     {
         var n = new LUtfNode() { Name = string.Format("{0}-{1}.lod{2}.{3}.vms", mdlName, mdl.Name, i, (int)mdl.LODs[i].Geometry.FVF), Parent = vms };
         n.Children = new List<LUtfNode>();
         n.Children.Add(new LUtfNode() { Name = "VMeshData", Parent = n, Data = mdl.LODs[i].Geometry.VMeshData() });
         vms.Children.Add(n);
     }
     if(vmeshlibrary == null)
         node3db.Children.Add(vms);
     if (mdl.LODs.Count > 1)
     {
         var multilevel = new LUtfNode() { Name = "MultiLevel", Parent = node3db };
         multilevel.Children = new List<LUtfNode>();
         var switch2 = new LUtfNode() { Name = "Switch2", Parent = multilevel };
         multilevel.Children.Add(switch2);
         for (int i = 0; i < mdl.LODs.Count; i++)
         {
             var n = new LUtfNode() { Name = "Level" + i, Parent = multilevel };
             n.Children = new List<LUtfNode>();
             n.Children.Add(new LUtfNode() { Name = "VMeshPart", Parent = n, Children = new List<LUtfNode>() });
             n.Children[0].Children.Add(new LUtfNode()
             {
                 Name = "VMeshRef",
                 Parent = n.Children[0],
                 Data = mdl.LODs[i].Geometry.VMeshRef(string.Format("{0}-{1}.lod{2}.{3}.vms", mdlName, mdl.Name, i, (int)mdl.LODs[i].Geometry.FVF))
             });
             multilevel.Children.Add(n);
         }
         //Generate Switch2: TODO - Be more intelligent about this
         var mlfloats = new float[multilevel.Children.Count];
         mlfloats[0] = 0;
         float cutOff = 2250;
         for (int i = 1; i < mlfloats.Length - 1; i++)
         {
             mlfloats[i] = cutOff;
             cutOff *= 2;
         }
         mlfloats[mlfloats.Length - 1] = 1000000;
         switch2.Data = UnsafeHelpers.CastArray(mlfloats);
         node3db.Children.Add(multilevel);
     }
     else
     {
         var part = new LUtfNode() { Name = "VMeshPart", Parent = node3db };
         part.Children = new List<LUtfNode>();
         part.Children.Add(new LUtfNode()
         {
             Name = "VMeshRef",
             Parent = part,
             Data = mdl.LODs[0].Geometry.VMeshRef(string.Format("{0}-{1}.lod0.{2}.vms", mdlName, mdl.Name, (int)mdl.LODs[0].Geometry.FVF))
         });
         node3db.Children.Add(part);
     }
 }
示例#10
0
 static LUtfNode DefaultTextureNode(LUtfNode parent, string name)
 {
     var texnode = new LUtfNode() { Name = name + ".dds", Parent = parent };
     texnode.Children = new List<LUtfNode>();
     var d = new byte[DefaultTexture.Data.Length];
     Buffer.BlockCopy(DefaultTexture.Data, 0, d, 0, DefaultTexture.Data.Length);
     texnode.Children.Add(new LUtfNode() { Name = "MIPS", Parent = texnode, Data = d });
     return texnode;
 }
 public static JointMapView Create(LUtfNode node)
 {
     try
     {
         return(new JointMapView(node));
     }
     catch (Exception)
     {
         return(null);
     }
 }
示例#12
0
        void DoNode(LUtfNode node, LUtfNode parent, int idx)
        {
            string id = ImGuiExt.IDWithExtra(node.Name, parent.Name + idx);

            if (node.Children != null)
            {
                var flags  = selectedNode == node ? ImGuiTreeNodeFlags.Selected | tflags : tflags;
                var isOpen = ImGui.TreeNodeEx(id, flags);
                if (ImGui.IsItemClicked(0))
                {
                    selectedNode = node;
                }
                if (node.ResolvedName != null)
                {
                    ImGui.SameLine();
                    ImGui.TextDisabled("(" + ImGuiExt.IDSafe(node.ResolvedName) + ")");
                }
                ImGui.PushID(id);
                DoNodeMenu(id, node, parent);
                ImGui.PopID();
                //int i = 0;
                if (isOpen)
                {
                    for (int i = 0; i < node.Children.Count; i++)
                    {
                        DoNode(node.Children[i], node, (idx * 1024) + i);
                    }
                    ImGui.TreePop();
                }
            }
            else
            {
                if (node.Data != null)
                {
                    ImGui.Bullet();
                }
                else
                {
                    ImGui.Text($"  {Icons.BulletEmpty}");
                    ImGui.SameLine();
                }
                bool selected = selectedNode == node;
                if (ImGui.Selectable(id, ref selected))
                {
                    selectedNode = node;
                }
                if (node.ResolvedName != null)
                {
                    ImGui.SameLine();
                    ImGui.TextDisabled("(" + ImGuiExt.IDSafe(node.ResolvedName) + ")");
                }
                DoNodeMenu(id, node, parent);
            }
        }
示例#13
0
        void ProcessConstruct(string parentName, OutModel mdl, LUtfNode cmpnd, FixConstructor fix, string suffix, ref int index)
        {
            cmpnd.Children.Add(CmpndNode(cmpnd, "PART_" + mdl.Name, mdl.Name + suffix, mdl.Name, index++));
            if(mdl.Transform == true) {
                fix.Add(parentName, mdl.Name, mdl.Def.Transform);
            } else {
                fix.Add(parentName, mdl.Name, Matrix4x4.Identity);
            }
            foreach (var child in mdl.Children)
                ProcessConstruct(mdl.Name, child, cmpnd, fix, suffix, ref index);

        }
        void WriteNode(LUtfNode node, BinaryWriter writer, Dictionary <string, int> strOff, Dictionary <LUtfNode, int> datOff, bool last)
        {
            if (node.Data != null)
            {
                if (last)
                {
                    writer.Write((int)0);                     //no siblings
                }
                else
                {
                    writer.Write((int)(writer.BaseStream.Position + sizeof(int) * 11)); //peerOffset
                }
                writer.Write(strOff[node.Name]);                                        //nameOffset
                writer.Write((int)LL.NodeFlags.Leaf);                                   //leafNode
                writer.Write((int)0);                                                   //padding
                writer.Write(datOff[node]);                                             //dataOffset
                int dataAlloc = node.Data.Length + 3 & ~3;
                writer.Write(dataAlloc);                                                //allocatedSize (?)
                writer.Write(node.Data.Length);                                         //usedSize
                writer.Write(node.Data.Length);                                         //uncompressedSize

                writer.Write(-2037297339);
                writer.Write(-2037297339);
                writer.Write(-2037297339);
                return;
            }

            long startPos = writer.BaseStream.Position;

            writer.Write((int)0);                                 //peerOffset
            writer.Write(strOff[node.Name]);
            writer.Write((int)LL.NodeFlags.Intermediate);         //intermediateNode
            writer.Write((int)0);                                 //padding
            writer.Write((int)(writer.BaseStream.Position + 28)); //children start immediately after node
            writer.Write((int)0);                                 //allocatedSize
            writer.Write((int)0);                                 //usedSize
            writer.Write((int)0);                                 //uncompressedSize
            writer.Write(-2037297339);
            writer.Write(-2037297339);
            writer.Write(-2037297339);
            //There should be 3 more DWORDS here but we can safely not write them for FL
            for (int i = 0; i < node.Children.Count; i++)
            {
                WriteNode(node.Children[i], writer, strOff, datOff, i == (node.Children.Count - 1));
            }
            if (!last)             //if there's siblings
            {
                var endPos = writer.BaseStream.Position;
                writer.BaseStream.Seek(startPos, SeekOrigin.Begin);
                writer.Write((int)endPos);
                writer.BaseStream.Seek(endPos, SeekOrigin.Begin);
            }
        }
        static LL.Node ExportNode(LUtfNode n)
        {
            if (n.Data != null)
            {
                return(new LL.LeafNode(n.Name, n.Data));
            }
            var children = new List <LL.Node>();

            foreach (var child in n.Children)
            {
                children.Add(ExportNode(child));
            }
            return(new LL.IntermediateNode(n.Name, children));
        }
        string GetUtfPath(LUtfNode n)
        {
            List <string> strings = new List <string>();
            LUtfNode      node    = n;

            while (node.Name != "/" && node.Name != "\\")
            {
                strings.Add(node.Name);
                node = node.Parent;
            }
            strings.Reverse();
            var path = "/" + string.Join("/", strings);

            return(path);
        }
        public static List <LUtfNode> TGAMipmaps(string input, MipmapMethod mipm, bool flip)
        {
            var raw   = ReadFile(input, flip);
            var mips  = Crunch.GenerateMipmaps(raw.Data, raw.Width, raw.Height, (CrnglueMipmaps)mipm);
            var nodes = new List <LUtfNode>(mips.Count);

            for (int i = 0; i < mips.Count; i++)
            {
                var n = new LUtfNode {
                    Name = "MIP" + i, Data = TargaRGBA(mips[i].Bytes, mips[i].Width, mips[i].Height)
                };
                nodes.Add(n);
            }
            return(nodes);
        }
示例#18
0
 bool HasChild(LUtfNode node, string name)
 {
     if (node.Children == null)
     {
         return(false);
     }
     foreach (var child in node.Children)
     {
         if (child.Name == name)
         {
             return(true);
         }
     }
     return(false);
 }
示例#19
0
        public LUtfNode MakeCopy()
        {
            var copy = new LUtfNode();

            copy.Name = Name;
            copy.Data = Data;
            if (Children != null)
            {
                copy.Children = new List <LUtfNode>(Children.Count);
                foreach (var child in Children)
                {
                    copy.Children.Add(child.MakeCopy());
                }
            }
            return(copy);
        }
示例#20
0
        void WriteNode(LUtfNode node, BinaryWriter writer, Dictionary <string, int> strOff, Dictionary <LUtfNode, int> datOff, int nodeblockoffset, bool last)
        {
            if (node.Data != null)
            {
                if (last)
                {
                    writer.Write((int)0);                     //no siblings
                }
                else
                {
                    writer.Write((int)(writer.BaseStream.Position - nodeblockoffset + sizeof(int) * 11)); //peerOffset
                }
                writer.Write(strOff[node.Name]);                                                          //nameOffset
                writer.Write((int)LL.NodeFlags.Leaf);                                                     //leafNode

                writer.Write((int)0);                                                                     //zero
                writer.Write(datOff[node]);                                                               //dataOffset
                writer.Write((int)0);                                                                     //allocatedSize (?)
                writer.Write(node.Data.Length);
                writer.Write(node.Data.Length);

                writer.Write((int)0);                 //padding/timestamp?
                writer.Write((int)0);
                writer.Write((int)0);
                return;
            }

            long startPos = writer.BaseStream.Position;

            writer.Write((int)0);                                                  //peerOffset
            writer.Write(strOff[node.Name]);
            writer.Write((int)LL.NodeFlags.Intermediate);                          //intermediateNode
            writer.Write((int)0);                                                  //padding
            writer.Write((int)(writer.BaseStream.Position - nodeblockoffset + 4)); //children start immediately after node
            for (int i = 0; i < node.Children.Count; i++)
            {
                WriteNode(node.Children[i], writer, strOff, datOff, nodeblockoffset, i == (node.Children.Count - 1));
            }
            if (!last)             //if there's siblings
            {
                var endPos = writer.BaseStream.Position;
                writer.BaseStream.Seek(startPos, SeekOrigin.Begin);
                writer.Write((int)endPos - nodeblockoffset);
                writer.BaseStream.Seek(endPos, SeekOrigin.Begin);
            }
        }
示例#21
0
        void DoNode(LUtfNode node, LUtfNode parent, int idx)
        {
            string id = node.Name + "##" + parent.Name + idx;

            if (node.Children != null)
            {
                var flags  = selectedNode == node ? TreeNodeFlags.Selected | tflags : tflags;
                var isOpen = ImGui.TreeNodeEx(id, flags);
                if (ImGuiNative.igIsItemClicked(0))
                {
                    selectedNode = node;
                    SelectedChanged();
                }
                ImGui.PushID(id);
                DoNodeMenu(id, node, parent);
                ImGui.PopID();
                //int i = 0;
                if (isOpen)
                {
                    for (int i = 0; i < node.Children.Count; i++)
                    {
                        DoNode(node.Children[i], node, (idx * 1024) + i);
                    }
                    ImGui.TreePop();
                }
            }
            else
            {
                if (node.Data != null)
                {
                    ImGui.Bullet();
                }
                else
                {
                    ImGui.Image((IntPtr)ImGuiHelper.CircleId, new Vector2(15, 19), Vector2.Zero, Vector2.One, Vector4.One, Vector4.Zero);
                    ImGui.SameLine();
                }
                bool selected = selectedNode == node;
                if (ImGui.SelectableEx(id, ref selected))
                {
                    selectedNode = node;
                    SelectedChanged();
                }
                DoNodeMenu(id, node, parent);
            }
        }
示例#22
0
        void AddPopup(PopupData data)
        {
            ImGui.Text("Name: ");
            ImGui.SameLine();
            bool entered = ImGui.InputText("", text.Pointer, (uint)text.Size, InputTextFlags.EnterReturnsTrue, text.Callback);

            if (data.DoFocus)
            {
                ImGui.SetKeyboardFocusHere();
            }
            if (entered || ImGui.Button("Ok"))
            {
                var node = new LUtfNode()
                {
                    Name = text.GetText().Trim(), Parent = addParent ?? addNode
                };
                if (node.Name.Length == 0)
                {
                    ErrorPopup("Node name cannot be empty");
                }
                else
                {
                    if (addParent != null)
                    {
                        addParent.Children.Insert(addParent.Children.IndexOf(addNode) + addOffset, node);
                    }
                    else
                    {
                        addNode.Data = null;
                        if (addNode.Children == null)
                        {
                            addNode.Children = new List <LUtfNode>();
                        }
                        addNode.Children.Add(node);
                    }
                    selectedNode = node;
                }
                ImGui.CloseCurrentPopup();
            }
            ImGui.SameLine();
            if (ImGui.Button("Cancel"))
            {
                ImGui.CloseCurrentPopup();
            }
        }
示例#23
0
        void DoNode(LUtfNode node, LUtfNode parent, int idx)
        {
            string id = node.Name + "##" + parent.Name + idx;

            if (node.Children != null)
            {
                var flags  = selectedNode == node ? ImGuiTreeNodeFlags.Selected | tflags : tflags;
                var isOpen = ImGui.TreeNodeEx(id, flags);
                if (ImGui.IsItemClicked(0))
                {
                    selectedNode = node;
                }
                ImGui.PushID(id);
                DoNodeMenu(id, node, parent);
                ImGui.PopID();
                //int i = 0;
                if (isOpen)
                {
                    for (int i = 0; i < node.Children.Count; i++)
                    {
                        DoNode(node.Children[i], node, (idx * 1024) + i);
                    }
                    ImGui.TreePop();
                }
            }
            else
            {
                if (node.Data != null)
                {
                    ImGui.Bullet();
                }
                else
                {
                    Theme.Icon("node_empty", Color4.White);
                    ImGui.SameLine();
                }
                bool selected = selectedNode == node;
                if (ImGui.Selectable(id, ref selected))
                {
                    selectedNode = node;
                }
                DoNodeMenu(id, node, parent);
            }
        }
示例#24
0
        public string GetUtfPath()
        {
            if (selectedNode == null)
            {
                return("None");
            }
            List <string> strings = new List <string>();
            LUtfNode      node    = selectedNode;

            while (node != Utf.Root)
            {
                strings.Add(node.Name);
                node = node.Parent;
            }
            strings.Reverse();
            var path = "/" + string.Join("/", strings);

            return(path);
        }
示例#25
0
        public static unsafe List <LUtfNode> TGAMipmaps(string input, MipmapMethod mipm)
        {
            LoadLibraries();
            var nodes = new List <LUtfNode>();
            var mips  = GenerateMipmapsRGBA(input, mipm);

            for (int i = 0; i < mips.Count; i++)
            {
                using (var stream = new MemoryStream()) {
                    mips[i].SaveToStream(TeximpNet.ImageFormat.TARGA, stream);
                    var n = new LUtfNode()
                    {
                        Name = "MIP" + i, Data = stream.ToArray()
                    };
                    nodes.Add(n);
                    mips[i].Dispose();
                }
            }
            return(nodes);
        }
示例#26
0
        LUtfNode ConvertNode(LL.Node node)
        {
            var n = new LUtfNode();

            n.Name = node.Name;
            if (node is LL.IntermediateNode)
            {
                var im = (LL.IntermediateNode)node;
                n.Children = new List <LUtfNode>();
                foreach (var child in im)
                {
                    n.Children.Add(ConvertNode(child));
                }
            }
            else
            {
                var lf = (LL.LeafNode)node;
                n.Data = lf.ByteArrayData;
            }
            return(n);
        }
示例#27
0
 void DoNodeMenu(string id, LUtfNode node, LUtfNode parent)
 {
     if (ImGui.BeginPopupContextItem(id))
     {
         ImGui.MenuItem(node.Name, false);
         ImGui.Separator();
         if (ImGui.MenuItem("Rename", node != Utf.Root))
         {
             text.SetText(node.Name);
             renameNode = node;
             doRename   = true;
         }
         if (ImGui.MenuItem("Delete", node != Utf.Root))
         {
             deleteParent = parent;
             deleteNode   = node;
             doDelete     = true;
         }
         ImGui.EndPopup();
     }
 }
示例#28
0
        void DoNode(LUtfNode node, LUtfNode parent, int idx)
        {
            string id = node.Name + "##" + idx;

            if (node.Children != null)
            {
                var flags  = selectedNode == node ? TreeNodeFlags.Selected | tflags : tflags;
                var isOpen = ImGui.TreeNodeEx(id, flags);
                if (ImGuiNative.igIsItemClicked(0))
                {
                    selectedNode = node;
                }
                ImGui.PushID(id);
                DoNodeMenu(id, node, parent);
                ImGui.PopID();
                int i = 0;
                if (isOpen)
                {
                    foreach (var c in node.Children)
                    {
                        DoNode(c, node, i++);
                    }
                    ImGui.TreePop();
                }
            }
            else
            {
                ImGui.Bullet();
                bool selected = selectedNode == node;
                if (ImGui.SelectableEx(id, ref selected))
                {
                    selectedNode = node;
                }
                DoNodeMenu(id, node, parent);
            }
        }
示例#29
0
 void DoNodeMenu(string id, LUtfNode node, LUtfNode parent)
 {
     if (ImGui.BeginPopupContextItem(id))
     {
         ImGui.MenuItem(node.Name, false);
         ImGui.MenuItem(string.Format("CRC: 0x{0:X}", CrcTool.FLModelCrc(node.Name)), false);
         ImGui.Separator();
         if (Theme.IconMenuItem(Icons.Edit, "Rename", node != Utf.Root))
         {
             text.SetText(node.Name);
             renameNode = node;
             popups.OpenPopup("Rename Node");
         }
         if (Theme.IconMenuItem(Icons.TrashAlt, "Delete", node != Utf.Root))
         {
             deleteParent = parent;
             deleteNode   = node;
             Confirm("Are you sure you want to delete: '" + node.Name + "'?", () =>
             {
                 if (selectedNode == deleteNode)
                 {
                     selectedNode = null;
                 }
                 deleteParent.Children.Remove(deleteNode);
             });
         }
         if (Theme.IconMenuItem(Icons.Eraser, "Clear", node.Children != null || node.Data != null))
         {
             clearNode = node;
             Confirm("Clearing this node will delete all data and children. Continue?", () =>
             {
                 clearNode.Data = null;
                 if (clearNode == Utf.Root)
                 {
                     clearNode.Children = new List <LUtfNode>();
                 }
                 else
                 {
                     clearNode.Children = null;
                 }
             });
         }
         ImGui.Separator();
         if (Theme.BeginIconMenu(Icons.PlusCircle, "Add"))
         {
             if (ImGui.MenuItem("Child"))
             {
                 text.SetText("");
                 addParent = null;
                 addNode   = node;
                 if (node.Data != null)
                 {
                     Confirm("Adding a node will clear data. Continue?", () =>
                     {
                         popups.OpenPopup("New Node");
                     });
                 }
                 else
                 {
                     popups.OpenPopup("New Node");
                 }
             }
             if (ImGui.MenuItem("Before", node != Utf.Root))
             {
                 text.SetText("");
                 addParent = parent;
                 addNode   = node;
                 addOffset = 0;
                 popups.OpenPopup("New Node");
             }
             if (ImGui.MenuItem("After", node != Utf.Root))
             {
                 text.SetText("");
                 addParent = parent;
                 addNode   = node;
                 addOffset = 1;
                 popups.OpenPopup("New Node");
             }
             ImGui.EndMenu();
         }
         ImGui.Separator();
         if (Theme.IconMenuItem(Icons.Cut, "Cut", node != Utf.Root))
         {
             parent.Children.Remove(node);
             main.ClipboardCopy = false;
             main.Clipboard     = node;
         }
         if (Theme.IconMenuItem(Icons.Copy, "Copy", node != Utf.Root))
         {
             main.ClipboardCopy = true;
             main.Clipboard     = node.MakeCopy();
         }
         if (main.Clipboard != null)
         {
             if (Theme.BeginIconMenu(Icons.Paste, "Paste"))
             {
                 if (ImGui.MenuItem("Before", node != Utf.Root))
                 {
                     if (main.ClipboardCopy)
                     {
                         var cpy = main.Clipboard.MakeCopy();
                         cpy.Parent = parent;
                         parent.Children.Insert(parent.Children.IndexOf(node), cpy);
                     }
                     else
                     {
                         main.Clipboard.Parent = parent;
                         parent.Children.Insert(parent.Children.IndexOf(node), main.Clipboard);
                         main.Clipboard = null;
                     }
                 }
                 if (ImGui.MenuItem("After", node != Utf.Root))
                 {
                     if (main.ClipboardCopy)
                     {
                         var cpy = main.Clipboard.MakeCopy();
                         cpy.Parent = parent;
                         parent.Children.Insert(parent.Children.IndexOf(node) + 1, cpy);
                     }
                     else
                     {
                         main.Clipboard.Parent = parent;
                         parent.Children.Insert(parent.Children.IndexOf(node) + 1, main.Clipboard);
                         main.Clipboard = null;
                     }
                 }
                 if (ImGui.MenuItem("Into"))
                 {
                     if (node.Data == null)
                     {
                         if (node.Children == null)
                         {
                             node.Children = new List <LUtfNode>();
                         }
                         if (main.ClipboardCopy)
                         {
                             var cpy = main.Clipboard.MakeCopy();
                             cpy.Parent = node;
                             node.Children.Add(cpy);
                         }
                         else
                         {
                             main.Clipboard.Parent = node;
                             node.Children.Add(main.Clipboard);
                             main.Clipboard = null;
                         }
                     }
                     else
                     {
                         pasteInto = node;
                         Confirm("Adding children will delete this node's data. Continue?", () =>
                         {
                             pasteInto.Data     = null;
                             pasteInto.Children = new List <LUtfNode>();
                             if (main.ClipboardCopy)
                             {
                                 var cpy    = main.Clipboard.MakeCopy();
                                 cpy.Parent = pasteInto;
                                 pasteInto.Children.Add(cpy);
                             }
                             else
                             {
                                 main.Clipboard.Parent = pasteInto;
                                 pasteInto.Children.Add(main.Clipboard);
                                 main.Clipboard = null;
                             }
                         });
                     }
                 }
                 ImGui.EndMenu();
             }
         }
         else
         {
             Theme.IconMenuItem(Icons.Paste, "Paste", false);
         }
         ImGui.EndPopup();
     }
 }
示例#30
0
        public override void Draw()
        {
            //Child Window
            var size = ImGui.GetWindowSize();

            ImGui.BeginChild("##utfchild", new Vector2(size.X - 15, size.Y - 50), false, 0);
            //Layout
            if (selectedNode != null)
            {
                ImGui.Columns(2, "NodeColumns", true);
            }
            //Headers
            ImGui.Separator();
            ImGui.Text("Nodes");
            if (selectedNode != null)
            {
                ImGui.NextColumn();
                ImGui.Text("Node Information");
                ImGui.NextColumn();
            }
            ImGui.Separator();
            //Tree
            ImGui.BeginChild("##scroll");
            var flags  = selectedNode == Utf.Root ? ImGuiTreeNodeFlags.Selected | tflags : tflags;
            var isOpen = ImGui.TreeNodeEx("/", flags);

            if (ImGui.IsItemClicked(0))
            {
                selectedNode = Utf.Root;
            }
            ImGui.PushID("/##ROOT");
            DoNodeMenu("/##ROOT", Utf.Root, null);
            ImGui.PopID();
            if (isOpen)
            {
                for (int i = 0; i < Utf.Root.Children.Count; i++)
                {
                    DoNode(Utf.Root.Children[i], Utf.Root, i);
                }
                ImGui.TreePop();
            }
            ImGui.EndChild();
            //End Tree
            if (selectedNode != null)
            {
                //Node preview
                ImGui.NextColumn();
                NodeInformation();
            }
            //Action Bar
            ImGui.EndChild();
            ImGui.Separator();
            if (ImGui.Button("Actions"))
            {
                ImGui.OpenPopup("actions");
            }
            if (ImGui.BeginPopup("actions"))
            {
                if (ImGui.MenuItem("View Model"))
                {
                    IDrawable  drawable = null;
                    ModelNodes hpn      = new ModelNodes();
                    try
                    {
                        drawable = LibreLancer.Utf.UtfLoader.GetDrawable(Utf.Export(), main.Resources);
                        drawable.Initialize(main.Resources);
                        if (Utf.Root.Children.Any((x) => x.Name.Equals("cmpnd", StringComparison.OrdinalIgnoreCase)))
                        {
                            foreach (var child in Utf.Root.Children.Where((x) => x.Name.EndsWith(".3db", StringComparison.OrdinalIgnoreCase)))
                            {
                                var n = new ModelHpNode();
                                n.Name           = child.Name;
                                n.Node           = child;
                                n.HardpointsNode = child.Children.FirstOrDefault((x) => x.Name.Equals("hardpoints", StringComparison.OrdinalIgnoreCase));
                                hpn.Nodes.Add(n);
                            }
                            var cmpnd = Utf.Root.Children.First((x) => x.Name.Equals("cmpnd", StringComparison.OrdinalIgnoreCase));
                            hpn.Cons = cmpnd.Children.FirstOrDefault((x) => x.Name.Equals("cons", StringComparison.OrdinalIgnoreCase));
                        }
                        else
                        {
                            var n = new ModelHpNode();
                            n.Name           = "ROOT";
                            n.Node           = Utf.Root;
                            n.HardpointsNode = Utf.Root.Children.FirstOrDefault((x) => x.Name.Equals("hardpoints", StringComparison.OrdinalIgnoreCase));
                            hpn.Nodes.Add(n);
                        }
                    }
                    catch (Exception ex) { ErrorPopup("Could not open as model\n" + ex.Message + "\n" + ex.StackTrace); drawable = null; }
                    if (drawable != null)
                    {
                        main.AddTab(new ModelViewer(DocumentName, drawable, main, this, hpn));
                    }
                }
                if (ImGui.MenuItem("Export Collada"))
                {
                    LibreLancer.Utf.Cmp.ModelFile model = null;
                    LibreLancer.Utf.Cmp.CmpFile   cmp   = null;
                    try
                    {
                        var drawable = LibreLancer.Utf.UtfLoader.GetDrawable(Utf.Export(), main.Resources);
                        model = (drawable as LibreLancer.Utf.Cmp.ModelFile);
                        cmp   = (drawable as LibreLancer.Utf.Cmp.CmpFile);
                    }
                    catch (Exception) { ErrorPopup("Could not open as model"); model = null; }
                    if (model != null)
                    {
                        var output = FileDialog.Save();
                        if (output != null)
                        {
                            model.Path = DocumentName;
                            try
                            {
                                ColladaExport.ExportCollada(model, main.Resources, output);
                            }
                            catch (Exception ex)
                            {
                                ErrorPopup("Error\n" + ex.Message + "\n" + ex.StackTrace);
                            }
                        }
                    }
                    if (cmp != null)
                    {
                        var output = FileDialog.Save();
                        if (output != null)
                        {
                            cmp.Path = DocumentName;
                            try
                            {
                                ColladaExport.ExportCollada(cmp, main.Resources, output);
                            }
                            catch (Exception ex)
                            {
                                ErrorPopup("Error\n" + ex.Message + "\n" + ex.StackTrace);
                            }
                        }
                    }
                }
                if (ImGui.MenuItem("View Ale"))
                {
                    AleFile ale = null;
                    try
                    {
                        ale = new AleFile(Utf.Export());
                    }
                    catch (Exception)
                    {
                        ErrorPopup("Could not open as ale");
                        ale = null;
                    }
                    if (ale != null)
                    {
                        main.AddTab(new AleViewer(Title, ale, main));
                    }
                }

                if (ImGui.MenuItem("Resolve Audio Hashes"))
                {
                    var folder = FileDialog.ChooseFolder();
                    if (folder != null)
                    {
                        var idtable = new IDTable(folder);
                        foreach (var n in Utf.Root.IterateAll())
                        {
                            if (n.Name.StartsWith("0x"))
                            {
                                uint v;
                                if (uint.TryParse(n.Name.Substring(2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out v))
                                {
                                    idtable.UtfNicknameTable.TryGetValue(v, out n.ResolvedName);
                                }
                            }
                            else
                            {
                                n.ResolvedName = null;
                            }
                        }
                    }
                }
                ImGui.EndPopup();
            }
            ImGui.SameLine();
            if (ImGui.Button("Reload Resources"))
            {
                main.Resources.RemoveResourcesForId(Unique.ToString());
                main.Resources.AddResources(Utf.Export(), Unique.ToString());
            }
            Popups();
        }